Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// setup the notification (same a FF default background, white text)
extension.browserAction.setBadgeBackgroundColor({ color: '#d90000' });
// listen to all messages and handle appropriately
extension.runtime.onConnect.addListener((port): void => {
// shouldn't happen, however... only listen to what we know about
assert([PORT_CONTENT, PORT_EXTENSION].includes(port.name), `Unknown connection from ${port.name}`);
// message and disconnect handlers
port.onMessage.addListener((data): void => handlers(data, port));
port.onDisconnect.addListener((): void => console.log(`Disconnected from ${port.name}`));
});
// initial setup
cryptoWaitReady()
.then((): void => {
console.log('crypto initialized');
// load all the keyring data
keyring.loadAll({ store: new ExtensionStore(), type: 'sr25519' });
console.log('initialization completed');
})
.catch((error): void => {
console.error('initialization failed', error);
});
// Copyright 2017-2019 @polkadot/app-accounts authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { cryptoWaitReady, mnemonicGenerate, mnemonicToMiniSecret, naclKeypairFromSeed, schnorrkelKeypairFromSeed } from '@polkadot/util-crypto';
const ctx: Worker = self as unknown as Worker;
cryptoWaitReady().catch((): void => {
// ignore
});
ctx.onmessage = async ({ data: { pairType } }): Promise => {
await cryptoWaitReady();
const seed = mnemonicGenerate();
const miniSecret = mnemonicToMiniSecret(seed);
const { publicKey } = pairType === 'sr25519'
? schnorrkelKeypairFromSeed(miniSecret)
: naclKeypairFromSeed(miniSecret);
ctx.postMessage({
publicKey,
seed
});
export default async function cmdSign (account: string, seed: string, type: Curves, [payload]: string[]): Promise {
await cryptoWaitReady();
const keyring = new Keyring({ type });
const pair = keyring.createFromUri(seed);
const signature = pair.sign(hexToU8a(payload));
const prefix = new Uint8Array(curvePrefixes[type]);
console.log(`Signature: ${u8aToHex(u8aConcat(prefix, signature))}`);
process.exit(0);
}
indicator++;
if (indicator === INDICATORS.length) {
indicator = 0;
}
process.stdout.write(`\r[${INDICATORS[indicator]}] ${(total.toString().match(NUMBER_REGEX) || []).join(',')} keys in ${(elapsed).toFixed(2)}s (${(total / elapsed).toFixed(0)} keys/s)`);
}
function showBest (): void {
const { address, count, mnemonic, offset, seed } = best;
console.log(`\r::: ${address.slice(0, offset)}${chalk.cyan(address.slice(offset, count + offset))}${address.slice(count + offset)} <= ${u8aToHex(seed)} (count=${count}, offset=${offset})${mnemonic ? '\n ' + mnemonic : ''}`);
}
cryptoWaitReady()
.then((): void => {
while (true) {
const nextBest = generator(options).found.reduce((best, match): Best => {
if ((match.count > best.count) || ((match.count === best.count) && (match.offset <= best.offset))) {
return match;
}
return best;
}, best);
total += options.runs;
if (nextBest.address !== best.address) {
best = nextBest;
showBest();
showProgress();
<section>
<label>ss58 format</label>
<select value="{ss58Format}">
{settings.availablePrefixes
.filter((_, index): boolean => index !== 0)
.map(({ text, value }): React.ReactNode => (
<option value="{value}">{text}</option>
))
}
</select>
</section>
);
}
cryptoWaitReady().then((): void => {
keyring.loadAll({ ss58Format: 42, type: 'sr25519' });
ReactDOM.render(, rootElement);
});
public async start (config: ConfigPartial): Promise {
await cryptoWaitReady();
const verStatus = await clientId.getNpmStatus();
const status = verStatus
? `(${verStatus})`
: '';
this.sync = config.sync;
l.log(`Running version ${clientId.version} ${status}`);
l.log(`Initializing for ${this.sync} sync on chain ${config.chain}`);
this.chain = new Chain(config as Config);
if (config.p2p && config.p2p.active && config.p2p.port) {
this.p2p = new P2p(config as Config, this.chain);
}