@walletconnect/utils
Advanced tools
Comparing version 1.0.0-beta.24 to 1.0.0-beta.25
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
58
722171
5
1047
+ Addedbignumber.js@^8.1.1
+ Added@ethersproject/address@5.7.0(transitive)
+ Added@ethersproject/bignumber@5.7.0(transitive)
+ Added@ethersproject/bytes@5.7.0(transitive)
+ Added@ethersproject/constants@5.7.0(transitive)
+ Added@ethersproject/keccak256@5.7.0(transitive)
+ Added@ethersproject/logger@5.7.0(transitive)
+ Added@ethersproject/rlp@5.7.0(transitive)
+ Added@ethersproject/strings@5.7.0(transitive)
+ Addedbignumber.js@8.1.1(transitive)
+ Addedbn.js@5.2.1(transitive)
+ Addedjs-sha3@0.8.0(transitive)
- Removedethers@^4.0.27
- Removedaes-js@3.0.0(transitive)
- Removedbn.js@4.12.0(transitive)
- Removedbrorand@1.1.0(transitive)
- Removedelliptic@6.5.4(transitive)
- Removedethers@4.0.49(transitive)
- Removedhash.js@1.1.3(transitive)
- Removedhmac-drbg@1.0.1(transitive)
- Removedinherits@2.0.4(transitive)
- Removedjs-sha3@0.5.7(transitive)
- Removedminimalistic-assert@1.0.1(transitive)
- Removedminimalistic-crypto-utils@1.0.1(transitive)
- Removedscrypt-js@2.0.4(transitive)
- Removedsetimmediate@1.0.4(transitive)
- Removeduuid@2.0.1(transitive)
- Removedxmlhttprequest@1.8.0(transitive)