Skip to content

Commit

Permalink
feat: allow hot wallet to sign with stake key (#251)
Browse files Browse the repository at this point in the history
* feat: allow hot wallet to sign with stake key

* fix: fmt

* chore: changeset
  • Loading branch information
MartinSchere authored Feb 27, 2025
1 parent 3838b63 commit d5bc041
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/ten-stingrays-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blaze-cardano/wallet": minor
---

Add the ability to sign with the stake key
28 changes: 26 additions & 2 deletions packages/blaze-wallet/src/hot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TransactionWitnessSet>} - The signed transaction.
*/
async signTransaction(
tx: Transaction,
partialSign: boolean = true,
signWithStakeKey: boolean = false,
): Promise<TransactionWitnessSet> {
if (partialSign == false) {
throw new Error(
Expand All @@ -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;
}

Expand Down

0 comments on commit d5bc041

Please sign in to comment.