Skip to content

Commit

Permalink
change general offline signer to generic
Browse files Browse the repository at this point in the history
  • Loading branch information
Zetazzz committed Nov 19, 2024
1 parent cb6c9b2 commit f891787
Show file tree
Hide file tree
Showing 18 changed files with 68 additions and 68 deletions.
4 changes: 2 additions & 2 deletions networks/cosmos/src/base/base-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import {
AminoSignResponse,
DirectSignResponse,
ICosmosGeneralOfflineSigner,
ICosmosGenericOfflineSigner,
OfflineAminoSigner,
OfflineDirectSigner,
WalletOptions,
Expand Down Expand Up @@ -145,7 +145,7 @@ implements ICosmosWallet, OfflineAminoSigner, OfflineDirectSigner
* @param signMode sign mode. (direct or amino)
* @returns general offline signer for direct or amino
*/
toGeneralOfflineSigner(signMode: string): ICosmosGeneralOfflineSigner {
toGenericOfflineSigner(signMode: string): ICosmosGenericOfflineSigner {
switch (signMode) {
case SIGN_MODE.DIRECT:
return {
Expand Down
10 changes: 5 additions & 5 deletions networks/cosmos/src/signers/amino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
SignerOptions,
} from '../types';
import { AminoDocAuth } from '../types/docAuth';
import { IAminoGeneralOfflineSigner, isOfflineAminoSigner, OfflineAminoSigner } from '../types/wallet';
import { IAminoGenericOfflineSigner, isOfflineAminoSigner, OfflineAminoSigner } from '../types/wallet';

/**
* AminoDocSigner is a signer for Amino document.
Expand Down Expand Up @@ -125,7 +125,7 @@ export class AminoSigner
* if there're multiple accounts in the wallet, it will return the first one by default.
*/
static async fromWallet(
signer: OfflineAminoSigner | IAminoGeneralOfflineSigner,
signer: OfflineAminoSigner | IAminoGenericOfflineSigner,
encoders: Encoder[],
converters: AminoConverter[],
endpoint?: string | HttpEndpoint,
Expand All @@ -136,7 +136,7 @@ export class AminoSigner
if(isOfflineAminoSigner(signer)){
[auth] = await AminoDocAuth.fromOfflineSigner(signer);
} else {
[auth] = await AminoDocAuth.fromGeneralOfflineSigner(signer);
[auth] = await AminoDocAuth.fromGenericOfflineSigner(signer);
}

return new AminoSigner(auth, encoders, converters, endpoint, options);
Expand All @@ -147,7 +147,7 @@ export class AminoSigner
* if there're multiple accounts in the wallet, it will return all of the signers.
*/
static async fromWalletToSigners(
signer: OfflineAminoSigner | IAminoGeneralOfflineSigner,
signer: OfflineAminoSigner | IAminoGenericOfflineSigner,
encoders: Encoder[],
converters: AminoConverter[],
endpoint?: string | HttpEndpoint,
Expand All @@ -158,7 +158,7 @@ export class AminoSigner
if(isOfflineAminoSigner(signer)) {
auths = await AminoDocAuth.fromOfflineSigner(signer);
} else {
auths = await AminoDocAuth.fromGeneralOfflineSigner(signer);
auths = await AminoDocAuth.fromGenericOfflineSigner(signer);
}

return auths.map((auth) => {
Expand Down
10 changes: 5 additions & 5 deletions networks/cosmos/src/signers/direct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
SignerOptions,
} from '../types';
import { DirectDocAuth } from '../types/docAuth';
import { IDirectGeneralOfflineSigner, isOfflineDirectSigner, OfflineDirectSigner } from '../types/wallet';
import { IDirectGenericOfflineSigner, isOfflineDirectSigner, OfflineDirectSigner } from '../types/wallet';

/**
* DirectDocSigner is a signer for Direct document.
Expand Down Expand Up @@ -72,7 +72,7 @@ export class DirectSigner
* If there're multiple accounts in the wallet, it will return the first one by default.
*/
static async fromWallet(
signer: OfflineDirectSigner | IDirectGeneralOfflineSigner,
signer: OfflineDirectSigner | IDirectGenericOfflineSigner,
encoders: Encoder[],
endpoint?: string | HttpEndpoint,
options?: SignerOptions
Expand All @@ -82,7 +82,7 @@ export class DirectSigner
if(isOfflineDirectSigner(signer)){
[auth] = await DirectDocAuth.fromOfflineSigner(signer);
} else {
[auth] = await DirectDocAuth.fromGeneralOfflineSigner(signer);
[auth] = await DirectDocAuth.fromGenericOfflineSigner(signer);
}

return new DirectSigner(auth, encoders, endpoint, options);
Expand All @@ -93,7 +93,7 @@ export class DirectSigner
* If there're multiple accounts in the wallet, it will return all of the signers.
*/
static async fromWalletToSigners(
signer: OfflineDirectSigner | IDirectGeneralOfflineSigner,
signer: OfflineDirectSigner | IDirectGenericOfflineSigner,
encoders: Encoder[],
endpoint?: string | HttpEndpoint,
options?: SignerOptions
Expand All @@ -103,7 +103,7 @@ export class DirectSigner
if(isOfflineDirectSigner(signer)) {
auths = await DirectDocAuth.fromOfflineSigner(signer);
} else {
auths = await DirectDocAuth.fromGeneralOfflineSigner(signer);
auths = await DirectDocAuth.fromGenericOfflineSigner(signer);
}

return auths.map((auth) => {
Expand Down
16 changes: 8 additions & 8 deletions networks/cosmos/src/signing-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
QueryClient,
} from './types';
import {
IAminoGeneralOfflineSigner,
ICosmosGeneralOfflineSigner,
IDirectGeneralOfflineSigner,
IAminoGenericOfflineSigner,
ICosmosGenericOfflineSigner,
IDirectGenericOfflineSigner,
isOfflineAminoSigner,
isOfflineDirectSigner,
OfflineSigner,
Expand Down Expand Up @@ -39,7 +39,7 @@ import {
*/
export class SigningClient {
readonly client: QueryClient | null | undefined;
readonly offlineSigner: ICosmosGeneralOfflineSigner;
readonly offlineSigner: ICosmosGenericOfflineSigner;
readonly options: SignerOptions;

readonly signers: Record<string, DirectSigner | AminoSigner> = {};
Expand All @@ -53,7 +53,7 @@ export class SigningClient {

constructor(
client: QueryClient | null | undefined,
offlineSigner: ICosmosGeneralOfflineSigner,
offlineSigner: ICosmosGenericOfflineSigner,
options: SignerOptions = {}
) {
this.client = client;
Expand All @@ -74,7 +74,7 @@ export class SigningClient {

static async connectWithSigner(
endpoint: string | HttpEndpoint,
signer: ICosmosGeneralOfflineSigner,
signer: ICosmosGenericOfflineSigner,
options: SignerOptions = {}
): Promise<SigningClient> {
const signingClient = new SigningClient(
Expand All @@ -94,7 +94,7 @@ export class SigningClient {
switch (this.offlineSigner.signMode) {
case SIGN_MODE.DIRECT:
signers = await DirectSigner.fromWalletToSigners(
this.offlineSigner as IDirectGeneralOfflineSigner,
this.offlineSigner as IDirectGenericOfflineSigner,
this.encoders,
this.endpoint,
{
Expand All @@ -105,7 +105,7 @@ export class SigningClient {

case SIGN_MODE.AMINO:
signers = await AminoSigner.fromWalletToSigners(
this.offlineSigner as IAminoGeneralOfflineSigner,
this.offlineSigner as IAminoGenericOfflineSigner,
this.encoders,
this.converters,
this.endpoint,
Expand Down
10 changes: 5 additions & 5 deletions networks/cosmos/src/types/docAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import {
} from '@interchainjs/types';
import { Key } from '@interchainjs/utils';

import { AminoSignResponse, DirectSignResponse, IAminoGeneralOfflineSigner, IDirectGeneralOfflineSigner, isOfflineAminoSigner, isOfflineDirectSigner, OfflineAminoSigner, OfflineDirectSigner } from './wallet';
import { AminoSignResponse, DirectSignResponse, IAminoGenericOfflineSigner, IDirectGenericOfflineSigner, isOfflineAminoSigner, isOfflineDirectSigner, OfflineAminoSigner, OfflineDirectSigner } from './wallet';
import { CosmosAminoDoc, CosmosDirectDoc } from './signer';

/**
* a helper class to sign the StdSignDoc with Amino encoding using offline signer.
*/
export class AminoDocAuth extends BaseDocAuth<OfflineAminoSigner | IAminoGeneralOfflineSigner, StdSignDoc> {
export class AminoDocAuth extends BaseDocAuth<OfflineAminoSigner | IAminoGenericOfflineSigner, StdSignDoc> {
getPublicKey(): IKey {
return Key.from(this.pubkey);
}
Expand Down Expand Up @@ -49,7 +49,7 @@ export class AminoDocAuth extends BaseDocAuth<OfflineAminoSigner | IAminoGeneral
});
}

static async fromGeneralOfflineSigner(offlineSigner: IAminoGeneralOfflineSigner) {
static async fromGenericOfflineSigner(offlineSigner: IAminoGenericOfflineSigner) {
if(offlineSigner.signMode !== SIGN_MODE.AMINO) {
throw new Error('not an amino general offline signer');
}
Expand All @@ -75,7 +75,7 @@ export class AminoDocAuth extends BaseDocAuth<OfflineAminoSigner | IAminoGeneral
/**
* a helper class to sign the SignDoc with Direct encoding using offline signer.
*/
export class DirectDocAuth extends BaseDocAuth<OfflineDirectSigner | IDirectGeneralOfflineSigner, SignDoc> {
export class DirectDocAuth extends BaseDocAuth<OfflineDirectSigner | IDirectGenericOfflineSigner, SignDoc> {
getPublicKey(): IKey {
return Key.from(this.pubkey);
}
Expand Down Expand Up @@ -112,7 +112,7 @@ export class DirectDocAuth extends BaseDocAuth<OfflineDirectSigner | IDirectGene
});
}

static async fromGeneralOfflineSigner(offlineSigner: IDirectGeneralOfflineSigner) {
static async fromGenericOfflineSigner(offlineSigner: IDirectGenericOfflineSigner) {
if(offlineSigner.signMode !== SIGN_MODE.DIRECT) {
throw new Error('not a direct general offline signer');
}
Expand Down
2 changes: 1 addition & 1 deletion networks/cosmos/src/types/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
CreateDocResponse,
HttpEndpoint,
IAccount,
IGeneralOfflineSigner,
IGenericOfflineSigner,
IKey,
Price,
SignerConfig,
Expand Down
14 changes: 7 additions & 7 deletions networks/cosmos/src/types/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AccountData, IGeneralOfflineSignArgs, IGeneralOfflineSigner, SIGN_MODE, SignerConfig } from '@interchainjs/types';
import { AccountData, IGeneralOfflineSignArgs, IGenericOfflineSigner, SIGN_MODE, SignerConfig } from '@interchainjs/types';

import { CosmosAminoDoc, CosmosDirectDoc } from './signer';

Expand Down Expand Up @@ -26,7 +26,7 @@ export interface StdSignature {
/**
* general offline signer for cosmos chains
*/
export type ICosmosGeneralOfflineSigner = IAminoGeneralOfflineSigner | IDirectGeneralOfflineSigner;
export type ICosmosGenericOfflineSigner = IAminoGenericOfflineSigner | IDirectGenericOfflineSigner;

/**
* Offline signer response
Expand Down Expand Up @@ -87,19 +87,19 @@ export function isOfflineDirectSigner(
/**
* Offline signer can be either amino or direct signer or both
*/
export type OfflineSigner = OfflineAminoSigner | OfflineDirectSigner | ICosmosGeneralOfflineSigner;
export type OfflineSigner = OfflineAminoSigner | OfflineDirectSigner | ICosmosGenericOfflineSigner;

/**
* Amino general offline signer.
*/
export interface IAminoGeneralOfflineSigner extends IGeneralOfflineSigner<string, CosmosAminoDoc, AminoSignResponse> {
export interface IAminoGenericOfflineSigner extends IGenericOfflineSigner<string, CosmosAminoDoc, AminoSignResponse> {

}

/**
* Direct general offline signer.
*/
export interface IDirectGeneralOfflineSigner extends IGeneralOfflineSigner<string, CosmosDirectDoc, DirectSignResponse> {
export interface IDirectGenericOfflineSigner extends IGenericOfflineSigner<string, CosmosDirectDoc, DirectSignResponse> {

}

Expand All @@ -110,7 +110,7 @@ export type IDirectGeneralOfflineSignArgs = IGeneralOfflineSignArgs<string, Cosm
* Amino general offline signer.
* This is a wrapper for offline amino signer.
*/
export class AminoGeneralOfflineSigner implements IAminoGeneralOfflineSigner {
export class AminoGenericOfflineSigner implements IAminoGenericOfflineSigner {
constructor(public offlineSigner: OfflineAminoSigner) {

}
Expand All @@ -128,7 +128,7 @@ export class AminoGeneralOfflineSigner implements IAminoGeneralOfflineSigner {
* Direct general offline signer.
* This is a wrapper for offline direct signer.
*/
export class DirectGeneralOfflineSigner implements IDirectGeneralOfflineSigner {
export class DirectGenericOfflineSigner implements IDirectGenericOfflineSigner {
constructor(public offlineSigner: OfflineDirectSigner) {

}
Expand Down
2 changes: 1 addition & 1 deletion networks/cosmos/src/wallets/secp256k1hd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import {
AminoSignResponse,
DirectSignResponse,
ICosmosGeneralOfflineSigner,
ICosmosGenericOfflineSigner,
OfflineAminoSigner,
OfflineDirectSigner,
WalletOptions,
Expand Down
6 changes: 3 additions & 3 deletions networks/ethereum/devnet/__tests__/send.icjs.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'ethers';
import { EthereumGeneralOfflineSigner, IEthereumGeneralOfflineSigner } from "@interchainjs/ethereum/types/wallet";
import { EthereumGenericOfflineSigner, IEthereumGenericOfflineSigner } from "@interchainjs/ethereum/types/wallet";
import { Eip712Signer } from "@interchainjs/ethereum/signers/eip712";

const ENDPOINT = 'http://127.0.0.1:8545';
Expand All @@ -9,7 +9,7 @@ describe('ETH Transfer Test', () => {
let wallet0: ethers.Wallet;
let wallet1: ethers.Wallet;

let offlineSigner1: IEthereumGeneralOfflineSigner;
let offlineSigner1: IEthereumGenericOfflineSigner;
let eip712Signer: Eip712Signer;

const privateKey0 = '0x0000000000000000000000000000000000000000000000000000000000000001';
Expand All @@ -24,7 +24,7 @@ describe('ETH Transfer Test', () => {

wallet1 = new ethers.Wallet(privateKey1, provider); // only used to receive token

offlineSigner1 = new EthereumGeneralOfflineSigner(wallet0);
offlineSigner1 = new EthereumGenericOfflineSigner(wallet0);

eip712Signer = await Eip712Signer.fromWallet(offlineSigner1, ENDPOINT);
});
Expand Down
4 changes: 2 additions & 2 deletions networks/ethereum/src/signers/eip712.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IKey, SignDocResponse, SignResponse, BroadcastOptions, Auth, isDocAuth,
import { JsonRpcProvider, Provider, TransactionRequest, TransactionResponse } from "ethers";
import { UniEip712Signer } from "../types";
import { Eip712DocAuth } from "../types/docAuth";
import { IEthereumGeneralOfflineSigner } from "../types/wallet";
import { IEthereumGenericOfflineSigner } from "../types/wallet";

export class Eip712Signer implements UniEip712Signer {
provider: Provider;
Expand All @@ -17,7 +17,7 @@ export class Eip712Signer implements UniEip712Signer {
* if there're multiple accounts in the wallet, it will return the first one by default.
*/
static async fromWallet(
signer: IEthereumGeneralOfflineSigner,
signer: IEthereumGenericOfflineSigner,
endpoint?: string,
) {
const auth = await Eip712DocAuth.fromOfflineSigner(signer);
Expand Down
8 changes: 4 additions & 4 deletions networks/ethereum/src/types/docAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import {
IKey,
SignDocResponse,
} from '@interchainjs/types';
import { IEthereumGeneralOfflineSigner } from './wallet';
import { IEthereumGenericOfflineSigner } from './wallet';
import { TransactionRequest } from 'ethers';

export class Eip712DocAuth extends BaseDocAuth<IEthereumGeneralOfflineSigner, TransactionRequest, unknown, string, string, string> {
export class Eip712DocAuth extends BaseDocAuth<IEthereumGenericOfflineSigner, TransactionRequest, unknown, string, string, string> {

constructor(
offlineSigner: IEthereumGeneralOfflineSigner,
offlineSigner: IEthereumGenericOfflineSigner,
address: string,
) {
super(offlineSigner, address);
}

static async fromOfflineSigner(offlineSigner: IEthereumGeneralOfflineSigner) {
static async fromOfflineSigner(offlineSigner: IEthereumGenericOfflineSigner) {
const [account] = await offlineSigner.getAccounts();

return new Eip712DocAuth(
Expand Down
6 changes: 3 additions & 3 deletions networks/ethereum/src/types/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { IGeneralOfflineSigner, SIGN_MODE } from "@interchainjs/types";
import { IGenericOfflineSigner, SIGN_MODE } from "@interchainjs/types";
import { Transaction, TransactionRequest, Signer as ethersOfflineSigner } from "ethers";

export interface IEthereumGeneralOfflineSigner extends IGeneralOfflineSigner<string, unknown, string, TransactionRequest, string> {
export interface IEthereumGenericOfflineSigner extends IGenericOfflineSigner<string, unknown, string, TransactionRequest, string> {
}

export class EthereumGeneralOfflineSigner implements IEthereumGeneralOfflineSigner {
export class EthereumGenericOfflineSigner implements IEthereumGenericOfflineSigner {
constructor(public offlineSigner: ethersOfflineSigner) {
}

Expand Down
Loading

0 comments on commit f891787

Please sign in to comment.