From d5bc041d78cfa3ec1e6cca60682074e06dffe194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Schere?= <61954243+MartinSchere@users.noreply.github.com> Date: Thu, 27 Feb 2025 10:44:04 +0100 Subject: [PATCH] feat: allow hot wallet to sign with stake key (#251) * feat: allow hot wallet to sign with stake key * fix: fmt * chore: changeset --- .changeset/ten-stingrays-study.md | 5 +++++ packages/blaze-wallet/src/hot.ts | 28 ++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 .changeset/ten-stingrays-study.md diff --git a/.changeset/ten-stingrays-study.md b/.changeset/ten-stingrays-study.md new file mode 100644 index 0000000..335523c --- /dev/null +++ b/.changeset/ten-stingrays-study.md @@ -0,0 +1,5 @@ +--- +"@blaze-cardano/wallet": minor +--- + +Add the ability to sign with the stake key diff --git a/packages/blaze-wallet/src/hot.ts b/packages/blaze-wallet/src/hot.ts index 68c60ea..693ac39 100644 --- a/packages/blaze-wallet/src/hot.ts +++ b/packages/blaze-wallet/src/hot.ts @@ -215,11 +215,13 @@ export class HotWallet implements Wallet { * Requests a transaction signature from the wallet. * @param {string} tx - The transaction to sign. * @param {boolean} partialSign - Whether to partially sign the transaction. + * @param {boolean} signWithStakeKey - Whether to also sign the transaction with the stake key. * @returns {Promise} - The signed transaction. */ async signTransaction( tx: Transaction, partialSign: boolean = true, + signWithStakeKey: boolean = false, ): Promise { if (partialSign == false) { throw new Error( @@ -230,12 +232,34 @@ export class HotWallet implements Wallet { const signature = await this.signingKey .toRawKey() .sign(HexBlob(tx.getId())); + const tws = new TransactionWitnessSet(); - const vkw = new VkeyWitness( + + const payemntVkw = new VkeyWitness( this.publicKey.toRawKey().hex(), signature.hex(), ); - tws.setVkeys(CborSet.fromCore([vkw.toCore()], VkeyWitness.fromCore)); + + const vkeys = [payemntVkw.toCore()]; + + if (signWithStakeKey) { + if (!this.stakeSigningKey) { + throw new Error( + "signTx: Signing with stake key requested but no stake key is available", + ); + } + const stakeSignature = await this.stakeSigningKey + .toRawKey() + .sign(HexBlob(tx.getId())); + const stakePublicKey = (await this.stakeSigningKey.toPublic()) + .toRawKey() + .hex(); + const stakeVkw = new VkeyWitness(stakePublicKey, stakeSignature.hex()); + + vkeys.push(stakeVkw.toCore()); + } + + tws.setVkeys(CborSet.fromCore(vkeys, VkeyWitness.fromCore)); return tws; }