Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add CoinType config #84

Merged
merged 3 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ All notable changes to the Cosmy Wasmy extension will be documented in this file

- For localnet chains, all contracts on the chain can be imported in single click.
- Support [Finschia testnet](https://www.finschia.io/) - Finschia aims to become the world’s No. 1 blockchain ecosystem, leading the popularization of Web3 and securing over 1 billion users. Added configurations for localnet as well as testnet chains
- Support `coinType` - Can use it when generate account, default `118`.

### Changed

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ The structure of the expected setting for `cosmywasamy.chains`:
"chainGasDenom": "uosmo", // The micro denom used to pay for gas
"chainDenomDecimals": "6", // Default decimals to display account balance
"signType": "tmsecp256k1", // Which signing scheme to use? tmsecp256k1 or ethsecp256k1
"coinType": "118", // Coin type registered for the chain
"chainDenom": "uosmo", // the micro denom used to track account balance
"faucetEndpoint": "http://localhost:8000", //Faucet address and port to request funds
"accountExplorerLink": "https://testnet.mintscan.io/osmosis-testnet/account/${accountAddress}", //Block explorer url which includes '${accountAddress}' text to generate account url
Expand Down
299 changes: 278 additions & 21 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@
"%cosmywasmy.chains.items.signType.ethsecp256k1.desc%"
]
},
"coinType": {
"type": "string",
"default": "118",
"description": "%cosmywasmy.chains.items.coinType.desc%"
},
"chainDenom": {
"type": "string",
"description": "%cosmywasmy.chains.items.chainDenom.desc%"
Expand Down Expand Up @@ -483,6 +488,7 @@
"rpcEndpoint": "http://localhost:26657",
"defaultGasPrice": "0.015",
"chainDenom": "cony",
"coinType": "438",
"faucetEndpoint": "http://localhost:8081"
},
{
Expand All @@ -493,6 +499,7 @@
"rpcEndpoint": "https://ebony-rpc.finschia.io/",
"defaultGasPrice": "0.015",
"chainDenom": "tcony",
"coinType": "438",
"accountExplorerLink": "https://explorer.blockchain.line.me/ebony/address/${accountAddress}",
"txExplorerLink": "https://explorer.blockchain.line.me/ebony/transaction/${txHash}",
"faucetEndpoint": "https://faucet-ebonynw.line-apps.com"
Expand Down Expand Up @@ -1237,6 +1244,7 @@
"@cosmjs/launchpad": "^0.27.1",
"@cosmjs/math": "^0.30.1",
"@cosmjs/proto-signing": "^0.28.4",
"@cosmjs/crypto": "^0.31.0",
"@terran-one/cw-simulate": "^2.8.0",
"@vscode/l10n": "^0.0.10",
"@vscode/l10n-dev": "^0.0.24",
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"cosmywasmy.chains.items.signType.desc": "The signature algorithm when signing transactions, `ethsecp256k1` or `tmsecp256k1`, default `tmsecp256k1`",
"cosmywasmy.chains.items.signType.tmsecp256k1.desc": "Used for Cosmos/Tendermint chains signing",
"cosmywasmy.chains.items.signType.ethsecp256k1.desc": "Used for Ethereum/EVM chains signing",
"cosmywasmy.chains.items.coinType.desc": "Used for distinguishing between different cryptocurrencies in hierarchical deterministic wallets, default `118`",
"cosmywasmy.chains.items.faucetEndpoint.desc": "Faucet address and port to request funds",
"cosmywasmy.chains.items.accountExplorerLink.desc": "Block explorer url which includes '${accountAddress}' text to generate account url",
"cosmywasmy.chains.items.txExplorerLink.desc": "Block explorer url which includes '${txHash}' text to generate tx url",
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/Cosmwasm/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class Cosmwasm {

public static async GetSigningClient(): Promise<SigningCosmWasmClient> {
const account = Workspace.GetSelectedAccount();
let signer = await WrapWallet.fromMnemonic(global.workspaceChain.signType, account.mnemonic, {
let signer = await WrapWallet.fromMnemonic(global.workspaceChain.signType, global.workspaceChain.coinType, account.mnemonic, {
prefix: global.workspaceChain.addressPrefix,
});
let gasDenom = global.workspaceChain.chainGasDenom;
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/Cosmwasm/SmartExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class SmartExecutor {
private client: SigningCosmWasmClient;

public async SetupAccount(mnemonic: string, addressPrefix: string) {
this.wallet = await WrapWallet.fromMnemonic(global.workspaceChain.signType, mnemonic, {
this.wallet = await WrapWallet.fromMnemonic(global.workspaceChain.signType, global.workspaceChain.coinType, mnemonic, {
prefix: addressPrefix,
});
const accounts = await this.wallet.getAccounts();
Expand Down
20 changes: 16 additions & 4 deletions src/helpers/Sign/wrapwallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import { EthSecp256k1HdWallet } from './ethsecp256k1hdwallet';
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing';
import { Secp256k1HdWallet } from "@cosmjs/launchpad";
import {DirectSecp256k1HdWalletOptions} from "@cosmjs/proto-signing/build/directsecp256k1hdwallet"
import { DirectSecp256k1HdWalletOptions } from "@cosmjs/proto-signing/build/directsecp256k1hdwallet";
import { HdPath,Slip10RawIndex } from "@cosmjs/crypto";

export const SIGN_TYPE = {
ethsecp256k1: 'ethsecp256k1',
Expand All @@ -11,15 +12,24 @@ export const SIGN_TYPE = {

export class WrapWallet {
private signType;
private hdPath:HdPath;
public mnemonic;

constructor(type, mnemonic, options) {
constructor(type, coinType, mnemonic, options) {
this.mnemonic = mnemonic;
this.signType = WrapWallet.isEthSecp256k1(type) ? SIGN_TYPE.ethsecp256k1 : SIGN_TYPE.tmsecp256k1;
const currentCoinType = coinType || "118";
this.hdPath = [
Slip10RawIndex.hardened(44),
Slip10RawIndex.hardened(Number(currentCoinType)),
Slip10RawIndex.hardened(0),
Slip10RawIndex.normal(0),
Slip10RawIndex.normal(0),
];
}

static async fromMnemonic(type: string, mnemonic: string, options?: Partial<DirectSecp256k1HdWalletOptions>): Promise<WrapWallet>{
return new WrapWallet(type, mnemonic, {
static async fromMnemonic(type: string, coinType: string, mnemonic: string, options?: Partial<DirectSecp256k1HdWalletOptions>): Promise<WrapWallet>{
return new WrapWallet(type, coinType, mnemonic, {
...options,
});
}
Expand Down Expand Up @@ -60,10 +70,12 @@ export class WrapWallet {
async getWallet(){
if (this.signType !== SIGN_TYPE.ethsecp256k1){
return DirectSecp256k1HdWallet.fromMnemonic(this.mnemonic, {
hdPaths: [this.hdPath],
prefix: global.workspaceChain.addressPrefix,
},);
}
return EthSecp256k1HdWallet.fromMnemonic(this.mnemonic, {
hdPaths: [this.hdPath],
prefix: global.workspaceChain.addressPrefix,
},);
}
Expand Down
1 change: 1 addition & 0 deletions src/helpers/Workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export class ChainConfig {
chainGasDenom!: string;
chainDenomDecimals!: string;
signType!: string;
coinType!: string;

public Validate() {
if (!this) {
Expand Down
4 changes: 2 additions & 2 deletions src/models/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class Account extends vscode.TreeItem {
public static async GetAccounts(context: vscode.Memento): Promise<Account[]> {
const accountData = this.GetAccountsBasic(context);
for (let account of accountData) {
const wallet = await WrapWallet.fromMnemonic(global.workspaceChain.signType, account.mnemonic, {
const wallet = await WrapWallet.fromMnemonic(global.workspaceChain.signType, global.workspaceChain.coinType, account.mnemonic, {
prefix: global.workspaceChain.addressPrefix
});
const accounts = await wallet.getAccounts();
Expand All @@ -45,7 +45,7 @@ export class Account extends vscode.TreeItem {
public static async AddAccount(context: vscode.Memento, account: Account) {
try{
//fix import error mnemonic, failed to load account when restart vscode
await (await WrapWallet.fromMnemonic(global.workspaceChain.signType, account.mnemonic, {
await (await WrapWallet.fromMnemonic(global.workspaceChain.signType, global.workspaceChain.coinType, account.mnemonic, {
prefix: global.workspaceChain.addressPrefix
})).getAccounts();

Expand Down
2 changes: 1 addition & 1 deletion src/views/SignProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class SignProvider implements vscode.WebviewViewProvider {
return;
}
try {
let wallet = await WrapWallet.fromMnemonic(global.workspaceChain.signType, account.mnemonic, {
let wallet = await WrapWallet.fromMnemonic(global.workspaceChain.signType, global.workspaceChain.coinType, account.mnemonic, {
prefix: global.workspaceChain.addressPrefix,
});
const signDoc = this.makeSignDoc(account.address, data.value);
Expand Down
Loading