Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.portisCallInProgress = new Promise( async (resolve, reject) => {
try {
await this.portisCallInProgress
} catch (e) {
console.error(e)
}
for (let i = 0; i < msg.length; i++) {
const { addressNList, coin } = msg[i];
const bitcoinSlip44 = 0x80000000 + slip44ByCoin('Bitcoin')
// TODO we really shouldnt be every using the "bitcoin" string parameter but is here for now to make it work with their btc address on their portis wallet.
const portisResult = await this.portis.getExtendedPublicKey(addressNListToBIP32(addressNList), addressNList[1] === bitcoinSlip44 ? 'Bitcoin' : '')
const { result, error } = portisResult
if(error)
reject(error)
publicKeys.push({ xpub: result })
}
resolve(publicKeys)
})
return this.portisCallInProgress
export async function ethGetAddress (transport: TrezorTransport, msg: ETHGetAddress): Promise {
console.assert(!msg.showDisplay || !!msg.address,
"HDWalletTrezor::ethGetAddress: expected address is required for showDisplay")
let args: any = {
path: addressNListToBIP32(msg.addressNList),
showOnTrezor: msg.showDisplay !== false,
}
if (msg.address)
args.address = msg.address
let res = await transport.call('ethereumGetAddress', args)
handleError(transport, res, "Could not get ETH address from Trezor")
return res.payload.address
}
function describeUTXOPath (path: BIP32Path, coin: Coin, scriptType: BTCInputScriptType): PathDescription {
let pathStr = addressNListToBIP32(path)
let unknown: PathDescription = {
verbose: pathStr,
coin,
scriptType,
isKnown: false
}
if (!Btc.btcSupportsCoin(coin))
return unknown
if (!Btc.btcSupportsScriptType(coin, scriptType))
return unknown
if (path.length !== 3 && path.length !== 5)
return unknown
export async function btcGetAddress (msg: BTCGetAddress, portis: any): Promise {
if(!msg.addressNList.length)
throw new Error('Empty addressNList')
const scriptType = msg.scriptType
const purpose = msg.addressNList[0]
const hardPath = hardenedPath(msg.addressNList)
const hardPathString = addressNListToBIP32(hardPath)
const { result: xpub } = await portis.getExtendedPublicKey(hardPathString, "Bitcoin")
const relPath = relativePath(msg.addressNList)
const relPathString = addressNListToBIP32(relPath).substr(2)
const args = { pubkey: fromBase58(xpub).derivePath(relPathString).publicKey }
let result
switch (scriptType) {
case BTCInputScriptType.SpendAddress:
result = payments.p2pkh(args)
break
case BTCInputScriptType.SpendWitness:
result = payments.p2wpkh(args)
break
function describeUTXOPath (path: core.BIP32Path, coin: core.Coin, scriptType: core.BTCInputScriptType) {
let pathStr = core.addressNListToBIP32(path)
let unknown: core.PathDescription = {
verbose: pathStr,
coin,
scriptType,
isKnown: false
}
if (!btc.btcSupportsCoin(coin))
return unknown
if (!btc.btcSupportsScriptType(coin, scriptType))
return unknown
if (path.length !== 3 && path.length !== 5)
return unknown
export async function btcGetAddress (transport: LedgerTransport, msg: BTCGetAddress): Promise {
const bip32path = addressNListToBIP32(msg.addressNList)
const opts = {
verify: !!msg.showDisplay,
format: translateScriptType(msg.scriptType)
}
const res = await transport.call('Btc', 'getWalletPublicKey', bip32path, opts)
handleError(res, transport, 'Unable to obtain BTC address from device')
return res.payload.bitcoinAddress
}
function describeUTXOPath (path: BIP32Path, coin: Coin, scriptType: BTCInputScriptType) {
let pathStr = addressNListToBIP32(path)
let unknown: PathDescription = {
verbose: pathStr,
coin,
scriptType,
isKnown: false
}
if (!Btc.btcSupportsCoin(coin))
return unknown
if (!Btc.btcSupportsScriptType(coin, scriptType))
return unknown
if (path.length !== 3 && path.length !== 5)
return unknown
function describeCosmosPath (path: BIP32Path): PathDescription {
let pathStr = addressNListToBIP32(path)
let unknown: PathDescription = {
verbose: pathStr,
coin: 'Atom',
isKnown: false
}
if (path.length != 5) {
return unknown
}
if (path[0] != 0x80000000 + 44) {
return unknown
}
if (path[1] != 0x80000000 + slip44ByCoin('Atom')) {
return unknown
function describeETHPath (path: BIP32Path): PathDescription {
let pathStr = addressNListToBIP32(path)
let unknown: PathDescription = {
verbose: pathStr,
coin: 'Ethereum',
isKnown: false
}
if (path.length !== 5)
return unknown
if (path[0] !== 0x80000000 + 44)
return unknown
if (path[1] !== 0x80000000 + slip44ByCoin('Ethereum'))
return unknown
if ((path[2] & 0x80000000) >>> 0 !== 0x80000000)