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

@harmony-js/crypto

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@harmony-js/crypto - npm Package Compare versions

Comparing version 0.0.21 to 0.0.22

dist/bech32.d.ts

4

dist/address.d.ts
export declare class HarmonyAddress {
static isValidBasic(str: string): boolean;
static isValidChecksum(str: string): boolean;
static isValidBech32(str: string): boolean;
static isValidBech32TestNet(str: string): boolean;
raw: string;

@@ -8,2 +10,4 @@ basic: string;

readonly checksum: string;
readonly bech32: string;
readonly bech32TestNet: string;
constructor(raw: string);

@@ -10,0 +14,0 @@ private getBasic;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var utils_1 = require("@harmony-js/utils");
var keyTool_1 = require("./keyTool");
var utils_1 = require("@harmony-js/utils");
var bech32_1 = require("./bech32");
var HarmonyAddress = /** @class */ (function () {

@@ -20,2 +21,12 @@ function HarmonyAddress(raw) {

};
// static validator
HarmonyAddress.isValidBech32 = function (str) {
var toTest = new HarmonyAddress(str);
return toTest.raw === toTest.bech32;
};
// static validator
HarmonyAddress.isValidBech32TestNet = function (str) {
var toTest = new HarmonyAddress(str);
return toTest.raw === toTest.bech32TestNet;
};
Object.defineProperty(HarmonyAddress.prototype, "basicHex", {

@@ -30,3 +41,3 @@ get: function () {

get: function () {
return keyTool_1.toChecksumAddress(this.basic);
return keyTool_1.toChecksumAddress("0x" + this.basic);
},

@@ -36,7 +47,31 @@ enumerable: true,

});
Object.defineProperty(HarmonyAddress.prototype, "bech32", {
get: function () {
return bech32_1.toBech32(this.basic, bech32_1.HRP);
},
enumerable: true,
configurable: true
});
Object.defineProperty(HarmonyAddress.prototype, "bech32TestNet", {
get: function () {
return bech32_1.toBech32(this.basic, bech32_1.tHRP);
},
enumerable: true,
configurable: true
});
HarmonyAddress.prototype.getBasic = function (addr) {
var basicBool = utils_1.isAddress(addr);
var bech32Bool = utils_1.isBech32Address(addr);
var bech32TestNetBool = utils_1.isBech32TestNetAddress(addr);
if (basicBool) {
return addr.replace('0x', '').toLowerCase();
}
if (bech32Bool) {
var fromB32 = bech32_1.fromBech32(addr, bech32_1.HRP);
return fromB32.replace('0x', '').toLowerCase();
}
if (bech32TestNetBool) {
var fromB32TestNet = bech32_1.fromBech32(addr, bech32_1.tHRP);
return fromB32TestNet.replace('0x', '').toLowerCase();
}
throw new Error(addr + " is valid address format");

@@ -43,0 +78,0 @@ };

@@ -843,2 +843,14 @@ /**

}
/**
* isValidChecksumAddress
*
* takes hex-encoded string and returns boolean if address is checksumed
*
* @param {string} address
* @returns {boolean}
*/
var isValidChecksumAddress = function (address) {
return (utils.isAddress(address.replace('0x', '')) &&
toChecksumAddress(address) === address);
};

@@ -1020,2 +1032,49 @@ /*! *****************************************************************************

var HarmonyAddress = /** @class */ (function () {
function HarmonyAddress(raw) {
this.raw = raw;
this.basic = this.getBasic(this.raw);
}
// static validator
HarmonyAddress.isValidBasic = function (str) {
var toTest = new HarmonyAddress(str);
return toTest.raw === toTest.basic;
};
// static validator
HarmonyAddress.isValidChecksum = function (str) {
var toTest = new HarmonyAddress(str);
return toTest.raw === toTest.checksum;
};
Object.defineProperty(HarmonyAddress.prototype, "basicHex", {
get: function () {
return "0x" + this.basic;
},
enumerable: true,
configurable: true
});
Object.defineProperty(HarmonyAddress.prototype, "checksum", {
get: function () {
return toChecksumAddress(this.basic);
},
enumerable: true,
configurable: true
});
HarmonyAddress.prototype.getBasic = function (addr) {
var basicBool = utils.isAddress(addr);
if (basicBool) {
return addr.replace('0x', '').toLowerCase();
}
throw new Error(addr + " is valid address format");
};
return HarmonyAddress;
}());
function getAddress(address) {
try {
return new HarmonyAddress(address);
}
catch (error) {
throw error;
}
}
exports.hdkey = hdkey;

@@ -1036,2 +1095,3 @@ exports.bip39 = bip39;

exports.recoverAddress = recoverAddress;
exports.isValidChecksumAddress = isValidChecksumAddress;
exports.encrypt = encrypt;

@@ -1082,2 +1142,4 @@ exports.decrypt = decrypt;

exports.info = info;
exports.HarmonyAddress = HarmonyAddress;
exports.getAddress = getAddress;
//# sourceMappingURL=index.cjs.js.map

@@ -11,2 +11,4 @@ import hdkey from 'hdkey';

export * from './errors';
export * from './base58';
export * from './bech32';
export * from './types';

@@ -13,0 +15,0 @@ export * from './address';

@@ -7,3 +7,3 @@ /**

import elliptic from 'elliptic';
import { isPrivateKey, strip0x } from '@harmony-js/utils';
import { isPrivateKey, strip0x, isAddress } from '@harmony-js/utils';
import aes from 'aes-js';

@@ -841,2 +841,14 @@ import scrypt from 'scrypt.js';

}
/**
* isValidChecksumAddress
*
* takes hex-encoded string and returns boolean if address is checksumed
*
* @param {string} address
* @returns {boolean}
*/
var isValidChecksumAddress = function (address) {
return (isAddress(address.replace('0x', '')) &&
toChecksumAddress(address) === address);
};

@@ -1018,3 +1030,50 @@ /*! *****************************************************************************

export { randomBytes, generatePrivateKey, getPubkeyFromPrivateKey, getAddressFromPrivateKey, getPublic, getAddressFromPublicKey, toChecksumAddress, sign, getContractAddress, verifySignature, recoverPublicKey, recoverAddress, encrypt, decrypt, isHexable, isArrayish, arrayify, concat, stripZeros, padZeros, isHexString, hexlify, hexDataLength, hexDataSlice, hexStripZeros, hexZeroPad, bytesPadLeft, bytesPadRight, isSignature, splitSignature, joinSignature, hexToByteArray, hexToIntArray, isHex, encode, decode, keccak256, UNKNOWN_ERROR, NOT_IMPLEMENTED, MISSING_NEW, CALL_EXCEPTION, INVALID_ARGUMENT, MISSING_ARGUMENT, UNEXPECTED_ARGUMENT, NUMERIC_FAULT, INSUFFICIENT_FUNDS, NONCE_EXPIRED, REPLACEMENT_UNDERPRICED, UNSUPPORTED_OPERATION, throwError, checkNew, checkArgumentCount, setCensorship, checkNormalize, setLogLevel, warn, info };
var HarmonyAddress = /** @class */ (function () {
function HarmonyAddress(raw) {
this.raw = raw;
this.basic = this.getBasic(this.raw);
}
// static validator
HarmonyAddress.isValidBasic = function (str) {
var toTest = new HarmonyAddress(str);
return toTest.raw === toTest.basic;
};
// static validator
HarmonyAddress.isValidChecksum = function (str) {
var toTest = new HarmonyAddress(str);
return toTest.raw === toTest.checksum;
};
Object.defineProperty(HarmonyAddress.prototype, "basicHex", {
get: function () {
return "0x" + this.basic;
},
enumerable: true,
configurable: true
});
Object.defineProperty(HarmonyAddress.prototype, "checksum", {
get: function () {
return toChecksumAddress(this.basic);
},
enumerable: true,
configurable: true
});
HarmonyAddress.prototype.getBasic = function (addr) {
var basicBool = isAddress(addr);
if (basicBool) {
return addr.replace('0x', '').toLowerCase();
}
throw new Error(addr + " is valid address format");
};
return HarmonyAddress;
}());
function getAddress(address) {
try {
return new HarmonyAddress(address);
}
catch (error) {
throw error;
}
}
export { randomBytes, generatePrivateKey, getPubkeyFromPrivateKey, getAddressFromPrivateKey, getPublic, getAddressFromPublicKey, toChecksumAddress, sign, getContractAddress, verifySignature, recoverPublicKey, recoverAddress, isValidChecksumAddress, encrypt, decrypt, isHexable, isArrayish, arrayify, concat, stripZeros, padZeros, isHexString, hexlify, hexDataLength, hexDataSlice, hexStripZeros, hexZeroPad, bytesPadLeft, bytesPadRight, isSignature, splitSignature, joinSignature, hexToByteArray, hexToIntArray, isHex, encode, decode, keccak256, UNKNOWN_ERROR, NOT_IMPLEMENTED, MISSING_NEW, CALL_EXCEPTION, INVALID_ARGUMENT, MISSING_ARGUMENT, UNEXPECTED_ARGUMENT, NUMERIC_FAULT, INSUFFICIENT_FUNDS, NONCE_EXPIRED, REPLACEMENT_UNDERPRICED, UNSUPPORTED_OPERATION, throwError, checkNew, checkArgumentCount, setCensorship, checkNormalize, setLogLevel, warn, info, HarmonyAddress, getAddress };
//# sourceMappingURL=index.esm.js.map

@@ -17,3 +17,5 @@ "use strict";

tslib_1.__exportStar(require("./errors"), exports);
tslib_1.__exportStar(require("./base58"), exports);
tslib_1.__exportStar(require("./bech32"), exports);
tslib_1.__exportStar(require("./address"), exports);
//# sourceMappingURL=index.js.map

@@ -840,2 +840,14 @@ /**

}
/**
* isValidChecksumAddress
*
* takes hex-encoded string and returns boolean if address is checksumed
*
* @param {string} address
* @returns {boolean}
*/
var isValidChecksumAddress = function (address) {
return (utils.isAddress(address.replace('0x', '')) &&
toChecksumAddress(address) === address);
};

@@ -1017,2 +1029,49 @@ /*! *****************************************************************************

var HarmonyAddress = /** @class */ (function () {
function HarmonyAddress(raw) {
this.raw = raw;
this.basic = this.getBasic(this.raw);
}
// static validator
HarmonyAddress.isValidBasic = function (str) {
var toTest = new HarmonyAddress(str);
return toTest.raw === toTest.basic;
};
// static validator
HarmonyAddress.isValidChecksum = function (str) {
var toTest = new HarmonyAddress(str);
return toTest.raw === toTest.checksum;
};
Object.defineProperty(HarmonyAddress.prototype, "basicHex", {
get: function () {
return "0x" + this.basic;
},
enumerable: true,
configurable: true
});
Object.defineProperty(HarmonyAddress.prototype, "checksum", {
get: function () {
return toChecksumAddress(this.basic);
},
enumerable: true,
configurable: true
});
HarmonyAddress.prototype.getBasic = function (addr) {
var basicBool = utils.isAddress(addr);
if (basicBool) {
return addr.replace('0x', '').toLowerCase();
}
throw new Error(addr + " is valid address format");
};
return HarmonyAddress;
}());
function getAddress(address) {
try {
return new HarmonyAddress(address);
}
catch (error) {
throw error;
}
}
exports.hdkey = hdkey;

@@ -1033,2 +1092,3 @@ exports.bip39 = bip39;

exports.recoverAddress = recoverAddress;
exports.isValidChecksumAddress = isValidChecksumAddress;
exports.encrypt = encrypt;

@@ -1079,2 +1139,4 @@ exports.decrypt = decrypt;

exports.info = info;
exports.HarmonyAddress = HarmonyAddress;
exports.getAddress = getAddress;

@@ -1081,0 +1143,0 @@ Object.defineProperty(exports, '__esModule', { value: true });

6

package.json
{
"name": "@harmony-js/crypto",
"version": "0.0.21",
"version": "0.0.22",
"description": "crypto libraries for harmony",

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

"dependencies": {
"@harmony-js/utils": "0.0.21",
"@harmony-js/utils": "0.0.22",
"aes-js": "^3.1.2",

@@ -35,3 +35,3 @@ "base-x": "^3.0.5",

},
"gitHead": "7a51fd2bcccc294bd32f991181f755fdbc88f6e8"
"gitHead": "5c53415c333ab12d727fc1808be2e603d40489e0"
}

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

import {
isAddress,
isBech32Address,
isBech32TestNetAddress,
} from '@harmony-js/utils';
import { toChecksumAddress } from './keyTool';
import { isAddress } from '@harmony-js/utils';
import { fromBech32, toBech32, HRP, tHRP } from './bech32';

@@ -17,2 +23,13 @@ export class HarmonyAddress {

// static validator
static isValidBech32(str: string) {
const toTest = new HarmonyAddress(str);
return toTest.raw === toTest.bech32;
}
// static validator
static isValidBech32TestNet(str: string) {
const toTest = new HarmonyAddress(str);
return toTest.raw === toTest.bech32TestNet;
}
raw: string;

@@ -24,4 +41,12 @@ basic: string;

get checksum() {
return toChecksumAddress(this.basic);
return toChecksumAddress(`0x${this.basic}`);
}
get bech32() {
return toBech32(this.basic, HRP);
}
get bech32TestNet() {
return toBech32(this.basic, tHRP);
}
constructor(raw: string) {

@@ -34,2 +59,4 @@ this.raw = raw;

const basicBool = isAddress(addr);
const bech32Bool = isBech32Address(addr);
const bech32TestNetBool = isBech32TestNetAddress(addr);

@@ -40,2 +67,12 @@ if (basicBool) {

if (bech32Bool) {
const fromB32 = fromBech32(addr, HRP);
return fromB32.replace('0x', '').toLowerCase();
}
if (bech32TestNetBool) {
const fromB32TestNet = fromBech32(addr, tHRP);
return fromB32TestNet.replace('0x', '').toLowerCase();
}
throw new Error(`${addr} is valid address format`);

@@ -42,0 +79,0 @@ }

@@ -12,2 +12,4 @@ import hdkey from 'hdkey';

export * from './errors';
export * from './base58';
export * from './bech32';

@@ -14,0 +16,0 @@ // export types

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