Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/snap/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 3 additions & 2 deletions packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"version": "1.0.0",
"version": "1.0.1",
"description": "Web3-native decentralized communication protocol. Encrypted, efficient and borderless.",
"proposedName": "Web3MQ",
"repository": {
"type": "git",
"url": "https://github.com/Generative-Labs/Web3MQ-Snap.git"
},
"source": {
"shasum": "G2nRnIQhfgjoKwLg6lOqrX4/n9WsGByDbn6vIXdOnaE=",
"shasum": "I/e7K3a6hRfiXDJlcdn0FrpsJ44cy8c1GxmpjEJ1Has=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand All @@ -18,6 +18,7 @@
}
},
"initialPermissions": {
"snap_getEntropy": {},
"snap_notify": {},
"snap_manageState": {},
"endowment:ethereum-provider": {},
Expand Down
3 changes: 3 additions & 0 deletions packages/snap/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export const userRegisterRequest = async (
): Promise<RegisterApiResponse> => {
return await Request.post('/api/user_register_v2/', payload);
};
export const resetPasswordRequest = async (payload: RegisterParams): Promise<RegisterApiResponse> => {
return await Request.post('/api/user_reset_password_v2/', payload);
};
export const sendMessageRequest = async (
payload: SendMessageParams,
): Promise<any> => {
Expand Down
25 changes: 18 additions & 7 deletions packages/snap/src/register/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
Uint8ToBase64String,
} from '../encryption';
import {
getUserInfoRequest,
getUserInfoRequest, resetPasswordRequest,
userLoginRequest,
userRegisterRequest,
} from '../api';
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -188,13 +188,19 @@ export class Register {
getMainKeypairSignContent = async (
options: GetMainKeypairParams,
): Promise<GetSignContentResponse> => {
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.

Expand Down Expand Up @@ -278,6 +284,7 @@ Issued At: ${getCurrentDate()}`;
signature,
password,
userid,
isRetry= false,
} = payload;

const params: RegisterParams = {
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/snap/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ export type RegisterToWeb3MQParams = {
registerTime: number; // require by register
nickname?: string;
avatarUrl?: string;
isRetry?: boolean;
userid: string;
};

Expand Down