From a694b679745ce40ce022add25c9a3e011e31c740 Mon Sep 17 00:00:00 2001 From: lukeglwang Date: Mon, 11 Sep 2023 11:56:34 -0700 Subject: [PATCH 1/3] Updated magicString implementation --- packages/snap/src/register/index.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/snap/src/register/index.ts b/packages/snap/src/register/index.ts index 49e38aa..5072653 100644 --- a/packages/snap/src/register/index.ts +++ b/packages/snap/src/register/index.ts @@ -188,13 +188,23 @@ export class Register { getMainKeypairSignContent = async ( options: GetMainKeypairParams, ): Promise => { - const { password, did_value, did_type } = options; - const keyIndex = 1; - const keyMSG = `${did_type}:${did_value}${keyIndex}${password}`; - const magicString = Uint8ToBase64String( - new TextEncoder().encode(sha3_224(`$web3mq${keyMSG}web3mq$`)), - ); + //original implementation of magicString + // const { password, did_value, did_type } = options; + // const keyIndex = 1; + // const keyMSG = `${did_type}:${did_value}${keyIndex}${password}`; + + // const magicString = Uint8ToBase64String( + // new TextEncoder().encode(sha3_224(`$web3mq${keyMSG}web3mq$`)), + // ); + + //hotfixed magicString implementation until cryptography issue reaches consensus + const magicString= await snap.request({ + method: 'snap_getEntropy', + params: { + version: 1 + }, + }); 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. From dd3fb5cd3e2e1a6a2ec3863a46720402676ce1c8 Mon Sep 17 00:00:00 2001 From: zhaowei Date: Tue, 12 Sep 2023 13:57:30 +0800 Subject: [PATCH 2/3] hotfix register main keys magic string --- packages/snap/snap.manifest.json | 3 ++- packages/snap/src/api/index.ts | 3 +++ packages/snap/src/register/index.ts | 25 +++++++++++++------------ packages/snap/src/types.ts | 1 + 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/packages/snap/snap.manifest.json b/packages/snap/snap.manifest.json index ca3564e..c039968 100644 --- a/packages/snap/snap.manifest.json +++ b/packages/snap/snap.manifest.json @@ -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 5072653..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(); @@ -189,20 +189,16 @@ export class Register { options: GetMainKeypairParams, ): Promise => { - //original implementation of magicString - // const { password, did_value, did_type } = options; - // const keyIndex = 1; - // const keyMSG = `${did_type}:${did_value}${keyIndex}${password}`; + const { did_value, did_type, password } = options; + const keyIndex = 1; - // const magicString = Uint8ToBase64String( - // new TextEncoder().encode(sha3_224(`$web3mq${keyMSG}web3mq$`)), - // ); + const keyMSG = `${did_type}:${did_value}${keyIndex}${password}`; - //hotfixed magicString implementation until cryptography issue reaches consensus const magicString= await snap.request({ method: 'snap_getEntropy', params: { - version: 1 + version: 1, + salt: keyMSG }, }); @@ -288,6 +284,7 @@ Issued At: ${getCurrentDate()}`; signature, password, userid, + isRetry= false, } = payload; const params: RegisterParams = { @@ -306,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; }; From 3351ec73c35cd017759e3bcac6624d27de1ffe07 Mon Sep 17 00:00:00 2001 From: zhaowei Date: Tue, 12 Sep 2023 13:59:56 +0800 Subject: [PATCH 3/3] update version --- packages/snap/package.json | 2 +- packages/snap/snap.manifest.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 c039968..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": {