Socket
Socket
Sign inDemoInstall

@particle-network/auth

Package Overview
Dependencies
Maintainers
1
Versions
118
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@particle-network/auth - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

64

lib/auth.js

@@ -18,2 +18,3 @@ "use strict";

const crypto_js_1 = __importDefault(require("crypto-js"));
const events_1 = require("events");
const types_1 = require("./types");

@@ -25,2 +26,3 @@ const utils_1 = require("./utils");

this.userStore = "particle_user_info";
this.events = new events_1.EventEmitter();
this.secretKey = "";

@@ -36,2 +38,5 @@ this._authResult = null;

if (data.error) {
if (data.error.code === 8005 || data.error.code === 10005) {
this.events.emit("disconnect");
}
this._authResult.reject(data.error);

@@ -61,2 +66,3 @@ }

resolve: (value) => {
this.events.emit("connect", value);
resolve(value);

@@ -77,2 +83,3 @@ },

this.setUserInfo(null);
this.events.emit("disconnect");
resolve();

@@ -89,4 +96,4 @@ },

return __awaiter(this, void 0, void 0, function* () {
if (!this.checkWallet()) {
return Promise.reject(types_1.AuthError.unauthorized());
if (!this.walletExist()) {
return Promise.reject(types_1.AuthError.walletNotCreated());
}

@@ -124,4 +131,4 @@ const iframe = this.getIframe();

return __awaiter(this, void 0, void 0, function* () {
if (!this.checkWallet()) {
return Promise.reject(types_1.AuthError.unauthorized());
if (!this.walletExist()) {
return Promise.reject(types_1.AuthError.walletNotCreated());
}

@@ -139,4 +146,4 @@ if (this.config.chainName !== "solana") {

return __awaiter(this, void 0, void 0, function* () {
if (!this.checkWallet()) {
return Promise.reject(types_1.AuthError.unauthorized());
if (!this.walletExist()) {
return Promise.reject(types_1.AuthError.walletNotCreated());
}

@@ -180,10 +187,10 @@ if (this.config.chainName === "solana") {

const wallets = userInfo.wallets;
let wallet;
if (chain.name === "solana") {
wallet = wallets.find((w) => w.chain_name === "solana");
if (this.config.chainName === chain.name && this.config.chainId === chain.id) {
return Promise.resolve(wallets);
}
else {
wallet = wallets.find((w) => w.chain_name === "evm_chain");
}
const wallet = this.wallet();
if (wallet) {
this.config.chainName = chain.name;
this.config.chainId = chain.id;
this.events.emit("chainChanged", chain);
return Promise.resolve(wallets);

@@ -200,2 +207,5 @@ }

resolve: (value) => {
this.config.chainName = chain.name;
this.config.chainId = chain.id;
this.events.emit("chainChanged", chain);
resolve(value);

@@ -211,2 +221,5 @@ },

}
basicCredentials() {
return `Basic ${Buffer.from(`${this.config.projectId}:${this.config.clientKey}`, "utf8").toString("base64")}`;
}
isLogin() {

@@ -219,11 +232,28 @@ return this.userInfo() !== null;

}
checkWallet() {
walletExist() {
return this.wallet() != null;
}
wallet() {
const userInfo = this.userInfo();
if (!userInfo) {
return false;
return null;
}
const wallets = userInfo.wallets;
const wallet = wallets.find((wallet) => wallet.chain_name === this.walletChainName());
return wallet !== undefined;
const wallet = userInfo.wallets.find((wallet) => wallet.chain_name === this.walletChainName());
if (wallet !== undefined && wallet.public_address.length > 0) {
return wallet;
}
return null;
}
on(event, listener) {
this.events.on(event, listener);
}
once(event, listener) {
this.events.once(event, listener);
}
off(event, listener) {
this.events.off(event, listener);
}
removeListener(event, listener) {
this.events.removeListener(event, listener);
}
walletChainName() {

@@ -230,0 +260,0 @@ return this.config.chainName === "solana" ? "solana" : "evm_chain";

@@ -18,3 +18,5 @@ "use strict";

__exportStar(require("./particle-network"), exports);
__exportStar(require("./types"), exports);
__exportStar(require("./utils"), exports);
__exportStar(require("./auth"), exports);
//# sourceMappingURL=index.js.map

@@ -8,3 +8,2 @@ "use strict";

constructor(config) {
this.config = config;
if (typeof config.chainName === "string" &&

@@ -11,0 +10,0 @@ typeof config.chainId === "number" &&

@@ -29,2 +29,5 @@ "use strict";

}
static walletNotCreated() {
return new AuthError(8006, "Wallet not created");
}
}

@@ -31,0 +34,0 @@ exports.AuthError = AuthError;

@@ -0,1 +1,3 @@

/// <reference types="node" />
import { EventEmitter } from "events";
import { Config, UserInfo, AuthType, Wallet, ChainInfo } from "./types";

@@ -7,2 +9,3 @@ declare type PrefixedHexString = string;

private userStore;
events: EventEmitter;
private secretKey;

@@ -13,3 +16,3 @@ private _authResult;

logout(): Promise<void>;
private sign;
sign(method: string, message: Base58String | PrefixedHexString): Promise<string>;
signAllTransactions(messages: Base58String[]): Promise<string[]>;

@@ -19,5 +22,11 @@ sendTransaction(message: Base58String | PrefixedHexString): Promise<string>;

chainId(): number;
basicCredentials(): string;
isLogin(): boolean;
userInfo(): UserInfo | null;
private checkWallet;
walletExist(): boolean;
wallet(): Wallet | null;
on(event: string, listener: (...args: any[]) => void): void;
once(event: string, listener: (...args: any[]) => void): void;
off(event: string, listener: (...args: any[]) => void): void;
removeListener(event: string, listener: (...args: any[]) => void): void;
private walletChainName;

@@ -24,0 +33,0 @@ private setAuthResult;

export * from "./particle-network";
export type { AuthType, UserInfo, Wallet, supportChains, Config, ChainName, ChainInfo } from "./types";
export * from "./types";
export * from "./utils";
export * from "./auth";
import { Auth } from "./auth";
import { Config } from "./types";
export declare class ParticleNetwork {
private config;
readonly auth: Auth;
private readonly config;
constructor(config: Config);
}

@@ -11,2 +11,3 @@ export declare class AuthError {

static notLogin(): AuthError;
static walletNotCreated(): AuthError;
}

@@ -67,3 +68,2 @@ export interface RequestArguments {

chainId: number;
rpcUrl?: string;
authUrl?: string;

@@ -70,0 +70,0 @@ }

{
"name": "@particle-network/auth",
"version": "0.1.1",
"version": "0.2.0",
"files": [

@@ -5,0 +5,0 @@ "lib",

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc