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.2 to 2.4.0-viemtest.1

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 } 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 } from './utils.js';
export * from './types.js';
export * from './validation.js';
import type { ConnectionInfo } from 'ethers/lib/utils';
import type 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,3 +78,3 @@ /**

* A method that takes `WalletHelpers` and
* returns an initialised `WalletModule` or array of `WalletModule`s.
* returns an initialized `WalletModule` or array of `WalletModule`s.
*/

@@ -121,3 +120,2 @@ export type WalletInit = (helpers: WalletHelpers) => WalletModule | WalletModule[] | null;

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

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

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

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

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

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

@@ -1,1 +0,5 @@

export declare function weiToEth(wei: string): string;
export declare const isAddress: (address: string) => address is `0x${string}`;
export declare const weiHexToEth: (wei: string) => string;
export declare const weiToEth: (wei: string) => string;
export declare const ethToWeiBigInt: (eth: string | number) => bigint;
export declare const bigIntToHex: (value: bigint) => string;

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

import Bignumber from 'bignumber.js';
export function weiToEth(wei) {
return new Bignumber(wei).div(1e18).toString(10);
}
const addressRegex = /^0x[a-fA-F0-9]{40}$/;
export const isAddress = (address) => {
return addressRegex.test(address);
};
export const weiHexToEth = (wei) => {
const weiBigInt = BigInt(parseInt(wei, 16));
const ethBalance = divideBigIntWithDecimalResolution(weiBigInt, BigInt('1000000000000000000'));
return ethBalance.toString();
};
export const weiToEth = (wei) => {
if (!wei)
return wei;
const weiBigInt = BigInt(parseInt(wei));
const ethBalance = divideBigIntWithDecimalResolution(weiBigInt, BigInt('1000000000000000000'));
return ethBalance.toString();
};
const divideBigIntWithDecimalResolution = (dividend, divisor, decimalPlaces = 8) => {
if (typeof dividend !== 'bigint' || typeof divisor !== 'bigint') {
throw new Error('dividend and divisor must be BigInt values');
}
if (typeof decimalPlaces !== 'number' || decimalPlaces < 0) {
throw new Error('decimalPlaces must be a non-negative number');
}
// Multiply the dividend by 10 ** decimalPlaces to add precision
const adjustedDividend = dividend * BigInt(10 ** decimalPlaces);
const quotient = adjustedDividend / divisor;
// Convert the result back to a decimal number
const decimalPart = String(quotient % BigInt(10 ** decimalPlaces)).padStart(decimalPlaces, '0');
const integerPart = quotient / BigInt(10 ** decimalPlaces);
const result = `${integerPart}.${decimalPart}`;
return parseFloat(result);
};
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;
const decimalSplit = ethString.split('.');
const integerPart = BigInt(decimalSplit[0]);
const decimalPart = decimalSplit.length > 1 ? BigInt(decimalSplit[1]) : BigInt(0);
const decimalLength = decimalSplit.length > 1 ? decimalSplit[1].length : 0;
const weiFactor = BigInt(10 ** (18 - decimalLength));
// Perform the conversion from Eth to Wei
const weiValue = integerPart * BigInt(10 ** 18) + decimalPart * weiFactor;
return BigInt(weiValue);
};
export const bigIntToHex = (value) => {
return `0x${value.toString(16)}`;
};
{
"name": "@web3-onboard/common",
"version": "2.3.2",
"version": "2.4.0-viemtest.1",
"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.",

@@ -73,9 +73,8 @@ "keywords": [

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