增加网页版内置钱包扫码登录的功能
This commit is contained in:
parent
6f6fdd52b9
commit
47c1c81ccb
5
src/JCWallet.d.ts
vendored
5
src/JCWallet.d.ts
vendored
@ -25,6 +25,11 @@ declare namespace jsb {
|
|||||||
export function scanQRCode(id: number, title: string);
|
export function scanQRCode(id: number, title: string);
|
||||||
export function restoreKey(id: number, oid: string);
|
export function restoreKey(id: number, oid: string);
|
||||||
export function generateWallet(idHash: string, seedHash: string);
|
export function generateWallet(idHash: string, seedHash: string);
|
||||||
|
export function hexDeflate(str: string): string;
|
||||||
|
export function hexInflate(str: string): string;
|
||||||
|
export function encryptedLocalKey(pk: string): string;
|
||||||
|
export function walletEncrypt(str: string): string;
|
||||||
|
export function walletDecrypt(str: string): string;
|
||||||
export function prepareWallet(
|
export function prepareWallet(
|
||||||
idHash: string,
|
idHash: string,
|
||||||
seedHash: string,
|
seedHash: string,
|
||||||
|
@ -32,7 +32,6 @@ export function getWalletInfo() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function uploadWalletInfo(data) {
|
export function uploadWalletInfo(data) {
|
||||||
console.log("uploadWalletInfo: " + data);
|
|
||||||
const url = `${WALLET_API_HOST}/wallet/info`;
|
const url = `${WALLET_API_HOST}/wallet/info`;
|
||||||
return POST_JSON(url, data);
|
return POST_JSON(url, data);
|
||||||
}
|
}
|
||||||
@ -46,3 +45,8 @@ export function uploadUserCollection(data) {
|
|||||||
const url = `${WALLET_API_HOST}/wallet/collection`;
|
const url = `${WALLET_API_HOST}/wallet/collection`;
|
||||||
return POST_JSON(url, data);
|
return POST_JSON(url, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function uploadInfoForWebLogin(data) {
|
||||||
|
const url = `${WALLET_API_HOST}/bridge/upload`;
|
||||||
|
return POST_JSON(url, data);
|
||||||
|
}
|
||||||
|
11
src/index.ts
11
src/index.ts
@ -23,6 +23,7 @@ import { AllChains } from "./data/allchain";
|
|||||||
import { IAccount, INFT, initAccount, initNFT } from "./data/DataModel";
|
import { IAccount, INFT, initAccount, initNFT } from "./data/DataModel";
|
||||||
import { singleton } from "./decorator/singleton.decorator";
|
import { singleton } from "./decorator/singleton.decorator";
|
||||||
import { saveData } from "./manage/DataManage";
|
import { saveData } from "./manage/DataManage";
|
||||||
|
import { parseUrl } from "./manage/SchemeManage";
|
||||||
import {
|
import {
|
||||||
loadInternalWallet,
|
loadInternalWallet,
|
||||||
restoreWalletByMnemonic,
|
restoreWalletByMnemonic,
|
||||||
@ -42,6 +43,7 @@ import {
|
|||||||
} from "./util/chain.util";
|
} from "./util/chain.util";
|
||||||
import { fromTokenMinimalUnit } from "./util/number.util";
|
import { fromTokenMinimalUnit } from "./util/number.util";
|
||||||
import { buildLoginSignMsg, signLogin } from "./util/sign.util";
|
import { buildLoginSignMsg, signLogin } from "./util/sign.util";
|
||||||
|
import { findUrlScheme } from "./util/string.util";
|
||||||
|
|
||||||
var global =
|
var global =
|
||||||
(typeof globalThis !== "undefined" && globalThis) ||
|
(typeof globalThis !== "undefined" && globalThis) ||
|
||||||
@ -661,6 +663,15 @@ export default class JCWallet {
|
|||||||
}
|
}
|
||||||
return this.feeAddressMap.get(typeName);
|
return this.feeAddressMap.get(typeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async scanQr(title: string) {
|
||||||
|
let result = (await this.nativeSvr.scanQRCode(title)) + "";
|
||||||
|
console.log("scan qr code: " + result);
|
||||||
|
if (result && result.indexOf("://") >= 0) {
|
||||||
|
await parseUrl(result);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// window.jc = window.jc || {wallet: new JCWallet()};
|
// window.jc = window.jc || {wallet: new JCWallet()};
|
||||||
|
17
src/manage/SchemeManage.ts
Normal file
17
src/manage/SchemeManage.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { findUrlScheme } from "../util/string.util";
|
||||||
|
import { parseWebLogin } from "./WalletManage";
|
||||||
|
|
||||||
|
export function parseUrl(str: string) {
|
||||||
|
let scheme = findUrlScheme(str);
|
||||||
|
if (!scheme) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const dataStr = str.replace(scheme + "://", "");
|
||||||
|
switch (scheme) {
|
||||||
|
case "weblogin":
|
||||||
|
parseWebLogin(dataStr);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
@ -9,6 +9,7 @@ import {
|
|||||||
googleAuth,
|
googleAuth,
|
||||||
tikTokAuth,
|
tikTokAuth,
|
||||||
twitterAuth,
|
twitterAuth,
|
||||||
|
uploadInfoForWebLogin,
|
||||||
uploadWalletInfo,
|
uploadWalletInfo,
|
||||||
} from "../api/WalletApi";
|
} from "../api/WalletApi";
|
||||||
import { WalletEnv } from "../config/WalletEnv";
|
import { WalletEnv } from "../config/WalletEnv";
|
||||||
@ -140,3 +141,19 @@ export function walletSign(str: string) {
|
|||||||
let result = jsb.walletSign(str);
|
let result = jsb.walletSign(str);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function parseWebLogin(dataStr: string) {
|
||||||
|
console.log("found web login scheme, begin login");
|
||||||
|
if (dataStr.indexOf("|") < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let datas = dataStr.split("|");
|
||||||
|
let webtoken = datas[0];
|
||||||
|
let pk64 = datas[1];
|
||||||
|
let pk = jsb.hexInflate(pk64);
|
||||||
|
let keyEncrypt = jsb.encryptedLocalKey(pk);
|
||||||
|
console.log("webtoken: " + webtoken);
|
||||||
|
console.log("local key: " + keyEncrypt);
|
||||||
|
let result = await uploadInfoForWebLogin({ key: keyEncrypt, webtoken });
|
||||||
|
console.log("login result: " + result);
|
||||||
|
}
|
||||||
|
9
src/util/string.util.ts
Normal file
9
src/util/string.util.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
export const RE_URL_SCHEME = /^(.+?):\/\/.+?$/;
|
||||||
|
|
||||||
|
export function findUrlScheme(url: string) {
|
||||||
|
let result = url.match(RE_URL_SCHEME);
|
||||||
|
if (!result) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return result[1];
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user