@@ -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
@@ -387,7 +388,7 @@ export default class UserStorageController extends BaseController<
387
388
encryptMessage : async ( message : string , publicKeyHex : string ) => {
388
389
const erc1024Payload = encrypt ( {
389
390
// eth-sig-util expects the public key to be in base64 format
390
- publicKey : bytesToBase64 ( hexToBytes ( publicKeyHex ) ) ,
391
+ publicKey : byteArrayToBase64 ( hexToBytes ( publicKeyHex ) ) ,
391
392
data : message ,
392
393
version : 'x25519-xsalsa20-poly1305' ,
393
394
} ) ;
@@ -682,6 +683,7 @@ export default class UserStorageController extends BaseController<
682
683
683
684
/**
684
685
* Calls the snap to attempt to decrypt the message.
686
+ *
685
687
* @param ciphertext - the encrypted text to decrypt.
686
688
* @returns The decrypted message, if decryption was possible.
687
689
*/
0 commit comments