Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function recodeAddress (address: string, accounts: AccountJson[], genesisHash?: string | null): [string, AccountJson | null, Chain] {
// decode and create a shortcut for the encoded address
const publicKey = decodeAddress(address);
// find our account using the actual publicKey, and then find the associated chain
const account = findAccount(accounts, publicKey);
const chain = findChain((account && account.genesisHash) || genesisHash);
return [
// always allow the actual settings to override the display
encodeAddress(publicKey, settings.prefix === -1 ? chain.ss58Format : settings.prefix),
account,
chain
];
}
function generateIcon (seed: string = encodeAddress(randomAsU8a(32))): void {
const start = Date.now();
if (isNull(element)) {
throw new Error('Unable to find #demo element');
}
element.appendChild(
identicon(seed, 100, 'padded')
);
console.log(`Icon generated in ${(Date.now() - start)}ms`);
}
export default function generator (test: string[][], options: GeneratorOptions): GeneratorMatch {
const mnemonic = options.withHex
? undefined
: mnemonicGenerate(12);
const seed = mnemonic
? mnemonicToMiniSecret(mnemonic)
: randomAsU8a();
const pair = options.type === 'sr25519'
? schnorrkelKeypairFromSeed(seed)
: naclKeypairFromSeed(seed);
const address = encodeAddress(pair.publicKey);
const { count, offset } = calculate(test, address, options);
return {
address,
count,
mnemonic,
offset,
seed
};
}
public toString (): string {
const length = AccountIndex.calcLength(this);
return encodeAddress(this.toU8a().subarray(0, length));
}
get address (): string {
return encodeAddress(publicKey);
},
get meta (): KeyringPair$Meta {
function encodeAccount (value: string | Uint8Array, prefix?: Prefix): Account {
try {
const address = isU8a(value) || isHex(value)
? encodeAddress(value as string, prefix)
: value;
const publicKey = u8aToHex(decodeAddress(address, false, prefix));
return { address, publicKey };
} catch (error) {
return { address: '', publicKey: '0x' };
}
}
public static getDerivedStateFromProps ({ prefix = IdentityIcon.prefix, value }: Props, prevState: State): State | null {
try {
const address = isU8a(value) || isHex(value)
? encodeAddress(value, prefix)
: (value || '');
const publicKey = u8aToHex(decodeAddress(address, false, prefix));
return address === prevState.address
? null
: {
address,
publicKey
};
} catch (error) {
return {
address: '',
publicKey: '0x'
};
}
}