Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
senderPublicKey,
type,
}) => {
if (!(recipientId || recipientPublicKey)) {
throw new Error(
'Either recipientId or recipientPublicKey must be provided.',
);
}
if (typeof recipientId !== 'undefined') {
validateAddress(recipientId);
}
if (typeof recipientPublicKey !== 'undefined') {
validatePublicKey(recipientPublicKey);
}
if (
recipientId &&
recipientPublicKey &&
recipientId !== getAddressFromPublicKey(recipientPublicKey)
) {
throw new Error('recipientId does not match recipientPublicKey.');
}
if (!senderPublicKey) {
throw new Error(
'senderPublicKey must be provided.',
);
}
async run(): Promise {
const {
args,
flags: { password: passwordSource },
} = this.parse(ForgingCommand);
const { status, publicKey }: Args = args;
validatePublicKey(publicKey);
const client = getAPIClient(this.userConfig.api);
const { password } = await getInputsFromSources({
password: {
source: passwordSource,
},
});
const result = await processInput(client, status, publicKey, password);
this.print(result);
}
}
if (!recipientId && !recipientPublicKey) {
throw new Error(
'Either recipientId or recipientPublicKey must be provided.',
);
}
if (typeof recipientId !== 'undefined') {
validateAddress(recipientId);
}
if (typeof senderPublicKey !== 'undefined') {
validatePublicKey(senderPublicKey);
}
if (typeof recipientPublicKey !== 'undefined') {
validatePublicKey(recipientPublicKey);
}
if (
recipientId &&
recipientPublicKey &&
recipientId !== getAddressFromPublicKey(recipientPublicKey)
) {
throw new Error('recipientId does not match recipientPublicKey.');
}
if (data && data.length > 0) {
if (typeof data !== 'string') {
throw new Error(
'Invalid encoding in transaction data. Data must be utf-8 encoded string.',
);
}
if (!validateTransferAmount(amount)) {
throw new Error('Amount must be a valid number in string format.');
}
if (!recipientId && !recipientPublicKey) {
throw new Error(
'Either recipientId or recipientPublicKey must be provided.',
);
}
if (typeof recipientId !== 'undefined') {
validateAddress(recipientId);
}
if (typeof senderPublicKey !== 'undefined') {
validatePublicKey(senderPublicKey);
}
if (typeof recipientPublicKey !== 'undefined') {
validatePublicKey(recipientPublicKey);
}
if (
recipientId &&
recipientPublicKey &&
recipientId !== getAddressFromPublicKey(recipientPublicKey)
) {
throw new Error('recipientId does not match recipientPublicKey.');
}
if (data && data.length > 0) {
if (typeof data !== 'string') {
if (
recipientId &&
recipientPublicKey &&
recipientId !== getAddressFromPublicKey(recipientPublicKey)
) {
throw new Error('recipientId does not match recipientPublicKey.');
}
if (!senderPublicKey) {
throw new Error(
'senderPublicKey must be provided.',
);
}
if (typeof senderPublicKey !== 'undefined') {
validatePublicKey(senderPublicKey);
}
if (!type || typeof type !== 'number') {
throw new Error(
'type must be provided.',
);
}
};