Skip to content

Instantly share code, notes, and snippets.

@dimitardanailov
Created February 12, 2022 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimitardanailov/e9f44a5e6335202106d577c5b3811e8f to your computer and use it in GitHub Desktop.
Save dimitardanailov/e9f44a5e6335202106d577c5b3811e8f to your computer and use it in GitHub Desktop.
Algorand sign transaction
signTxn(sk: Uint8Array) {
// construct signed message
const sTxn: EncodedSignedTransaction = {
sig: this.rawSignTxn(sk),
txn: this.get_obj_for_encoding(),
};
// add AuthAddr if signing with a different key than From indicates
const keypair = nacl.keyPairFromSecretKey(sk);
const pubKeyFromSk = keypair.publicKey;
if (
address.encodeAddress(pubKeyFromSk) !==
address.encodeAddress(this.from.publicKey)
) {
sTxn.sgnr = Buffer.from(pubKeyFromSk);
}
return new Uint8Array(encoding.encode(sTxn));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment