Skip to content

Commit 8fd4340

Browse files
committed
wip: Try to improve submitRequestValue
1 parent 32f1a4b commit 8fd4340

File tree

2 files changed

+26
-37
lines changed

2 files changed

+26
-37
lines changed

packages/secret-contracts-scripts/src/functions/secretpath/encryptPayload.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,6 @@ import {
1111
recoverPublicKey,
1212
hexlify,
1313
} from "ethers/lib/utils.js";
14-
import config from '../../config/deploy.js';
15-
16-
const { chainId, secretGateway: { gatewayContractEncryptionKeyForChaChaPoly1305 } } =
17-
config.secret.network == "testnet"
18-
? config.secret.testnet
19-
: config.secret.localhost;
20-
21-
let vars;
22-
if (config.evm.network == "sepolia") {
23-
vars = config.evm.sepolia;
24-
} else if (config.evm.network == "localhost") {
25-
vars = config.evm.localhost;
26-
} else {
27-
throw new Error(`Unsupported network.`)
28-
}
29-
const { } = vars;
30-
3114

3215
export async function encryptPayload(
3316
payload: any,
@@ -39,10 +22,12 @@ export async function encryptPayload(
3922
handle: any,
4023
callbackGasLimit: any,
4124
iface: any,
42-
callbackSelector: any
25+
callbackSelector: any,
26+
task_destination_network: any,
27+
lastNonce: any,
4328
) {
4429
const plaintext = json_to_bytes(payload);
45-
const nonce = crypto.getRandomValues(bytes(12));
30+
const nonce = lastNonce;
4631
// const nonce = window.crypto.getRandomValues(bytes(12));
4732

4833
const [ciphertextClient, tagClient] = chacha20_poly1305_seal(
@@ -70,7 +55,7 @@ export async function encryptPayload(
7055
user_key: hexlify(userPublicKeyBytes),
7156
user_pubkey: user_pubkey,
7257
routing_code_hash: routing_code_hash,
73-
task_destination_network: chainId,
58+
task_destination_network: task_destination_network,
7459
handle: handle,
7560
nonce: hexlify(nonce),
7661
payload: hexlify(ciphertext),

packages/secret-contracts-scripts/src/submitRequestValue.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { queryPubkey } from "./functions/query/queryPubkey.js";
1717
import { arrayify, hexlify, SigningKey, keccak256, recoverPublicKey, computeAddress } from "ethers/lib/utils.js";
1818
import { assert } from "console";
1919

20-
const { secretNunya: { nunyaContractCodeId, nunyaContractAddress, nunyaContractCodeHash } } =
20+
const { chainId: secretChainId, secretNunya: { nunyaContractCodeId, nunyaContractAddress, nunyaContractCodeHash } } =
2121
config.secret.network == "testnet"
2222
? config.secret.testnet
2323
: config.secret.localhost;
@@ -30,7 +30,7 @@ if (config.evm.network == "sepolia") {
3030
} else {
3131
throw new Error(`Unsupported network.`)
3232
}
33-
const { chainId, endpoint, nunyaBusinessContractAddress, gatewayContractAddress, privateKey } = vars;
33+
const { chainId: evmChainId, endpoint, nunyaBusinessContractAddress, gatewayContractAddress, privateKey } = vars;
3434

3535
const SECRET_ADDRESS = nunyaContractAddress;
3636
const CONTRACT_CODE_HASH = nunyaContractCodeHash;
@@ -109,10 +109,10 @@ async function unsafeRequestValue() {
109109
// // Data are the calldata/parameters that are passed into the contract
110110
// const data = JSON.stringify({ myArg: "123" });
111111

112-
// assert!(chainId.toString() == (await provider.getNetwork()).chainId.toString());
112+
// assert!(evmChainId.toString() == (await provider.getNetwork()).chainId.toString());
113113

114114
// // EVM gateway contract address
115-
// // const publicClientAddress = await getPublicClientAddress(chainId);
115+
// // const publicClientAddress = await getPublicClientAddress(evmChainId);
116116
// const publicClientAddress = gatewayContractAddress;
117117

118118
// const callbackAddress = publicClientAddress.toLowerCase();
@@ -130,6 +130,8 @@ async function unsafeRequestValue() {
130130
// callbackGasLimit
131131
// );
132132

133+
// const taskDestinationNetwork = secretChainId;
134+
133135
// // TODO: temporarily skip the below that encrypts the payload until resolve
134136
// // https://github.com/blake-regalia/belt/issues/1
135137
// const {
@@ -147,7 +149,9 @@ async function unsafeRequestValue() {
147149
// handle,
148150
// callbackGasLimit,
149151
// ifaceGateway,
150-
// callbackSelector
152+
// callbackSelector,
153+
// taskDestinationNetwork,
154+
// lastNonce,
151155
// );
152156

153157
// // TODO - temporary only but remove after resolve
@@ -190,7 +194,7 @@ async function unsafeRequestValue() {
190194
// user_key: hexlify(userPublicKeyBytes),
191195
// user_pubkey: userPublicKey, // user_pubkey;
192196
// routing_code_hash: routing_code_hash,
193-
// task_destination_network: chainId,
197+
// task_destination_network: secretChainId,
194198
// handle: handle,
195199
// nonce: hexlify(nextNonce),
196200
// payload: hexlify(ciphertext),
@@ -219,31 +223,31 @@ async function unsafeRequestValue() {
219223
// let amountOfGas;
220224
// let my_gas = 150000;
221225

222-
// if (chainId.toString() === "4202") {
226+
// if (evmChainId.toString() === "4202") {
223227
// amountOfGas = gasFee.mul(callbackGasLimit).mul(100000).div(2);
224-
// } else if (chainId.toString() === "128123") {
228+
// } else if (evmChainId.toString() === "128123") {
225229
// amountOfGas = gasFee.mul(callbackGasLimit).mul(1000).div(2);
226230
// my_gas = 15000000;
227-
// } else if (chainId.toString() === "1287") {
231+
// } else if (evmChainId.toString() === "1287") {
228232
// amountOfGas = gasFee.mul(callbackGasLimit).mul(1000).div(2);
229233
// my_gas = 15000000;
230-
// } else if (chainId.toString() === "300") {
234+
// } else if (evmChainId.toString() === "300") {
231235
// amountOfGas = gasFee.mul(callbackGasLimit).mul(100000).div(2);
232236
// my_gas = 15000000;
233-
// } else if (chainId.toString() === "5003") {
237+
// } else if (evmChainId.toString() === "5003") {
234238
// amountOfGas = gasFee.mul(callbackGasLimit).mul(1000000).div(2);
235239
// my_gas = 1500000000;
236-
// } else if (chainId.toString() === "80002") {
240+
// } else if (evmChainId.toString() === "80002") {
237241
// amountOfGas = gasFee.mul(callbackGasLimit).mul(100).div(2);
238242
// my_gas = 200000;
239-
// } else if (chainId.toString() === "1995") {
243+
// } else if (evmChainId.toString() === "1995") {
240244
// amountOfGas = gasFee.mul(callbackGasLimit).mul(100).div(2);
241245
// my_gas = 200000;
242-
// } else if (chainId.toString() === "713715") {
246+
// } else if (evmChainId.toString() === "713715") {
243247
// amountOfGas = gasFee.mul(callbackGasLimit).mul(100).div(2);
244248
// my_gas = 200000;
245249
// } else {
246-
// // Note: Sepolia Ethereum has chainId 11155111
250+
// // Note: Sepolia Ethereum has evmChainId 11155111
247251
// amountOfGas = gasFee.mul(callbackGasLimit).mul(3).div(2);
248252
// }
249253
// // Note: Only if get error `replacement fee too low` then just increase gasPrice by 10%
@@ -259,7 +263,7 @@ async function unsafeRequestValue() {
259263
// // from: myAddress,
260264
// // value: hexlify(amountOfGas),
261265
// // data: functionData,
262-
// // chainId: chainId,
266+
// // chainId: evmChainId,
263267
// // };
264268

265269
// // TODO: should the `gasLimit` instead be `hexlify(amountOfGas)`?
@@ -271,7 +275,7 @@ async function unsafeRequestValue() {
271275
// gasPrice: hexlify(my_gas),
272276
// nonce: nextNonce,
273277
// data: functionData,
274-
// chainId: chainId,
278+
// chainId: evmChainId,
275279
// }
276280

277281
// const tx = await managedSigner.sendTransaction(tx_params);

0 commit comments

Comments
 (0)