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

@walletconnect/utils

Package Overview
Dependencies
Maintainers
1
Versions
661
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@walletconnect/utils - npm Package Compare versions

Comparing version 1.0.0-beta.24 to 1.0.0-beta.25

4

lib/index.d.ts

@@ -20,3 +20,3 @@ /// <reference types="node" />

export declare function convertNumberToUtf8(num: number): string;
export declare function convertNumberToHex(num: number, noPrefix?: boolean): string;
export declare function convertNumberToHex(num: number | string, noPrefix?: boolean): string;
export declare function convertHexToBuffer(hex: string): Buffer;

@@ -29,2 +29,4 @@ export declare function convertHexToArrayBuffer(hex: string): ArrayBuffer;

export declare function removeHexPrefix(hex: string): string;
export declare function isHexString(value: any): boolean;
export declare function isEmptyString(value: string): boolean;
export declare function payloadId(): number;

@@ -31,0 +33,0 @@ export declare function uuid(): string;

{
"name": "@walletconnect/utils",
"version": "1.0.0-beta.24",
"version": "1.0.0-beta.25",
"description": "Utility Library for WalletConnect",

@@ -47,3 +47,3 @@ "scripts": {

"@types/lodash.isnumber": "^3.0.5",
"@types/mocha": "^5.2.5",
"@types/mocha": "^5.2.6",
"@types/node": "^10.12.18",

@@ -59,6 +59,9 @@ "chai": "^4.1.2",

"dependencies": {
"@walletconnect/types": "^1.0.0-beta.23",
"ethers": "^4.0.27"
"@ethersproject/address": "^5.0.0-beta.125",
"@ethersproject/bytes": "^5.0.0-beta.126",
"@ethersproject/strings": "^5.0.0-beta.125",
"@walletconnect/types": "^1.0.0-beta.25",
"bignumber.js": "^8.1.1"
},
"gitHead": "165f7993c2acc907c653c02847fb02721052c6e7"
}

@@ -39,2 +39,5 @@ # WalletConnect Utils

function isHexString (value: any): boolean
function isEmptyString (value: string): boolean
function payloadId (): number

@@ -41,0 +44,0 @@ function uuid (): string

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

import { utils } from 'ethers'
import BigNumber from 'bignumber.js'
import {
isHexString as _isHexString,
hexlify,
arrayify
} from '@ethersproject/bytes'
import { getAddress } from '@ethersproject/address'
import { toUtf8Bytes, toUtf8String } from '@ethersproject/strings'

@@ -23,3 +30,3 @@ import {

export function convertArrayBufferToUtf8 (arrayBuffer: ArrayBuffer): string {
const utf8 = utils.toUtf8String(new Uint8Array(arrayBuffer))
const utf8 = toUtf8String(new Uint8Array(arrayBuffer))
return utf8

@@ -32,3 +39,3 @@ }

): string {
let hex = utils.hexlify(new Uint8Array(arrayBuffer))
let hex = hexlify(new Uint8Array(arrayBuffer))
if (noPrefix) {

@@ -88,3 +95,3 @@ hex = removeHexPrefix(hex)

export function convertUtf8ToArrayBuffer (utf8: string): ArrayBuffer {
const arrayBuffer = utils.toUtf8Bytes(utf8).buffer
const arrayBuffer = toUtf8Bytes(utf8).buffer
return arrayBuffer

@@ -105,3 +112,3 @@ }

export function convertUtf8ToNumber (utf8: string): number {
const num = utils.bigNumberify(utf8).toNumber()
const num = new BigNumber(utf8).toNumber()
return num

@@ -125,8 +132,12 @@ }

export function convertNumberToUtf8 (num: number): string {
const utf8 = utils.bigNumberify(num).toString()
const utf8 = new BigNumber(num).toString()
return utf8
}
export function convertNumberToHex (num: number, noPrefix?: boolean): string {
let hex = utils.bigNumberify(num).toHexString()
export function convertNumberToHex (
num: number | string,
noPrefix?: boolean
): string {
let hex = new BigNumber(num).toString(16)
hex = sanitizeHex(hex)
if (noPrefix) {

@@ -148,3 +159,3 @@ hex = removeHexPrefix(hex)

hex = addHexPrefix(hex)
const arrayBuffer = utils.arrayify(hex).buffer
const arrayBuffer = arrayify(hex).buffer
return arrayBuffer

@@ -160,3 +171,3 @@ }

export function convertHexToNumber (hex: string): number {
const num = utils.bigNumberify(hex).toNumber()
const num = new BigNumber(hex).toNumber()
return num

@@ -170,3 +181,5 @@ }

hex = hex.length % 2 !== 0 ? '0' + hex : hex
hex = addHexPrefix(hex)
if (hex) {
hex = addHexPrefix(hex)
}
return hex

@@ -189,2 +202,10 @@ }

export function isHexString (value: any): boolean {
return _isHexString(value)
}
export function isEmptyString (value: string): boolean {
return value === '' || (typeof value === 'string' && value.trim() === '')
}
export function payloadId (): number {

@@ -215,3 +236,3 @@ const datePart: number = new Date().getTime() * Math.pow(10, 3)

export const toChecksumAddress = (address: string) => {
return utils.getAddress(address)
return getAddress(address)
}

@@ -457,4 +478,4 @@

export function parsePersonalSign (params: string[]): string[] {
if (!utils.isHexString(params[1])) {
params[1] = convertUtf8ToHex(params[1])
if (!isHexString(params[0])) {
params[0] = convertUtf8ToHex(params[0])
}

@@ -473,7 +494,11 @@ return params

let result = value
if (!utils.isHexString(value)) {
if (typeof value === 'string') {
value = convertUtf8ToNumber(value)
if (
typeof value === 'number' ||
(typeof value === 'string' && !isEmptyString(value))
) {
if (!isHexString(value)) {
result = convertNumberToHex(value)
} else if (typeof value === 'string') {
result = sanitizeHex(value)
}
result = convertNumberToHex(value)
}

@@ -500,3 +525,4 @@ return result

typeof txData.nonce === 'undefined' ? '' : parseHexValues(txData.nonce),
data: typeof txData.data === 'undefined' ? '' : sanitizeHex(txData.data)
data:
typeof txData.data === 'undefined' ? '' : sanitizeHex(txData.data) || '0x'
}

@@ -503,0 +529,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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