Skip to content

Commit

Permalink
Merge pull request #1460 from input-output-hk/feat/lw-9643-add-trezor…
Browse files Browse the repository at this point in the history
…-conway-era-certs

feat: add Trezor conway era certificates
  • Loading branch information
AngelCastilloB authored Sep 4, 2024
2 parents 077e000 + 644c32c commit 03e159f
Show file tree
Hide file tree
Showing 28 changed files with 1,437 additions and 722 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable sonarjs/cognitive-complexity, complexity, sonarjs/cognitive-complexity, max-statements */
import * as Crypto from '@cardano-sdk/crypto';
import { Address, RewardAddress } from '../../Cardano/Address';
import { CborReader, CborReaderState, CborWriter } from '../CBOR';
import { CborReader, CborReaderState, CborTag, CborWriter } from '../CBOR';
import { CborSet, Hash } from '../Common';
import { Certificate } from '../Certificates';
import { HexBlob } from '@cardano-sdk/util';
Expand Down Expand Up @@ -924,11 +924,26 @@ export class TransactionBody {
return this.#donation;
}

/**
* Computes the hash of the transaction body.
*
* @returns The hash of the transaction body.
*/
hash() {
const hash = Crypto.blake2b(Crypto.blake2b.BYTES).update(hexToBytes(this.toCbor())).digest();
return TransactionId.fromHexBlob(HexBlob.fromBytes(hash));
}

/**
* Checks if the transaction body has tagged sets.
*
* @returns true if the transaction body has tagged sets, false otherwise.
*/
hasTaggedSets() {
const reader = new CborReader(this.#inputs.toCbor());
return reader.peekState() === CborReaderState.Tag && reader.peekTag() === CborTag.Set;
}

/**
* Gets the size of the serialized map.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,14 @@ describe('TransactionBody', () => {
// hex characters only
expect(Buffer.from(txId, 'hex').toString('hex')).toEqual(txId);
});

it('hasTaggedSets() returns true for transaction bodies with 6.258 tags', () => {
const body = TransactionBody.fromCbor(conwayCborWithSets);
expect(body.hasTaggedSets()).toBe(true);
});

it('hasTaggedSets() returns false for transaction bodies without 6.258 tags', () => {
const body = TransactionBody.fromCbor(cbor);
expect(body.hasTaggedSets()).toBe(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,7 @@ export class MultiSigWallet {
async sign(multiSigTx: MultiSigTx): Promise<MultiSigTx> {
const currentSignatures = multiSigTx.getTransaction().witness.signatures;
const newSignatures = await this.#inMemoryKeyAgent.signTransaction(
{
body: multiSigTx.getTransaction().body,
hash: multiSigTx.getTransaction().id
},
Serialization.TransactionBody.fromCore(multiSigTx.getTransaction().body),
{ knownAddresses: [this.#address], txInKeyPathMap: {} },
{ additionalKeyPaths: [DERIVATION_PATH] }
);
Expand Down
10 changes: 2 additions & 8 deletions packages/e2e/test/wallet_epoch_0/SharedWallet/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,7 @@ const createWitnessData = async (
): Promise<Cardano.Witness> => ({
scripts: [paymentScript, stakingScript],
signatures: await keyAgent.signTransaction(
{
body: tx.body().toCore(),
hash: tx.getId()
},
tx.body(),
context,
{ ...options, additionalKeyPaths: [...(options?.additionalKeyPaths ?? []), DERIVATION_PATH] } // The key agent wont be able to find the right key if we don't provide the derivation path.
)
Expand Down Expand Up @@ -244,10 +241,7 @@ export class SharedWalletWitnesser implements Witnesser {
const extraSignatures: Cardano.Signatures = new Map();
if (options?.extraSigners) {
for (const extraSigner of options?.extraSigners) {
const extraSignature = await extraSigner.sign({
body: coreTx.body,
hash
});
const extraSignature = await extraSigner.sign(tx.body());
extraSignatures.set(extraSignature.pubKey, extraSignature.signature);
}
}
Expand Down
9 changes: 7 additions & 2 deletions packages/hardware-ledger/src/LedgerKeyAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Label,
ProtectedHeaderMap
} from '@emurgo/cardano-message-signing-nodejs';
import { Cardano, NotImplementedError, util as coreUtils } from '@cardano-sdk/core';
import { Cardano, NotImplementedError, Serialization, util as coreUtils } from '@cardano-sdk/core';
import {
CardanoKeyConst,
Cip1852PathLevelIndexes,
Expand Down Expand Up @@ -688,10 +688,12 @@ export class LedgerKeyAgent extends KeyAgentBase {
// however, multi sig transaction do not reference the CIP-1854 directly, but rather the script hash
// so we need to be able to instruct the HW to sign the transaction with arbitrary keys.
async signTransaction(
{ body, hash }: Cardano.TxBodyWithHash,
txBody: Serialization.TransactionBody,
{ knownAddresses, txInKeyPathMap }: SignTransactionContext
): Promise<Cardano.Signatures> {
try {
const body = txBody.toCore();
const hash = txBody.hash() as unknown as HexBlob;
const dRepPublicKey = await this.derivePublicKey(util.DREP_KEY_DERIVATION_PATH);
const dRepKeyHashHex = (await Crypto.Ed25519PublicKey.fromHex(dRepPublicKey).hash()).hex();
const ledgerTxData = await toLedgerTx(body, {
Expand All @@ -709,6 +711,9 @@ export class LedgerKeyAgent extends KeyAgentBase {

const signingMode = LedgerKeyAgent.getSigningMode(ledgerTxData);
const result = await deviceConnection.signTransaction({
options: {
tagCborSets: txBody.hasTaggedSets()
},
signingMode,
tx: ledgerTxData
});
Expand Down
Loading

0 comments on commit 03e159f

Please sign in to comment.