Skip to content

Commit

Permalink
Merge pull request #1259 from input-output-hk/feat/log-tx-id
Browse files Browse the repository at this point in the history
feat(web-extension): add log of transaction id when signing
  • Loading branch information
mkazlauskas committed May 9, 2024
2 parents 898a821 + ba5871b commit 5a51904
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
3 changes: 2 additions & 1 deletion packages/e2e/test/web-extension/extension/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ const signingCoordinator = new SigningCoordinator(
keyAgentFactory: createKeyAgentFactory({
bip32Ed25519: new Crypto.SodiumBip32Ed25519(),
logger
})
}),
logger
}
);

Expand Down
3 changes: 2 additions & 1 deletion packages/web-extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ const signingCoordinator = new SigningCoordinator(
keyAgentFactory: createKeyAgentFactory({
bip32Ed25519: new Crypto.SodiumBip32Ed25519(),
logger
})
}),
logger
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CustomError } from 'ts-custom-error';
import { InMemoryWallet, WalletType } from '../types';
import { KeyAgent, SignBlobResult, TrezorConfig, errors } from '@cardano-sdk/key-management';
import { KeyAgentFactory } from './KeyAgentFactory';
import { Logger } from 'ts-log';
import {
RequestBase,
RequestContext,
Expand All @@ -17,6 +18,7 @@ import {
} from './types';
import { Subject } from 'rxjs';
import { WrongTargetError } from '../../messaging';
import { contextLogger } from '@cardano-sdk/util';

export type HardwareKeyAgentOptions = TrezorConfig;

Expand All @@ -26,6 +28,7 @@ export type SigningCoordinatorProps = {

export type SigningCoordinatorDependencies = {
keyAgentFactory: KeyAgentFactory;
logger: Logger;
};

class NoRejectError extends CustomError {
Expand Down Expand Up @@ -72,10 +75,12 @@ export class SigningCoordinator<WalletMetadata extends {}, AccountMetadata exten
readonly signDataRequest$ = new Subject<SignDataRequest<WalletMetadata, AccountMetadata>>();
readonly #hwOptions: HardwareKeyAgentOptions;
readonly #keyAgentFactory: KeyAgentFactory;
readonly #logger: Logger;

constructor(props: SigningCoordinatorProps, { keyAgentFactory }: SigningCoordinatorDependencies) {
constructor(props: SigningCoordinatorProps, { keyAgentFactory, logger }: SigningCoordinatorDependencies) {
this.#hwOptions = props.hwOptions;
this.#keyAgentFactory = keyAgentFactory;
this.#logger = contextLogger(logger, 'SigningCoordinator');
}

async signTransaction(
Expand All @@ -91,15 +96,18 @@ export class SigningCoordinator<WalletMetadata extends {}, AccountMetadata exten
transaction,
walletType: requestContext.wallet.type
},
(keyAgent) =>
keyAgent.signTransaction(
(keyAgent) => {
const hash = transaction.getId();
this.#logger.info('Signing transaction', hash);
return keyAgent.signTransaction(
{
body: transaction.body().toCore(),
hash: transaction.getId()
hash
},
signContext,
options
)
);
}
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Ed25519PublicKeyHex, Ed25519SignatureHex, Hash28ByteBase16 } from '@car
import { HexBlob } from '@cardano-sdk/util';
import { InMemoryWallet, KeyAgentFactory, SigningCoordinator, WalletType, WrongTargetError } from '../../src';
import { createAccount } from './util';
import { dummyLogger } from 'ts-log';
import { firstValueFrom } from 'rxjs';

describe('SigningCoordinator', () => {
Expand Down Expand Up @@ -54,7 +55,7 @@ describe('SigningCoordinator', () => {
}
}
},
{ keyAgentFactory }
{ keyAgentFactory, logger: dummyLogger }
);
});

Expand Down

0 comments on commit 5a51904

Please sign in to comment.