Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function isPortis(wallet: HDWallet): wallet is PortisHDWallet {
return isObject(wallet) && (wallet as any)._isPortis
}
export class PortisHDWallet implements HDWallet, ETHWallet, BTCWallet {
_supportsETH: boolean = true
_supportsETHInfo: boolean = true
_supportsBTCInfo: boolean = true
_supportsBTC: boolean = true
_supportsCosmosInfo: boolean = false
_supportsCosmos: boolean = false
_supportsDebugLink: boolean = false
_isPortis: boolean = true
transport = new PortisTransport(new Keyring())
portis: any
web3: any
info: PortisHDWalletInfo & HDWalletInfo
ethAddress: string
// used as a mutex to ensure calls to portis.getExtendedPublicKey cannot happen before a previous call has resolved
portisCallInProgress: Promise = Promise.resolve()
constructor(portis) {
this.portis = portis
this.web3 = new Web3(portis.provider)
this.info = new PortisHDWalletInfo()
}
public async isLocked(): Promise {
public call (...args: any[]): Promise {
return Promise.resolve()
}
}
export class MetaMaskHDWallet implements HDWallet, ETHWallet {
_supportsETH: boolean = true
_supportsETHInfo: boolean = true
_supportsBTCInfo: boolean = false
_supportsBTC: boolean = false
_supportsDebugLink: boolean = false
_isMetaMask: boolean = true
transport = new MetaMaskTransport(new Keyring())
info: MetaMaskHDWalletInfo & HDWalletInfo
ethereum: any
accounts: string[]
constructor(ethereum) {
console.log('runnin with the devil')
this.ethereum = ethereum
this.info = new MetaMaskHDWalletInfo()
this.accounts = []
}
public async isLocked(): Promise {
return false
}
export async function createWallet (): Promise {
const keyring = new Keyring()
let wallet = await getDevice(keyring) || await getEmulator(keyring)
if (!wallet)
throw new Error("No suitable test KeepKey found")
wallet.transport.on(Events.BUTTON_REQUEST, async () => {
if (autoButton && supportsDebugLink(wallet)) {
await wallet.pressYes()
}
})
wallet.transport.onAny((event: string[], ...values: any[]) => {
//console.info(event, ...values)
})
import { WebUSBKeepKeyAdapter } from "@shapeshiftoss/hdwallet-keepkey-webusb";
import { TrezorAdapter } from "@shapeshiftoss/hdwallet-trezor-connect";
export interface HDWalletContextValue {
keyring: Keyring;
pairedDevices: { [index: string]: HDWallet };
getAdapter: (
adapterName: string
) => WebUSBKeepKeyAdapter | TrezorAdapter | any;
}
let hdWalletContext: React.Context;
const initialValue = {
keyring: new Keyring(),
pairedDevices: {},
getAdapter: () => {}
};
export function getHDWalletContext() {
if (!hdWalletContext) {
hdWalletContext = React.createContext(initialValue);
}
return hdWalletContext;
}
export function resethdWalletContext() {
hdWalletContext = React.createContext(initialValue);
}
export async function createWallet (): Promise {
let keyring = new Keyring()
let transport = new MockTransport(keyring)
return createTrezor(transport as TrezorTransport, true)
}
import { PortisAdapter } from '@shapeshiftoss/hdwallet-portis'
import {
BTCInputScriptType,
BTCOutputScriptType,
BTCOutputAddressType,
} from '@shapeshiftoss/hdwallet-core/src/bitcoin'
import * as btcBech32TxJson from './json/btcBech32Tx.json'
import * as btcTxJson from './json/btcTx.json'
import * as btcSegWitTxJson from './json/btcSegWitTx.json'
import * as dashTxJson from './json/dashTx.json'
import * as dogeTxJson from './json/dogeTx.json'
import * as ltcTxJson from './json/ltcTx.json'
const keyring = new Keyring()
const portisAppId = 'ff763d3d-9e34-45a1-81d1-caa39b9c64f9'
const keepkeyAdapter = WebUSBKeepKeyAdapter.useKeyring(keyring)
const kkemuAdapter = TCPKeepKeyAdapter.useKeyring(keyring)
const portisAdapter = PortisAdapter.useKeyring(keyring, { portisAppId })
const log = debug.default('hdwallet')
keyring.onAny((name: string[], ...values: any[]) => {
const [[ , event ]] = values
const { from_wallet = false } = event
let direction = from_wallet ? "🔑" : "💻"
log(direction + ' ' + name.join('.'), event)
})
export async function createWallet (type: any = 'Bitcoin'): Promise {
let keyring = new Keyring()
let transport = new MockTransport(keyring, type)
return createLedger(transport as any)
}