Skip to content

Commit 07a7305

Browse files
feat!: witnesser witness method now takes a complete serializable Transaction
BREAKING CHANGE: Witnesser witness method now takes a complete serializable Transaction
1 parent 89f8a31 commit 07a7305

File tree

5 files changed

+36
-12
lines changed

5 files changed

+36
-12
lines changed

packages/key-management/src/InMemoryKeyAgent.ts

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ export class InMemoryKeyAgent extends KeyAgentBase implements KeyAgent {
161161
async #decryptRootPrivateKey(noCache?: true) {
162162
const passphrase = await getPassphraseRethrowTypedError(() => this.#getPassphrase(noCache));
163163
let decryptedRootKeyBytes: Uint8Array;
164+
164165
try {
165166
decryptedRootKeyBytes = await emip3decrypt(
166167
new Uint8Array((this.serializableData as SerializableInMemoryKeyAgentData).encryptedRootPrivateKeyBytes),

packages/key-management/src/types.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as Crypto from '@cardano-sdk/crypto';
2-
import { Cardano } from '@cardano-sdk/core';
2+
import { Cardano, Serialization } from '@cardano-sdk/core';
33
import { HexBlob, OpaqueString, Shutdown } from '@cardano-sdk/util';
44
import { Logger } from 'ts-log';
55
import type { Runtime } from 'webextension-polyfill';
@@ -222,12 +222,13 @@ export interface Witnesser {
222222
/**
223223
* Generates the witness data for a given transaction.
224224
*
225-
* @param txInternals The transaction body along with its hash for which the witness data is to be generated.
225+
* @param transaction The transaction along with its hash for which the witness data is to be generated.
226+
* @param context The witness sign transaction context
226227
* @param options Optional additional parameters that may influence how the witness data is generated.
227228
* @returns A promise that resolves to the generated witness data for the transaction.
228229
*/
229230
witness(
230-
txInternals: Cardano.TxBodyWithHash,
231+
transaction: Serialization.Transaction,
231232
context: SignTransactionContext,
232233
options?: WitnessOptions
233234
): Promise<Cardano.Witness>;

packages/key-management/src/util/createWitnesser.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
WitnessOptions,
88
Witnesser
99
} from '../types';
10-
import { Cardano } from '@cardano-sdk/core';
10+
import { Cardano, Serialization } from '@cardano-sdk/core';
1111
import { HexBlob } from '@cardano-sdk/util';
1212

1313
/** A witnesser that uses a {@link KeyAgent} to generate witness data for a transaction. */
@@ -19,11 +19,20 @@ export class Bip32Ed25519Witnesser implements Witnesser {
1919
}
2020

2121
async witness(
22-
txInternals: Cardano.TxBodyWithHash,
22+
tx: Serialization.Transaction,
2323
context: SignTransactionContext,
2424
options: WitnessOptions
2525
): Promise<Cardano.Witness> {
26-
return { signatures: await this.#keyAgent.signTransaction(txInternals, context, options) };
26+
return {
27+
signatures: await this.#keyAgent.signTransaction(
28+
{
29+
body: tx.body().toCore(),
30+
hash: tx.getId()
31+
},
32+
context,
33+
options
34+
)
35+
};
2736
}
2837

2938
async signBlob(

packages/key-management/test/util/createWitnesser.test.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AsyncKeyAgent, SignBlobResult, Witnesser, util } from '../../src';
2-
import { Cardano } from '@cardano-sdk/core';
2+
import { Cardano, Serialization } from '@cardano-sdk/core';
33
import { HexBlob } from '@cardano-sdk/util';
44

55
describe('createBip32Ed25519Witnesser', () => {
@@ -24,14 +24,20 @@ describe('createBip32Ed25519Witnesser', () => {
2424
});
2525

2626
it('signTransaction is unchanged', async () => {
27+
const transaction = new Serialization.Transaction(
28+
Serialization.TransactionBody.fromCore({ fee: 20_000n, inputs: [], outputs: [], validityInterval: {} }),
29+
new Serialization.TransactionWitnessSet()
30+
);
31+
2732
const txInternals = {
28-
body: { fee: 20_000n, inputs: [], outputs: [], validityInterval: {} } as Cardano.HydratedTxBody,
29-
hash: Cardano.TransactionId('8561258e210352fba2ac0488afed67b3427a27ccf1d41ec030c98a8199bc22ec')
33+
body: transaction.body().toCore(),
34+
hash: Cardano.TransactionId('3643bb5fe745ba0532977f82ecf54699963c97adef2626f7c780225d218e9ba6')
3035
};
36+
3137
const options = { knownAddresses: [], txInKeyPathMap: {} };
3238
const result = {} as Cardano.Signatures;
3339
asyncKeyAgent.signTransaction.mockResolvedValueOnce(result);
34-
await expect(witnesser.witness(txInternals, options)).resolves.toEqual({ signatures: result });
40+
await expect(witnesser.witness(transaction, options)).resolves.toEqual({ signatures: result });
3541
expect(asyncKeyAgent.signTransaction).toBeCalledWith(txInternals, options, void 0);
3642
});
3743
});

packages/tx-construction/src/tx-builder/finalizeTx.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Cardano, TxCBOR } from '@cardano-sdk/core';
1+
import { Cardano, Serialization, TxCBOR } from '@cardano-sdk/core';
22
import { FinalizeTxDependencies, SignedTx, TxContext } from './types';
33
import {
44
SignTransactionContext,
@@ -15,7 +15,14 @@ const getSignatures = async (
1515
signingOptions?: SignTransactionOptions,
1616
extraSigners?: TransactionSigner[]
1717
) => {
18-
const { signatures } = await witnesser.witness(txInternals, signingContext, signingOptions);
18+
const { signatures } = await witnesser.witness(
19+
new Serialization.Transaction(
20+
Serialization.TransactionBody.fromCore(txInternals.body),
21+
new Serialization.TransactionWitnessSet()
22+
),
23+
signingContext,
24+
signingOptions
25+
);
1926

2027
if (extraSigners) {
2128
for (const extraSigner of extraSigners) {

0 commit comments

Comments
 (0)