Socket
Socket
Sign inDemoInstall

@web3-onboard/common

Package Overview
Dependencies
Maintainers
2
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@web3-onboard/common - npm Package Compare versions

Comparing version 2.3.4 to 2.4.0-alpha.2

2

dist/index.d.ts
export { ProviderRpcError } from './errors.js';
export { createEIP1193Provider } from './eip-1193.js';
export { InterVar } from './fonts.js';
export { weiToEth } from './utils.js';
export { weiHexToEth, weiToEth, isAddress, bigIntToHex, ethToWeiBigInt, createDownloadMessage, chainIdToViemImport } from './utils.js';
export * from './types.js';
export * from './validation.js';
export { ProviderRpcError } from './errors.js';
export { createEIP1193Provider } from './eip-1193.js';
export { InterVar } from './fonts.js';
export { weiToEth } from './utils.js';
export { weiHexToEth, weiToEth, isAddress, bigIntToHex, ethToWeiBigInt, createDownloadMessage, chainIdToViemImport } from './utils.js';
export * from './types.js';
export * from './validation.js';
import type { ConnectionInfo } from 'ethers/lib/utils';
import type EventEmitter from 'eventemitter3';
import EventEmitter from 'eventemitter3';
import type { TypedData as EIP712TypedData } from 'eip-712';
import type { ethers } from 'ethers';
export type { TypedData as EIP712TypedData } from 'eip-712';

@@ -79,7 +78,12 @@ /**

* A method that takes `WalletHelpers` and
* returns an initialised `WalletModule` or array of `WalletModule`s.
* returns an initialized `WalletModule` or array of `WalletModule`s.
*/
export type WalletInit = (helpers: WalletHelpers) => WalletModule | WalletModule[] | null;
export type DeviceNotBrowser = {
type: null;
os: null;
browser: null;
};
export type WalletHelpers = {
device: Device;
device: Device | DeviceNotBrowser;
};

