add ethereum app

This commit is contained in:
liangping 2022-06-03 11:24:05 +08:00
parent 4ca5dbce33
commit d8c0f02bc6
7 changed files with 171 additions and 64 deletions

View File

@ -12,8 +12,6 @@
"analyz": "vue-cli-service build --report"
},
"dependencies": {
"@tharsis/address-converter": "^0.1.7",
"@tharsis/transactions": "^0.2.2",
"@casl/ability": "4.1.6",
"@casl/vue": "1.1.1",
"@cosmjs/amino": "^0.28.4",
@ -28,12 +26,12 @@
"@ledgerhq/hw-app-eth": "^6.28.2",
"@ledgerhq/hw-transport-web-ble": "^6.27.1",
"@ledgerhq/hw-transport-webusb": "^6.27.1",
"@tharsis/address-converter": "^0.1.7",
"@tharsis/transactions": "^0.2.2",
"@vue/composition-api": "^1.4.9",
"@vueuse/core": "4.0.0",
"animate.css": "4.1.1",
"apexcharts": "3.24.0",
"axios": "0.21.2",
"axios-mock-adapter": "1.19.0",
"apexcharts": "3.2.0",
"babel-runtime": "^6.26.0",
"bootstrap": "4.6.0",
"bootstrap-vue": "2.21.1",
@ -93,6 +91,7 @@
},
"devDependencies": {
"@babel/eslint-parser": "^7.5.4",
"@protobufs/osmosis": "^0.0.8",
"@typescript-eslint/eslint-plugin": "^5.25.0",
"@typescript-eslint/parser": "^5.25.0",
"@vue/cli-plugin-babel": "~5.0.4",
@ -105,8 +104,8 @@
"@vuepress/plugin-medium-zoom": "^1.7.1",
"compression-webpack-plugin": "6.1.1",
"eslint": "^8.15.0",
"eslint-plugin-vue": "9.0.1",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-vue": "9.0.1",
"eslint-plugin-vuejs-accessibility": "^1.1.1",
"sass": "1.32.*",
"sass-loader": "^10.1.0",

View File

@ -1,5 +1,5 @@
import { AminoSignResponse, OfflineAminoSigner, Pubkey, StdSignature, StdSignDoc } from "@cosmjs/amino";
import { AccountData, AminoSignResponse, OfflineAminoSigner, Pubkey, StdSignature, StdSignDoc } from "@cosmjs/amino";
import { AddressAndPubkey } from "@cosmjs/ledger-amino";
import Transport from "@ledgerhq/hw-transport";
@ -12,15 +12,15 @@ import { HdPath } from "@cosmjs/crypto";
import { ethToCosmos } from '@tharsis/address-converter'
import eth from "@tharsis/proto/dist/proto/ethermint/crypto/v1/ethsecp256k1/keys";
export type Algo = "secp256k1" | "ed25519" | "sr25519" | "ethsecp256k1";
export interface AccountData {
/** A printable address (typically bech32 encoded) */
readonly address: string;
readonly algo: Algo;
readonly pubkey: Uint8Array;
}
// export type Algo = "secp256k1" | "ed25519" | "sr25519" | "ethsecp256k1";
// export interface AccountData {
// /** A printable address (typically bech32 encoded) */
// readonly address: string;
// readonly algo: Algo;
// readonly pubkey: Uint8Array;
// }
export class EthereumLedgerSigner {
export class EthereumLedgerSigner implements OfflineAminoSigner{
app: Eth
hdpath: string
@ -40,12 +40,12 @@ export class EthereumLedgerSigner {
const x1: AccountData = {
pubkey: new TextEncoder().encode(x.publicKey),
address: x.address,
algo: "ethsecp256k1" // should be 'ethsecp256k1'
algo: "secp256k1" // should be 'ethsecp256k1'
}
const x2: AccountData = {
pubkey: new TextEncoder().encode(x.publicKey),
address: ethToCosmos(x.address),
algo: "ethsecp256k1" // // should be 'ethsecp256k1'
algo: "secp256k1" // // should be 'ethsecp256k1'
}
return [x1, x2]
})
@ -91,7 +91,11 @@ export class EthereumLedgerSigner {
return new Promise((r, j) => { })
}
async signTransaction(rawTxHex: string, resolution: LedgerEthTransactionResolution) {
// async sign712Transaction(rawTxHex: string, resolution: LedgerEthTransactionResolution) {
// return this.app.signEIP712HashedMessage(this.hdpath, rawTxHex, resolution)
// }
async signTransaction(rawTxHex: string, resolution?: LedgerEthTransactionResolution) {
return this.app.signTransaction(this.hdpath, rawTxHex, resolution)
}
}

View File

@ -0,0 +1,77 @@
import {
AminoTypes,
SignerData,
SigningStargateClient,
SigningStargateClientOptions,
StargateClient
} from '@cosmjs/stargate';
import { Registry, OfflineSigner, EncodeObject } from '@cosmjs/proto-signing';
import { defaultRegistryTypes } from '@cosmjs/stargate';
import { LedgerSigner } from '@cosmjs/ledger-amino';
import { EthereumLedgerSigner } from './EthereumLedgerSigner';
import TransportWebUSB from '@ledgerhq/hw-transport-webusb';
import TransportWebBLE from '@ledgerhq/hw-transport-web-ble'
import { stringToPath } from '@cosmjs/crypto';
import { StdFee } from "@cosmjs/amino";
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
// export async function sign(device, chainId, signerAddress, messages, fee, memo, signerData) {
// // let transport
// let signer
// const hdpath = getHdPath(signerAddress)
// const coinType = Number(hdpath[1])
// switch (device) {
// case 'ledgerBle':
// signer = await getLedgerAppName(coinType, device, hdpath)
// break
// case 'ledgerUSB':
// signer = await getLedgerAppName(coinType, device, hdpath)
// break
// case 'keplr':
// default:
// if (!window.getOfflineSigner || !window.keplr) {
// throw new Error('Please install keplr extension')
// }
// await window.keplr.enable(chainId)
// signer = window.getOfflineSignerOnlyAmino(chainId)
// }
// // Ensure the address has some tokens to spend
// const client = await PingWalletClient.offline(signer)
// return client.signAmino(device.startsWith('ledger') ? toSignAddress(signerAddress) : signerAddress, messages, fee, memo, signerData)
// }
export declare type SigningClient = SigningStargateClient | SigningEthermintClient;
export async function getSigningClient(device, hdpath) : Promise<SigningClient> {
let ledgerAppName = 'Cosmos'
let coinType = Number(stringToPath(hdpath)[1])
switch (coinType) {
case 60:
return new SigningEthermintClient(await EthereumLedgerSigner.create(device, hdpath)) // 'Ethereum'
case 529:
ledgerAppName = 'Secret' // 'Secret'
break
case 852:
ledgerAppName = 'Desmos' // 'Desmos'
break
case 118:
default:
}
const transport = await (device === 'ledgerBle' ? TransportWebBLE.create() : TransportWebUSB.create())
const signer = new LedgerSigner(transport, { hdPaths: [hdpath], ledgerAppName })
return SigningStargateClient.offline(signer)
}
export class SigningEthermintClient {
readonly signer: OfflineSigner
constructor(signer: OfflineSigner) {
this.signer = signer
}
sign(signerAddress: string, messages: readonly EncodeObject[], fee: StdFee, memo: string, explicitSignerData?: SignerData): Promise<TxRaw> {
return new Promise(()=>{return TxRaw.decode(null)})
}
}

View File

@ -39,7 +39,7 @@ export default class ChainFetch {
let chain = store.state.chains.selected
const lschains = localStorage.getItem('chains')
if (lschains) {
chain = JSON.parse(lschains)[chain.chain_name]
chain = JSON.parse(lschains)[chain?.chain_name || 'cosmos']
}
if (!chain.sdk_version) {
chain.sdk_version = '0.33'

View File

@ -12,7 +12,7 @@
"allowSyntheticDefaultImports": true
},
"include": [
"src/**/*.ts",
"src/**/*",
],
"exclude": ["node_modules"]
}

View File

@ -1,9 +1,9 @@
const path = require('path')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
const CompressionWebpackPlugin = require('compression-webpack-plugin')
// const CompressionWebpackPlugin = require('compression-webpack-plugin')
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin')
const productionGzipExtensions = ['js', 'css']
// const productionGzipExtensions = ['js', 'css']
module.exports = {
publicPath: '/',
@ -25,6 +25,7 @@ module.exports = {
'@validations': path.resolve(__dirname, 'src/@core/utils/validations/validations.js'),
'@axios': path.resolve(__dirname, 'src/libs/axios'),
},
extensions: ['.json', '.js', '.jsx', '.ts', '.tsx'],
},
plugins: [
new NodePolyfillPlugin(),
@ -32,11 +33,11 @@ module.exports = {
analyzerMode: 'disabled',
openAnalyzer: false,
}),
new CompressionWebpackPlugin({
test: new RegExp(`\\.(${productionGzipExtensions.join('|')})$`),
threshold: 8192,
minRatio: 0.8,
}),
// new CompressionWebpackPlugin({
// test: new RegExp(`\\.(${productionGzipExtensions.join('|')})$`),
// threshold: 8192,
// minRatio: 0.8,
// }),
],
},
chainWebpack: config => {

100
yarn.lock
View File

@ -1722,6 +1722,52 @@
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
integrity sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==
"@protobufs/cosmos@^0.0.8":
version "0.0.8"
resolved "https://registry.yarnpkg.com/@protobufs/cosmos/-/cosmos-0.0.8.tgz#b64bc2f95f33eb02837edfc00d9cc57586c5bdbf"
integrity sha512-2pAgqJHPSU2MLlySBtbayz62B8tdssgY3T/bOYesK+ltQ6GBiNZ52NwGRpxeiHkwHBwve279IofqcDMQygCrtw==
dependencies:
"@protobufs/cosmos_proto" "^0.0.8"
"@protobufs/gogoproto" "^0.0.8"
"@protobufs/google" "^0.0.8"
"@protobufs/tendermint" "^0.0.8"
"@protobufs/cosmos_proto@^0.0.8":
version "0.0.8"
resolved "https://registry.yarnpkg.com/@protobufs/cosmos_proto/-/cosmos_proto-0.0.8.tgz#cc3be5f97cd4d7ad4509601481a95c5c3c4d77a3"
integrity sha512-9gE6C2DIrk8iqGG9OcUsa3Uzg9Bufw0094wunweX96i+N0zAR5gope1JXanqil0baqTrBvcSFj2jzxBHf7Tzcg==
dependencies:
"@protobufs/google" "^0.0.8"
"@protobufs/gogoproto@^0.0.8":
version "0.0.8"
resolved "https://registry.yarnpkg.com/@protobufs/gogoproto/-/gogoproto-0.0.8.tgz#b0a59bc6e60a6586eef240e61842608b8d966fe0"
integrity sha512-WUYFhTLRfTNe/GYveQ+aEY2w1iZIkrsB5uAJwozI9uIyZVXk0Wstcn+GYr0tWwdDIBqHSMtTUukG6hCQ7zxYpg==
dependencies:
"@protobufs/google" "^0.0.8"
"@protobufs/google@^0.0.8":
version "0.0.8"
resolved "https://registry.yarnpkg.com/@protobufs/google/-/google-0.0.8.tgz#849d2b8eb6fdd7d5b818f5f9128fd2b1e4458f6c"
integrity sha512-q8GvVT6k/FfLWCOh6N4nuyjzFF7ECvsVA1RqWBYOwAwKszRBREiQri3oaJY5jBT+L6vajbJ0tAAFhhWm8wRAOw==
"@protobufs/osmosis@^0.0.8":
version "0.0.8"
resolved "https://registry.yarnpkg.com/@protobufs/osmosis/-/osmosis-0.0.8.tgz#efbe8c54e1b7b58164a0808016147c5e21f3c74f"
integrity sha512-GJbZLf6CCawTRgrD4r4CgBt2S1yk8g9QBYuJUXENLx5TthgH5GvRuiO6AvtZTgw4mZLJCsrfRqoKh0mXoj4Qyw==
dependencies:
"@protobufs/cosmos" "^0.0.8"
"@protobufs/gogoproto" "^0.0.8"
"@protobufs/google" "^0.0.8"
"@protobufs/tendermint@^0.0.8":
version "0.0.8"
resolved "https://registry.yarnpkg.com/@protobufs/tendermint/-/tendermint-0.0.8.tgz#3c5df7d04ca37aa336dbd1f978e18d2e36d02c8f"
integrity sha512-SUvhbC8hPAcfLX72qpyXEL+vpOn/ji3JBgpvoikCFTwantfP35I/B9M0J2ruz0j5W7AcrCVnSuwOM/AfEwyv2Q==
dependencies:
"@protobufs/gogoproto" "^0.0.8"
"@protobufs/google" "^0.0.8"
"@sideway/address@^4.1.3":
version "4.1.4"
resolved "https://registry.yarnpkg.com/@sideway/address/-/address-4.1.4.tgz#03dccebc6ea47fdc226f7d3d1ad512955d4783f0"
@ -2775,17 +2821,19 @@ anymatch@^3.0.0, anymatch@~3.1.2:
normalize-path "^3.0.0"
picomatch "^2.0.4"
apexcharts@3.24.0:
version "3.24.0"
resolved "https://registry.yarnpkg.com/apexcharts/-/apexcharts-3.24.0.tgz#0fc513e940448524ae9702d39ec287567522d1eb"
integrity sha512-iT6czJCIVrmAtrcO90MZTQCvC+xi6R6Acf0jNH/d40FVTtCfcqECuKIh5iAMyOTtgUb7+fQ8rbadH2bm1kbL9Q==
apexcharts@3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/apexcharts/-/apexcharts-3.2.0.tgz#160ce31635db11391c825f9b5d51638078f77013"
integrity sha512-CBdsK+Wc+YXSwl8xDOJm1/XrxgbE4WdMoe39fKV87h+P633W9XD8HR75GrGXhA/H8XiTPWJZjzkynxqq8SKb+A==
dependencies:
svg.draggable.js "^2.2.2"
promise-polyfill "8.1.0"
svg.draggable.js "^2.2.1"
svg.easing.js "^2.0.0"
svg.filter.js "^2.0.2"
svg.js "^2.6.6"
svg.pathmorphing.js "^0.1.3"
svg.resize.js "^1.4.3"
svg.select.js "^3.0.1"
svg.resize.js "^1.4.1"
svg.select.js "^2.1.2"
arch@^2.1.1:
version "2.2.0"
@ -2904,21 +2952,6 @@ available-typed-arrays@^1.0.5:
resolved "https://registry.yarnpkg.com/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz#92f95616501069d07d10edb2fc37d3e1c65123b7"
integrity sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw==
axios-mock-adapter@1.19.0:
version "1.19.0"
resolved "https://registry.yarnpkg.com/axios-mock-adapter/-/axios-mock-adapter-1.19.0.tgz#9d72e321a6c5418e1eff067aa99761a86c5188a4"
integrity sha512-D+0U4LNPr7WroiBDvWilzTMYPYTuZlbo6BI8YHZtj7wYQS8NkARlP9KBt8IWWHTQJ0q/8oZ0ClPBtKCCkx8cQg==
dependencies:
fast-deep-equal "^3.1.3"
is-buffer "^2.0.3"
axios@0.21.2:
version "0.21.2"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.2.tgz#21297d5084b2aeeb422f5d38e7be4fbb82239017"
integrity sha512-87otirqUw3e8CzHTMO+/9kh/FSgXt/eVDvipijwDtEuwbkySWZ9SBm6VEubmJ/kLKEoLQV/POhxXFb66bfekfg==
dependencies:
follow-redirects "^1.14.0"
axios@^0.21.2:
version "0.21.4"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.4.tgz#c67b90dc0568e5c1cf2b0b858c43ba28e2eda575"
@ -5459,11 +5492,6 @@ is-boolean-object@^1.1.0:
call-bind "^1.0.2"
has-tostringtag "^1.0.0"
is-buffer@^2.0.3:
version "2.0.5"
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-2.0.5.tgz#ebc252e400d22ff8d77fa09888821a24a658c191"
integrity sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==
is-callable@^1.1.3, is-callable@^1.1.4, is-callable@^1.2.4:
version "1.2.4"
resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.2.4.tgz#47301d58dd0259407865547853df6d61fe471945"
@ -7236,6 +7264,11 @@ promise-inflight@^1.0.1:
resolved "https://registry.yarnpkg.com/promise-inflight/-/promise-inflight-1.0.1.tgz#98472870bf228132fcbdd868129bad12c3c029e3"
integrity sha1-mEcocL8igTL8vdhoEputEsPAKeM=
promise-polyfill@8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/promise-polyfill/-/promise-polyfill-8.1.0.tgz#30059da54d1358ce905ac581f287e184aedf995d"
integrity sha512-OzSf6gcCUQ01byV4BgwyUCswlaQQ6gzXc23aLQWhicvfX9kfsUiUhgt3CCQej8jDnl8/PhGF31JdHX2/MzF3WA==
protobufjs-cli-dbx@^7.0.7:
version "7.0.7"
resolved "https://registry.yarnpkg.com/protobufjs-cli-dbx/-/protobufjs-cli-dbx-7.0.7.tgz#4afbcba6da1de5d24e968a9a859729fd6750515a"
@ -8205,7 +8238,7 @@ svg-tags@^1.0.0:
resolved "https://registry.yarnpkg.com/svg-tags/-/svg-tags-1.0.0.tgz#58f71cee3bd519b59d4b2a843b6c7de64ac04764"
integrity sha1-WPcc7jvVGbWdSyqEO2x95krAR2Q=
svg.draggable.js@^2.2.2:
svg.draggable.js@^2.2.1:
version "2.2.2"
resolved "https://registry.yarnpkg.com/svg.draggable.js/-/svg.draggable.js-2.2.2.tgz#c514a2f1405efb6f0263e7958f5b68fce50603ba"
integrity sha512-JzNHBc2fLQMzYCZ90KZHN2ohXL0BQJGQimK1kGk6AvSeibuKcIdDX9Kr0dT9+UJ5O8nYA0RB839Lhvk4CY4MZw==
@ -8226,7 +8259,7 @@ svg.filter.js@^2.0.2:
dependencies:
svg.js "^2.2.5"
svg.js@>=2.3.x, svg.js@^2.0.1, svg.js@^2.2.5, svg.js@^2.4.0, svg.js@^2.6.5:
svg.js@>=2.3.x, svg.js@^2.0.1, svg.js@^2.2.5, svg.js@^2.4.0, svg.js@^2.6.5, svg.js@^2.6.6:
version "2.7.1"
resolved "https://registry.yarnpkg.com/svg.js/-/svg.js-2.7.1.tgz#eb977ed4737001eab859949b4a398ee1bb79948d"
integrity sha512-ycbxpizEQktk3FYvn/8BH+6/EuWXg7ZpQREJvgacqn46gIddG24tNNe4Son6omdXCnSOaApnpZw6MPCBA1dODA==
@ -8238,7 +8271,7 @@ svg.pathmorphing.js@^0.1.3:
dependencies:
svg.js "^2.4.0"
svg.resize.js@^1.4.3:
svg.resize.js@^1.4.1:
version "1.4.3"
resolved "https://registry.yarnpkg.com/svg.resize.js/-/svg.resize.js-1.4.3.tgz#885abd248e0cd205b36b973c4b578b9a36f23332"
integrity sha512-9k5sXJuPKp+mVzXNvxz7U0uC9oVMQrrf7cFsETznzUDDm0x8+77dtZkWdMfRlmbkEEYvUn9btKuZ3n41oNA+uw==
@ -8253,13 +8286,6 @@ svg.select.js@^2.1.2:
dependencies:
svg.js "^2.2.5"
svg.select.js@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/svg.select.js/-/svg.select.js-3.0.1.tgz#a4198e359f3825739226415f82176a90ea5cc917"
integrity sha512-h5IS/hKkuVCbKSieR9uQCj9w+zLHoPh+ce19bBYyqF53g6mnPB8sAtIbe1s9dh2S2fCmYX2xel1Ln3PJBbK4kw==
dependencies:
svg.js "^2.6.5"
svgo@^2.7.0:
version "2.8.0"
resolved "https://registry.yarnpkg.com/svgo/-/svgo-2.8.0.tgz#4ff80cce6710dc2795f0c7c74101e6764cfccd24"