Skip to content

Commit 49909c9

Browse files
committed
feat: display raw key in message signing result
we were displaying only 'cose key' structure that wraps the raw key which does not for Glacier Drop
1 parent bf09dd4 commit 49909c9

File tree

5 files changed

+50
-5
lines changed

5 files changed

+50
-5
lines changed

apps/browser-extension-wallet/src/views/browser-view/features/sign-message/SignMessageDrawer.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,25 @@ export const SignMessageDrawer: React.FC = () => {
216216
className={styles.customTextArea}
217217
/>
218218
</div>
219+
<div className={styles.inputGroup}>
220+
<Flex justifyContent="space-between" alignItems="center">
221+
<Text.Body.Normal weight="$medium" data-testid={'result-message-key-label'}>
222+
{t('core.signMessage.rawKey')}
223+
</Text.Body.Normal>
224+
{renderCopyToClipboard({
225+
text: signatureObject.rawKey,
226+
handleCopy,
227+
t,
228+
testId: 'raw-public-key-copy-to-clipboard-button'
229+
})}
230+
</Flex>
231+
<TextArea
232+
value={signatureObject.rawKey}
233+
dataTestId="sign-message-raw-key"
234+
rows={4}
235+
className={styles.customTextArea}
236+
/>
237+
</div>
219238
</div>
220239
);
221240

apps/browser-extension-wallet/src/views/browser-view/features/sign-message/useSignMessageState.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ import { useAnalyticsContext } from '@providers';
1212
import { useSecrets } from '@lace/core';
1313
import { parseError } from '@src/utils/parse-error';
1414

15+
type SignatureObject = Cip30DataSignature & { rawKey: Wallet.Crypto.Ed25519PublicKeyHex };
16+
1517
interface SignMessageState {
1618
usedAddresses: { address: string; id: number; type: 'payment' | 'stake' }[];
1719
isSigningInProgress: boolean;
18-
signatureObject: Cip30DataSignature | undefined;
20+
signatureObject: SignatureObject | undefined;
1921
error: string;
2022
errorObj?: Error;
2123
hardwareWalletError: string;
@@ -31,7 +33,7 @@ export const useSignMessageState = (): SignMessageState => {
3133

3234
const { inMemoryWallet, isHardwareWallet } = useWalletStore();
3335
const [isSigningInProgress, setIsSigningInProgress] = useState(false);
34-
const [signature, setSignature] = useState<Cip30DataSignature>();
36+
const [signatureObject, setSignatureObject] = useState<SignatureObject | undefined>();
3537
const [error, setError] = useState<string>('');
3638
const [errorObj, setErrorObj] = useState<Error | undefined>();
3739
const [hardwareWalletError, setHardwareWalletError] = useState<string>('');
@@ -44,7 +46,7 @@ export const useSignMessageState = (): SignMessageState => {
4446
setError('');
4547
setHardwareWalletError('');
4648
setErrorObj(undefined);
47-
setSignature(undefined);
49+
setSignatureObject(undefined);
4850
}, []);
4951

5052
const performSigning = useCallback(
@@ -74,7 +76,10 @@ export const useSignMessageState = (): SignMessageState => {
7476
clearSecrets
7577
);
7678

77-
setSignature(signatureGenerated);
79+
setSignatureObject({
80+
...signatureGenerated,
81+
rawKey: Wallet.util.coseKeyToRaw(signatureGenerated.key)
82+
});
7883
} catch (signingError: unknown) {
7984
logger.error('Error signing message:', signingError);
8085
setErrorObj(parseError(signingError));
@@ -117,7 +122,7 @@ export const useSignMessageState = (): SignMessageState => {
117122
return {
118123
usedAddresses,
119124
isSigningInProgress,
120-
signatureObject: signature,
125+
signatureObject,
121126
error,
122127
errorObj,
123128
hardwareWalletError,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { COSEKey, Label, Int } from '@emurgo/cardano-message-signing-nodejs';
2+
import type { Cip30DataSignature } from '@cardano-sdk/dapp-connector';
3+
import { Ed25519PublicKeyHex } from '@cardano-sdk/crypto';
4+
5+
export const coseKeyToRaw = (coseKey: Cip30DataSignature['key']): Ed25519PublicKeyHex => {
6+
const parsedKey = COSEKey.from_bytes(Buffer.from(coseKey, 'hex'));
7+
// eslint-disable-next-line no-magic-numbers
8+
const rawKeyLabelX = Label.new_int(Int.new_i32(-2));
9+
const keyCbor = parsedKey.header(rawKeyLabelX);
10+
const keyBytes = keyCbor?.as_bytes();
11+
keyCbor?.free();
12+
rawKeyLabelX.free();
13+
parsedKey.free();
14+
if (!keyBytes) {
15+
throw new Error('expected COSE key with label "x" (-2)');
16+
}
17+
// eslint-disable-next-line new-cap
18+
return Ed25519PublicKeyHex(Buffer.from(keyBytes).toString('hex'));
19+
};

packages/cardano/src/wallet/util/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ export * from './drep';
77
export * from './voter';
88
export * from './derive-ed25519-key-hash-from-bip32-public-key';
99
export * from './is-nft';
10+
export * from './cose-key-to-raw';

packages/translation/src/lib/translations/core/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@
231231
"core.signMessage.successTitle": "All done!",
232232
"core.signMessage.signature": "Signature",
233233
"core.signMessage.key": "Public Key",
234+
"core.signMessage.rawKey": "Public Key (Glacier Drop Compatible)",
234235
"core.signMessage.nextButton": "Next",
235236
"core.signMessage.closeButton": "Close",
236237
"core.signMessage.cancelButton": "Cancel",

0 commit comments

Comments
 (0)