Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@particle-network/provider

Package Overview
Dependencies
Maintainers
4
Versions
138
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@particle-network/provider - npm Package Compare versions

Comparing version 0.9.3 to 0.9.4

42

lib/auth-adapter.js

@@ -23,3 +23,3 @@ "use strict";

return __awaiter(this, void 0, void 0, function* () {
if (request.method === "eth_requestAccounts" || request.method === "eth_accounts") {
if (request.method === 'eth_requestAccounts' || request.method === 'eth_accounts') {
let wallet = this.auth.wallet();

@@ -35,9 +35,9 @@ if (wallet) {

else {
throw new Error("Create wallet failed");
throw new Error('Create wallet failed');
}
}
else if (request.method === "eth_chainId") {
else if (request.method === 'eth_chainId') {
return (0, auth_1.intToHex)(this.auth.chainId());
}
else if (request.method === "eth_sendTransaction") {
else if (request.method === 'eth_sendTransaction') {
if (request.params && request.params instanceof Array && request.params[0]) {

@@ -48,6 +48,6 @@ const txData = request.params[0];

// set transaction default type "0x2", EIP1559.
txData.type = "0x2";
txData.type = '0x2';
}
else {
txData.type = "0x0";
txData.type = '0x0';
}

@@ -59,6 +59,6 @@ }

if ((0, auth_1.isNullish)(txData.nonce)) {
txData.nonce = "0x0";
txData.nonce = '0x0';
}
if ((0, auth_1.isNullish)(txData.data)) {
txData.data = "0x";
txData.data = '0x';
}

@@ -71,7 +71,7 @@ return this.auth.sendTransaction(this.legacyToString(request.params[0]));

}
else if (request.method === "eth_signTypedData_v3" || request.method === "eth_signTypedData_v4") {
else if (request.method === 'eth_signTypedData_v3' || request.method === 'eth_signTypedData_v4') {
if (request.params && request.params instanceof Array && request.params.length >= 2) {
let typedData = request.params[1];
if (typeof typedData === "string" && !typedData.startsWith("0x")) {
typedData = (0, auth_1.addHexPrefix)(Buffer.from(typedData).toString("hex"));
if (typeof typedData === 'string' && !typedData.startsWith('0x')) {
typedData = (0, auth_1.addHexPrefix)(Buffer.from(typedData).toString('hex'));
}

@@ -84,7 +84,7 @@ return this.auth.sign(request.method, this.legacyToString(typedData));

}
else if (request.method === "eth_signTypedData" || request.method === "eth_signTypedData_v1") {
else if (request.method === 'eth_signTypedData' || request.method === 'eth_signTypedData_v1') {
if (request.params && request.params instanceof Array && request.params[0]) {
let typedData = request.params[0];
if (typeof typedData === "string" && !typedData.startsWith("0x")) {
typedData = (0, auth_1.addHexPrefix)(Buffer.from(typedData).toString("hex"));
if (typeof typedData === 'string' && !typedData.startsWith('0x')) {
typedData = (0, auth_1.addHexPrefix)(Buffer.from(typedData).toString('hex'));
}

@@ -97,3 +97,3 @@ return this.auth.sign(request.method, this.legacyToString(typedData));

}
else if (request.method === "personal_sign") {
else if (request.method === 'personal_sign') {
if (request.params && request.params instanceof Array && request.params[0]) {

@@ -106,3 +106,3 @@ return this.auth.sign(request.method, this.legacyToString(request.params[0]));

}
else if (request.method === "wallet_switchEthereumChain") {
else if (request.method === 'wallet_switchEthereumChain') {
if (request.params && request.params instanceof Array && request.params[0] && request.params[0].chainId) {

@@ -129,15 +129,15 @@ const chainId = Number(request.params[0].chainId);

let message;
if (typeof params === "number") {
if (typeof params === 'number') {
message = (0, auth_1.addHexPrefix)(params.toString(16));
}
else if (typeof params === "string") {
if (params.toString().startsWith("0x")) {
else if (typeof params === 'string') {
if (params.toString().startsWith('0x')) {
message = params;
}
else {
message = (0, auth_1.addHexPrefix)(Buffer.from(params).toString("hex"));
message = (0, auth_1.addHexPrefix)(Buffer.from(params).toString('hex'));
}
}
else {
message = (0, auth_1.addHexPrefix)(Buffer.from(JSON.stringify(params)).toString("hex"));
message = (0, auth_1.addHexPrefix)(Buffer.from(JSON.stringify(params)).toString('hex'));
}

@@ -144,0 +144,0 @@ return message;

@@ -30,3 +30,3 @@ "use strict";

get connected() {
return typeof this.api !== "undefined";
return typeof this.api !== 'undefined';
}

@@ -48,6 +48,6 @@ get connecting() {

return __awaiter(this, void 0, void 0, function* () {
if (typeof this.api === "undefined") {
if (typeof this.api === 'undefined') {
this.api = yield this.register();
}
return this.api.post("/", request).then((res) => res.data);
return this.api.post('/', request).then((res) => res.data);
});

@@ -64,5 +64,5 @@ }

return new Promise((resolve, reject) => {
this.events.once("open", () => {
if (typeof this.api === "undefined") {
return reject(new Error("HTTP connection is missing or invalid"));
this.events.once('open', () => {
if (typeof this.api === 'undefined') {
return reject(new Error('HTTP connection is missing or invalid'));
}

@@ -78,4 +78,4 @@ resolve(this.api);

headers: {
Accept: "application/json",
"Content-Type": "application/json",
Accept: 'application/json',
'Content-Type': 'application/json',
},

@@ -86,3 +86,3 @@ });

if (config.headers) {
config.headers["Authorization"] = connectConfig.basicCredentials;
config.headers['Authorization'] = connectConfig.basicCredentials;
}

@@ -109,7 +109,7 @@ else {

this.registering = false;
this.events.emit("open");
this.events.emit('open');
}
onClose() {
this.api = undefined;
this.events.emit("close");
this.events.emit('close');
}

@@ -116,0 +116,0 @@ }

@@ -28,11 +28,13 @@ "use strict";

const event = this.events;
this.signerProvider.on("connect", (result) => event.emit("connect", result));
this.signerProvider.on("disconnect", (result) => event.emit("disconnect", result));
this.signerProvider.on("message", (result) => event.emit("message", result));
this.signerProvider.on("chainChanged", (result) => event.emit("chainChanged", result));
this.signerProvider.on("accountsChanged", (result) => event.emit("accountsChanged", result));
this.signerProvider.on('connect', (result) => event.emit('connect', result));
this.signerProvider.on('disconnect', (result) => event.emit('disconnect', result));
this.signerProvider.on('message', (result) => event.emit('message', result));
this.signerProvider.on('chainChanged', (result) => event.emit('chainChanged', result));
this.signerProvider.on('accountsChanged', (result) => event.emit('accountsChanged', result));
}
setConnection() {
return new connection_1.HttpConnection({
url: (0, auth_1.isParticleDev)() ? "https://rpc-debug.particle.network/evm-chain" : "https://rpc.particle.network/evm-chain",
url: (0, auth_1.isParticleDev)()
? 'https://rpc-debug.particle.network/evm-chain'
: 'https://rpc.particle.network/evm-chain',
basicCredentials: this.auth.basicCredentials(),

@@ -46,3 +48,3 @@ chainId: () => { var _a; return (_a = this.chainId) !== null && _a !== void 0 ? _a : this.auth.chainId(); },

const provider = this.signerProvider;
if (provider.disconnect && typeof provider.disconnect === "function") {
if (provider.disconnect && typeof provider.disconnect === 'function') {
try {

@@ -64,3 +66,3 @@ yield provider.disconnect();

let result;
if (provider.enable && typeof provider.enable === "function") {
if (provider.enable && typeof provider.enable === 'function') {
try {

@@ -72,3 +74,3 @@ result = yield provider.enable();

result = yield this.request({
method: "eth_requestAccounts",
method: 'eth_requestAccounts',
});

@@ -91,3 +93,3 @@ }

id: (_a = request.id) !== null && _a !== void 0 ? _a : (0, uuid_1.v4)(),
jsonrpc: (_b = request.jsonrpc) !== null && _b !== void 0 ? _b : "2.0",
jsonrpc: (_b = request.jsonrpc) !== null && _b !== void 0 ? _b : '2.0',
method: request.method,

@@ -97,3 +99,3 @@ params: request.params,

if (types_1.signerMethods.includes(rpcRequest.method)) {
console.log("Particle Signer Provider Request", rpcRequest);
console.log('Particle Signer Provider Request', rpcRequest);
return yield this.signerProvider.request(rpcRequest);

@@ -103,3 +105,3 @@ }

try {
this.chainId = Number(yield this.signerProvider.request({ method: "eth_chainId" }));
this.chainId = Number(yield this.signerProvider.request({ method: 'eth_chainId' }));
}

@@ -110,3 +112,3 @@ catch (error) {

const particlePpcRequest = Object.assign(Object.assign({}, rpcRequest), { chainId: this.chainId });
console.log("Particle Provider Delegate Request", particlePpcRequest);
console.log('Particle Provider Delegate Request', particlePpcRequest);
return yield this.requestStrict(particlePpcRequest);

@@ -113,0 +115,0 @@ }

@@ -26,8 +26,8 @@ "use strict";

this.authAdapter = new auth_adapter_1.AuthEVMAdapter(this.auth);
this.auth.on("chainChanged", (chain) => {
if (chain.name !== "Solana") {
this.emit("chainChanged", (0, auth_1.intToHex)(chain.id));
this.auth.on('chainChanged', (chain) => {
if (chain.name !== 'Solana') {
this.emit('chainChanged', (0, auth_1.intToHex)(chain.id));
}
});
if (typeof window !== "undefined" && window.particle) {
if (typeof window !== 'undefined' && window.particle) {
window.particle.particleProvider = this;

@@ -38,3 +38,5 @@ }

return new connection_1.HttpConnection({
url: (0, auth_1.isParticleDev)() ? "https://rpc-debug.particle.network/evm-chain" : "https://rpc.particle.network/evm-chain",
url: (0, auth_1.isParticleDev)()
? 'https://rpc-debug.particle.network/evm-chain'
: 'https://rpc.particle.network/evm-chain',
basicCredentials: this.auth.basicCredentials(),

@@ -59,3 +61,3 @@ chainId: () => this.auth.chainId(),

return this.request({
method: "eth_requestAccounts",
method: 'eth_requestAccounts',
});

@@ -73,7 +75,7 @@ });

}
console.log("Particle Provider Request", request);
console.log('Particle Provider Request', request);
const rpcRequest = {
chainId: Number(this.auth.chainId()),
id: (_a = request.id) !== null && _a !== void 0 ? _a : (0, uuid_1.v4)(),
jsonrpc: (_b = request.jsonrpc) !== null && _b !== void 0 ? _b : "2.0",
jsonrpc: (_b = request.jsonrpc) !== null && _b !== void 0 ? _b : '2.0',
method: request.method,

@@ -105,4 +107,4 @@ params: request.params,

yield this.connection.open();
this.connection.on("close", () => this.emit("disconnect"));
this.emit("connect", {
this.connection.on('close', () => this.emit('disconnect'));
this.emit('connect', {
chainId: (0, auth_1.intToHex)(this.auth.chainId()),

@@ -109,0 +111,0 @@ });

@@ -16,24 +16,24 @@ "use strict";

static userRejectedRequest() {
return new ProviderError(4001, "The user rejected the request");
return new ProviderError(4001, 'The user rejected the request');
}
static userCancelOperation() {
return new ProviderError(4011, "The user cancel the operation");
return new ProviderError(4011, 'The user cancel the operation');
}
static unauthorized() {
return new ProviderError(4100, "The requested method and/or account has not been authorized by the user");
return new ProviderError(4100, 'The requested method and/or account has not been authorized by the user');
}
static unsupportedMethod() {
return new ProviderError(4200, "The Provider does not support the requested method");
return new ProviderError(4200, 'The Provider does not support the requested method');
}
static unsupportedChain() {
return new ProviderError(4201, "The Provider does not support the chain");
return new ProviderError(4201, 'The Provider does not support the chain');
}
static disconnected() {
return new ProviderError(4900, "The Provider is disconnected from all chains");
return new ProviderError(4900, 'The Provider is disconnected from all chains');
}
static chainDisconnected() {
return new ProviderError(4901, "The Provider is not connected to the requested chain");
return new ProviderError(4901, 'The Provider is not connected to the requested chain');
}
static paramsError() {
return new ProviderError(8002, "Param error, see doc for more info");
return new ProviderError(8002, 'Param error, see doc for more info');
}

@@ -83,17 +83,17 @@ }

exports.IJsonRpcProvider = IJsonRpcProvider;
exports.notSupportMethods = ["eth_signTransaction", "eth_sign", "eth_sendRawTransaction"];
exports.notSupportMethods = ['eth_signTransaction', 'eth_sign', 'eth_sendRawTransaction'];
exports.signerMethods = [
"eth_requestAccounts",
"eth_accounts",
"eth_chainId",
"eth_sendTransaction",
"eth_signTypedData",
"eth_signTypedData_v1",
"eth_signTypedData_v3",
"eth_signTypedData_v4",
"personal_sign",
"wallet_switchEthereumChain",
"wallet_addEthereumChain",
"wallet_watchAsset", //EIP-747
'eth_requestAccounts',
'eth_accounts',
'eth_chainId',
'eth_sendTransaction',
'eth_signTypedData',
'eth_signTypedData_v1',
'eth_signTypedData_v3',
'eth_signTypedData_v4',
'personal_sign',
'wallet_switchEthereumChain',
'wallet_addEthereumChain',
'wallet_watchAsset', //EIP-747
];
//# sourceMappingURL=types.js.map

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

import type { Auth, JsonRpcRequest } from "@particle-network/auth";
import type { IAuthAdapter } from "./types";
import type { Auth, JsonRpcRequest } from '@particle-network/auth';
import type { IAuthAdapter } from './types';
export declare class AuthEVMAdapter implements IAuthAdapter {

@@ -4,0 +4,0 @@ private auth;

@@ -1,4 +0,4 @@

import type { JsonRpcResponse, ParticleRpcRequest } from "@particle-network/auth";
import { IJsonRpcConnection } from "./types";
import type { ConnectionConfig } from "./types";
import type { JsonRpcResponse, ParticleRpcRequest } from '@particle-network/auth';
import { IJsonRpcConnection } from './types';
import type { ConnectionConfig } from './types';
export declare class HttpConnection extends IJsonRpcConnection {

@@ -5,0 +5,0 @@ private config;

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

import { IEthereumProvider, IJsonRpcProvider, ProviderAccounts } from "./types";
import { Auth, JsonRpcRequest } from "@particle-network/auth";
import { IEthereumProvider, IJsonRpcProvider, ProviderAccounts } from './types';
import { Auth, JsonRpcRequest } from '@particle-network/auth';
export declare class ParticleDelegateProvider extends IJsonRpcProvider implements IEthereumProvider {

@@ -4,0 +4,0 @@ private auth;

@@ -1,2 +0,2 @@

export * from "./provider";
export * from "./delegate-provider";
export * from './provider';
export * from './delegate-provider';

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

import { IEthereumProvider, IJsonRpcProvider, ProviderAccounts } from "./types";
import { Auth, JsonRpcRequest } from "@particle-network/auth";
import { IEthereumProvider, IJsonRpcProvider, ProviderAccounts } from './types';
import { Auth, JsonRpcRequest } from '@particle-network/auth';
export declare class ParticleProvider extends IJsonRpcProvider implements IEthereumProvider {

@@ -4,0 +4,0 @@ private auth;

/// <reference types="node" />
import { JsonRpcRequest, JsonRpcResponse, ParticleRpcRequest, RequestArguments } from "@particle-network/auth";
import { EventEmitter } from "events";
import { JsonRpcRequest, JsonRpcResponse, ParticleRpcRequest, RequestArguments } from '@particle-network/auth';
import { EventEmitter } from 'events';
export declare class ProviderError extends Error {

@@ -28,3 +28,3 @@ code: number;

export interface EIP1102Request extends RequestArguments {
method: "eth_requestAccounts";
method: 'eth_requestAccounts';
}

@@ -69,7 +69,7 @@ export interface ConnectionConfig {

export interface IEthereumProvider {
on(event: "connect", listener: (info: ProviderConnectInfo) => void): void;
on(event: "disconnect", listener: (error?: ProviderError) => void): void;
on(event: "message", listener: (message: ProviderMessage) => void): void;
on(event: "chainChanged", listener: (chainId: ProviderChainId) => void): void;
on(event: "accountsChanged", listener: (accounts: ProviderAccounts) => void): void;
on(event: 'connect', listener: (info: ProviderConnectInfo) => void): void;
on(event: 'disconnect', listener: (error?: ProviderError) => void): void;
on(event: 'message', listener: (message: ProviderMessage) => void): void;
on(event: 'chainChanged', listener: (chainId: ProviderChainId) => void): void;
on(event: 'accountsChanged', listener: (accounts: ProviderAccounts) => void): void;
on(event: string, listener: any): void;

@@ -76,0 +76,0 @@ once(event: string, listener: any): void;

{
"name": "@particle-network/provider",
"version": "0.9.3",
"files": [
"es",
"lib",
"LICENSE"
],
"main": "lib/index.js",
"module": "es/index.js",
"types": "lib/types/index.d.ts",
"license": "Apache-2.0",
"publishConfig": {
"access": "public"
},
"peerDependencies": {
"@particle-network/auth": "^0.9.2"
},
"dependencies": {
"axios": "^0.27.2",
"uuid": "^8.3.2"
},
"devDependencies": {
"@particle-network/auth": "^0.9.3",
"@types/uuid": "^8.3.4",
"ts-loader": "^9.3.1",
"webpack-cli": "^4.10.0"
},
"scripts": {
"build": "yarn clean && tsc -p tsconfig.json && node ./esBuild.js",
"clean": "shx rm -rf lib/* && shx rm -rf es/*",
"build:min.js": "webpack"
},
"gitHead": "bab3bc95b4cae5735ddb0c8fc9ce63a9706db3b0"
"name": "@particle-network/provider",
"version": "0.9.4",
"files": [
"es",
"lib",
"LICENSE"
],
"main": "lib/index.js",
"module": "es/index.js",
"types": "lib/types/index.d.ts",
"license": "Apache-2.0",
"publishConfig": {
"access": "public"
},
"peerDependencies": {
"@particle-network/auth": "^0.9.3"
},
"dependencies": {
"axios": "^0.27.2",
"uuid": "^8.3.2"
},
"devDependencies": {
"@particle-network/auth": "^0.9.4",
"@types/uuid": "^8.3.4",
"ts-loader": "^9.3.1",
"webpack-cli": "^4.10.0"
},
"scripts": {
"build": "yarn clean && tsc -p tsconfig.json && node ./esBuild.js",
"clean": "shx rm -rf lib/* && shx rm -rf es/*",
"build:min.js": "webpack"
},
"gitHead": "f55fa711e664029af978b40262c1333c9015db28"
}

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

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