Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(key-management): add payload to SignDataContext when signing cip8 structure #1087

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/key-management/src/cip8/cip30signData.ts
Original file line number Diff line number Diff line change
@@ -93,7 +93,8 @@ const signSigStructure = (
sender?: MessageSender
) => {
try {
return witnesser.signBlob(derivationPath, util.bytesToHex(sigStructure.to_bytes()), { address, sender });
const payload = util.bytesToHex(sigStructure.payload());
return witnesser.signBlob(derivationPath, util.bytesToHex(sigStructure.to_bytes()), { address, payload, sender });
} catch (error) {
throw new Cip30DataSignError(Cip30DataSignErrorCode.UserDeclined, 'Failed to sign', error);
}
2 changes: 2 additions & 0 deletions packages/key-management/src/types.ts
Original file line number Diff line number Diff line change
@@ -149,6 +149,8 @@ export interface SignTransactionContext {

export interface SignDataContext {
address?: Cardano.PaymentAddress | Cardano.RewardAccount | Cardano.DRepID;
/** Present when signing CIP-0008 structure */
payload?: HexBlob;
sender?: MessageSender;
}

9 changes: 7 additions & 2 deletions packages/key-management/test/cip8/cip30signData.test.ts
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ import { HexBlob } from '@cardano-sdk/util';
import { testAsyncKeyAgent, testKeyAgent } from '../mocks';

describe('cip30signData', () => {
const payload = HexBlob('abc123');
const addressDerivationPath = { index: 0, type: AddressType.External };
let keyAgent: KeyAgent;
let witnesser: Bip32Ed25519Witnesser;
@@ -39,7 +40,7 @@ describe('cip30signData', () => {
) => {
const dataSignature = await cip8.cip30signData({
knownAddresses,
payload: HexBlob('abc123'),
payload,
sender,
signWith,
witnesser
@@ -113,6 +114,10 @@ describe('cip30signData', () => {
const signBlobSpy = jest.spyOn(witnesser, 'signBlob');
const sender = { url: 'https://lace.io' };
await signAndDecode(address.address, [address], sender);
expect(signBlobSpy).toBeCalledWith(expect.anything(), expect.anything(), { address: address.address, sender });
expect(signBlobSpy).toBeCalledWith(expect.anything(), expect.anything(), {
address: address.address,
payload,
sender
});
});
});
5 changes: 3 additions & 2 deletions packages/wallet/test/PersonalWallet/methods.test.ts
Original file line number Diff line number Diff line change
@@ -438,8 +438,9 @@ describe('PersonalWallet methods', () => {
it('passes through context to witnesser', async () => {
const sender = { url: 'https://lace.io' };
const signBlobSpy = jest.spyOn(witnesser, 'signBlob');
await wallet.signData({ payload: HexBlob('abc123'), sender, signWith: address });
expect(signBlobSpy).toBeCalledWith(expect.anything(), expect.anything(), { address, sender });
const payload = HexBlob('abc123');
await wallet.signData({ payload, sender, signWith: address });
expect(signBlobSpy).toBeCalledWith(expect.anything(), expect.anything(), { address, payload, sender });
});

test('rejects if bech32 DRepID is not a type 6 address', async () => {