@@ -121,3 +125,2 @@ export interface APIKey {

appMetadata: AppMetadata | null;
BigNumber: typeof ethers.BigNumber;
EventEmitter: typeof EventEmitter;

@@ -144,3 +147,3 @@ };

}
export type AccountAddress = string;
export type AccountAddress = Address;
/**

@@ -190,3 +193,3 @@ * An array of addresses

}
type Address = string;
export type Address = `0x${string}`;
type Message = string;

@@ -193,0 +196,0 @@ export interface EthSignMessageRequest {

@@ -1,1 +0,9 @@

export declare function weiToEth(wei: string): string;
import type { Chain } from './types.js';
import type { Chain as ViemChain } from 'viem';
export declare const isAddress: (address: string) => address is `0x${string}`;
export declare const weiHexToEth: (wei: `0x${string}`) => string;
export declare const weiToEth: (wei: string) => string;
export declare const ethToWeiBigInt: (eth: string | number) => bigint;
export declare const bigIntToHex: (value: bigint) => string;
export declare const createDownloadMessage: (walletLabel: string, download?: string | (() => void)) => string;
export declare const chainIdToViemImport: (w3oChain: Chain) => Promise<ViemChain | unknown>;

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

import Bignumber from 'bignumber.js';
export function weiToEth(wei) {
return new Bignumber(wei).div(1e18).toString(10);
}
import { formatEther, fromHex, hexToBigInt, numberToHex, parseEther } from 'viem';
export const isAddress = (address) => {
return isAddress(address);
};
export const weiHexToEth = (wei) => {
const weiBigInt = hexToBigInt(wei);
return formatEther(weiBigInt);
};
export const weiToEth = (wei) => {
if (!wei)
return wei;
const weiBigInt = fromHex(wei, 'bigint');
return formatEther(weiBigInt);
};
export const ethToWeiBigInt = (eth) => {
if (typeof eth !== 'string' && typeof eth !== 'number') {
throw new Error('eth must be a string or number value');
}
const ethString = typeof eth === 'number' ? eth.toString() : eth;
return parseEther(ethString);
};
export const bigIntToHex = (value) => {
return numberToHex(value);
};
export const createDownloadMessage = (walletLabel, download) => {
if (!download)
return `Please switch to ${walletLabel} to continue`;
if (typeof download === 'function') {
return `Please <a href="#" onclick="${() => download()}">install</a> or enable to ${walletLabel} to continue`;
}
else {
return `Please <a href="${download}" target="_blank">install</a> or enable to ${walletLabel} to continue`;
}
};
export const chainIdToViemImport = async (w3oChain) => {
const viemChains = await import('viem/chains');
const { id, label, token, publicRpcUrl, blockExplorerUrl, rpcUrl } = w3oChain;
switch (id) {
case '0x89': {
const { polygon } = viemChains;
return polygon;
}
case '0xa': {
const { optimism } = viemChains;
return optimism;
}
case '0xa4b1': {
const { arbitrum } = viemChains;
return arbitrum;
}
case '0x144': {
const { zkSync } = viemChains;
return zkSync;
}
case '0x38': {
const { bsc } = viemChains;
return bsc;
}
case '0x1': {
const { mainnet } = viemChains;
return mainnet;
}
case '0xaa36a7': {
const { sepolia } = viemChains;
return sepolia;
}
case '0xfa': {
const { fantom } = viemChains;
return fantom;
}
case '0xa86a': {
const { avalanche } = viemChains;
return avalanche;
}
case '0xa4ec': {
const { celo } = viemChains;
return celo;
}
case '0x2105': {
const { base } = viemChains;
return base;
}
case '0x14a33': {
const { baseGoerli } = viemChains;
return baseGoerli;
}
case '0x64': {
const { gnosis } = viemChains;
return gnosis;
}
case '0x63564C40': {
const { harmonyOne } = viemChains;
return harmonyOne;
}
case '0x27bc86aa': {
const { degen } = viemChains;
return degen;
}
default: {
const { extractChain, defineChain } = await import('viem');
const nonNativeChain = extractChain({
chains: Object.values(viemChains),
id: fromHex(id, 'number')
});
if (nonNativeChain)
return nonNativeChain;
return defineChain({
id: fromHex(id, 'number'),
name: label !== null && label !== void 0 ? label : '',
nativeCurrency: {
decimals: 18,
name: token !== null && token !== void 0 ? token : '',
symbol: token !== null && token !== void 0 ? token : ''
},
rpcUrls: {
default: {
http: [rpcUrl !== null && rpcUrl !== void 0 ? rpcUrl : '', publicRpcUrl !== null && publicRpcUrl !== void 0 ? publicRpcUrl : '']
}
},
blockExplorers: {
default: { name: 'Explorer', url: blockExplorerUrl !== null && blockExplorerUrl !== void 0 ? blockExplorerUrl : '' }
}
});
}
}
};

@@ -6,4 +6,2 @@ import Joi from 'joi';

export declare const chainNamespaceValidation: Joi.StringSchema<string>;
/** Related to ConnectionInfo from 'ethers/lib/utils' */
export declare const providerConnectionInfoValidation: Joi.ObjectSchema<any>;
export declare const chainValidation: Joi.ObjectSchema<any>;

@@ -8,15 +8,2 @@ import Joi from 'joi';

export const chainNamespaceValidation = Joi.string().valid('evm');
/** Related to ConnectionInfo from 'ethers/lib/utils' */
export const providerConnectionInfoValidation = Joi.object({
url: Joi.string().required(),
headers: Joi.object(),
user: Joi.string(),
password: Joi.string(),
allowInsecureAuthentication: Joi.boolean(),
allowGzip: Joi.boolean(),
throttleLimit: Joi.number(),
throttleSlotInterval: Joi.number(),
throttleCallback: Joi.function(),
timeout: Joi.number()
});
const secondaryTokenValidation = Joi.object({

@@ -40,4 +27,3 @@ address: Joi.string().required(),

protectedRpcUrl: Joi.string(),
blockExplorerUrl: Joi.string(),
providerConnectionInfoValidation
blockExplorerUrl: Joi.string()
});
{
"name": "@web3-onboard/common",
"version": "2.3.4",
"version": "2.4.0-alpha.2",
"description": "Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardised spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.",

@@ -74,9 +74,9 @@ "keywords": [

"tslib": "^2.0.0",
"typescript": "^4.5.5"
"typescript": "^5.4.5",
"ethers": "5.5.4"
},
"dependencies": {
"bignumber.js": "^9.1.0",
"ethers": "5.5.4",
"joi": "17.9.1"
"joi": "17.9.1",
"viem": "2.12.0"
}
}
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