@@ -11,6 +11,7 @@ import type {
11
11
StateMetadata ,
12
12
} from '@metamask/base-controller' ;
13
13
import { BaseController } from '@metamask/base-controller' ;
14
+ import { encrypt } from '@metamask/eth-sig-util' ;
14
15
import {
15
16
type KeyringControllerGetStateAction ,
16
17
type KeyringControllerLockEvent ,
@@ -26,6 +27,7 @@ import type {
26
27
NetworkControllerUpdateNetworkAction ,
27
28
} from '@metamask/network-controller' ;
28
29
import type { HandleSnapRequest } from '@metamask/snaps-controllers' ;
30
+ import { hexToBytes } from '@noble/hashes/utils' ;
29
31
30
32
import {
31
33
saveInternalAccountToUserStorage ,
@@ -37,6 +39,7 @@ import {
37
39
startNetworkSyncing ,
38
40
} from './network-syncing/controller-integration' ;
39
41
import { Env , UserStorage } from '../../sdk' ;
42
+ import { byteArrayToBase64 } from '../../shared/encryption/utils' ;
40
43
import type { UserStorageFeatureKeys } from '../../shared/storage-schema' ;
41
44
import {
42
45
type UserStoragePathWithFeatureAndKey ,
@@ -54,8 +57,6 @@ import {
54
57
createSnapEncryptionPublicKeyRequest ,
55
58
createSnapSignMessageRequest ,
56
59
} from '../authentication/auth-snap-requests' ;
57
- import { encrypt } from '@metamask/eth-sig-util' ;
58
- import { bytesToBase64 , hexToBytes } from '@metamask/utils' ;
59
60
60
61
const controllerName = 'UserStorageController' ;
61
62
@@ -390,7 +391,7 @@ export default class UserStorageController extends BaseController<
390
391
encryptMessage : async ( message : string , publicKeyHex : string ) => {
391
392
const erc1024Payload = encrypt ( {
392
393
// eth-sig-util expects the public key to be in base64 format
393
- publicKey : bytesToBase64 ( hexToBytes ( publicKeyHex ) ) ,
394
+ publicKey : byteArrayToBase64 ( hexToBytes ( publicKeyHex ) ) ,
394
395
data : message ,
395
396
version : 'x25519-xsalsa20-poly1305' ,
396
397
} ) ;
@@ -690,6 +691,7 @@ export default class UserStorageController extends BaseController<
690
691
691
692
/**
692
693
* Calls the snap to attempt to decrypt the message.
694
+ *
693
695
* @param ciphertext - the encrypted text to decrypt.
694
696
* @returns The decrypted message, if decryption was possible.
695
697
*/
0 commit comments