|
1 | 1 | import {ethers, JsonRpcProvider, Provider, toNumber, TransactionRequest, Wallet,} from "ethers"; |
2 | | -import {decrypt} from "./crypto_utils"; |
3 | | - |
4 | | -const block_size = 16 // AES block size in bytes |
5 | | -const hexBase = 16 |
6 | 2 |
|
7 | 3 | export async function printNetworkDetails(provider: Provider) { |
8 | 4 | if (!await isProviderConnected(provider)) { |
@@ -113,37 +109,6 @@ export async function isGasEstimationValid(provider: Provider, tx: TransactionRe |
113 | 109 | return {valid: true, gasEstimation: estimatedGas} |
114 | 110 | } |
115 | 111 |
|
116 | | -export function decryptUint(ciphertext: bigint, userKey: string) { |
117 | | - // Convert CT to bytes |
118 | | - let ctString = ciphertext.toString(hexBase) |
119 | | - let ctArray = Buffer.from(ctString, "hex") |
120 | | - while (ctArray.length < 32) { |
121 | | - // When the first bits are 0, bigint bit size is less than 32 and need to re-add the bits |
122 | | - ctString = "0" + ctString |
123 | | - ctArray = Buffer.from(ctString, "hex") |
124 | | - } |
125 | | - // Split CT into two 128-bit arrays r and cipher |
126 | | - const cipher = ctArray.subarray(0, block_size) |
127 | | - const r = ctArray.subarray(block_size) |
128 | | - |
129 | | - // Decrypt the cipher |
130 | | - const decryptedMessage = decrypt(Buffer.from(userKey, "hex"), r, cipher) |
131 | | - |
132 | | - return BigInt("0x" + decryptedMessage.toString("hex")) |
133 | | -} |
134 | | - |
135 | | -export function decryptString(ciphertext: Array<bigint>, userKey: string) { |
136 | | - let decryptedStr = new Array<number>(ciphertext.length) |
137 | | - |
138 | | - for (let i = 0; i < ciphertext.length; i++) { |
139 | | - decryptedStr[i] = Number(decryptUint(ciphertext[i], userKey)) |
140 | | - } |
141 | | - |
142 | | - let decoder = new TextDecoder() |
143 | | - |
144 | | - return decoder.decode(new Uint8Array(decryptedStr)) |
145 | | -} |
146 | | - |
147 | 112 | export async function isProviderConnected(provider: Provider): Promise<boolean> { |
148 | 113 | if (provider == undefined) { |
149 | 114 | throw Error('Provider does not exist.') |
|
0 commit comments