diff --git a/contract/helper-hardhat-config.js b/contract/helper-hardhat-config.js index dce181d..7d4a9c8 100644 --- a/contract/helper-hardhat-config.js +++ b/contract/helper-hardhat-config.js @@ -115,11 +115,10 @@ const networkConfig = { fee: "0.1", fundAmount: "100", // 100 automationUpdateInterval: "30" - }, - + } }; -const developmentChains = ["hardhat", "localhost"] -const VERIFICATION_BLOCK_CONFIRMATIONS = 6 +const developmentChains = ["hardhat", "localhost"]; +const VERIFICATION_BLOCK_CONFIRMATIONS = 6; module.exports = { networkConfig, diff --git a/locales/en.yaml b/locales/en.yaml index 7eb02bc..6a039e2 100644 --- a/locales/en.yaml +++ b/locales/en.yaml @@ -25,9 +25,11 @@ common: "pick a site": Pick a site "need key tips": Please provider your private key to get message safety. - connect: Connect + connect: Connect Wallet + disconnect: Disconnect Wallet update: Update - "public key": Public Key + "public key": Nostr Public Key + "wallet address": Wallet Address "input private key": Input your Private Key "input private key here": Type your key here diff --git a/locales/zh-CN.yaml b/locales/zh-CN.yaml index 980b170..f41ea18 100644 --- a/locales/zh-CN.yaml +++ b/locales/zh-CN.yaml @@ -25,9 +25,11 @@ common: "pick a site": 选择一个 Site "need key tips": 请提供你的私钥,用以建立安全通信 - connect: 连接 + connect: 连接钱包 + disconnect: 断开连接钱包 update: 更新 - "public key": 公钥 + "public key": nostr公钥 + "wallet address": 钱包地址 "input private key": 请输入私钥 "input private key here": 在此处输入私钥 diff --git a/public/serverConfig.json b/public/serverConfig.json index edb80e0..88327ff 100644 --- a/public/serverConfig.json +++ b/public/serverConfig.json @@ -4,12 +4,12 @@ "Theme": "light", "Relay": [ { - "name": "gw105", - "url": "wss://nostr.gw105.oneitfarm.com", - "lat": 34.7732, - "long": 113.722, - "city": "Shanghai", - "flag": "twemoji:flag-china" + "name": "gw106", + "url": "wss://nostr.gw106.oneitfarm.com", + "lat": 1.2929, + "long": 103.8547, + "city": "Singapore", + "flag": "twemoji:flag-singapore" } ] } diff --git a/src/components/Modal/account.vue b/src/components/Modal/account.vue index b0adf36..b75a923 100644 --- a/src/components/Modal/account.vue +++ b/src/components/Modal/account.vue @@ -5,52 +5,76 @@ const { t } = useLang(); import { getNewNostrPrivateKey, md5 } from "@/utils/shared"; import { getPublicKey } from "nostr-tools"; import { getUserHubContract } from "@/utils/contract/user-hub"; -import { handleEtherError, encrypt } from "@/utils/shared"; import { signMessage, getWalletAddres } from "@/utils/contract/web3"; -import { decrypt } from "@/utils/shared"; +import { handleEtherError, decrypt, encrypt } from "@/utils/shared"; +import { useAccountStore } from "@/store/modules/account"; const privateKey = ref(""); const loading = ref(false); const handleSubmit = async () => { - privateKey.value = getNewNostrPrivateKey(); - const publicKey = getPublicKey(privateKey.value); - + const address = await getWalletAddres(); const contract = await getUserHubContract(); + const data = await contract.getUserInfo(address); + console.log(data); + console.log(address); + console.log(contract); + if (!data[0]) { + // register + privateKey.value = getNewNostrPrivateKey(); + console.log(privateKey); + const publicKey = getPublicKey(privateKey.value); - let encryptKey; - try { - loading.value = true; - encryptKey = await signMessage("CloudX3"); - } catch (e) { - window.alert(t("user.cancelSign")); - loading.value = false; - return; - } + let encryptKey; + try { + loading.value = true; + encryptKey = await signMessage("CloudX3"); + console.log(encryptKey); + } catch (e) { + window.alert(t("user.cancelSign")); + loading.value = false; + return; + } - try { - loading.value = true; - const nostrEncryptKey = encrypt(privateKey.value, encryptKey); - console.log(decrypt(nostrEncryptKey, encryptKey)); - console.log( - "用户信息\r\n钱包地址:%s\r\n签名结果:%s\r\nNostr公钥:%s\r\nNostr明文私钥:%s\r\nNostr加密私钥:%s", - await getWalletAddres(), - encryptKey, - publicKey, - privateKey.value, - nostrEncryptKey - ); - const transaction = await contract.registerUser( - publicKey, - nostrEncryptKey, - md5(publicKey) - ); + try { + loading.value = true; + const nostrEncryptKey = encrypt(privateKey.value, encryptKey); + console.log(nostrEncryptKey); + console.log(decrypt(nostrEncryptKey, encryptKey)); + console.log( + "用户信息\r\n钱包地址:%s\r\n签名结果:%s\r\nNostr公钥:%s\r\nNostr明文私钥:%s\r\nNostr加密私钥:%s", + await getWalletAddres(), + encryptKey, + publicKey, + privateKey.value, + nostrEncryptKey + ); + const transaction = await contract.registerUser( + publicKey, + nostrEncryptKey, + md5(publicKey) + ); - await transaction.wait(); - window.location.reload(); - } catch (e) { - loading.value = false; - handleEtherError(e); + await transaction.wait(); + window.location.reload(); + useAccountStore().savePrivateKey(privateKey.value); + } catch (e) { + loading.value = false; + handleEtherError(e); + } + } else { + try { + const chainPrivateKey = data[1].privateKey; + const signKey = await signMessage("CloudX3"); + const truePrivateKey = decrypt(chainPrivateKey, signKey); + useAccountStore().savePrivateKey(truePrivateKey); + window.location.reload(); + } catch (e) { + window.alert( + "Please sign the message for build security tunnel with server" + ); + // handleEtherError(e); + } } }; diff --git a/src/config/chain.ts b/src/config/chain.ts index fb3dffc..0875e54 100644 --- a/src/config/chain.ts +++ b/src/config/chain.ts @@ -96,11 +96,11 @@ const chains: Chain[] = [ oracle: "0xC1A56c1c85a4D957a513719FdB30eac50a861433", - podContract: "0xC033615137D482f51718106489035bE6CCDcE0DD", - podJobId: "780d3dd1933a4a9d839f4c78d92ab595", + podContract: "0xC7F694fbbc168CE02F2ce9cE84d748957F283336", + podJobId: "c1efad95d1b34cc9b3e2ee06802a2a6d", - deploymentContract: "0x70F4C5425bf1eAcd1fcfdaC5BfF5393EF45cA53E", - deploymentJobId: "68c1dc5cd63841459ff2395a931f042c", + deploymentContract: "0x6Ca351492b3b137aBb94052B847Af891bb067eFe", + deploymentJobId: "d61b61a4e6684116be70d6ec6e58b52e", nodeContract: "0x1Acc504c02768ff00fBcEB331dB5Eda37fAC006E", nodeJobId: "aa7198c0190f4cc29d4e4470c08f6391", @@ -112,10 +112,10 @@ const chains: Chain[] = [ codContract: "0x754e87664F278f2be89b3f496955752f127fBdf8", - stcMarketContract: "0x6051273DB68F2af68617589f30F8a91f859e5b82", - stcMarketTokenContract: "0x8b321Dde4CAe93848f756895fdb34E889A6c831b", + stcMarketContract: "0xa05D733aE699a1cd3Eb3443ca932FfB69e1e7fFC", + stcMarketTokenContract: "0xe0bf50E501236845580A090c180B218CdAc46204", - userHubContract: "0xE87a986fDc35170c66C3a2449bC4Aee6350cc1F6" + userHubContract: "0x51923dcd6Bb170bd28AD4425A6Dd5cD0456F8e52" }, { chainId: "0x15eb", @@ -155,7 +155,7 @@ const chains: Chain[] = [ } ]; -let currentChain: ChainName = "Optimism Goerli Testnet"; +let currentChain: ChainName = "Sepolia"; export function setCurrentChain(name: ChainName) { currentChain = name; } diff --git a/src/layout/components/avatar.vue b/src/layout/components/avatar.vue index 69b89f9..54e6bc7 100644 --- a/src/layout/components/avatar.vue +++ b/src/layout/components/avatar.vue @@ -1,9 +1,18 @@ diff --git a/src/store/modules/account.ts b/src/store/modules/account.ts index ae1c59b..df40671 100644 --- a/src/store/modules/account.ts +++ b/src/store/modules/account.ts @@ -4,13 +4,15 @@ import { accountType } from "./types"; import { getPublicKey } from "nostr-tools"; // import { storageLocal } from "@pureadmin/utils"; import { getUserHubContract } from "@/utils/contract/user-hub"; -import { handleEtherError, decrypt } from "@/utils/shared"; +import { handleEtherError, decrypt, md5 } from "@/utils/shared"; import { getWalletAddres, signMessage } from "@/utils/contract/web3"; +import { storageSession } from "@pureadmin/utils"; export const useAccountStore = defineStore({ id: "account-settings", state: (): accountType => ({ name: "", + address: "", publicKey: "", privateKey: "" //storageLocal().getItem("sk") || "" }), @@ -32,6 +34,9 @@ export const useAccountStore = defineStore({ SET_PRIVATEKEY(key: string) { this.privateKey = key; }, + SET_ADDRESS(key: string) { + this.address = key; + }, async init(): Promise { try { const address = await getWalletAddres(); @@ -41,8 +46,13 @@ export const useAccountStore = defineStore({ const { privateKey } = data[1]; try { - const signKey = await signMessage("CloudX3"); + const cacheKey = await md5(address); + const signKey = storageSession().getItem(cacheKey) as string; + if (!signKey) { + return; + } const truePrivateKey = decrypt(privateKey, signKey); + this.SET_ADDRESS(address); this.savePrivateKey(truePrivateKey); } catch (e) { window.alert( diff --git a/src/store/modules/types.ts b/src/store/modules/types.ts index 3154c72..dcf686e 100644 --- a/src/store/modules/types.ts +++ b/src/store/modules/types.ts @@ -12,6 +12,7 @@ export type setType = { export type accountType = { name: string; // show name + address: string; // show address publicKey: string; // public key privateKey: string; // private key };