Skip to content

Commit 9b59636

Browse files
committed
Remove branching
1 parent 1003450 commit 9b59636

1 file changed

Lines changed: 4 additions & 22 deletions

File tree

  • packages/client/src/components/communicator/webBased

packages/client/src/components/communicator/webBased/encoding.ts

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ type EncodedResponseContent =
77
| { failure: SerializedEthereumRpcError }
88
| {
99
encrypted: {
10-
iv: string | Record<string, number>;
11-
cipherText: string | Record<string, number>;
10+
iv: string;
11+
cipherText: string;
1212
};
1313
};
1414

@@ -30,11 +30,8 @@ export function decodeResponseURLParams(params: URLSearchParams): RPCResponseMes
3030
const { iv, cipherText } = contentParam.encrypted;
3131
content = {
3232
encrypted: {
33-
iv: typeof iv === 'string' ? hexToBytes(iv) : convertObjectToUint8Array(iv),
34-
cipherText:
35-
typeof cipherText === 'string'
36-
? hexToBytes(cipherText)
37-
: convertObjectToUint8Array(cipherText),
33+
iv: hexToBytes(iv),
34+
cipherText: hexToBytes(cipherText),
3835
},
3936
};
4037
}
@@ -76,18 +73,3 @@ export function encodeRequestURLParams(request: RPCRequestMessage) {
7673

7774
return urlParams.toString();
7875
}
79-
80-
/**
81-
* Converts from a JSON.stringify-ied object to a Uint8Array
82-
* `{ "0": 1, "1": 2, "2": 3 }` to `Uint8Array([1, 2, 3])`
83-
*/
84-
function convertObjectToUint8Array(obj: Record<string, number>): Uint8Array {
85-
const length = Object.keys(obj).length;
86-
const bytes = new Uint8Array(length);
87-
88-
for (let i = 0; i < length; i++) {
89-
bytes[i] = obj[i];
90-
}
91-
92-
return bytes;
93-
}

0 commit comments

Comments
 (0)