We need to sign the transaction using our secret key to prove that we own the Ripple account and we are authorized to send money. The api.sign function mentioned in the following takes the prepared JSON from the previous step and our account's secret key as input to sign the transaction. Your secret key is used to sign the transaction locally and it isn't sent to the Ripple network:
const {signedTransaction} = api.sign(prepared.txJSON, sourceSecret);