Skip to content

Commit 6b06a3f

Browse files
committed
fix: rtol ltol issue
1 parent 021167d commit 6b06a3f

6 files changed

Lines changed: 34 additions & 5 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
};

packages/extension/src/providers/bitcoin/ui/btc-sign-message.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import { ProviderRequestOptions } from '@/types/provider';
6565
import { BitcoinNetwork } from '../types/bitcoin-network';
6666
import { EnkryptAccount } from '@enkryptcom/types';
6767
import { MessageSigner } from './libs/signer';
68+
import { getRTLOLTLOSafeString } from '@/libs/utils/unicode-detection';
6869
6970
const windowPromise = WindowPromiseHandler(4);
7071
const 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

packages/extension/src/providers/ethereum/ui/eth-sign-message.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import HardwareWalletMsg from '@/providers/common/ui/verify-transaction/hardware
5959
import { EvmNetwork } from '../types/evm-network';
6060
import { EnkryptAccount } from '@enkryptcom/types';
6161
import { MessageSigner } from './libs/signer';
62+
import { getRTLOLTLOSafeString } from '@/libs/utils/unicode-detection';
6263
6364
const windowPromise = WindowPromiseHandler(3);
6465
const 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

packages/extension/src/providers/kadena/ui/kda-sign-message.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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
6869
const windowPromise = WindowPromiseHandler(0);
6970
const network = ref<KadenaNetwork>(DEFAULT_KADENA_NETWORK);
@@ -81,7 +82,7 @@ const account = ref({ address: '' } as EnkryptAccount);
8182
onBeforeMount(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,

packages/extension/src/providers/polkadot/ui/dot-sign-message.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import { ProviderRequestOptions } from '@/types/provider';
5656
import { EnkryptAccount } from '@enkryptcom/types';
5757
import { MessageSigner } from './libs/signer';
5858
import { hexToBuffer } from '@enkryptcom/utils';
59+
import { getRTLOLTLOSafeString } from '@/libs/utils/unicode-detection';
5960
6061
const 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;

packages/extension/src/providers/solana/ui/sol-sign-message.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import { SolSignInResponse } from './types';
7676
import { isUtf8 } from '@polkadot/util';
7777
import { hexToUtf8 } from 'web3-utils';
7878
import { MessageSigner } from './libs/signer';
79+
import { getRTLOLTLOSafeString } from '@/libs/utils/unicode-detection';
7980
8081
const windowPromise = WindowPromiseHandler(3);
8182
const 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)))

0 commit comments

Comments
 (0)