Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
name: "on segwit recipient",
transaction: fromTransactionRaw({
family: "bitcoin",
recipient: "34N7XoKANmM66ZQDyQf2j8hPaTo6v5X8eA",
amount: "998",
feePerByte: "1",
networkInfo
}),
expectedStatus: {
amount: BigNumber("998"),
// FIXME fee are reloaded?
// estimatedFees: BigNumber("250"),
// totalSpent: BigNumber("1248"),
errors: {},
warnings: {
feeTooHigh: new FeeTooHigh()
}
}
},
{
name: "on native segwit recipient",
transaction: fromTransactionRaw({
family: "bitcoin",
recipient: "bc1qqmxqdrkxgx6swrvjl9l2e6szvvkg45all5u4fl",
amount: "997",
feePerByte: "1",
networkInfo
}),
expectedStatus: {
amount: BigNumber("997"),
// FIXME fee are reloaded?
// estimatedFees: BigNumber("250"),
{
raw: accountTZnew,
test: (expect, account) => {
expect(account.operations).toEqual([]);
},
transactions: [
{
name: "send 10% to existing tz",
transaction: t => ({
...t,
recipient: addressTZregular,
useAllAmount: true
}),
expectedStatus: {
errors: {
amount: new NotEnoughBalance()
},
warnings: {}
}
}
]
}
// FIXME libcore bugs
/*
{
raw: accountTZwithKT,
transactions: [
{
name: "from KT 1, send max to new account",
transaction: (t, account) => (
invariant(account.subAccounts, "subAccounts"),
};
let status = await bridge.getTransactionStatus(account, t);
expect(status.errors.recipient).toBeUndefined();
expect(status.errors.feePerByte).toEqual(new FeeNotLoaded());
t = await bridge.prepareTransaction(account, t);
expect(t.feePerByte).toBeInstanceOf(BigNumber);
t.feePerByte = BigNumber(1); // for predictible tests
status = await bridge.getTransactionStatus(account, t);
expect(status.errors.feePerByte).toBeUndefined();
t = {
...t,
feePerByte: BigNumber(0)
};
t = await bridge.prepareTransaction(account, t);
status = await bridge.getTransactionStatus(account, t);
expect(status.errors.feePerByte).toEqual(new FeeRequired());
});
log("ble-frame", "<= " + value.toString("hex"));
}),
share()
);
const notif = notifyObservable.subscribe();
const transport = new BluetoothTransport(
device,
writeC,
notifyObservable,
deviceModel
);
if (!device.gatt.connected) {
throw new DisconnectedDevice();
}
// eslint-disable-next-line require-atomic-updates
transportsCache[transport.id] = transport;
const onDisconnect = e => {
console.log("onDisconnect!", e);
delete transportsCache[transport.id];
transport.notYetDisconnected = false;
notif.unsubscribe();
device.removeEventListener("gattserverdisconnected", onDisconnect);
log("ble-verbose", `BleTransport(${transport.id}) disconnected`);
transport.emit("disconnect", e);
};
device.addEventListener("gattserverdisconnected", onDisconnect);
let beforeMTUTime = Date.now();
tap(value => {
logSubject.next({
type: 'ble-frame-read',
message: value.toString('hex'),
})
}),
share(),
)
const notif = notifyObservable.subscribe()
const deviceModel = null // FIXME
const transport = new BluetoothTransport(device, writeC, notifyObservable, deviceModel)
if (device.state === 'disconnected') {
throw new DisconnectedDevice()
}
transportsCache[transport.id] = transport
const onDisconnect = e => {
delete transportsCache[transport.id]
transport.notYetDisconnected = false
notif.unsubscribe()
device.removeListener('disconnect', onDisconnect)
logSubject.next({
type: 'verbose',
message: `BleTransport(${transport.id}) disconnected`,
})
transport.emit('disconnect', e)
}
device.addListener('disconnect', onDisconnect) // will it catch their own "on" events? peripheral.once('disconnect', callback);
return Promise.resolve().then(() => {
if (transportInstance) {
log("hid-verbose", "reusing opened transport instance");
return transportInstance;
}
const device = getDevices()[0];
if (!device) throw new CantOpenDevice("no device found");
log("hid-verbose", "new HID transport");
transportInstance = new TransportNodeHidSingleton(
new HID.HID(device.path)
);
const unlisten = listenDevices(
() => {},
() => {
// assume any ledger disconnection concerns current transport
if (transportInstance) {
transportInstance.emit("disconnect");
}
}
);
const onDisconnect = () => {
if (!transportInstance) return;
log("hid-verbose", "transport instance was disconnected");
submit = async () => {
const id = ++this.submitId;
const { password } = this.state;
const { unlock } = this.props;
if (!password) return;
try {
const credentials = await Keychain.getGenericPassword();
if (id !== this.submitId) return;
if (credentials && credentials.password === password) {
unlock();
} else if (credentials) {
Vibration.vibrate(VIBRATION_PATTERN_ERROR);
this.setState({
passwordError: new PasswordIncorrectError(),
password: "",
});
} else {
console.log("no credentials stored"); // eslint-disable-line
}
} catch (err) {
if (id !== this.submitId) return;
console.log("could not load credentials"); // eslint-disable-line
this.setState({ passwordError: err, password: "" });
}
};
const getHID = (): HID => {
// $FlowFixMe
const { hid } = navigator;
if (!hid)
throw new TransportError(
"navigator.hid is not supported",
"HIDNotSupported"
);
return hid;
};
function wrapU2FTransportError(originalError, message, id) {
const err = new TransportError(message, id);
// $FlowFixMe
err.originalError = originalError;
return err;
}
const attemptExchange = (
apdu: Buffer,
timeout: number,
scrambleKey: ?Buffer
): Promise => {
if (!scrambleKey) {
throw new TransportError(
"transport.setScrambleKey must be used to set a scramble key. Refer to documentation.",
"NoScrambleKey"
);
}
if (!navigator.credentials) {
throw new TransportError("WebAuthn not supported", "NotSupported");
}
return (
navigator.credentials
// $FlowFixMe
.get({
publicKey: {
timeout,
challenge: new Uint8Array(32),
allowCredentials: [
{
type: "public-key",
id: new Uint8Array(wrapApdu(apdu, scrambleKey))
}
]
}