diff --git a/packages/snap/package.json b/packages/snap/package.json index 01b6524..6178b95 100644 --- a/packages/snap/package.json +++ b/packages/snap/package.json @@ -1,6 +1,6 @@ { "name": "@web3mq/snap", - "version": "1.0.0", + "version": "1.0.1", "description": "Web3-native decentralized communication protocol. Encrypted, efficient and borderless.", "repository": { "type": "git", diff --git a/packages/snap/snap.manifest.json b/packages/snap/snap.manifest.json index ca3564e..ebbd3d7 100644 --- a/packages/snap/snap.manifest.json +++ b/packages/snap/snap.manifest.json @@ -1,5 +1,5 @@ { - "version": "1.0.0", + "version": "1.0.1", "description": "Web3-native decentralized communication protocol. Encrypted, efficient and borderless.", "proposedName": "Web3MQ", "repository": { @@ -7,7 +7,7 @@ "url": "https://github.com/Generative-Labs/Web3MQ-Snap.git" }, "source": { - "shasum": "G2nRnIQhfgjoKwLg6lOqrX4/n9WsGByDbn6vIXdOnaE=", + "shasum": "I/e7K3a6hRfiXDJlcdn0FrpsJ44cy8c1GxmpjEJ1Has=", "location": { "npm": { "filePath": "dist/bundle.js", @@ -18,6 +18,7 @@ } }, "initialPermissions": { + "snap_getEntropy": {}, "snap_notify": {}, "snap_manageState": {}, "endowment:ethereum-provider": {}, diff --git a/packages/snap/src/api/index.ts b/packages/snap/src/api/index.ts index c7585d1..4ea151e 100644 --- a/packages/snap/src/api/index.ts +++ b/packages/snap/src/api/index.ts @@ -53,6 +53,9 @@ export const userRegisterRequest = async ( ): Promise => { return await Request.post('/api/user_register_v2/', payload); }; +export const resetPasswordRequest = async (payload: RegisterParams): Promise => { + return await Request.post('/api/user_reset_password_v2/', payload); +}; export const sendMessageRequest = async ( payload: SendMessageParams, ): Promise => { diff --git a/packages/snap/src/register/index.ts b/packages/snap/src/register/index.ts index 49e38aa..ef9a02e 100644 --- a/packages/snap/src/register/index.ts +++ b/packages/snap/src/register/index.ts @@ -17,7 +17,7 @@ import { Uint8ToBase64String, } from '../encryption'; import { - getUserInfoRequest, + getUserInfoRequest, resetPasswordRequest, userLoginRequest, userRegisterRequest, } from '../api'; @@ -149,7 +149,7 @@ export class Register { } catch (e) { } if (!decode_dataStr) { - throw new Error('Private key decode error, please retry') + throw new Error('Invalid Password, please retry') } try { const timestamp = Date.now(); @@ -188,13 +188,19 @@ export class Register { getMainKeypairSignContent = async ( options: GetMainKeypairParams, ): Promise => { - const { password, did_value, did_type } = options; + + const { did_value, did_type, password } = options; const keyIndex = 1; + const keyMSG = `${did_type}:${did_value}${keyIndex}${password}`; - const magicString = Uint8ToBase64String( - new TextEncoder().encode(sha3_224(`$web3mq${keyMSG}web3mq$`)), - ); + const magicString= await snap.request({ + method: 'snap_getEntropy', + params: { + version: 1, + salt: keyMSG + }, + }); const signContent = `Signing this message will allow this app to decrypt messages in the Web3MQ protocol for the following address: ${did_value}. This won’t cost you anything. @@ -278,6 +284,7 @@ Issued At: ${getCurrentDate()}`; signature, password, userid, + isRetry= false, } = payload; const params: RegisterParams = { @@ -296,7 +303,11 @@ Issued At: ${getCurrentDate()}`; testnet_access_key: this.appKey, }; try { - await userRegisterRequest(params); + if (isRetry) { + await resetPasswordRequest(params) + } else { + await userRegisterRequest(params); + } await this.connectWeb3MQNetwork({ walletType: walletType, walletAddress, diff --git a/packages/snap/src/types.ts b/packages/snap/src/types.ts index 5f24b97..4466fcb 100644 --- a/packages/snap/src/types.ts +++ b/packages/snap/src/types.ts @@ -259,6 +259,7 @@ export type RegisterToWeb3MQParams = { registerTime: number; // require by register nickname?: string; avatarUrl?: string; + isRetry?: boolean; userid: string; };