Socket
Socket
Sign inDemoInstall

@starport/vuex

Package Overview
Dependencies
14
Maintainers
3
Versions
163
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.1-alpha-981c153fc04d45c3a87b5806366a788243fdcbff.0 to 0.2.1-alpha-98615befeb379e8c352d6d09941c85439d2ded4a.0

4

package.json
{
"name": "@starport/vuex",
"version": "0.2.1-alpha-981c153fc04d45c3a87b5806366a788243fdcbff.0+981c153",
"version": "0.2.1-alpha-98615befeb379e8c352d6d09941c85439d2ded4a.0+98615be",
"description": "A library of Vuex 4 (for Vue 3) standard store modules for state management of cosmos-sdk chains' frontends",

@@ -31,3 +31,3 @@ "author": "Tendermint, Inc <hello@tendermint.com>",

},
"gitHead": "981c153fc04d45c3a87b5806366a788243fdcbff"
"gitHead": "98615befeb379e8c352d6d09941c85439d2ded4a"
}

@@ -55,9 +55,5 @@ import { SigningStargateClient } from '@cosmjs/stargate'

this.connectivityTest()
if (this.wsAddr) {
this.socket = new ReconnectingWebSocket(this.wsAddr)
this.socket.onopen = this.onOpenWS.bind(this)
this.socket.onmessage = this.onMessageWS.bind(this)
this.socket.onerror = this.onErrorWS.bind(this)
this.socket.onclose = this.onCloseWS.bind(this)
this.connectWS()
}

@@ -78,4 +74,15 @@ }

