Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
sign(tx: Transaction): Promise {
if (tx.txParams && tx.txParams.pubKey) {
// attempt to find the address
const senderAddress = zcrypto.getAddressFromPublicKey(tx.txParams.pubKey);
if (!this.accounts[senderAddress]) {
throw new Error(
`Could not sign the transaction with ${senderAddress} as it does not exist`,
);
}
return this.signWith(tx, senderAddress);
}
if (!this.defaultAccount) {
throw new Error('This wallet has no default account.');
}
return this.signWith(tx, this.defaultAccount.address);
}
constructor(privateKey: string) {
this.privateKey = this.normalizePrivateKey(privateKey);
this.publicKey = zcrypto.getPubKeyFromPrivateKey(this.privateKey);
this.address = zcrypto.getAddressFromPublicKey(this.publicKey);
this.bech32Address = zcrypto.toBech32Address(this.address);
}
get senderAddress(): string {
if (!this.pubKey) {
return '0'.repeat(40);
}
return getAddressFromPublicKey(this.pubKey);
}