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

@harmony-js/utils

Package Overview
Dependencies
Maintainers
3
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@harmony-js/utils - npm Package Compare versions

Comparing version 0.1.43 to 0.1.45

129

dist/chain.d.ts

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

/**
* ## About this package
*
* `@harmony-js/util` provides utility functions for Harmony dapps and other `harmony-js` packages
*
* Develop can use this package to:
* - Transform the unit of token (fromWei, toWei...)
* - Convert variable to different type (hexToBN, numberToHex...)
* - Check validators information (isAddress, isPublicKey, isBlockNumber...)
*
* ## How to use this package
*
* ### Step 1: create a Harmony Instance
* ```javascript
* const { Harmony } = require('@harmony-js/core');
* const { ChainID, ChainType } = require('@harmony-js/utils');
* const { BN } = require('@harmony-js/crypto');
*
* const hmy = new Harmony(
* 'http://localhost:9500',
* {
* chainType: ChainType.Harmony,
* chainId: ChainID.HmyLocal,
* },
* );
* ```
*
* ### Step 2: Select and call functions
* Here are some examples:
*
* ```javascript
* // numberToString
* const num = 123;
* const str = hmy.utils.numberToString(num)
* console.log(str);
*
* // add0xToString
* const str = '12345';
* const expected = hmy.utils.add0xToString(str)
* console.log(expected);
*
* // fromWei
* const Wei = new BN('1000000000000000000');
* const expected = hmy.utils.fromWei(Wei, hmy.utils.Units.one);
* console.log(expected);
*
* // toWei
* const one = new BN('1');
* const expected = hmy.utils.toWei(one, hmy.utils.Units.one);
* const num = hmy.utils.numToStr(expected);
* console.log(num);
* ```
*
* ### Step 3: Using unit class to convet the token unit
* ```javascript
* // convert one to Gwei
* const one = new hmy.utils.Unit('1').asOne();
* const oneToGwei = one.toGwei();
* console.log(oneToGwei);
* ```
*
* ## Some Important consts and Enums
* ### Chain Type
* ```javascript
* Harmony = 'hmy',
* Ethereum = 'eth',
* ```
*
* ### Chain ID
* ```javascript
* Default = 0,
EthMainnet = 1,
Morden = 2,
Ropsten = 3,
Rinkeby = 4,
RootstockMainnet = 30,
RootstockTestnet = 31,
Kovan = 42,
EtcMainnet = 61,
EtcTestnet = 62,
Geth = 1337,
Ganache = 0,
HmyMainnet = 1,
HmyTestnet = 2,
HmyLocal = 2,
HmyPangaea = 3,
* ```
*
* ### Default Config
* ```javascript
* export const defaultConfig = {
* Default: {
* Chain_ID: ChainID.HmyLocal,
* Chain_Type: ChainType.Harmony,
* Chain_URL: 'http://localhost:9500',
* Network_ID: 'Local',
* },
* DefaultWS: {
* Chain_ID: ChainID.HmyLocal,
* Chain_Type: ChainType.Harmony,
* Chain_URL: 'ws://localhost:9800',
* Network_ID: 'LocalWS',
* },
* };
* ```
*
* ### Unit Map
* ```
* [Units.wei, '1'], // 1 wei
* [Units.Kwei, '1000'], // 1e3 wei
* [Units.Mwei, '1000000'], // 1e6 wei
* [Units.Gwei, '1000000000'], // 1e9 wei
* [Units.szabo, '1000000000000'], // 1e12 wei
* [Units.finney, '1000000000000000'], // 1e15 wei
* [Units.ether, '1000000000000000000'], // 1e18 wei
* [Units.one, '1000000000000000000'], // 1e18 wei
* [Units.Kether, '1000000000000000000000'], // 1e21 wei
* [Units.Mether, '1000000000000000000000000'], // 1e24 wei
* [Units.Gether, '1000000000000000000000000000'], // 1e27 wei
* [Units.Tether, '1000000000000000000000000000000'], // 1e30 wei
* ```
*
* @packageDocumentation
* @module harmony-utils
*/
export declare const enum ChainType {

@@ -23,2 +148,3 @@ Harmony = "hmy",

}
/** @hidden */
export declare const defaultConfig: {

@@ -38,2 +164,3 @@ Default: {

};
/** @hidden */
export declare abstract class HarmonyCore {

@@ -48,4 +175,6 @@ chainType: ChainType;

}
/** @hidden */
export declare const HDPath = "m/44'/1023'/0'/0/";
/** @hidden */
export declare const AddressSuffix = "-";
//# sourceMappingURL=chain.d.ts.map

134

dist/chain.js
"use strict";
/**
* ## About this package
*
* `@harmony-js/util` provides utility functions for Harmony dapps and other `harmony-js` packages
*
* Develop can use this package to:
* - Transform the unit of token (fromWei, toWei...)
* - Convert variable to different type (hexToBN, numberToHex...)
* - Check validators information (isAddress, isPublicKey, isBlockNumber...)
*
* ## How to use this package
*
* ### Step 1: create a Harmony Instance
* ```javascript
* const { Harmony } = require('@harmony-js/core');
* const { ChainID, ChainType } = require('@harmony-js/utils');
* const { BN } = require('@harmony-js/crypto');
*
* const hmy = new Harmony(
* 'http://localhost:9500',
* {
* chainType: ChainType.Harmony,
* chainId: ChainID.HmyLocal,
* },
* );
* ```
*
* ### Step 2: Select and call functions
* Here are some examples:
*
* ```javascript
* // numberToString
* const num = 123;
* const str = hmy.utils.numberToString(num)
* console.log(str);
*
* // add0xToString
* const str = '12345';
* const expected = hmy.utils.add0xToString(str)
* console.log(expected);
*
* // fromWei
* const Wei = new BN('1000000000000000000');
* const expected = hmy.utils.fromWei(Wei, hmy.utils.Units.one);
* console.log(expected);
*
* // toWei
* const one = new BN('1');
* const expected = hmy.utils.toWei(one, hmy.utils.Units.one);
* const num = hmy.utils.numToStr(expected);
* console.log(num);
* ```
*
* ### Step 3: Using unit class to convet the token unit
* ```javascript
* // convert one to Gwei
* const one = new hmy.utils.Unit('1').asOne();
* const oneToGwei = one.toGwei();
* console.log(oneToGwei);
* ```
*
* ## Some Important consts and Enums
* ### Chain Type
* ```javascript
* Harmony = 'hmy',
* Ethereum = 'eth',
* ```
*
* ### Chain ID
* ```javascript
* Default = 0,
EthMainnet = 1,
Morden = 2,
Ropsten = 3,
Rinkeby = 4,
RootstockMainnet = 30,
RootstockTestnet = 31,
Kovan = 42,
EtcMainnet = 61,
EtcTestnet = 62,
Geth = 1337,
Ganache = 0,
HmyMainnet = 1,
HmyTestnet = 2,
HmyLocal = 2,
HmyPangaea = 3,
* ```
*
* ### Default Config
* ```javascript
* export const defaultConfig = {
* Default: {
* Chain_ID: ChainID.HmyLocal,
* Chain_Type: ChainType.Harmony,
* Chain_URL: 'http://localhost:9500',
* Network_ID: 'Local',
* },
* DefaultWS: {
* Chain_ID: ChainID.HmyLocal,
* Chain_Type: ChainType.Harmony,
* Chain_URL: 'ws://localhost:9800',
* Network_ID: 'LocalWS',
* },
* };
* ```
*
* ### Unit Map
* ```
* [Units.wei, '1'], // 1 wei
* [Units.Kwei, '1000'], // 1e3 wei
* [Units.Mwei, '1000000'], // 1e6 wei
* [Units.Gwei, '1000000000'], // 1e9 wei
* [Units.szabo, '1000000000000'], // 1e12 wei
* [Units.finney, '1000000000000000'], // 1e15 wei
* [Units.ether, '1000000000000000000'], // 1e18 wei
* [Units.one, '1000000000000000000'], // 1e18 wei
* [Units.Kether, '1000000000000000000000'], // 1e21 wei
* [Units.Mether, '1000000000000000000000000'], // 1e24 wei
* [Units.Gether, '1000000000000000000000000000'], // 1e27 wei
* [Units.Tether, '1000000000000000000000000000000'], // 1e30 wei
* ```
*
* @packageDocumentation
* @module harmony-utils
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.AddressSuffix = exports.HDPath = exports.HarmonyCore = exports.defaultConfig = exports.ChainID = exports.ChainType = void 0;
var ChainType;

@@ -27,2 +153,3 @@ (function (ChainType) {

})(ChainID = exports.ChainID || (exports.ChainID = {}));
/** @hidden */
exports.defaultConfig = {

@@ -42,2 +169,3 @@ Default: {

};
/** @hidden */
var HarmonyCore = /** @class */ (function () {

@@ -63,3 +191,3 @@ function HarmonyCore(chainType, chainId) {

},
enumerable: true,
enumerable: false,
configurable: true

@@ -71,3 +199,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -84,4 +212,6 @@ });

exports.HarmonyCore = HarmonyCore;
/** @hidden */
exports.HDPath = "m/44'/1023'/0'/0/";
/** @hidden */
exports.AddressSuffix = '-';
//# sourceMappingURL=chain.js.map

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

/**
* @packageDocumentation
* @ignore
*/
//# sourceMappingURL=errors.d.ts.map
"use strict";
/**
* @packageDocumentation
* @ignore
*/
//# sourceMappingURL=errors.js.map

@@ -13,2 +13,6 @@ /**

/**
* @packageDocumentation
* @module harmony-utils
*/
var isKeyString = function (keyString, lengh) {

@@ -166,5 +170,3 @@ return !!keyString.replace('0x', '').match("^[0-9a-fA-F]{" + lengh + "}$");

}
if (isAddress(address) ||
isBech32Address(address) ||
isBech32TestNetAddress(address)) {
if (isAddress(address) || isBech32Address(address) || isBech32TestNetAddress(address)) {
return true;

@@ -179,14 +181,14 @@ }

/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
Copyright (c) Microsoft Corporation.
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */

@@ -211,2 +213,6 @@

/**
* @packageDocumentation
* @module harmony-utils
*/
(function (Units) {

@@ -226,2 +232,3 @@ Units["wei"] = "wei";

})(exports.Units || (exports.Units = {}));
/** @hidden */
var unitMap = new Map([

@@ -241,5 +248,9 @@ ["wei" /* wei */, '1'],

]);
/** @hidden */
var DEFAULT_OPTIONS = {
pad: false,
};
/**
* Convert Number to String
*/
var numberToString = function (obj, radix) {

@@ -260,2 +271,5 @@ if (radix === void 0) { radix = 10; }

};
/**
* Convert Number to String
*/
var numToStr = function (input) {

@@ -290,2 +304,5 @@ if (typeof input === 'string') {

};
/**
* Convert number to hex
*/
var numberToHex = function (obj) {

@@ -299,2 +316,5 @@ try {

};
/**
* Convert hex to Decimal number
*/
var hexToNumber = function (hex) {

@@ -312,2 +332,5 @@ if (isHex(hex) && hex[0] !== '-') {

};
/**
* Convert hex to Big Number
*/
var hexToBN = function (hex) {

@@ -325,2 +348,5 @@ if (isHex(hex) && hex[0] !== '-') {

};
/**
* Converts any ONE value into wei
*/
var toWei = function (input, unit) {

@@ -373,2 +399,5 @@ try {

};
/**
* Converts any wei value into a ONE value.
*/
var fromWei = function (wei, unit, options) {

@@ -625,2 +654,6 @@ if (options === void 0) { options = DEFAULT_OPTIONS; }

/**
* @packageDocumentation
* @module harmony-utils
*/
(function (AssertType) {

@@ -630,2 +663,3 @@ AssertType["required"] = "required";

})(exports.AssertType || (exports.AssertType = {}));
/** @hidden */
var validatorArray = {

@@ -714,2 +748,127 @@ isNumber: [isNumber],

/**
* ## About this package
*
* `@harmony-js/util` provides utility functions for Harmony dapps and other `harmony-js` packages
*
* Develop can use this package to:
* - Transform the unit of token (fromWei, toWei...)
* - Convert variable to different type (hexToBN, numberToHex...)
* - Check validators information (isAddress, isPublicKey, isBlockNumber...)
*
* ## How to use this package
*
* ### Step 1: create a Harmony Instance
* ```javascript
* const { Harmony } = require('@harmony-js/core');
* const { ChainID, ChainType } = require('@harmony-js/utils');
* const { BN } = require('@harmony-js/crypto');
*
* const hmy = new Harmony(
* 'http://localhost:9500',
* {
* chainType: ChainType.Harmony,
* chainId: ChainID.HmyLocal,
* },
* );
* ```
*
* ### Step 2: Select and call functions
* Here are some examples:
*
* ```javascript
* // numberToString
* const num = 123;
* const str = hmy.utils.numberToString(num)
* console.log(str);
*
* // add0xToString
* const str = '12345';
* const expected = hmy.utils.add0xToString(str)
* console.log(expected);
*
* // fromWei
* const Wei = new BN('1000000000000000000');
* const expected = hmy.utils.fromWei(Wei, hmy.utils.Units.one);
* console.log(expected);
*
* // toWei
* const one = new BN('1');
* const expected = hmy.utils.toWei(one, hmy.utils.Units.one);
* const num = hmy.utils.numToStr(expected);
* console.log(num);
* ```
*
* ### Step 3: Using unit class to convet the token unit
* ```javascript
* // convert one to Gwei
* const one = new hmy.utils.Unit('1').asOne();
* const oneToGwei = one.toGwei();
* console.log(oneToGwei);
* ```
*
* ## Some Important consts and Enums
* ### Chain Type
* ```javascript
* Harmony = 'hmy',
* Ethereum = 'eth',
* ```
*
* ### Chain ID
* ```javascript
* Default = 0,
EthMainnet = 1,
Morden = 2,
Ropsten = 3,
Rinkeby = 4,
RootstockMainnet = 30,
RootstockTestnet = 31,
Kovan = 42,
EtcMainnet = 61,
EtcTestnet = 62,
Geth = 1337,
Ganache = 0,
HmyMainnet = 1,
HmyTestnet = 2,
HmyLocal = 2,
HmyPangaea = 3,
* ```
*
* ### Default Config
* ```javascript
* export const defaultConfig = {
* Default: {
* Chain_ID: ChainID.HmyLocal,
* Chain_Type: ChainType.Harmony,
* Chain_URL: 'http://localhost:9500',
* Network_ID: 'Local',
* },
* DefaultWS: {
* Chain_ID: ChainID.HmyLocal,
* Chain_Type: ChainType.Harmony,
* Chain_URL: 'ws://localhost:9800',
* Network_ID: 'LocalWS',
* },
* };
* ```
*
* ### Unit Map
* ```
* [Units.wei, '1'], // 1 wei
* [Units.Kwei, '1000'], // 1e3 wei
* [Units.Mwei, '1000000'], // 1e6 wei
* [Units.Gwei, '1000000000'], // 1e9 wei
* [Units.szabo, '1000000000000'], // 1e12 wei
* [Units.finney, '1000000000000000'], // 1e15 wei
* [Units.ether, '1000000000000000000'], // 1e18 wei
* [Units.one, '1000000000000000000'], // 1e18 wei
* [Units.Kether, '1000000000000000000000'], // 1e21 wei
* [Units.Mether, '1000000000000000000000000'], // 1e24 wei
* [Units.Gether, '1000000000000000000000000000'], // 1e27 wei
* [Units.Tether, '1000000000000000000000000000000'], // 1e30 wei
* ```
*
* @packageDocumentation
* @module harmony-utils
*/
(function (ChainType) {

@@ -737,2 +896,3 @@ ChainType["Harmony"] = "hmy";

})(exports.ChainID || (exports.ChainID = {}));
/** @hidden */
var defaultConfig = {

@@ -752,2 +912,3 @@ Default: {

};
/** @hidden */
var HarmonyCore = /** @class */ (function () {

@@ -773,3 +934,3 @@ function HarmonyCore(chainType, chainId) {

},
enumerable: true,
enumerable: false,
configurable: true

@@ -781,3 +942,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -793,5 +954,12 @@ });

}());
/** @hidden */
var HDPath = "m/44'/1023'/0'/0/";
/** @hidden */
var AddressSuffix = '-';
/**
* @packageDocumentation
* @module harmony-utils
* @hidden
*/
function defineReadOnly(object, name, value) {

@@ -805,2 +973,8 @@ Object.defineProperty(object, name, {

/**
* @packageDocumentation
* @module harmony-utils
* @ignore
*/
exports.isKeyString = isKeyString;

@@ -807,0 +981,0 @@ exports.isAddress = isAddress;

@@ -0,1 +1,6 @@

/**
* @packageDocumentation
* @module harmony-utils
* @ignore
*/
export * from './validators';

@@ -2,0 +7,0 @@ export * from './transformers';

@@ -7,2 +7,6 @@ /**

/**
* @packageDocumentation
* @module harmony-utils
*/
var isKeyString = function (keyString, lengh) {

@@ -161,5 +165,3 @@ return !!keyString.replace('0x', '').match("^[0-9a-fA-F]{" + lengh + "}$");

}
if (isAddress(address) ||
isBech32Address(address) ||
isBech32TestNetAddress(address)) {
if (isAddress(address) || isBech32Address(address) || isBech32TestNetAddress(address)) {
return true;

@@ -174,14 +176,14 @@ }

/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
Copyright (c) Microsoft Corporation.
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */

@@ -206,2 +208,6 @@

/**
* @packageDocumentation
* @module harmony-utils
*/
var Units;

@@ -222,2 +228,3 @@ (function (Units) {

})(Units || (Units = {}));
/** @hidden */
var unitMap = new Map([

@@ -237,5 +244,9 @@ ["wei" /* wei */, '1'],

]);
/** @hidden */
var DEFAULT_OPTIONS = {
pad: false,
};
/**
* Convert Number to String
*/
var numberToString = function (obj, radix) {

@@ -256,2 +267,5 @@ if (radix === void 0) { radix = 10; }

};
/**
* Convert Number to String
*/
var numToStr = function (input) {

@@ -286,2 +300,5 @@ if (typeof input === 'string') {

};
/**
* Convert number to hex
*/
var numberToHex = function (obj) {

@@ -295,2 +312,5 @@ try {

};
/**
* Convert hex to Decimal number
*/
var hexToNumber = function (hex) {

@@ -308,2 +328,5 @@ if (isHex(hex) && hex[0] !== '-') {

};
/**
* Convert hex to Big Number
*/
var hexToBN = function (hex) {

@@ -321,2 +344,5 @@ if (isHex(hex) && hex[0] !== '-') {

};
/**
* Converts any ONE value into wei
*/
var toWei = function (input, unit) {

@@ -369,2 +395,5 @@ try {

};
/**
* Converts any wei value into a ONE value.
*/
var fromWei = function (wei, unit, options) {

@@ -621,2 +650,7 @@ if (options === void 0) { options = DEFAULT_OPTIONS; }

/**
* @packageDocumentation
* @module harmony-utils
*/
/** @hidden */
var AssertType;

@@ -627,2 +661,3 @@ (function (AssertType) {

})(AssertType || (AssertType = {}));
/** @hidden */
var validatorArray = {

@@ -711,2 +746,127 @@ isNumber: [isNumber],

/**
* ## About this package
*
* `@harmony-js/util` provides utility functions for Harmony dapps and other `harmony-js` packages
*
* Develop can use this package to:
* - Transform the unit of token (fromWei, toWei...)
* - Convert variable to different type (hexToBN, numberToHex...)
* - Check validators information (isAddress, isPublicKey, isBlockNumber...)
*
* ## How to use this package
*
* ### Step 1: create a Harmony Instance
* ```javascript
* const { Harmony } = require('@harmony-js/core');
* const { ChainID, ChainType } = require('@harmony-js/utils');
* const { BN } = require('@harmony-js/crypto');
*
* const hmy = new Harmony(
* 'http://localhost:9500',
* {
* chainType: ChainType.Harmony,
* chainId: ChainID.HmyLocal,
* },
* );
* ```
*
* ### Step 2: Select and call functions
* Here are some examples:
*
* ```javascript
* // numberToString
* const num = 123;
* const str = hmy.utils.numberToString(num)
* console.log(str);
*
* // add0xToString
* const str = '12345';
* const expected = hmy.utils.add0xToString(str)
* console.log(expected);
*
* // fromWei
* const Wei = new BN('1000000000000000000');
* const expected = hmy.utils.fromWei(Wei, hmy.utils.Units.one);
* console.log(expected);
*
* // toWei
* const one = new BN('1');
* const expected = hmy.utils.toWei(one, hmy.utils.Units.one);
* const num = hmy.utils.numToStr(expected);
* console.log(num);
* ```
*
* ### Step 3: Using unit class to convet the token unit
* ```javascript
* // convert one to Gwei
* const one = new hmy.utils.Unit('1').asOne();
* const oneToGwei = one.toGwei();
* console.log(oneToGwei);
* ```
*
* ## Some Important consts and Enums
* ### Chain Type
* ```javascript
* Harmony = 'hmy',
* Ethereum = 'eth',
* ```
*
* ### Chain ID
* ```javascript
* Default = 0,
EthMainnet = 1,
Morden = 2,
Ropsten = 3,
Rinkeby = 4,
RootstockMainnet = 30,
RootstockTestnet = 31,
Kovan = 42,
EtcMainnet = 61,
EtcTestnet = 62,
Geth = 1337,
Ganache = 0,
HmyMainnet = 1,
HmyTestnet = 2,
HmyLocal = 2,
HmyPangaea = 3,
* ```
*
* ### Default Config
* ```javascript
* export const defaultConfig = {
* Default: {
* Chain_ID: ChainID.HmyLocal,
* Chain_Type: ChainType.Harmony,
* Chain_URL: 'http://localhost:9500',
* Network_ID: 'Local',
* },
* DefaultWS: {
* Chain_ID: ChainID.HmyLocal,
* Chain_Type: ChainType.Harmony,
* Chain_URL: 'ws://localhost:9800',
* Network_ID: 'LocalWS',
* },
* };
* ```
*
* ### Unit Map
* ```
* [Units.wei, '1'], // 1 wei
* [Units.Kwei, '1000'], // 1e3 wei
* [Units.Mwei, '1000000'], // 1e6 wei
* [Units.Gwei, '1000000000'], // 1e9 wei
* [Units.szabo, '1000000000000'], // 1e12 wei
* [Units.finney, '1000000000000000'], // 1e15 wei
* [Units.ether, '1000000000000000000'], // 1e18 wei
* [Units.one, '1000000000000000000'], // 1e18 wei
* [Units.Kether, '1000000000000000000000'], // 1e21 wei
* [Units.Mether, '1000000000000000000000000'], // 1e24 wei
* [Units.Gether, '1000000000000000000000000000'], // 1e27 wei
* [Units.Tether, '1000000000000000000000000000000'], // 1e30 wei
* ```
*
* @packageDocumentation
* @module harmony-utils
*/
var ChainType;

@@ -736,2 +896,3 @@ (function (ChainType) {

})(ChainID || (ChainID = {}));
/** @hidden */
var defaultConfig = {

@@ -751,2 +912,3 @@ Default: {

};
/** @hidden */
var HarmonyCore = /** @class */ (function () {

@@ -772,3 +934,3 @@ function HarmonyCore(chainType, chainId) {

},
enumerable: true,
enumerable: false,
configurable: true

@@ -780,3 +942,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -792,5 +954,12 @@ });

}());
/** @hidden */
var HDPath = "m/44'/1023'/0'/0/";
/** @hidden */
var AddressSuffix = '-';
/**
* @packageDocumentation
* @module harmony-utils
* @hidden
*/
function defineReadOnly(object, name, value) {

@@ -804,3 +973,9 @@ Object.defineProperty(object, name, {

/**
* @packageDocumentation
* @module harmony-utils
* @ignore
*/
export { isKeyString, isAddress, isPrivateKey, isPublicKey, isHash, isNumber, isInt, isString, isBoolean, isArray, isJsonString, isObject, isFunction, isHex, isHttp, isWs, DefaultBlockParams, isBlockNumber, isBech32Address, isBech32TestNetAddress, isValidAddress, Units, unitMap, numberToString, numToStr, add0xToString, strip0x, numberToHex, hexToNumber, hexToBN, toWei, fromWei, Unit, AssertType, validatorArray, validateArgs, generateValidateObjects, assertObject, ChainType, ChainID, defaultConfig, HarmonyCore, HDPath, AddressSuffix, defineReadOnly };
//# sourceMappingURL=index.esm.js.map
"use strict";
/**
* @packageDocumentation
* @module harmony-utils
* @ignore
*/
Object.defineProperty(exports, "__esModule", { value: true });

@@ -3,0 +8,0 @@ var tslib_1 = require("tslib");

@@ -13,2 +13,6 @@ /**

/**
* @packageDocumentation
* @module harmony-utils
*/
var isKeyString = function (keyString, lengh) {

@@ -166,5 +170,3 @@ return !!keyString.replace('0x', '').match("^[0-9a-fA-F]{" + lengh + "}$");

}
if (isAddress(address) ||
isBech32Address(address) ||
isBech32TestNetAddress(address)) {
if (isAddress(address) || isBech32Address(address) || isBech32TestNetAddress(address)) {
return true;

@@ -179,14 +181,14 @@ }

/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
Copyright (c) Microsoft Corporation.
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */

@@ -211,2 +213,6 @@

/**
* @packageDocumentation
* @module harmony-utils
*/
(function (Units) {

@@ -226,2 +232,3 @@ Units["wei"] = "wei";

})(exports.Units || (exports.Units = {}));
/** @hidden */
var unitMap = new Map([

@@ -241,5 +248,9 @@ ["wei" /* wei */, '1'],

]);
/** @hidden */
var DEFAULT_OPTIONS = {
pad: false,
};
/**
* Convert Number to String
*/
var numberToString = function (obj, radix) {

@@ -260,2 +271,5 @@ if (radix === void 0) { radix = 10; }

};
/**
* Convert Number to String
*/
var numToStr = function (input) {

@@ -290,2 +304,5 @@ if (typeof input === 'string') {

};
/**
* Convert number to hex
*/
var numberToHex = function (obj) {

@@ -299,2 +316,5 @@ try {

};
/**
* Convert hex to Decimal number
*/
var hexToNumber = function (hex) {

@@ -312,2 +332,5 @@ if (isHex(hex) && hex[0] !== '-') {

};
/**
* Convert hex to Big Number
*/
var hexToBN = function (hex) {

@@ -325,2 +348,5 @@ if (isHex(hex) && hex[0] !== '-') {

};
/**
* Converts any ONE value into wei
*/
var toWei = function (input, unit) {

@@ -373,2 +399,5 @@ try {

};
/**
* Converts any wei value into a ONE value.
*/
var fromWei = function (wei, unit, options) {

@@ -625,2 +654,6 @@ if (options === void 0) { options = DEFAULT_OPTIONS; }

/**
* @packageDocumentation
* @module harmony-utils
*/
(function (AssertType) {

@@ -630,2 +663,3 @@ AssertType["required"] = "required";

})(exports.AssertType || (exports.AssertType = {}));
/** @hidden */
var validatorArray = {

@@ -714,2 +748,127 @@ isNumber: [isNumber],

/**
* ## About this package
*
* `@harmony-js/util` provides utility functions for Harmony dapps and other `harmony-js` packages
*
* Develop can use this package to:
* - Transform the unit of token (fromWei, toWei...)
* - Convert variable to different type (hexToBN, numberToHex...)
* - Check validators information (isAddress, isPublicKey, isBlockNumber...)
*
* ## How to use this package
*
* ### Step 1: create a Harmony Instance
* ```javascript
* const { Harmony } = require('@harmony-js/core');
* const { ChainID, ChainType } = require('@harmony-js/utils');
* const { BN } = require('@harmony-js/crypto');
*
* const hmy = new Harmony(
* 'http://localhost:9500',
* {
* chainType: ChainType.Harmony,
* chainId: ChainID.HmyLocal,
* },
* );
* ```
*
* ### Step 2: Select and call functions
* Here are some examples:
*
* ```javascript
* // numberToString
* const num = 123;
* const str = hmy.utils.numberToString(num)
* console.log(str);
*
* // add0xToString
* const str = '12345';
* const expected = hmy.utils.add0xToString(str)
* console.log(expected);
*
* // fromWei
* const Wei = new BN('1000000000000000000');
* const expected = hmy.utils.fromWei(Wei, hmy.utils.Units.one);
* console.log(expected);
*
* // toWei
* const one = new BN('1');
* const expected = hmy.utils.toWei(one, hmy.utils.Units.one);
* const num = hmy.utils.numToStr(expected);
* console.log(num);
* ```
*
* ### Step 3: Using unit class to convet the token unit
* ```javascript
* // convert one to Gwei
* const one = new hmy.utils.Unit('1').asOne();
* const oneToGwei = one.toGwei();
* console.log(oneToGwei);
* ```
*
* ## Some Important consts and Enums
* ### Chain Type
* ```javascript
* Harmony = 'hmy',
* Ethereum = 'eth',
* ```
*
* ### Chain ID
* ```javascript
* Default = 0,
EthMainnet = 1,
Morden = 2,
Ropsten = 3,
Rinkeby = 4,
RootstockMainnet = 30,
RootstockTestnet = 31,
Kovan = 42,
EtcMainnet = 61,
EtcTestnet = 62,
Geth = 1337,
Ganache = 0,
HmyMainnet = 1,
HmyTestnet = 2,
HmyLocal = 2,
HmyPangaea = 3,
* ```
*
* ### Default Config
* ```javascript
* export const defaultConfig = {
* Default: {
* Chain_ID: ChainID.HmyLocal,
* Chain_Type: ChainType.Harmony,
* Chain_URL: 'http://localhost:9500',
* Network_ID: 'Local',
* },
* DefaultWS: {
* Chain_ID: ChainID.HmyLocal,
* Chain_Type: ChainType.Harmony,
* Chain_URL: 'ws://localhost:9800',
* Network_ID: 'LocalWS',
* },
* };
* ```
*
* ### Unit Map
* ```
* [Units.wei, '1'], // 1 wei
* [Units.Kwei, '1000'], // 1e3 wei
* [Units.Mwei, '1000000'], // 1e6 wei
* [Units.Gwei, '1000000000'], // 1e9 wei
* [Units.szabo, '1000000000000'], // 1e12 wei
* [Units.finney, '1000000000000000'], // 1e15 wei
* [Units.ether, '1000000000000000000'], // 1e18 wei
* [Units.one, '1000000000000000000'], // 1e18 wei
* [Units.Kether, '1000000000000000000000'], // 1e21 wei
* [Units.Mether, '1000000000000000000000000'], // 1e24 wei
* [Units.Gether, '1000000000000000000000000000'], // 1e27 wei
* [Units.Tether, '1000000000000000000000000000000'], // 1e30 wei
* ```
*
* @packageDocumentation
* @module harmony-utils
*/
(function (ChainType) {

@@ -737,2 +896,3 @@ ChainType["Harmony"] = "hmy";

})(exports.ChainID || (exports.ChainID = {}));
/** @hidden */
var defaultConfig = {

@@ -752,2 +912,3 @@ Default: {

};
/** @hidden */
var HarmonyCore = /** @class */ (function () {

@@ -773,3 +934,3 @@ function HarmonyCore(chainType, chainId) {

},
enumerable: true,
enumerable: false,
configurable: true

@@ -781,3 +942,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -793,5 +954,12 @@ });

}());
/** @hidden */
var HDPath = "m/44'/1023'/0'/0/";
/** @hidden */
var AddressSuffix = '-';
/**
* @packageDocumentation
* @module harmony-utils
* @hidden
*/
function defineReadOnly(object, name, value) {

@@ -805,2 +973,8 @@ Object.defineProperty(object, name, {

/**
* @packageDocumentation
* @module harmony-utils
* @ignore
*/
exports.isKeyString = isKeyString;

@@ -807,0 +981,0 @@ exports.isAddress = isAddress;

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

/**
* @packageDocumentation
* @module harmony-utils
* @hidden
*/
export declare function defineReadOnly(object: any, name: string, value: any): void;
//# sourceMappingURL=tools.d.ts.map
"use strict";
/**
* @packageDocumentation
* @module harmony-utils
* @hidden
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.defineReadOnly = void 0;
function defineReadOnly(object, name, value) {

@@ -4,0 +10,0 @@ Object.defineProperty(object, name, {

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

/**
* @packageDocumentation
* @module harmony-utils
*/
import BN from 'bn.js';

@@ -16,12 +20,34 @@ export declare const enum Units {

}
/** @hidden */
export declare const unitMap: Map<Units, string>;
export declare const numberToString: (obj: string | number | BN, radix?: number) => string;
/**
* Convert Number to String
*/
export declare const numberToString: (obj: BN | number | string, radix?: number) => string;
/**
* Convert Number to String
*/
export declare const numToStr: (input: any) => string;
export declare const add0xToString: (obj: string) => string;
export declare const strip0x: (obj: string) => string;
/**
* Convert number to hex
*/
export declare const numberToHex: (obj: any) => string;
/**
* Convert hex to Decimal number
*/
export declare const hexToNumber: (hex: string) => string;
/**
* Convert hex to Big Number
*/
export declare const hexToBN: (hex: string) => BN;
export declare const toWei: (input: string | BN, unit: Units) => BN;
export declare const fromWei: (wei: string | BN, unit: Units, options?: any) => string;
/**
* Converts any ONE value into wei
*/
export declare const toWei: (input: BN | string, unit: Units) => BN;
/**
* Converts any wei value into a ONE value.
*/
export declare const fromWei: (wei: BN | string, unit: Units, options?: any) => string;
export declare class Unit {

@@ -28,0 +54,0 @@ static from(str: BN | string): Unit;

"use strict";
/**
* @packageDocumentation
* @module harmony-utils
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Unit = exports.fromWei = exports.toWei = exports.hexToBN = exports.hexToNumber = exports.numberToHex = exports.strip0x = exports.add0xToString = exports.numToStr = exports.numberToString = exports.unitMap = exports.Units = void 0;
var tslib_1 = require("tslib");

@@ -21,2 +26,3 @@ var bn_js_1 = tslib_1.__importDefault(require("bn.js"));

})(Units = exports.Units || (exports.Units = {}));
/** @hidden */
exports.unitMap = new Map([

@@ -36,5 +42,9 @@ ["wei" /* wei */, '1'],

]);
/** @hidden */
var DEFAULT_OPTIONS = {
pad: false,
};
/**
* Convert Number to String
*/
exports.numberToString = function (obj, radix) {

@@ -55,2 +65,5 @@ if (radix === void 0) { radix = 10; }

};
/**
* Convert Number to String
*/
exports.numToStr = function (input) {

@@ -85,2 +98,5 @@ if (typeof input === 'string') {

};
/**
* Convert number to hex
*/
exports.numberToHex = function (obj) {

@@ -94,2 +110,5 @@ try {

};
/**
* Convert hex to Decimal number
*/
exports.hexToNumber = function (hex) {

@@ -107,2 +126,5 @@ if (validators_1.isHex(hex) && hex[0] !== '-') {

};
/**
* Convert hex to Big Number
*/
exports.hexToBN = function (hex) {

@@ -120,2 +142,5 @@ if (validators_1.isHex(hex) && hex[0] !== '-') {

};
/**
* Converts any ONE value into wei
*/
exports.toWei = function (input, unit) {

@@ -168,2 +193,5 @@ try {

};
/**
* Converts any wei value into a ONE value.
*/
exports.fromWei = function (wei, unit, options) {

@@ -170,0 +198,0 @@ if (options === void 0) { options = DEFAULT_OPTIONS; }

@@ -0,1 +1,6 @@

/**
* @packageDocumentation
* @module harmony-utils
*/
/** @hidden */
export declare const enum AssertType {

@@ -5,2 +10,3 @@ required = "required",

}
/** @hidden */
export declare const validatorArray: any;

@@ -7,0 +13,0 @@ export declare function validateArgs(args: any, requiredArgs: any, optionalArgs: any): boolean;

"use strict";
/**
* @packageDocumentation
* @module harmony-utils
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.assertObject = exports.generateValidateObjects = exports.validateArgs = exports.validatorArray = exports.AssertType = void 0;
var validators_1 = require("./validators");
/** @hidden */
var AssertType;

@@ -9,2 +15,3 @@ (function (AssertType) {

})(AssertType = exports.AssertType || (exports.AssertType = {}));
/** @hidden */
exports.validatorArray = {

@@ -11,0 +18,0 @@ isNumber: [validators_1.isNumber],

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

/**
* @packageDocumentation
* @module harmony-utils
*/
export declare const isKeyString: {

@@ -2,0 +6,0 @@ (keyString: string, lengh: number): boolean;

9

dist/validators.js
"use strict";
/**
* @packageDocumentation
* @module harmony-utils
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.isValidAddress = exports.isBech32TestNetAddress = exports.isBech32Address = exports.isBlockNumber = exports.DefaultBlockParams = exports.isWs = exports.isHttp = exports.isHex = exports.isFunction = exports.isObject = exports.isJsonString = exports.isArray = exports.isBoolean = exports.isString = exports.isInt = exports.isNumber = exports.isHash = exports.isPublicKey = exports.isPrivateKey = exports.isAddress = exports.isKeyString = void 0;
exports.isKeyString = function (keyString, lengh) {

@@ -156,5 +161,3 @@ return !!keyString.replace('0x', '').match("^[0-9a-fA-F]{" + lengh + "}$");

}
if (exports.isAddress(address) ||
exports.isBech32Address(address) ||
exports.isBech32TestNetAddress(address)) {
if (exports.isAddress(address) || exports.isBech32Address(address) || exports.isBech32TestNetAddress(address)) {
return true;

@@ -161,0 +164,0 @@ }

{
"name": "@harmony-js/utils",
"version": "0.1.43",
"version": "0.1.45",
"description": "utils for harmony",

@@ -24,3 +24,3 @@ "main": "dist/index.js",

},
"gitHead": "bdcfbf0f8050d96da22ed009da33465f7ad7671b"
"gitHead": "a35db780aea823fab8510da0881b22805d35648f"
}

@@ -0,1 +1,127 @@

/**
* ## About this package
*
* `@harmony-js/util` provides utility functions for Harmony dapps and other `harmony-js` packages
*
* Develop can use this package to:
* - Transform the unit of token (fromWei, toWei...)
* - Convert variable to different type (hexToBN, numberToHex...)
* - Check validators information (isAddress, isPublicKey, isBlockNumber...)
*
* ## How to use this package
*
* ### Step 1: create a Harmony Instance
* ```javascript
* const { Harmony } = require('@harmony-js/core');
* const { ChainID, ChainType } = require('@harmony-js/utils');
* const { BN } = require('@harmony-js/crypto');
*
* const hmy = new Harmony(
* 'http://localhost:9500',
* {
* chainType: ChainType.Harmony,
* chainId: ChainID.HmyLocal,
* },
* );
* ```
*
* ### Step 2: Select and call functions
* Here are some examples:
*
* ```javascript
* // numberToString
* const num = 123;
* const str = hmy.utils.numberToString(num)
* console.log(str);
*
* // add0xToString
* const str = '12345';
* const expected = hmy.utils.add0xToString(str)
* console.log(expected);
*
* // fromWei
* const Wei = new BN('1000000000000000000');
* const expected = hmy.utils.fromWei(Wei, hmy.utils.Units.one);
* console.log(expected);
*
* // toWei
* const one = new BN('1');
* const expected = hmy.utils.toWei(one, hmy.utils.Units.one);
* const num = hmy.utils.numToStr(expected);
* console.log(num);
* ```
*
* ### Step 3: Using unit class to convet the token unit
* ```javascript
* // convert one to Gwei
* const one = new hmy.utils.Unit('1').asOne();
* const oneToGwei = one.toGwei();
* console.log(oneToGwei);
* ```
*
* ## Some Important consts and Enums
* ### Chain Type
* ```javascript
* Harmony = 'hmy',
* Ethereum = 'eth',
* ```
*
* ### Chain ID
* ```javascript
* Default = 0,
EthMainnet = 1,
Morden = 2,
Ropsten = 3,
Rinkeby = 4,
RootstockMainnet = 30,
RootstockTestnet = 31,
Kovan = 42,
EtcMainnet = 61,
EtcTestnet = 62,
Geth = 1337,
Ganache = 0,
HmyMainnet = 1,
HmyTestnet = 2,
HmyLocal = 2,
HmyPangaea = 3,
* ```
*
* ### Default Config
* ```javascript
* export const defaultConfig = {
* Default: {
* Chain_ID: ChainID.HmyLocal,
* Chain_Type: ChainType.Harmony,
* Chain_URL: 'http://localhost:9500',
* Network_ID: 'Local',
* },
* DefaultWS: {
* Chain_ID: ChainID.HmyLocal,
* Chain_Type: ChainType.Harmony,
* Chain_URL: 'ws://localhost:9800',
* Network_ID: 'LocalWS',
* },
* };
* ```
*
* ### Unit Map
* ```
* [Units.wei, '1'], // 1 wei
* [Units.Kwei, '1000'], // 1e3 wei
* [Units.Mwei, '1000000'], // 1e6 wei
* [Units.Gwei, '1000000000'], // 1e9 wei
* [Units.szabo, '1000000000000'], // 1e12 wei
* [Units.finney, '1000000000000000'], // 1e15 wei
* [Units.ether, '1000000000000000000'], // 1e18 wei
* [Units.one, '1000000000000000000'], // 1e18 wei
* [Units.Kether, '1000000000000000000000'], // 1e21 wei
* [Units.Mether, '1000000000000000000000000'], // 1e24 wei
* [Units.Gether, '1000000000000000000000000000'], // 1e27 wei
* [Units.Tether, '1000000000000000000000000000000'], // 1e30 wei
* ```
*
* @packageDocumentation
* @module harmony-utils
*/
export const enum ChainType {

@@ -25,2 +151,3 @@ Harmony = 'hmy',

/** @hidden */
export const defaultConfig = {

@@ -41,2 +168,3 @@ Default: {

/** @hidden */
export abstract class HarmonyCore {

@@ -73,4 +201,6 @@ chainType: ChainType;

/** @hidden */
export const HDPath = `m/44'/1023'/0'/0/`;
/** @hidden */
export const AddressSuffix = '-';

@@ -0,1 +1,7 @@

/**
* @packageDocumentation
* @module harmony-utils
* @ignore
*/
export * from './validators';

@@ -2,0 +8,0 @@ export * from './transformers';

@@ -0,1 +1,7 @@

/**
* @packageDocumentation
* @module harmony-utils
* @hidden
*/
export function defineReadOnly(object: any, name: string, value: any): void {

@@ -2,0 +8,0 @@ Object.defineProperty(object, name, {

@@ -0,1 +1,6 @@

/**
* @packageDocumentation
* @module harmony-utils
*/
import BN from 'bn.js';

@@ -19,2 +24,3 @@ import { isString, isNumber, isHex } from './validators';

/** @hidden */
export const unitMap = new Map([

@@ -35,2 +41,3 @@ [Units.wei, '1'],

/** @hidden */
const DEFAULT_OPTIONS = {

@@ -40,2 +47,5 @@ pad: false,

/**
* Convert Number to String
*/
export const numberToString = (obj: BN | number | string, radix: number = 10): string => {

@@ -53,2 +63,5 @@ if (BN.isBN(obj)) {

/**
* Convert Number to String
*/
export const numToStr = (input: any) => {

@@ -87,2 +100,5 @@ if (typeof input === 'string') {

/**
* Convert number to hex
*/
export const numberToHex = (obj: any): string => {

@@ -96,2 +112,5 @@ try {

/**
* Convert hex to Decimal number
*/
export const hexToNumber = (hex: string): string => {

@@ -108,2 +127,5 @@ if (isHex(hex) && hex[0] !== '-') {

/**
* Convert hex to Big Number
*/
export const hexToBN = (hex: string): BN => {

@@ -120,2 +142,5 @@ if (isHex(hex) && hex[0] !== '-') {

/**
* Converts any ONE value into wei
*/
export const toWei = (input: BN | string, unit: Units): BN => {

@@ -179,2 +204,5 @@ try {

/**
* Converts any wei value into a ONE value.
*/
export const fromWei = (wei: BN | string, unit: Units, options: any = DEFAULT_OPTIONS): string => {

@@ -181,0 +209,0 @@ try {

@@ -0,1 +1,6 @@

/**
* @packageDocumentation
* @module harmony-utils
*/
import {

@@ -20,2 +25,3 @@ isNumber,

/** @hidden */
export const enum AssertType {

@@ -26,2 +32,3 @@ required = 'required',

/** @hidden */
export const validatorArray: any = {

@@ -46,7 +53,3 @@ isNumber: [isNumber],

export function validateArgs(
args: any,
requiredArgs: any,
optionalArgs: any,
): boolean {
export function validateArgs(args: any, requiredArgs: any, optionalArgs: any): boolean {
for (const key in requiredArgs) {

@@ -62,5 +65,3 @@ if (args[key] !== undefined) {

throw new Error(
`Validation failed for ${key},should be validated by ${
requiredArgs[key][i].validator
}`,
`Validation failed for ${key},should be validated by ${requiredArgs[key][i].validator}`,
);

@@ -84,5 +85,3 @@ }

throw new Error(
`Validation failed for ${key},should be validated by ${
optionalArgs[key][i].validator
}`,
`Validation failed for ${key},should be validated by ${optionalArgs[key][i].validator}`,
);

@@ -96,5 +95,3 @@ }

export function generateValidateObjects(validatorObject: {
[x: string]: any[];
}) {
export function generateValidateObjects(validatorObject: { [x: string]: any[] }) {
const requiredArgs: any = {};

@@ -117,7 +114,3 @@ const optionalArgs: any = {};

const assertObject = (input: any) => (
target: any,
key: any,
descriptor: PropertyDescriptor,
) => {
const assertObject = (input: any) => (target: any, key: any, descriptor: PropertyDescriptor) => {
const { requiredArgs, optionalArgs } = generateValidateObjects(input);

@@ -124,0 +117,0 @@ const original = descriptor.value;

@@ -0,1 +1,6 @@

/**
* @packageDocumentation
* @module harmony-utils
*/
export const isKeyString = (keyString: string, lengh: number): boolean => {

@@ -177,7 +182,3 @@ return !!keyString.replace('0x', '').match(`^[0-9a-fA-F]{${lengh}}$`);

}
if (
isAddress(address) ||
isBech32Address(address) ||
isBech32TestNetAddress(address)
) {
if (isAddress(address) || isBech32Address(address) || isBech32TestNetAddress(address)) {
return true;

@@ -184,0 +185,0 @@ } else {

@@ -0,1 +1,7 @@

/**
* @packageDocumentation
* @module harmony-utils
* @ignore
*/
// import BN from 'bn.js';

@@ -7,4 +13,3 @@

text: 'testString',
jsonString:
'{"name":"@harmony-js/utils","version":"0.0.48","description":"utils for harmony"}',
jsonString: '{"name":"@harmony-js/utils","version":"0.0.48","description":"utils for harmony"}',
hexNumber: 0x123,

@@ -22,6 +27,4 @@ hexString: '0x123',

export const advanceType = {
privateKey:
'0x97d2d3a21d829800eeb01aa7f244926f993a1427d9ba79d9dc3bf14fe04d9e37',
publicKey:
'0x028fe48b60c4511f31cf58906ddaa8422725d9313d4b994fab598d2cf220146228',
privateKey: '0x97d2d3a21d829800eeb01aa7f244926f993a1427d9ba79d9dc3bf14fe04d9e37',
publicKey: '0x028fe48b60c4511f31cf58906ddaa8422725d9313d4b994fab598d2cf220146228',
address: '0x84fece7d1f5629bc728c956ffd313dd0c3ac8f17',

@@ -28,0 +31,0 @@ hexAddress: '0x84fece7d1f5629bc728c956ffd313dd0c3ac8f17',

@@ -0,1 +1,7 @@

/**
* @packageDocumentation
* @module harmony-utils
* @ignore
*/
import { BN } from '@harmony-js/crypto';

@@ -2,0 +8,0 @@ import * as transformers from '../src/transformers';

@@ -0,1 +1,7 @@

/**
* @packageDocumentation
* @module harmony-utils
* @ignore
*/
import * as validators from '../src/validators';

@@ -2,0 +8,0 @@ import { basicType, advanceType } from './fixture';

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

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

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