Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const unlockError = this.unlockAccount(accountId as string, password);
if (unlockError) {
this.setState({ unlockError });
return;
}
}
if (payload) {
return makeExtrinsicSignature(
{
...payload,
...((isV2 && tip && !payload.tip) ? { tip: tip.toString() } : {})
},
queueTx,
keyring.getPair(accountId as string)
);
}
const submittable = extrinsic as SubmittableExtrinsic;
assert(submittable, 'Expected an extrinsic to be supplied to sendExtrinsic');
return isUnsigned
// eslint-disable-next-line @typescript-eslint/unbound-method
? this.makeExtrinsicCall(submittable, queueTx, submittable.send)
// eslint-disable-next-line @typescript-eslint/unbound-method
: this.makeExtrinsicCall(submittable, queueTx, submittable.signAndSend, keyring.getPair(accountId as string));
}
...((isV2 && tip && !payload.tip) ? { tip: tip.toString() } : {})
},
queueTx,
keyring.getPair(accountId as string)
);
}
const submittable = extrinsic as SubmittableExtrinsic;
assert(submittable, 'Expected an extrinsic to be supplied to sendExtrinsic');
return isUnsigned
// eslint-disable-next-line @typescript-eslint/unbound-method
? this.makeExtrinsicCall(submittable, queueTx, submittable.send)
// eslint-disable-next-line @typescript-eslint/unbound-method
: this.makeExtrinsicCall(submittable, queueTx, submittable.signAndSend, keyring.getPair(accountId as string));
}
export default function signMessage (publicKey: Uint8Array, nonce: BN | number, value: Uint8Array, apiSupport: EncodingVersions): Signed {
const message = encodeCall(publicKey, nonce, value, apiSupport);
const signature = keyring.getPair(publicKey).sign(message);
console.log(`signMessage : message :: ${u8aToHex(message)}`);
console.log(`signMessage : signature :: ${u8aToHex(signature)}`);
return {
data: u8aConcat(message, signature),
message,
signature
};
}
private unlockAccount (accountId: string, password?: string): string | null {
let publicKey;
try {
publicKey = keyring.decodeAddress(accountId);
} catch (error) {
console.error(error);
return 'unable to decode address';
}
const pair = keyring.getPair(publicKey);
if (!pair.isLocked()) {
return null;
}
try {
pair.decodePkcs8(password);
} catch (error) {
console.error(error);
return error.message;
}
return null;
}
const _doBackup = (): void => {
try {
const addressKeyring = address && keyring.getPair(address);
const json = addressKeyring && keyring.backupAccount(addressKeyring, password);
const blob = new Blob([JSON.stringify(json)], { type: 'application/json; charset=utf-8' });
FileSaver.saveAs(blob, `${address}.json`);
} catch (error) {
setBackupFailed(true);
console.error(error);
return;
}
onClose();
};
function Derive ({ className, from, onClose, t }: Props): React.ReactElement {
const { queueAction } = useContext(StatusContext);
const [source] = useState(keyring.getPair(from));
const [{ address, deriveError }, setDerived] = useState({ address: null, deriveError: null });
const [isConfirmationOpen, setIsConfirmationOpen] = useState(false);
const [isLocked, setIsLocked] = useState(source.isLocked);
const [{ isNameValid, name }, setName] = useState({ isNameValid: false, name: '' });
const [{ isPassValid, password }, setPassword] = useState({ isPassValid: false, password: '' });
const [rootPass, setRootPass] = useState('');
const [suri, setSuri] = useState('');
const debouncedSuri = useDebounce(suri);
const isValid = !!address && !deriveError && isNameValid && isPassValid;
const { cancelButtonRef, submitButtonRef, onInputEnterKey, onInputEscapeKey } = useForm();
useEffect((): void => {
setIsLocked(source.isLocked);
}, [source]);
const _onGenesisChange = (genesisHash: string | null): void => {
const account = keyring.getPair(address);
account && keyring.saveAccountMeta(account, { ...account.meta, genesisHash });
setGenesisHash(genesisHash);
};
const _onFavorite = (): void => toggleFavorite(address);
private getSigningPair (address: string): KeyringPair {
const pair = keyring.getPair(address);
assert(pair, 'Unable to find keypair');
return pair;
}
private signingApprovePassword ({ id, password }: RequestSigningApprovePassword): boolean {
const queued = this.state.getSignRequest(id);
assert(queued, 'Unable to find request');
const { request, resolve, reject } = queued;
const pair = keyring.getPair(request.inner.address);
if (!pair) {
reject(new Error('Unable to find pair'));
return false;
}
pair.decodePkcs8(password);
const result = request.sign(registry, pair);
pair.lock();
resolve({
id,
...result
});