Skip to content

Commit ba65055

Browse files
Feat/lw 11111 remove shared transactions from local storage (#1355)
* chore: bump SDK version * fix: replace finalizeTx with addSignatures when updating shared wallet witness - Lace no longer stores multi-sig transactions in local storage for eventual inspection, but instead retrieves them directly from the observable wallet signed$ observable when needed
1 parent 630a688 commit ba65055

File tree

14 files changed

+159
-199
lines changed

14 files changed

+159
-199
lines changed

apps/browser-extension-wallet/package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@
4141
},
4242
"dependencies": {
4343
"@ant-design/icons": "^4.7.0",
44-
"@cardano-sdk/cardano-services-client": "0.19.16",
45-
"@cardano-sdk/core": "0.37.0",
46-
"@cardano-sdk/dapp-connector": "0.12.28",
47-
"@cardano-sdk/input-selection": "0.13.10",
48-
"@cardano-sdk/tx-construction": "0.19.10",
44+
"@cardano-sdk/cardano-services-client": "0.20.0",
45+
"@cardano-sdk/core": "0.38.0",
46+
"@cardano-sdk/dapp-connector": "0.12.29",
47+
"@cardano-sdk/input-selection": "0.13.11",
48+
"@cardano-sdk/tx-construction": "0.20.0",
4949
"@cardano-sdk/util": "0.15.4",
50-
"@cardano-sdk/wallet": "0.41.0",
51-
"@cardano-sdk/web-extension": "0.30.0",
50+
"@cardano-sdk/wallet": "0.42.0",
51+
"@cardano-sdk/web-extension": "0.31.0",
5252
"@emurgo/cip14-js": "~3.0.1",
5353
"@input-output-hk/lace-ui-toolkit": "1.15.1",
5454
"@lace/cardano": "0.1.0",
@@ -95,7 +95,7 @@
9595
"zustand": "3.5.14"
9696
},
9797
"devDependencies": {
98-
"@cardano-sdk/hardware-ledger": "0.11.0",
98+
"@cardano-sdk/hardware-ledger": "0.11.1",
9999
"@emurgo/cardano-message-signing-asmjs": "1.0.1",
100100
"@openpgp/web-stream-tools": "0.0.11-patch-0",
101101
"@pdfme/common": "^4.0.2",

apps/browser-extension-wallet/src/hooks/__tests__/useCollateral.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ import { act } from 'react-dom/test-utils';
2323
import { waitFor } from '@testing-library/react';
2424
import { TxInspection } from '@cardano-sdk/tx-construction';
2525
import { WitnessedTx } from '@cardano-sdk/key-management';
26-
import { Cardano, HandleResolution, TxCBOR } from '@cardano-sdk/core';
26+
import { Cardano, HandleResolution, Serialization } from '@cardano-sdk/core';
2727
import { WalletType } from '@cardano-sdk/web-extension';
2828

2929
const txHash = 'e6eb1c8c806ae7f4d9fe148e9c23853607ffba692ef0a464688911ad3374a932';
3030
const address =
3131
'addr_test1qp9xn9gwdjkj0w300vc8xgctegvgty2ks4n875zdzjkkzy3qz69wq6z9tpmuj9tutsc7f0s4kx6mvh3mwupmjdjx2fjqf0q2j2';
3232
const addresses$ = new BehaviorSubject([{ address }]);
3333
const signedTx = {
34-
cbor: '' as TxCBOR,
34+
cbor: '' as Serialization.TxCBOR,
3535
tx: { id: 'txId' } as Cardano.Tx,
3636
context: {
3737
handles: [] as HandleResolution[],

apps/browser-extension-wallet/src/stores/slices/wallet-activities-slice.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import groupBy from 'lodash/groupBy';
77
import flatten from 'lodash/flatten';
88
import memoize from 'lodash/memoize';
99
import { Wallet } from '@lace/cardano';
10-
import { Reward, TxCBOR, epochSlotsCalc } from '@cardano-sdk/core';
10+
import { Reward, Serialization, epochSlotsCalc } from '@cardano-sdk/core';
1111
import {
1212
pendingTxTransformer,
1313
txHistoryTransformer,
@@ -241,7 +241,7 @@ const mapWalletActivities = memoize(
241241
...transformedTx,
242242
onClick: () => {
243243
if (sendAnalytics) sendAnalytics();
244-
const deserializedTx: Wallet.Cardano.Tx = TxCBOR.deserialize(tx.cbor);
244+
const deserializedTx: Wallet.Cardano.Tx = Serialization.TxCBOR.deserialize(tx.cbor);
245245
setTransactionActivityDetail({
246246
activity: deserializedTx,
247247
direction: TxDirections.Outgoing,

apps/browser-extension-wallet/src/types/local-storage.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { StakingBrowserPreferences } from '@lace/staking';
44
import { currencyCode } from '@providers/currency/constants';
55
import { ADASymbols } from '@src/utils/constants';
66
import { EnvironmentTypes } from '@stores';
7-
import { SharedWalletTransactionSchema } from '@lace/core';
87

98
export interface WalletStorage {
109
name: string;
@@ -67,6 +66,4 @@ export interface ILocalStorage {
6766
showMultiAddressModal?: boolean;
6867
userAvatar?: Record<`${EnvironmentTypes}${string}`, string>;
6968
isCustomSubmitApiEnabled?: Record<EnvironmentTypes, CustomSubmitApiConfig>;
70-
// TODO: LW-11111 remove once we switch to read signatures from $signed stream
71-
sharedWalletTransactions?: Record<string, SharedWalletTransactionSchema>;
7269
}

apps/browser-extension-wallet/src/views/browser-view/features/activity/components/SharedWalletTransactionDetailsWrapper.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ import {
99
import React, { ReactElement, useEffect, useMemo, useState } from 'react';
1010
import { useWalletStore } from '@stores';
1111
import { Wallet } from '@lace/cardano';
12-
import { useLocalStorage, useSharedWalletData } from '@hooks';
12+
import { useSharedWalletData } from '@hooks';
1313
import { AddressListType, getTransactionData } from '@views/browser/features/activity';
1414
import { useAddressBookContext, withAddressBookContext } from '@src/features/address-book/context';
1515
import { TransactionActivityDetail, TxDirection, TxDirections } from '@types';
16-
import { Serialization } from '@cardano-sdk/core';
1716

1817
interface SharedWalletTransactionDetailsProxyProps {
1918
amountTransformer: (amount: string) => string;
@@ -56,7 +55,6 @@ export const SharedWalletTransactionDetailsWrapper = withAddressBookContext(
5655
const [signPolicy, setSignPolicy] = useState<SignPolicy>();
5756
const [transactionCosigners, setTransactionCosigners] = useState<CoSignersListItem[]>([]);
5857
const { list: addressList } = useAddressBookContext();
59-
const [sharedWalletTransactions] = useLocalStorage('sharedWalletTransactions', {});
6058

6159
useEffect(() => {
6260
(async () => {
@@ -66,12 +64,8 @@ export const SharedWalletTransactionDetailsWrapper = withAddressBookContext(
6664
if (!coSigners) return;
6765

6866
const currentTransactionDetail = activityDetail.activity as Wallet.Cardano.Tx;
69-
const sharedWalletTransaction = sharedWalletTransactions[currentTransactionDetail.id];
7067

71-
const signatures = sharedWalletTransaction
72-
? Serialization.Transaction.fromCbor(Wallet.TxCBOR(sharedWalletTransaction.transaction.cborHex)).toCore()
73-
.witness.signatures
74-
: currentTransactionDetail.witness.signatures;
68+
const signatures = currentTransactionDetail.witness.signatures;
7569

7670
const cosignersWithSignStatus = await Promise.all(
7771
coSigners.map(async (signer) => ({
@@ -81,7 +75,7 @@ export const SharedWalletTransactionDetailsWrapper = withAddressBookContext(
8175
);
8276
setTransactionCosigners(cosignersWithSignStatus);
8377
})();
84-
}, [activityDetail.activity, coSigners, getSignPolicy, sharedWalletKey, sharedWalletTransactions]);
78+
}, [activityDetail.activity, coSigners, getSignPolicy, sharedWalletKey]);
8579

8680
const addressToNameMap = useMemo(
8781
() => new Map<string, string>(addressList?.map((item: AddressListType) => [item.address, item.name])),

apps/browser-extension-wallet/src/views/browser-view/features/activity/helpers/__tests__/pending-tx-transformer.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ let actualLovelacesToAdaString: any;
99
import { pendingTxTransformer } from '../pending-tx-transformer';
1010
import { Wallet } from '@lace/cardano';
1111
import { cardanoCoin } from '@utils/constants';
12-
import { TxCBOR } from '@cardano-sdk/core';
12+
import { Serialization } from '@cardano-sdk/core';
1313
import { DEFAULT_TIME_FORMAT, formatTime } from '@src/utils/format-date';
1414
import BigNumber from 'bignumber.js';
1515
import { getFormattedFiatAmount } from '../common-tx-transformer';
@@ -85,7 +85,7 @@ describe('Testing tx transformers utils', () => {
8585
mockLovelacesToAdaString.mockImplementation(actualLovelacesToAdaString);
8686
const date = new Date();
8787
const result = await pendingTxTransformer({
88-
tx: { ...pendingTx, cbor: TxCBOR.serialize(pendingTx) },
88+
tx: { ...pendingTx, cbor: Serialization.TxCBOR.serialize(pendingTx) },
8989
walletAddresses: [
9090
{
9191
address: sendingAddress,

apps/browser-extension-wallet/src/views/browser-view/features/send-transaction/components/ImportSharedWalletTransaction.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ export const ImportSharedWalletTransaction = (): JSX.Element => {
1717
onCancel={config.onClose}
1818
onContinue={async (txData) => {
1919
if (!txData) return;
20-
const importedSharedWalletTx = Serialization.Transaction.fromCbor(Wallet.TxCBOR(txData.transaction.cborHex));
20+
const importedSharedWalletTx = Serialization.Transaction.fromCbor(
21+
Wallet.Serialization.TxCBOR(txData.transaction.cborHex)
22+
);
2123
const { body, id } = importedSharedWalletTx.toCore();
2224

2325
const ownAddresses = new Set([...(walletState?.addresses || [])].map((address) => address.address));

apps/browser-extension-wallet/src/views/browser-view/features/send-transaction/components/SendTransactionDrawer/Footer.tsx

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { useHandleClose } from './Header';
2525
import { useWalletStore } from '@src/stores';
2626
import { AddressFormFooter } from './AddressFormFooter';
2727
import { METADATA_MAX_LENGTH, sectionsConfig } from '../../constants';
28-
import { useHandleResolver, useLocalStorage, useNetwork, useSharedWalletData } from '@hooks';
28+
import { useHandleResolver, useNetwork, useSharedWalletData } from '@hooks';
2929
import { PostHogAction, TxCreationType, TX_CREATION_TYPE_KEY } from '@providers/AnalyticsProvider/analyticsTracker';
3030
import { buttonIds } from '@hooks/useEnterKeyPress';
3131
import { AssetPickerFooter } from './AssetPickerFooter';
@@ -40,8 +40,7 @@ import { txSubmitted$ } from '@providers/AnalyticsProvider/onChain';
4040
import { withSignTxConfirmation } from '@lib/wallet-api-ui';
4141
import type { TranslationKey } from '@lace/translation';
4242
import { Serialization } from '@cardano-sdk/core';
43-
import { exportMultisigTransaction, constructMultiSigTransactionData, useSecrets } from '@lace/core';
44-
import { mergeWitnesses } from './utils';
43+
import { exportMultisigTransaction, useSecrets } from '@lace/core';
4544

4645
export const nextStepBtnLabels: Partial<Record<Sections, TranslationKey>> = {
4746
[Sections.FORM]: 'browserView.transaction.send.footer.review',
@@ -91,10 +90,6 @@ export const Footer = withAddressBookContext(
9190
const handleResolver = useHandleResolver();
9291
const { isMaxAdaLoading } = useMaxAdaStatus();
9392
const { sharedWalletKey, getSignPolicy } = useSharedWalletData();
94-
const [sharedWalletTransactions, { updateLocalStorage: updateSharedWalletTransactions }] = useLocalStorage(
95-
'sharedWalletTransactions',
96-
{}
97-
);
9893

9994
const isSummaryStep = currentSection.currentSection === Sections.SUMMARY;
10095

@@ -173,19 +168,10 @@ export const Footer = withAddressBookContext(
173168
let sharedWalletTx: Serialization.Transaction;
174169
try {
175170
if (builtTxData.importedSharedWalletTx) {
176-
const { auxiliaryData, body, id, witness } = builtTxData.importedSharedWalletTx.toCore();
177-
const txWithOwnSignature = await inMemoryWallet.finalizeTx({
178-
tx: {
179-
body,
180-
hash: id
181-
},
182-
auxiliaryData,
183-
bodyCbor: builtTxData.importedSharedWalletTx.body().toCbor()
184-
});
185-
builtTxData.importedSharedWalletTx.setWitnessSet(
186-
Serialization.TransactionWitnessSet.fromCore(mergeWitnesses(txWithOwnSignature.witness, witness))
171+
sharedWalletTx = Serialization.Transaction.fromCbor(
172+
await inMemoryWallet.addSignatures({ tx: builtTxData.importedSharedWalletTx.toCbor() })
187173
);
188-
sharedWalletTx = builtTxData.importedSharedWalletTx;
174+
builtTxData.importedSharedWalletTx.setWitnessSet(sharedWalletTx.witnessSet());
189175
} else {
190176
const { auxiliaryData, body, hash } = await builtTxData.tx.inspect();
191177
const signedTx = await inMemoryWallet.finalizeTx({
@@ -221,14 +207,6 @@ export const Footer = withAddressBookContext(
221207
});
222208
}
223209

224-
const transaction = {
225-
[sharedWalletTx.toCore().id.toString()]: constructMultiSigTransactionData({
226-
cborHex: sharedWalletTx.toCbor(),
227-
publicKey: sharedWalletKey,
228-
chainId: currentChain
229-
})
230-
};
231-
updateSharedWalletTransactions({ ...sharedWalletTransactions, ...transaction });
232210
setBuiltTxData({ ...builtTxData, collectedEnoughSharedWalletTxSignatures });
233211
} else {
234212
const signedTx = await builtTxData.tx.sign();
@@ -245,17 +223,7 @@ export const Footer = withAddressBookContext(
245223
creationType: TxCreationType.Internal
246224
});
247225
}
248-
}, [
249-
builtTxData,
250-
currentChain,
251-
getSignPolicy,
252-
inMemoryWallet,
253-
isSharedWallet,
254-
setBuiltTxData,
255-
sharedWalletKey,
256-
sharedWalletTransactions,
257-
updateSharedWalletTransactions
258-
]);
226+
}, [builtTxData, currentChain, getSignPolicy, inMemoryWallet, isSharedWallet, setBuiltTxData, sharedWalletKey]);
259227

260228
const handleVerifyPass = useCallback(async () => {
261229
if (isSubmitingTx) return;

packages/cardano/package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@
4040
"watch": "yarn build --watch"
4141
},
4242
"dependencies": {
43-
"@cardano-sdk/cardano-services-client": "0.19.16",
44-
"@cardano-sdk/core": "0.37.0",
43+
"@cardano-sdk/cardano-services-client": "0.20.0",
44+
"@cardano-sdk/core": "0.38.0",
4545
"@cardano-sdk/crypto": "0.1.29",
46-
"@cardano-sdk/hardware-ledger": "0.11.0",
47-
"@cardano-sdk/hardware-trezor": "0.5.0",
48-
"@cardano-sdk/key-management": "0.22.0",
46+
"@cardano-sdk/hardware-ledger": "0.11.1",
47+
"@cardano-sdk/hardware-trezor": "0.5.1",
48+
"@cardano-sdk/key-management": "0.23.0",
4949
"@cardano-sdk/util": "0.15.4",
50-
"@cardano-sdk/wallet": "0.41.0",
51-
"@cardano-sdk/web-extension": "0.30.0",
50+
"@cardano-sdk/wallet": "0.42.0",
51+
"@cardano-sdk/web-extension": "0.31.0",
5252
"@lace/common": "0.1.0",
5353
"@ledgerhq/devices": "^8.2.1",
5454
"@stablelib/chacha20poly1305": "1.0.1",
@@ -70,7 +70,7 @@
7070
"webextension-polyfill": "0.8.0"
7171
},
7272
"devDependencies": {
73-
"@cardano-sdk/util-dev": "0.22.1",
73+
"@cardano-sdk/util-dev": "0.22.2",
7474
"@emurgo/cardano-message-signing-browser": "1.0.1",
7575
"rollup-plugin-polyfill-node": "^0.8.0",
7676
"typescript": "^4.9.5"

packages/cardano/src/wallet/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export {
2020
EraSummary,
2121
HandleResolution,
2222
TxSubmissionError,
23-
TxCBOR
23+
Serialization
2424
} from '@cardano-sdk/core';
2525

2626
export { testnetEraSummaries } from '@cardano-sdk/util-dev';

0 commit comments

Comments
 (0)