@particle-network/auth
Advanced tools
Comparing version 0.6.2 to 0.6.3-alpha.0
123
lib/auth.js
@@ -64,2 +64,3 @@ "use strict"; | ||
this.PN_AUTH_USER_INFO = "pn_auth_user_info"; | ||
this.PN_AUTH_USER_LOIGN_ORIGIN = "pn_auth_user_loign_origin"; | ||
this.events = new events_1.EventEmitter(); | ||
@@ -73,2 +74,4 @@ this.secretKey = ""; | ||
window.addEventListener("message", function (event) { | ||
var _a; | ||
console.log("Particle Auth Message Event", event); | ||
if (event.data.name && event.data.name === "particle-network-provider" && _this._authResult) { | ||
@@ -96,3 +99,12 @@ var data = _this.decrypt(event.data.data); | ||
} | ||
_this._authResult.iframe.remove(); | ||
if ((_a = _this._authResult) === null || _a === void 0 ? void 0 : _a.container) { | ||
try { | ||
if ("remove" in _this._authResult.container) { | ||
_this._authResult.container.remove(); | ||
} | ||
} | ||
catch (e) { | ||
//ignore | ||
} | ||
} | ||
_this._authResult = null; | ||
@@ -109,4 +121,4 @@ var container = document.getElementById("particle-network-container"); | ||
var _a; | ||
var iframe = this.getIframe(); | ||
iframe.src = this.buildUrl("/login", { | ||
var container = null; | ||
var src = this.buildUrl("/login", { | ||
login_type: config === null || config === void 0 ? void 0 : config.preferredAuthType, | ||
@@ -117,2 +129,14 @@ support_auth_types: (_a = config === null || config === void 0 ? void 0 : config.supportAuthTypes) !== null && _a !== void 0 ? _a : "all", | ||
}); | ||
if (config && | ||
config.preferredAuthType && | ||
config.preferredAuthType !== "email" && | ||
config.preferredAuthType !== "phone") { | ||
container = (0, utils_1.popupWindow)(src, "login", 1000, 800); | ||
localStorage.setItem(this.concatStorageKey(this.PN_AUTH_USER_LOIGN_ORIGIN), "popup"); | ||
} | ||
else { | ||
container = this.getIframe(); | ||
container.src = src; | ||
localStorage.setItem(this.concatStorageKey(this.PN_AUTH_USER_LOIGN_ORIGIN), "iframe"); | ||
} | ||
return new Promise(function (resolve, reject) { | ||
@@ -125,3 +149,3 @@ _this.setAuthResult({ | ||
reject: reject, | ||
iframe: iframe, | ||
container: container, | ||
}); | ||
@@ -132,7 +156,18 @@ }); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var iframe; | ||
var iframe, container; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
iframe = this.getIframe(); | ||
iframe.src = this.buildUrl("/logout"); | ||
iframe = this.openUrl(this.buildUrl("/logout")); | ||
container = document.getElementById("particle-network-container"); | ||
if (container) { | ||
container.style.display = "none"; | ||
} | ||
try { | ||
if (iframe && "remove" in iframe) { | ||
iframe.style.display = "none"; | ||
} | ||
} | ||
catch (e) { | ||
//ignore | ||
} | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
@@ -146,3 +181,3 @@ _this.setAuthResult({ | ||
reject: reject, | ||
iframe: iframe, | ||
container: iframe, | ||
}); | ||
@@ -156,3 +191,3 @@ })]; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var iframe; | ||
var container; | ||
var _this = this; | ||
@@ -163,5 +198,4 @@ return __generator(this, function (_c) { | ||
} | ||
iframe = this.getIframe(); | ||
if (this.config.chainName === "solana") { | ||
iframe.src = this.buildUrl("/solana/sign", { | ||
container = this.openUrl(this.buildUrl("/solana/sign", { | ||
token: (_a = this.userInfo()) === null || _a === void 0 ? void 0 : _a.token, | ||
@@ -171,6 +205,6 @@ method: method, | ||
message: message, | ||
}); | ||
})); | ||
} | ||
else { | ||
iframe.src = this.buildUrl("/evm-chain/sign", { | ||
container = this.openUrl(this.buildUrl("/evm-chain/sign", { | ||
token: (_b = this.userInfo()) === null || _b === void 0 ? void 0 : _b.token, | ||
@@ -180,3 +214,3 @@ method: method, | ||
message: message, | ||
}); | ||
})); | ||
} | ||
@@ -190,3 +224,3 @@ return [2 /*return*/, new Promise(function (resolve, reject) { | ||
reject: reject, | ||
iframe: iframe, | ||
container: container, | ||
}); | ||
@@ -262,7 +296,6 @@ })]; | ||
//create wallet | ||
var iframe = this.getIframe(); | ||
iframe.src = this.buildUrl("/wallet", { | ||
var container = this.openUrl(this.buildUrl("/wallet", { | ||
token: userInfo.token, | ||
chain_name: chain.name, | ||
}); | ||
})); | ||
return new Promise(function (resolve, reject) { | ||
@@ -278,3 +311,3 @@ _this.setAuthResult({ | ||
reject: reject, | ||
iframe: iframe, | ||
container: container, | ||
}); | ||
@@ -374,9 +407,41 @@ }); | ||
iframe.name = "particle-network-iframe"; | ||
var bgColor = "background-color: #FFFFFF"; | ||
var bgColor = "#FFFFFF"; | ||
var themeType = this.getThemeType(); | ||
if (themeType === "dark") { | ||
bgColor = "background-color: #000000"; | ||
bgColor = "#000000"; | ||
} | ||
iframe.setAttribute("style", "position: absolute;left: 50%;top: 50%;transform: translate(-50%, -50%);width: 400px;height: 650px;border-radius: 0px;border: none;z-index: 2147483647;box-shadow: -1px 3px 11px 2px #00000073;border-radius: 10px;" + | ||
bgColor); | ||
var _a = document.body, offsetWidth = _a.offsetWidth, offsetHeight = _a.offsetHeight; | ||
var width = 400; | ||
var height = 650; | ||
var top_1 = "50%"; | ||
var left = "50%"; | ||
var borderRadius = 10; | ||
var transform = "translate(-50%, -50%)"; | ||
if (offsetWidth < 500) { | ||
width = offsetWidth; | ||
height = offsetHeight; | ||
borderRadius = 0; | ||
transform = "none"; | ||
top_1 = "0px"; | ||
left = "0px"; | ||
} | ||
var iframeStyles = { | ||
position: "absolute", | ||
left: left, | ||
top: top_1, | ||
transform: transform, | ||
width: "".concat(width, "px"), | ||
height: "".concat(height, "px"), | ||
border: "none", | ||
"border-radius": "".concat(borderRadius, "px"), | ||
"z-index": "2147483647", | ||
"box-shadow": "-1px 3px 11px 2px #00000073", | ||
"background-color": bgColor, | ||
}; | ||
iframe.setAttribute("style", Object.entries(iframeStyles) | ||
.map(function (_a) { | ||
var key = _a[0], value = _a[1]; | ||
return "".concat(key, ":").concat(value); | ||
}) | ||
.join(";")); | ||
containerDiv.appendChild(iframe); | ||
@@ -386,2 +451,14 @@ } | ||
}; | ||
Auth.prototype.openUrl = function (url) { | ||
if ((/Version\/([0-9\\._]+).*Mobile.*Safari.*/.exec(navigator.userAgent) || | ||
/Version\/([0-9\\._]+).*Safari/.exec(navigator.userAgent) || | ||
/iP(hone|od|ad)/.exec(navigator.userAgent)) && | ||
localStorage.getItem(this.concatStorageKey(this.PN_AUTH_USER_LOIGN_ORIGIN)) === "popup") { | ||
var container = (0, utils_1.popupWindow)(url, "login", 500, 750); | ||
return container; | ||
} | ||
var iframe = this.getIframe(); | ||
iframe.src = url; | ||
return iframe; | ||
}; | ||
Auth.prototype.buildUrl = function (path, extraParams) { | ||
@@ -388,0 +465,0 @@ var _a; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ParticleNetwork = void 0; | ||
var crypto_1 = require("@particle-network/crypto"); | ||
var auth_1 = require("./auth"); | ||
@@ -38,2 +39,3 @@ var types_1 = require("./types"); | ||
this.auth = new auth_1.Auth(this.config); | ||
window.particle = this; | ||
} | ||
@@ -50,2 +52,20 @@ else { | ||
}; | ||
/** | ||
* open wallet web wallet | ||
* @param target window open target | ||
* @param features window open features | ||
*/ | ||
ParticleNetwork.prototype.openWallet = function (target, features) { | ||
if (!this.auth.isLogin()) { | ||
throw types_1.AuthError.notLogin(); | ||
} | ||
if (!this.auth.walletExist()) { | ||
throw types_1.AuthError.walletNotCreated(); | ||
} | ||
var openWalletData = Object.create(this.config); | ||
openWalletData.authUserInfo = this.auth.userInfo(); | ||
var ciphertext = crypto_1.urlCrypto.encryptUrlParam(openWalletData); | ||
var url = "https://wallet.particle.network/?params=".concat(ciphertext, "&theme=").concat(this.auth.getThemeType()); | ||
window.open(url, target, features); | ||
}; | ||
return ParticleNetwork; | ||
@@ -52,0 +72,0 @@ }()); |
@@ -49,3 +49,3 @@ "use strict"; | ||
exports.supportChains = { | ||
ethereum: [1, 3, 4, 5, 42], | ||
ethereum: [1, 3, 4, 5], | ||
bsc: [56, 97], | ||
@@ -64,3 +64,4 @@ polygon: [137, 80001], | ||
solana: [101, 102, 103], | ||
platon: [210425, 2203181], | ||
}; | ||
//# sourceMappingURL=types.js.map |
@@ -9,2 +9,3 @@ /// <reference types="node" /> | ||
private PN_AUTH_USER_INFO; | ||
private PN_AUTH_USER_LOIGN_ORIGIN; | ||
events: EventEmitter; | ||
@@ -44,6 +45,7 @@ private secretKey; | ||
private getIframe; | ||
private openUrl; | ||
private buildUrl; | ||
private getThemeType; | ||
getThemeType(): string; | ||
private decrypt; | ||
} | ||
export {}; |
@@ -9,2 +9,8 @@ import { Auth } from "./auth"; | ||
setChainInfo(chain: ChainInfo): Promise<Wallet[]>; | ||
/** | ||
* open wallet web wallet | ||
* @param target window open target | ||
* @param features window open features | ||
*/ | ||
openWallet(target?: string, features?: string): void; | ||
} |
@@ -36,3 +36,3 @@ export declare class AuthError { | ||
declare type AuthTypeTuple = typeof AuthTypes; | ||
export declare type AuthType = AuthTypeTuple[number] | "all"; | ||
export declare type AuthType = AuthTypeTuple[number]; | ||
export interface UserInfo { | ||
@@ -72,2 +72,3 @@ id: number; | ||
solana: number[]; | ||
platon: number[]; | ||
}; | ||
@@ -74,0 +75,0 @@ export declare type ChainName = keyof typeof supportChains; |
export declare function isHttpUrl(url: string): boolean; | ||
export declare function getDeviceId(): string; | ||
export declare function getVersion(): string; | ||
export declare function popupWindow(url: string, title: string, w: number, h: number): Window | null; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getVersion = exports.getDeviceId = exports.isHttpUrl = void 0; | ||
exports.popupWindow = exports.getVersion = exports.getDeviceId = exports.isHttpUrl = void 0; | ||
var uuid_1 = require("uuid"); | ||
@@ -37,2 +37,15 @@ var HTTP_REGEX = "^https?:"; | ||
exports.getVersion = getVersion; | ||
function popupWindow(url, title, w, h) { | ||
var left = screen.width / 2 - w / 2; | ||
var top = screen.height / 2 - h / 2; | ||
return window.open(url, title, "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=" + | ||
w + | ||
", height=" + | ||
h + | ||
", top=" + | ||
top + | ||
", left=" + | ||
left); | ||
} | ||
exports.popupWindow = popupWindow; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "@particle-network/auth", | ||
"version": "0.6.2", | ||
"version": "0.6.3-alpha.0", | ||
"files": [ | ||
@@ -15,2 +15,4 @@ "lib", | ||
"dependencies": { | ||
"@particle-network/common": "^0.1.4", | ||
"@particle-network/crypto": "^0.1.0", | ||
"crypto-js": "^4.1.1", | ||
@@ -28,5 +30,6 @@ "uuid": "^8.3.2" | ||
"build": "yarn clean && tsc -p tsconfig.json", | ||
"dev:lib": "tsc -w", | ||
"build:min.js": "webpack" | ||
}, | ||
"gitHead": "2cb4e4fb6c65ed3d861b131a11256414f61c01de" | ||
"gitHead": "21ac77a2d3621d0dec1377fdc7a0b189337b2723" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
66453
863
4
+ Added@particle-network/common@0.1.11(transitive)
+ Added@particle-network/crypto@0.1.2(transitive)
+ Added@types/uuid@8.3.4(transitive)
+ Addeduuidv4@6.2.13(transitive)