this.wsAddr = wsAddr
this.socket.close()
this.connectWS()
}
public connectWS() {
this.socket = new ReconnectingWebSocket(this.wsAddr)
this.socket.onopen = this.onOpenWS.bind(this)
this.socket.onmessage = this.onMessageWS.bind(this)
this.socket.onerror = this.onErrorWS.bind(this)
this.socket.onclose = this.onCloseWS.bind(this)
}
public async switchRPC(rpcAddr: string): Promise<void> {

@@ -82,0 +89,0 @@ this.rpcAddr = rpcAddr

@@ -5,3 +5,2 @@ import SpVuexError from './errors/SpVuexError'

import env from './modules/common/env'
import relayers from './modules/common/relayers'
import transfers from './modules/common/transfers'

@@ -14,3 +13,2 @@ import wallet from './modules/common/wallet'

keyToWif,
relayers,
SpVuexError,

@@ -17,0 +15,0 @@ transfers,

@@ -117,3 +117,3 @@ import Client from '../../../client/SPClient'

await dispatch('config', config)
console.log('Vuex nodule: common.env initialized!')
console.log('Vuex module: common.env initialized!')
} catch (e) {

@@ -120,0 +120,0 @@ throw new SpVuexError('Env:Config', 'Could not configure environment')

@@ -39,3 +39,3 @@ import axios from 'axios'

init({ dispatch, rootGetters }) {
console.log('Vuex nodule: common.transfers initialized!')
console.log('Vuex module: common.transfers initialized!')
if (rootGetters['common/env/client']) {

@@ -42,0 +42,0 @@ rootGetters['common/env/client'].on('newblock', () => {

@@ -45,9 +45,2 @@ import { stringToPath } from '@cosmjs/crypto'

).pathIncrement,
relayers: (state) => {
return (
state.activeWallet?.accounts.find(
(x) => x.address == state.selectedAddress
).relayers ?? []
)
},
nameAvailable: (state) => (name) => {

@@ -126,15 +119,2 @@ return state.wallets.findIndex((x) => x.name == name) == -1

},
SET_RELAYERS(state, relayers) {
state.activeWallet.accounts.find(
(x) => x.address == state.selectedAddress
).relayers = relayers
if (state.activeWallet.name && state.activeWallet.password) {
state.wallets[
state.wallets.findIndex((x) => x.name === state.activeWallet.name)
].wallet = CryptoJS.AES.encrypt(
JSON.stringify(state.activeWallet),
state.activeWallet.password
).toString()
}
},
SET_SELECTED_ADDRESS(state, address) {

@@ -189,108 +169,2 @@ state.selectedAddress = address

},
async unlockWallet(
{ commit, state, dispatch, rootGetters },
{ name, password }
) {
const encryptedWallet =
state.wallets[state.wallets.findIndex((x) => x.name === name)].wallet
let wallet
if (name == 'Keplr Integration') {
wallet = JSON.parse(encryptedWallet)
} else {
wallet = JSON.parse(
CryptoJS.AES.decrypt(encryptedWallet, password).toString(
CryptoJS.enc.Utf8
)
)
}
commit('SET_ACTIVE_WALLET', wallet)
if (wallet.accounts.length > 0) {
let accountSigner
if (wallet.name == 'Keplr Integration') {
accountSigner = window.getOfflineSigner(
rootGetters['common/env/chainId']
)
} else {
accountSigner = await DirectSecp256k1HdWallet.fromMnemonic(
wallet.mnemonic,
{
hdPaths: [
stringToPath(wallet.HDpath + wallet.accounts[0].pathIncrement)
],
prefix: wallet.prefix
}
)
}
try {
await dispatch('common/env/signIn', accountSigner, {
root: true
})
let client = rootGetters['common/env/signingClient']
commit('SET_ACTIVE_CLIENT', client)
const [account] = await accountSigner.getAccounts()
commit('SET_SELECTED_ADDRESS', account.address)
} catch (e) {
console.log(e)
}
}
},
async updateRelayers({ commit, dispatch }, relayers) {
commit('SET_RELAYERS', relayers)
dispatch('storeWallets')
},
async switchAccount({ commit, state, rootGetters, dispatch }, address) {
const accountIndex = state.activeWallet.accounts.findIndex(
(acc) => acc.address == address
)
const accountSigner = await DirectSecp256k1HdWallet.fromMnemonic(
state.activeWallet.mnemonic,
{
hdPaths: [
stringToPath(
state.activeWallet.HDpath +
state.activeWallet.accounts[accountIndex].pathIncrement
)
],
prefix: state.activeWallet.prefix
}
)
try {
await dispatch('common/env/signIn', accountSigner, { root: true })
let client = rootGetters['common/env/signingClient']
commit('SET_ACTIVE_CLIENT', client)
const [account] = await accountSigner.getAccounts()
commit('SET_SELECTED_ADDRESS', account.address)
} catch (e) {
console.log(e)
}
},
async addAccount({ commit, state, dispatch }, pathIncrement) {
if (!pathIncrement) {
pathIncrement = state.activeWallet.pathIncrement + 1
commit('PATH_INCREMENT')
}
const accountSigner = await DirectSecp256k1HdWallet.fromMnemonic(
state.activeWallet.mnemonic,
{
hdPaths: [stringToPath(state.activeWallet.HDpath + pathIncrement)],
prefix: state.activeWallet.prefix
}
)
const [acc] = await accountSigner.getAccounts()
const account = {
address: acc.address,
pathIncrement: parseInt(pathIncrement)
}
if (
state.activeWallet.accounts.findIndex(
(acc) => acc.address == account.address
) == -1
) {
commit('ADD_ACCOUNT', account)
dispatch('storeWallets')
} else {
throw 'Account already in store.'
}
},
storeWallets({ commit, state }) {

@@ -300,124 +174,3 @@ window.localStorage.setItem('wallets', JSON.stringify(state.wallets))

},
async signInWithPrivateKey(
{ commit, rootGetters, dispatch },
{ prefix = 'cosmos', privKey }
) {
const pKey = keyFromWif(privKey.trim())
const accountSigner = await DirectSecp256k1Wallet.fromKey(pKey, {
prefix
})
const [firstAccount] = await accountSigner.getAccounts()
try {
await dispatch('common/env/signIn', accountSigner, { root: true })
let client = rootGetters['common/env/signingClient']
commit('SET_ACTIVE_CLIENT', client)
commit('SET_SELECTED_ADDRESS', firstAccount.address)
} catch (e) {
console.log(e)
}
},
async restoreWallet(
{ commit, dispatch, rootGetters, state },
{ encrypted, password }
) {
const wallet = JSON.parse(
CryptoJS.AES.decrypt(encrypted, password).toString(CryptoJS.enc.Utf8)
)
let newName = wallet.name
let incr = 1
while (state.wallets.findIndex((x) => x.name == newName) != -1) {
newName = wallet.name + '_' + incr
incr++
}
wallet.name = newName
const accountSigner = await DirectSecp256k1HdWallet.fromMnemonic(
wallet.mnemonic,
{
hdPaths: [stringToPath(wallet.HDpath + '0')],
prefix: wallet.prefix
}
)
const [firstAccount] = await accountSigner.getAccounts()
commit('ADD_WALLET', wallet)
try {
await dispatch('common/env/signIn', accountSigner, { root: true })
let client = rootGetters['common/env/signingClient']
commit('SET_ACTIVE_CLIENT', client)
commit('SET_SELECTED_ADDRESS', firstAccount.address)
} catch (e) {
console.log(e)
}
dispatch('storeWallets')
},
async createWalletWithMnemonic(
{ commit, dispatch, rootGetters },
{
name = null,
mnemonic,
HDpath = "m/44'/118'/0'/0/",
prefix = 'cosmos',
password = null
}
) {
const wallet = {
name,
mnemonic,
HDpath,
password,
prefix,
pathIncrement: 0,
accounts: []
}
const accountSigner = await DirectSecp256k1HdWallet.fromMnemonic(
mnemonic,
{
hdPaths: [stringToPath(HDpath + '0')],
prefix
}
)
const [firstAccount] = await accountSigner.getAccounts()
const account = { address: firstAccount.address, pathIncrement: 0 }
wallet.accounts.push(account)
commit('ADD_WALLET', wallet)
try {
await dispatch('common/env/signIn', accountSigner, { root: true })
let client = rootGetters['common/env/signingClient']
commit('SET_ACTIVE_CLIENT', client)
commit('SET_SELECTED_ADDRESS', firstAccount.address)
} catch (e) {
console.log(e)
}
dispatch('storeWallets')
},
async sendTransaction({ state }, { message, memo, denom }) {
const fee = {
amount: [{ amount: '0', denom }],
gas: '200000'
}
try {
console.log({
add: state.selectedAddress,
msg: [message],
fee,
memo
})
const result = await state.activeClient.signAndBroadcast(
state.selectedAddress,
[message],
fee,
memo
)
assertIsBroadcastTxSuccess(result)
} catch (e) {
console.log(e)
throw 'Failed to broadcast transaction.' + e
}
}
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc