Skip to content

Commit

Permalink
fix: resolve transaction signature mismatch with cosigners (#1324)
Browse files Browse the repository at this point in the history
* fix: signature mismatch with cosigners

* chore: update SDK packages

* chore: add todo task

* fix: use non-extended key hash in shared wallet script

---------

Co-authored-by: Martynas Kazlauskas <martynas.kazlauskas@iohk.io>
  • Loading branch information
greatertomi and mkazlauskas authored Jul 26, 2024
1 parent e09e9e2 commit 0e9f83b
Show file tree
Hide file tree
Showing 13 changed files with 318 additions and 339 deletions.
18 changes: 9 additions & 9 deletions apps/browser-extension-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@
},
"dependencies": {
"@ant-design/icons": "^4.7.0",
"@cardano-sdk/cardano-services-client": "0.19.9",
"@cardano-sdk/core": "0.34.0",
"@cardano-sdk/dapp-connector": "0.12.21",
"@cardano-sdk/input-selection": "0.13.3",
"@cardano-sdk/tx-construction": "0.19.3",
"@cardano-sdk/util": "0.15.2",
"@cardano-sdk/wallet": "0.38.4",
"@cardano-sdk/web-extension": "0.29.4",
"@cardano-sdk/cardano-services-client": "0.19.14",
"@cardano-sdk/core": "0.35.4",
"@cardano-sdk/dapp-connector": "0.12.26",
"@cardano-sdk/input-selection": "0.13.8",
"@cardano-sdk/tx-construction": "0.19.8",
"@cardano-sdk/util": "0.15.4",
"@cardano-sdk/wallet": "0.39.1",
"@cardano-sdk/web-extension": "0.29.10",
"@emurgo/cip14-js": "~3.0.1",
"@input-output-hk/lace-ui-toolkit": "1.9.0",
"@lace/cardano": "0.1.0",
Expand Down Expand Up @@ -91,7 +91,7 @@
"zustand": "3.5.14"
},
"devDependencies": {
"@cardano-sdk/hardware-ledger": "0.9.10",
"@cardano-sdk/hardware-ledger": "0.10.1",
"@emurgo/cardano-message-signing-asmjs": "1.0.1",
"@types/dotenv-webpack": "7.0.3",
"@types/pluralize": "^0.0.29",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
transactionSummaryInspector,
Cardano,
TokenTransferValue,
tokenTransferInspector
tokenTransferInspector,
Milliseconds
} from '@cardano-sdk/core';
import { createWalletAssetProvider } from '@cardano-sdk/wallet';
import { Skeleton } from 'antd';
Expand All @@ -31,6 +32,9 @@ interface DappTransactionContainerProps {
errorMessage?: string;
}

// eslint-disable-next-line no-magic-numbers
const TIMEOUT = 6000 as Milliseconds;

export const DappTransactionContainer = withAddressBookContext(
({ errorMessage }: DappTransactionContainerProps): React.ReactElement => {
const {
Expand Down Expand Up @@ -106,7 +110,9 @@ export const DappTransactionContainer = withAddressBookContext(
assetInfo$: inMemoryWallet.assetInfo$,
tx,
logger
})
}),
timeout: TIMEOUT,
logger: console
}),
summary: transactionSummaryInspector({
addresses: userAddresses,
Expand All @@ -118,7 +124,9 @@ export const DappTransactionContainer = withAddressBookContext(
assetInfo$: inMemoryWallet.assetInfo$,
tx,
logger
})
}),
timeout: TIMEOUT,
logger: console
})
});

Expand Down
11 changes: 10 additions & 1 deletion apps/browser-extension-wallet/src/hooks/useWalletManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -852,11 +852,12 @@ export const useWalletManager = (): UseWalletManager => {
name: signer.name,
sharedWalletKey: Wallet.Crypto.Bip32PublicKeyHex(signer.sharedWalletKey)
})),
// TODO: LW-11069 multiSigExtendedPublicKey can be removed from wallet metadata and this key fetched from accounts since addAccount is called
multiSigExtendedPublicKey: sharedWalletKey
},
ownSigners: [
{
accountIndex: 0,
accountIndex,
paymentScriptKeyPath,
purpose: KeyManagement.KeyPurpose.MULTI_SIG,
stakingScriptKeyPath,
Expand All @@ -870,6 +871,14 @@ export const useWalletManager = (): UseWalletManager => {

const scriptWalletId = await walletRepository.addWallet(createScriptWalletProps);

await walletRepository.addAccount({
accountIndex,
extendedAccountPublicKey: sharedWalletKey,
metadata: { name: defaultAccountName(accountIndex) },
purpose: KeyManagement.KeyPurpose.MULTI_SIG,
walletId: ownSignerWalletId
});

await walletManager.activate({
walletId: scriptWalletId,
chainId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { ActivityStatus, CoSignersListItem, SharedWalletTransactionDetails, SignPolicy, TxSummary } from '@lace/core';
import {
ActivityStatus,
CoSignersListItem,
hasSigned,
SharedWalletTransactionDetails,
SignPolicy,
TxSummary
} from '@lace/core';
import React, { ReactElement, useEffect, useMemo, useState } from 'react';
import { useWalletStore } from '@stores';
import { Wallet } from '@lace/cardano';
Expand Down Expand Up @@ -41,27 +48,29 @@ export const SharedWalletTransactionDetailsWrapper = withAddressBookContext(
({ amountTransformer, activityInfo, direction }: SharedWalletTransactionDetailsProxyProps): ReactElement => {
const {
walletUI: { cardanoCoin },
walletInfo
walletInfo,
activityDetail
} = useWalletStore();
const { sharedWalletKey, getSignPolicy, coSigners } = useSharedWalletData();
const [signPolicy, setSignPolicy] = useState<SignPolicy>();
const [transactionCosigners, setTransactionCosigners] = useState<CoSignersListItem[]>([]);
const { list: addressList } = useAddressBookContext();

useEffect(() => {
(async () => {
const policy = await getSignPolicy('payment');
setSignPolicy(policy);
})();
}, [getSignPolicy]);

const transactionCosigners = useMemo(
(): CoSignersListItem[] =>
coSigners?.map((signer) => ({
...signer,
signed: false
})) || [],
[coSigners]
);
const signatures = (activityDetail.activity as Wallet.Cardano.Tx).witness.signatures;
const cosignersWithSignStatus = await Promise.all(
coSigners.map(async (signer) => ({
...signer,
signed: await hasSigned(signer.sharedWalletKey, 'payment', signatures)
}))
);
setTransactionCosigners(cosignersWithSignStatus);
})();
}, [activityDetail.activity, coSigners, getSignPolicy, sharedWalletKey]);

const addressToNameMap = useMemo(
() => new Map<string, string>(addressList?.map((item: AddressListType) => [item.address, item.name])),
Expand Down
18 changes: 9 additions & 9 deletions packages/cardano/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@
"watch": "yarn build --watch"
},
"dependencies": {
"@cardano-sdk/cardano-services-client": "0.19.9",
"@cardano-sdk/core": "0.34.0",
"@cardano-sdk/crypto": "0.1.25",
"@cardano-sdk/hardware-ledger": "0.9.10",
"@cardano-sdk/hardware-trezor": "0.4.30",
"@cardano-sdk/key-management": "0.20.8",
"@cardano-sdk/util": "0.15.2",
"@cardano-sdk/wallet": "0.38.4",
"@cardano-sdk/web-extension": "0.29.4",
"@cardano-sdk/cardano-services-client": "0.19.14",
"@cardano-sdk/core": "0.35.4",
"@cardano-sdk/crypto": "0.1.28",
"@cardano-sdk/hardware-ledger": "0.10.1",
"@cardano-sdk/hardware-trezor": "0.4.35",
"@cardano-sdk/key-management": "0.21.1",
"@cardano-sdk/util": "0.15.4",
"@cardano-sdk/wallet": "0.39.1",
"@cardano-sdk/web-extension": "0.29.10",
"@lace/common": "0.1.0",
"@ledgerhq/devices": "^8.2.1",
"@stablelib/chacha20poly1305": "1.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export const deriveEd25519KeyHashFromBip32PublicKey = async (
): Promise<Crypto.Ed25519KeyHashHex> => {
const accountKey = Crypto.Bip32PublicKey.fromHex(key);
const derivedKey = await accountKey.derive([derivationPath.role, derivationPath.index]);
return Crypto.Ed25519KeyHashHex(await derivedKey.hash());
const derivedKeyHash = await derivedKey.toRawKey().hash();
return Crypto.Ed25519KeyHashHex(derivedKeyHash.hex());
};
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"watch": "yarn build --watch"
},
"dependencies": {
"@cardano-sdk/util": "0.15.2",
"@cardano-sdk/util": "0.15.4",
"antd": "^4.24.10",
"classnames": "^2.3.1",
"jdenticon": "3.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
},
"dependencies": {
"@ant-design/icons": "^4.7.0",
"@cardano-sdk/wallet": "0.38.4",
"@cardano-sdk/web-extension": "0.29.3",
"@cardano-sdk/wallet": "0.39.1",
"@cardano-sdk/web-extension": "0.29.10",
"@input-output-hk/lace-ui-toolkit": "1.9.0",
"@lace/cardano": "0.1.0",
"@lace/common": "0.1.0",
Expand Down
Empty file.
14 changes: 14 additions & 0 deletions packages/core/src/shared-wallets/utils/has-signed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Wallet } from '@lace/cardano';
import { paymentScriptKeyPath, stakingScriptKeyPath } from '@src/shared-wallets';

export const hasSigned = async (
key: Wallet.Crypto.Bip32PublicKeyHex,
type: 'payment' | 'staking',
signatures: Wallet.Cardano.Signatures,
) => {
const derivationPath = type === 'payment' ? paymentScriptKeyPath : stakingScriptKeyPath;
const accountKey = Wallet.Crypto.Bip32PublicKey.fromHex(key);
const xkey = await accountKey.derive([derivationPath.role, derivationPath.index]);
const hash = xkey.toRawKey().hex();
return signatures.has(hash);
};
1 change: 1 addition & 0 deletions packages/core/src/shared-wallets/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './derivation-path';
export * from './is-shared-wallet';
export * from './get-shared-wallet-sign-policy';
export * from './get-key-hash-to-wallet-name-map';
export * from './has-signed';
22 changes: 11 additions & 11 deletions packages/staking/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@
},
"devDependencies": {
"@babel/core": "^7.21.0",
"@cardano-sdk/core": "0.34.0",
"@cardano-sdk/input-selection": "0.13.3",
"@cardano-sdk/tx-construction": "0.19.3",
"@cardano-sdk/util": "0.15.2",
"@cardano-sdk/wallet": "0.38.4",
"@cardano-sdk/web-extension": "0.29.4",
"@cardano-sdk/core": "0.35.4",
"@cardano-sdk/input-selection": "0.13.8",
"@cardano-sdk/tx-construction": "0.19.8",
"@cardano-sdk/util": "0.15.4",
"@cardano-sdk/wallet": "0.39.1",
"@cardano-sdk/web-extension": "0.29.10",
"@storybook/addon-actions": "^7.6.7",
"@storybook/addon-essentials": "^7.6.7",
"@storybook/addon-interactions": "^7.6.7",
Expand Down Expand Up @@ -126,11 +126,11 @@
"wait-on": "^7.0.1"
},
"peerDependencies": {
"@cardano-sdk/input-selection": "0.13.3",
"@cardano-sdk/tx-construction": "0.19.3",
"@cardano-sdk/util": "0.15.2",
"@cardano-sdk/wallet": "0.38.4",
"@cardano-sdk/web-extension": "0.29.4",
"@cardano-sdk/input-selection": "0.13.8",
"@cardano-sdk/tx-construction": "0.19.8",
"@cardano-sdk/util": "0.15.4",
"@cardano-sdk/wallet": "0.39.1",
"@cardano-sdk/web-extension": "0.29.10",
"@lace/cardano": "^0.1.0",
"@lace/common": "^0.1.0",
"@lace/core": "0.1.0",
Expand Down
Loading

0 comments on commit 0e9f83b

Please sign in to comment.