Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
waitForDevices(async device => {
// const accounts = await scanAccountsOnDevice({
// devicePath: device.path,
// currencyId: 'bitcoin_testnet',
// })
// console.log(accounts)
try {
console.log(`> Creating transport`)
const transport = await CommNodeHid.open(device.path)
// transport.setDebugMode(true)
console.log(`> Instanciate BTC app`)
const hwApp = new Btc(transport)
console.log(`> Get currency`)
const currency = await getCurrency('bitcoin_testnet')
console.log(`> Create wallet`)
const wallet = CREATE ? await createWallet('khalil', currency) : await getWallet('khalil')
console.log(`> Create account`)
const account = CREATE ? await createAccount(wallet, hwApp) : await wallet.getAccount(0)
console.log(`> Sync account`)
if (CREATE) {
await syncAccount(account)
}
console.log(`> Create transaction`)
async function example() {
const transport = await TransportNodeHid.create(5000);
transport.setDebugMode(true);
const appBtc = new AppBtc(transport);
const o = await appBtc.getWalletPublicKey("44'/0'/0'/0");
console.log("getWalletPublicKey:", o);
}
async function scanAccountsOnDevice(props) {
try {
const { devicePath, currencyId } = props
console.log(`get or create wallet`)
const wallet = await getOrCreateWallet(currencyId)
console.log(`open device`)
const transport = await CommNodeHid.open(devicePath)
console.log(`create app`)
const hwApp = new Btc(transport)
console.log(`scan account`)
const accounts = await scanNextAccount(wallet, hwApp)
console.log(accounts)
return []
} catch (err) {
console.log(err)
}
}
async transport => {
try {
transport.setDebugMode(true);
const btc = new AppBtc(transport);
const { bitcoinAddress } = await btc.getWalletPublicKey(
path,
verify
);
this.setState({ address: bitcoinAddress });
} catch (error) {
this.setState({ error });
}
},
error => {
const { publicKey, chainCode } = await withDevice(devicePath)(transport =>
from(new Btc(transport).getWalletPublicKey(derivation)),
).toPromise()
onGetLedgerBitcoinAddress = async () => {
try {
this.setState({ error: null });
const transport = await TransportU2F.create();
const btc = new Btc(transport);
const { bitcoinAddress } = await btc.getWalletPublicKey("44'/0'/0'/0");
this.setState({ address: bitcoinAddress });
} catch (error) {
this.setState({ error });
}
};
onGetLedgerEthereumAddress = async () => {
const resolver: Resolver = async (
transport,
{ currency, path, verify, derivationMode, skipAppFailSafeCheck }
) => {
const btc = new Btc(transport);
const format = getAddressFormatDerivationMode(derivationMode);
invariant(
format === "legacy" || format === "p2sh" || format === "bech32",
"unsupported format %s",
format
);
const { bitcoinAddress, publicKey, chainCode } = await btc.getWalletPublicKey(
path,
{
verify,
format
}
);
if (!skipAppFailSafeCheck) {
if (isUnsubscribed()) return;
const derivationModes = getDerivationModesForCurrency(currency);
for (let i = 0; i < derivationModes.length; i++) {
const derivationMode = derivationModes[i];
const isSegwit = isSegwitDerivationMode(derivationMode);
const unsplitFork = isUnsplitDerivationMode(derivationMode)
? currency.forkedFrom
: null;
const { coinType } = unsplitFork
? getCryptoCurrencyById(unsplitFork)
: currency;
const path = `${isSegwit ? "49" : "44"}'/${coinType}'`;
const hwApp = new Btc(transport);
const { publicKey: seedIdentifier } = await hwApp.getWalletPublicKey(
path,
false,
isSegwit,
);
if (isUnsubscribed()) return;
const walletName = getWalletName({
seedIdentifier,
currency,
derivationMode,
});
const wallet = await getOrCreateWallet({
core,
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (this._ledgerBtc) {
_context.next = 5;
break;
}
_context.next = 3;
return Transport.create();
case 3:
transport = _context.sent;
this._ledgerBtc = new LedgerBtc(transport);
case 5:
case 'end':
return _context.stop();
}
}
}, _callee, this);
}));
export default async (
transport: Transport<*>,
currency: CryptoCurrency,
path: string,
{
segwit = true,
verify = false,
}: {
segwit?: boolean,
verify?: boolean,
},
) => {
const btc = new Btc(transport)
const { bitcoinAddress, publicKey } = await btc.getWalletPublicKey(path, verify, segwit)
const { bitcoinLikeInfo } = currency
if (bitcoinLikeInfo) {
const { P2SH, P2PKH } = await getBitcoinLikeInfo(transport)
if (P2SH !== bitcoinLikeInfo.P2SH || P2PKH !== bitcoinLikeInfo.P2PKH) {
if (
currency.id in oldP2SH &&
P2SH === oldP2SH[currency.id] &&
P2PKH === bitcoinLikeInfo.P2PKH
) {
throw new UpdateYourApp(`UpdateYourApp ${currency.id}`, currency)
}
throw new BtcUnmatchedApp(`BtcUnmatchedApp ${currency.id}`, currency)
}
}