File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ const fixedHex = ( number : number , length : number ) => {
2+ let str = number . toString ( 16 ) . toUpperCase ( ) ;
3+ while ( str . length < length ) str = '0' + str ;
4+ return str ;
5+ } ;
6+
7+ /* Creates a unicode literal based on the string */
8+ const unicodeLiteral = ( str : string ) => {
9+ let i ;
10+ let result = '' ;
11+ for ( i = 0 ; i < str . length ; ++ i ) {
12+ if ( str . charCodeAt ( i ) > 126 || str . charCodeAt ( i ) < 32 )
13+ result += '\\u' + fixedHex ( str . charCodeAt ( i ) , 4 ) ;
14+ else result += str [ i ] ;
15+ }
16+ return result ;
17+ } ;
18+ export const getRTLOLTLOSafeString = ( str : string ) : string => {
19+ const isrtloltlo = / [ \u202E \u200F ] / . test ( str ) || / [ \u202D \u200E ] / . test ( str ) ;
20+ if ( isrtloltlo ) return unicodeLiteral ( str ) ;
21+ return str ;
22+ } ;
Original file line number Diff line number Diff line change @@ -65,6 +65,7 @@ import { ProviderRequestOptions } from '@/types/provider';
6565import { BitcoinNetwork } from ' ../types/bitcoin-network' ;
6666import { EnkryptAccount } from ' @enkryptcom/types' ;
6767import { MessageSigner } from ' ./libs/signer' ;
68+ import { getRTLOLTLOSafeString } from ' @/libs/utils/unicode-detection' ;
6869
6970const windowPromise = WindowPromiseHandler (4 );
7071const network = ref <BitcoinNetwork >(DEFAULT_BTC_NETWORK );
@@ -92,7 +93,7 @@ onBeforeMount(async () => {
9293 account .value = Request .value .params ! [2 ] as EnkryptAccount ;
9394 identicon .value = network .value .identicon (account .value .address );
9495 Options .value = options ;
95- message .value = Request .value .params ! [0 ];
96+ message .value = getRTLOLTLOSafeString ( Request .value .params ! [0 ]) ;
9697 type .value = Request .value .params ! [1 ];
9798});
9899
Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ import HardwareWalletMsg from '@/providers/common/ui/verify-transaction/hardware
5959import { EvmNetwork } from ' ../types/evm-network' ;
6060import { EnkryptAccount } from ' @enkryptcom/types' ;
6161import { MessageSigner } from ' ./libs/signer' ;
62+ import { getRTLOLTLOSafeString } from ' @/libs/utils/unicode-detection' ;
6263
6364const windowPromise = WindowPromiseHandler (3 );
6465const network = ref <EvmNetwork >(DEFAULT_EVM_NETWORK );
@@ -85,7 +86,7 @@ onBeforeMount(async () => {
8586 identicon .value = network .value .identicon (account .value .address );
8687 Options .value = options ;
8788 message .value = isUtf8 (Request .value .params ! [0 ])
88- ? hexToUtf8 (Request .value .params ! [0 ])
89+ ? getRTLOLTLOSafeString ( hexToUtf8 (Request .value .params ! [0 ]) )
8990 : Request .value .params ! [0 ];
9091});
9192
Original file line number Diff line number Diff line change @@ -64,6 +64,7 @@ import {
6464 DEFAULT_KADENA_NETWORK ,
6565 getNetworkByName ,
6666} from ' @/libs/utils/networks' ;
67+ import { getRTLOLTLOSafeString } from ' @/libs/utils/unicode-detection' ;
6768
6869const windowPromise = WindowPromiseHandler (0 );
6970const network = ref <KadenaNetwork >(DEFAULT_KADENA_NETWORK );
@@ -81,7 +82,7 @@ const account = ref({ address: '' } as EnkryptAccount);
8182onBeforeMount (async () => {
8283 const { Request, options } = await windowPromise ;
8384 Options .value = options ;
84- message .value = Request .value .params ! [0 ].data ;
85+ message .value = getRTLOLTLOSafeString ( Request .value .params ! [0 ].data ) ;
8586 account .value = Request .value .params ! [1 ] as EnkryptAccount ;
8687 network .value = (await getNetworkByName (
8788 Request .value .params ! [0 ].network ,
Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ import { ProviderRequestOptions } from '@/types/provider';
5656import { EnkryptAccount } from ' @enkryptcom/types' ;
5757import { MessageSigner } from ' ./libs/signer' ;
5858import { hexToBuffer } from ' @enkryptcom/utils' ;
59+ import { getRTLOLTLOSafeString } from ' @/libs/utils/unicode-detection' ;
5960
6061const windowPromise = WindowPromiseHandler (0 );
6162
@@ -74,7 +75,9 @@ onBeforeMount(async () => {
7475 Options .value = options ;
7576
7677 message .value = isUtf8 (Request .value .params ! [0 ])
77- ? u8aToString (u8aUnwrapBytes (Request .value .params ! [0 ]))
78+ ? getRTLOLTLOSafeString (
79+ u8aToString (u8aUnwrapBytes (Request .value .params ! [0 ])),
80+ )
7881 : Request .value .params ! [0 ];
7982
8083 account .value = Request .value .params ! [1 ] as EnkryptAccount ;
Original file line number Diff line number Diff line change @@ -76,6 +76,7 @@ import { SolSignInResponse } from './types';
7676import { isUtf8 } from ' @polkadot/util' ;
7777import { hexToUtf8 } from ' web3-utils' ;
7878import { MessageSigner } from ' ./libs/signer' ;
79+ import { getRTLOLTLOSafeString } from ' @/libs/utils/unicode-detection' ;
7980
8081const windowPromise = WindowPromiseHandler (3 );
8182const keyring = new PublicKeyRing ();
@@ -144,7 +145,7 @@ onBeforeMount(async () => {
144145 } else if (reqMethod .value === ' sol_signMessage' ) {
145146 signMessage .value = JSON .parse (Request .value .params ! [1 ]);
146147 message .value = isUtf8 (signMessage .value ! .message )
147- ? hexToUtf8 (signMessage .value ! .message )
148+ ? getRTLOLTLOSafeString ( hexToUtf8 (signMessage .value ! .message ) )
148149 : signMessage .value ! .message ;
149150 keyring
150151 .getAccount (bufferToHex (bs58 .decode (signMessage .value ! .address )))
You can’t perform that action at this time.
0 commit comments