Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
protected async getKeyInfo(path: DerivationPath): Promise {
if (this.cache[path.prefix]) {
return this.cache[path.prefix];
}
const response = await TrezorConnect.getPublicKey({ path: path.prefix });
return {
publicKey: response.payload.publicKey,
chainCode: response.payload.chainCode
};
}
async values => {
TrezorConnect.manifest({
email: 'bridge-trezor@urbit.org',
appUrl: 'https://github.com/urbit/bridge',
});
const { success, payload } = await TrezorConnect.getPublicKey({
path: values.hdPath,
});
if (!success) {
return { [FORM_ERROR]: 'Failed to authenticate with your Trezor.' };
}
const publicKey = Buffer.from(payload.publicKey, 'hex');
const chainCode = Buffer.from(payload.chainCode, 'hex');
const pub = secp256k1.publicKeyConvert(publicKey, true);
const hd = bip32.fromPublicKey(pub, chainCode);
setWallet(Just(hd));
setWalletHdPath(values.hdPath);
},
[setWallet, setWalletHdPath]
protected async getKeyInfo(path: DerivationPath): Promise {
if (this.cache[path.prefix]) {
return this.cache[path.prefix];
}
const response = await TrezorConnect.getPublicKey({ path: path.prefix });
return {
publicKey: response.payload.publicKey,
chainCode: response.payload.chainCode
};
}
public async prefetch(paths: DerivationPath[]): Promise<{ [key: string]: KeyInfo }> {
const bundle = paths.filter(path => !path.isHardened).map(path => ({ path: path.prefix }));
const response = await TrezorConnect.getPublicKey({ bundle });
for (const { serializedPath, chainCode, publicKey } of response.payload) {
this.cache[serializedPath] = { chainCode, publicKey };
}
return this.cache;
}
public async prefetch(paths: DerivationPath[]): Promise<{ [key: string]: KeyInfo }> {
const bundle = paths.filter(path => !path.isHardened).map(path => ({ path: path.prefix }));
const response = await TrezorConnect.getPublicKey({ bundle });
for (const { serializedPath, chainCode, publicKey } of response.payload) {
this.cache[serializedPath] = { chainCode, publicKey };
}
return this.cache;
}
return new Promise(resolve => {
TrezorConnect.getPublicKey({
path: dpath
}).then((res: any) => {
if (res.success) {
resolve({
publicKey: res.payload.publicKey,
chainCode: res.payload.chainCode
});
} else {
throw new Error(res.error);
}
});
});
}
async pollDevice() {
const { setWallet, setWalletHdPath } = this.props;
const { hdpath } = this.state;
TrezorConnect.manifest({
email: 'bridge-trezor@urbit.org',
appUrl: 'https://github.com/urbit/bridge',
});
TrezorConnect.getPublicKey({ path: hdpath }).then(info => {
if (info.success === true) {
const payload = info.payload;
const publicKey = Buffer.from(payload.publicKey, 'hex');
const chainCode = Buffer.from(payload.chainCode, 'hex');
const pub = secp256k1.publicKeyConvert(publicKey, true);
const hd = bip32.fromPublicKey(pub, chainCode);
setWallet(Maybe.Just(hd));
setWalletHdPath(hdpath);
} else {
setWallet(Maybe.Nothing());
}
});
}