Skip to content

Commit

Permalink
rm duplicated types
Browse files Browse the repository at this point in the history
  • Loading branch information
lukachi committed May 24, 2024
1 parent 16101e9 commit 20d97c4
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 194 deletions.
34 changes: 0 additions & 34 deletions packages/connector/src/wallet/helpers/gas.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/connector/src/wallet/helpers/index.ts

This file was deleted.

106 changes: 6 additions & 100 deletions packages/connector/src/wallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import type {
DirectSignResponse,
OfflineDirectSigner,
} from '@cosmjs/proto-signing';
import type { StdSignDoc } from '@keplr-wallet/types';
import type { SignDoc } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
import { BigNumber } from 'ethers';

import { getGasPriceForChainName } from './helpers';
import type { SignAminoOptions, StdSignDoc } from './types';

import { defaultSnapOrigin, RARIMO_CHAINS, TARGET_CHAINS } from '@/consts';
import { RPCMethods } from '@/enums';
import { RarimeSnapBase } from '@/instances';
Expand Down Expand Up @@ -98,7 +96,11 @@ export class RarimeWallet
async signAmino(
signerAddress: string,
signDoc: StdSignDoc,
options?: SignAminoOptions,
options?: {
preferNoSetFee?: boolean;
isADR36?: boolean;
enableExtraEntropy?: boolean;
},
): Promise<AminoSignResponse> {
if (this.chainId !== signDoc.chain_id) {
throw new Error('Chain ID does not match signer chain ID');
Expand All @@ -116,34 +118,6 @@ export class RarimeWallet
throw new Error('Chain ID does not match signer chain ID');
}

const chain = this.supportedRarimoChains[this.chainId];

// Override gasPrice
if (!options?.preferNoSetFee) {
const gasPriceFromRegistry = await getGasPriceForChainName(
chain.chainName,
);

const gas: any =
'gasLimit' in signDoc.fee ? signDoc.fee.gasLimit : signDoc.fee.gas;

if (gasPriceFromRegistry) {
const amount = [
{
amount: BigNumber.from(
BigNumber.from(gasPriceFromRegistry)
.mul(BigNumber.from(gas))
.toNumber()
.toFixed(0),
).toString(),

denom: chain.currencies[0].coinDenom,
},
];
signDoc.fee.amount = amount;
}
}

return this.sendSnapRequest(RPCMethods.WalletSignAmino, {
chainId: this.chainId,
signerAddress,
Expand All @@ -154,72 +128,4 @@ export class RarimeWallet
}
}

// export const createWallet = (chainId: string) => {};

export * from './helpers';
export * from './types';

// /**
// * Helps to do signArbitrary of the data provided
// *
// * @param chainId - chainId
// * @param signer - signer
// * @param data - data
// * @returns signature
// */
// export async function signArbitrary(
// chainId: string,
// signer: string,
// data: string,
// signOptions?: { enableExtraEntropy?: boolean },
// ) {
// const { signDoc } = getADR36SignDoc(signer, data);
// const result = await requestSignAmino.bind(this)(chainId, signer, signDoc, {
// isADR36: true,
// preferNoSetFee: true,
// enableExtraEntropy: signOptions?.enableExtraEntropy,
// });
// return result.signature;
// }
//
// /**
// *
// * Gets the getADR36SignDoc of the signer and data
// *
// * @param signer - signer
// * @param data - data
// * @returns SignDoc and isADR36WithString
// */
// function getADR36SignDoc(
// signer: string,
// data: string | Uint8Array,
// ): { signDoc: StdSignDoc; isADR36WithString: boolean } {
// let isADR36WithString = false;
// let b64Data = '';
// if (typeof data === 'string') {
// b64Data = Buffer.from(data).toString('base64');
// isADR36WithString = true;
// } else {
// b64Data = Buffer.from(data).toString('base64');
// }
// const signDoc = {
// chain_id: '',
// account_number: '0',
// sequence: '0',
// fee: {
// gas: '0',
// amount: [],
// },
// msgs: [
// {
// type: 'sign/MsgSignData',
// value: {
// signer,
// b64Data,
// },
// },
// ],
// memo: '',
// };
// return { signDoc, isADR36WithString };
// }
3 changes: 1 addition & 2 deletions packages/connector/src/wallet/types/params.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { StdSignDoc } from '@keplr-wallet/types';
import type { SignDoc } from 'cosmjs-types/cosmos/tx/v1beta1/tx';

import type { StdSignDoc } from './wallet';

import type { ChainInfo } from '@/types';

export type RequestParams<T> = {
Expand Down
39 changes: 1 addition & 38 deletions packages/connector/src/wallet/types/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,4 @@
import type { AminoMsg, Coin } from '@cosmjs/amino';

export type SignAminoOptions = {
preferNoSetFee?: boolean;
isADR36?: boolean;
enableExtraEntropy?: boolean;
};

export type StdFee = {
amount: readonly Coin[];
readonly gas: string;
gasLimit?: string;
/** The granter address that is used for paying with feegrants */
readonly granter?: string;
/** The fee payer address. The payer must have signed the transaction. */
readonly payer?: string;
};

export type StdSignDoc = {
readonly chain_id?: string;
readonly chainId?: string;
readonly account_number: string;
readonly accountNumber?: string;
readonly sequence: string;
readonly fee: StdFee;
readonly msgs: readonly AminoMsg[];
readonly memo: string;
};

export type Pubkey = {
readonly type: string;
readonly value: any;
};

export type StdSignature = {
readonly pub_key: Pubkey;
readonly signature: string;
};
import type { StdSignature } from '@keplr-wallet/types';

export type WalletSignDirectResponse = {
signed: {
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/rarimo/rarime.git"
},
"source": {
"shasum": "NlMQIuppyW6ISF9mxzf921f2Y331KOl6/trxkV92dj8=",
"shasum": "qYWKcCxEVT7xl9bxffZGQo871IgaXVU8GjVPEv4zTw4=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/src/wallet/handlers/WalletGetKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const walletGetKey = async ({

const rarimoChainsManager = await RarimoChainsManager.create();

if (!(await rarimoChainsManager.isChainExist(chainId))) {
if (!rarimoChainsManager.isChainExist(chainId)) {
throw new Error('Invalid chainId');
}

Expand Down
5 changes: 1 addition & 4 deletions packages/snap/src/wallet/handlers/WalletSignAmino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ export const walletSignAmino = async ({

const rarimoChainsManager = await RarimoChainsManager.create();

if (
!params.isADR36 &&
!(await rarimoChainsManager.isChainExist(receivedChainId))
) {
if (!params.isADR36 && !rarimoChainsManager.isChainExist(receivedChainId)) {
throw new Error('Invalid chainId');
}

Expand Down
2 changes: 0 additions & 2 deletions packages/snap/src/wallet/handlers/WalletSuggestChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,5 @@ export const walletSuggestChain = async ({

await rarimoChainsManager.addChain(chainInfo);

// await addChain(chainInfo);

return { message: 'Successfully added chain', chainInfo };
};
12 changes: 1 addition & 11 deletions packages/snap/src/wallet/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { StdSignDoc } from '@cosmjs/amino';
import type { Pubkey, StdSignature, StdSignDoc } from '@cosmjs/amino';
import { ripemd160 } from '@noble/hashes/ripemd160';
import { sha256 } from '@noble/hashes/sha256';
import * as secp from '@noble/secp256k1';
Expand All @@ -9,16 +9,6 @@ import { SignDoc } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
import { StorageKeys } from '@/enums';
import { snapStorage } from '@/helpers';

export type Pubkey = {
readonly type: string;
readonly value: any;
};

export type StdSignature = {
readonly pub_key: Pubkey;
readonly signature: string;
};

export const encodeSecp256k1Pubkey = (pubkey: Uint8Array): Pubkey => {
if (pubkey.length !== 33 || (pubkey[0] !== 0x02 && pubkey[0] !== 0x03)) {
throw new TypeError(
Expand Down

0 comments on commit 20d97c4

Please sign in to comment.