Socket
Socket
Sign inDemoInstall

@taquito/utils

Package Overview
Dependencies
Maintainers
3
Versions
202
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@taquito/utils - npm Package Compare versions

Comparing version 13.0.1 to 14.0.0-beta-RC.0

dist/lib/format.js

6

dist/lib/constants.js

@@ -39,2 +39,4 @@ "use strict";

Prefix["VH"] = "vh";
Prefix["SASK"] = "sask";
Prefix["ZET1"] = "zet1";
//rollups

@@ -84,2 +86,4 @@ Prefix["TXR1"] = "txr1";

[Prefix.VH]: new Uint8Array([1, 106, 242]),
[Prefix.SASK]: new Uint8Array([11, 237, 20, 92]),
[Prefix.ZET1]: new Uint8Array([18, 71, 40, 223]),
[Prefix.TXR1]: new Uint8Array([1, 128, 120, 31]),

@@ -114,2 +118,4 @@ [Prefix.TXI]: new Uint8Array([79, 148, 196]),

[Prefix.VH]: 32,
[Prefix.SASK]: 169,
[Prefix.ZET1]: 43,
[Prefix.TXR1]: 20,

@@ -116,0 +122,0 @@ [Prefix.TXI]: 32,

36

dist/lib/errors.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ValueConversionError = exports.ProhibitedActionError = exports.DeprecationError = exports.InvalidOperationKindError = exports.InvalidOperationHashError = exports.InvalidProtocolHashError = exports.InvalidBlockHashError = exports.InvalidKeyHashError = exports.InvalidChainIdError = exports.InvalidAddressError = exports.InvalidContractAddressError = exports.InvalidMessageError = exports.InvalidSignatureError = exports.InvalidPublicKeyError = exports.InvalidKeyError = void 0;
exports.InvalidHexStringError = exports.ValueConversionError = exports.ProhibitedActionError = exports.DeprecationError = exports.InvalidOperationKindError = exports.InvalidOperationHashError = exports.InvalidProtocolHashError = exports.InvalidBlockHashError = exports.InvalidKeyHashError = exports.InvalidChainIdError = exports.InvalidAddressError = exports.InvalidContractAddressError = exports.InvalidMessageError = exports.InvalidSignatureError = exports.InvalidPublicKeyError = exports.InvalidKeyError = void 0;
/**

@@ -10,6 +10,8 @@ * @category Error

constructor(key, errorDetail) {
super(`The key ${key} is invalid. ${errorDetail}`);
super();
this.key = key;
this.errorDetail = errorDetail;
this.name = 'InvalidKeyError';
const baseMessage = `The key ${key} is invalid.`;
this.message = errorDetail ? `${baseMessage} ${errorDetail}` : baseMessage;
}

@@ -24,5 +26,7 @@ }

constructor(publicKey, errorDetail) {
super(`The public key '${publicKey}' is invalid. ${errorDetail}`);
super();
this.publicKey = publicKey;
this.name = 'InvalidPublicKeyError';
const baseMessage = `The public key '${publicKey}' is invalid.`;
this.message = errorDetail ? `${baseMessage} ${errorDetail}` : baseMessage;
}

@@ -37,5 +41,7 @@ }

constructor(signature, errorDetail) {
super(`The signature '${signature}' is invalid (${errorDetail})`);
super();
this.signature = signature;
this.name = 'InvalidSignatureError';
const baseMessage = `The signature '${signature}' is invalid.`;
this.message = errorDetail ? `${baseMessage} ${errorDetail}` : baseMessage;
}

@@ -50,6 +56,8 @@ }

constructor(msg, errorDetail) {
super(`The message '${msg}' is invalid. ${errorDetail}`);
super();
this.msg = msg;
this.errorDetail = errorDetail;
this.name = 'InvalidMessageError';
const baseMessage = `The message '${msg}' is invalid.`;
this.message = errorDetail ? `${baseMessage} ${errorDetail}` : baseMessage;
}

@@ -75,6 +83,8 @@ }

class InvalidAddressError extends Error {
constructor(address) {
super(`The address '${address}' is invalid`);
constructor(address, errorDetail) {
super();
this.address = address;
this.name = 'InvalidAddressError';
const baseMessage = `The address '${address}' is invalid.`;
this.message = errorDetail ? `${baseMessage} ${errorDetail}` : baseMessage;
}

@@ -190,2 +200,14 @@ }

exports.ValueConversionError = ValueConversionError;
/**
* @category Error
* @description Error that indicates an invalid hex string being passed or used
*/
class InvalidHexStringError extends Error {
constructor(message) {
super(message);
this.message = message;
this.name = 'InvalidHexStringError';
}
}
exports.InvalidHexStringError = InvalidHexStringError;
//# sourceMappingURL=errors.js.map

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.bytes2Char = exports.char2Bytes = exports.getPkhfromPk = exports.buf2hex = exports.mic2arr = exports.mergebuf = exports.hex2buf = exports.encodeKeyHash = exports.encodeKey = exports.encodeL2Address = exports.encodePubKey = exports.b58decodeL2Address = exports.b58decode = exports.b58cdecode = exports.b58cencode = exports.encodeOpHash = exports.encodeExpr = exports.validatePkAndExtractPrefix = exports.verifySignature = exports.prefixLength = exports.Prefix = exports.prefix = exports.VERSION = void 0;
exports.stripHexPrefix = exports.num2PaddedHex = exports.toHexBuf = exports.hex2Bytes = exports.bytes2Char = exports.char2Bytes = exports.getPkhfromPk = exports.buf2hex = exports.mic2arr = exports.mergebuf = exports.hex2buf = exports.encodeKeyHash = exports.encodeKey = exports.encodeL2Address = exports.encodePubKey = exports.b58decodeL2Address = exports.b58decode = exports.b58cdecode = exports.b58cencode = exports.encodeOpHash = exports.encodeExpr = exports.format = exports.validatePkAndExtractPrefix = exports.verifySignature = exports.prefixLength = exports.Prefix = exports.prefix = exports.VERSION = void 0;
/*

@@ -31,2 +31,3 @@ * Some code in this file is originally from sotez and eztz

const errors_1 = require("./errors");
const bignumber_js_1 = require("bignumber.js");
__exportStar(require("./validators"), exports);

@@ -43,2 +44,4 @@ var version_1 = require("./version");

__exportStar(require("./errors"), exports);
var format_1 = require("./format");
Object.defineProperty(exports, "format", { enumerable: true, get: function () { return format_1.format; } });
/**

@@ -358,2 +361,70 @@ *

exports.bytes2Char = bytes2Char;
/**
*
* @description Convert hex string/UintArray/Buffer to bytes
*
* @param hex String value to convert to bytes
*/
function hex2Bytes(hex) {
if (!hex.match(/[\da-f]{2}/gi)) {
throw new errors_1.InvalidHexStringError(`The hex string ${hex} does not have an even number of characters`);
}
return buffer_1.Buffer.from(hex, 'hex');
}
exports.hex2Bytes = hex2Bytes;
/**
*
* @description Converts a number or Bignumber to hexadecimal string
*
* @param val The value that will be converted to a hexadecimal string value
*/
function toHexBuf(val, bitLength = 8) {
return buffer_1.Buffer.from(num2PaddedHex(val, bitLength), 'hex');
}
exports.toHexBuf = toHexBuf;
/**
*
* @description Converts a number or BigNumber to a padded hexadecimal string
* @param val The value that will be converted into a padded hexadecimal string value
* @param bitLength The length of bits
*
*/
function num2PaddedHex(val, bitLength = 8) {
if (new bignumber_js_1.default(val).isPositive()) {
const nibbleLength = Math.ceil(bitLength / 4);
const hex = val.toString(16);
// check whether nibble (4 bits) length is higher or lowerthan the current hex string length
let targetLength = hex.length >= nibbleLength ? hex.length : nibbleLength;
// make sure the hex string target length is even
targetLength = targetLength % 2 == 0 ? targetLength : targetLength + 1;
return padHexWithZero(hex, targetLength);
}
else {
const twosCompliment = new bignumber_js_1.default(2)
.pow(bitLength)
.minus(new bignumber_js_1.default(val).abs());
return twosCompliment.toString(16);
}
}
exports.num2PaddedHex = num2PaddedHex;
function padHexWithZero(hex, targetLength) {
const padString = '0';
if (hex.length >= targetLength) {
return hex;
}
else {
const padLength = targetLength - hex.length;
return padString.repeat(padLength) + hex;
}
}
/**
*
* @description Strips the first 2 characters of a hex string (0x)
*
* @param hex string to strip prefix from
*/
function stripHexPrefix(hex) {
return hex.startsWith('0x') ? hex.slice(2) : hex;
}
exports.stripHexPrefix = stripHexPrefix;
//# sourceMappingURL=taquito-utils.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateBlock = exports.validateProtocol = exports.validateOperation = exports.validatePublicKey = exports.validateSignature = exports.validateKeyHash = exports.validateContractAddress = exports.validateChain = exports.validateAddress = exports.isValidPrefix = exports.ValidationResult = void 0;
exports.validateSpendingKey = exports.validateBlock = exports.validateProtocol = exports.validateOperation = exports.validatePublicKey = exports.validateSignature = exports.validateKeyHash = exports.validateContractAddress = exports.validateChain = exports.validateAddress = exports.isValidPrefix = exports.ValidationResult = void 0;
const constants_1 = require("./constants");

@@ -233,2 +233,11 @@ const bs58check_1 = require("bs58check");

exports.validateBlock = validateBlock;
/**
* @description Used to check if a spending key is valid.
* @returns 0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).
*
*/
function validateSpendingKey(value) {
return validatePrefixedValue(value, [constants_1.Prefix.SASK]);
}
exports.validateSpendingKey = validateSpendingKey;
//# sourceMappingURL=validators.js.map

4

dist/lib/version.js

@@ -6,5 +6,5 @@ "use strict";

exports.VERSION = {
"commitHash": "6d90b3d5e616a6e9b9ad9dd8453b5068e7396fff",
"version": "13.0.1"
"commitHash": "8f69726d044c2033a3bd367fd7cbc593e5f036e2",
"version": "14.0.0-beta-RC.0"
};
//# sourceMappingURL=version.js.map

@@ -6,2 +6,3 @@ import { Buffer } from 'buffer';

import bs58check from 'bs58check';
import BigNumber from 'bignumber.js';
import elliptic from 'elliptic';

@@ -45,2 +46,4 @@ import toBuffer from 'typedarray-to-buffer';

Prefix["VH"] = "vh";
Prefix["SASK"] = "sask";
Prefix["ZET1"] = "zet1";
//rollups

@@ -90,2 +93,4 @@ Prefix["TXR1"] = "txr1";

[Prefix.VH]: new Uint8Array([1, 106, 242]),
[Prefix.SASK]: new Uint8Array([11, 237, 20, 92]),
[Prefix.ZET1]: new Uint8Array([18, 71, 40, 223]),
[Prefix.TXR1]: new Uint8Array([1, 128, 120, 31]),

@@ -120,2 +125,4 @@ [Prefix.TXI]: new Uint8Array([79, 148, 196]),

[Prefix.VH]: 32,
[Prefix.SASK]: 169,
[Prefix.ZET1]: 43,
[Prefix.TXR1]: 20,

@@ -136,6 +143,8 @@ [Prefix.TXI]: 32,

constructor(key, errorDetail) {
super(`The key ${key} is invalid. ${errorDetail}`);
super();
this.key = key;
this.errorDetail = errorDetail;
this.name = 'InvalidKeyError';
const baseMessage = `The key ${key} is invalid.`;
this.message = errorDetail ? `${baseMessage} ${errorDetail}` : baseMessage;
}

@@ -149,5 +158,7 @@ }

constructor(publicKey, errorDetail) {
super(`The public key '${publicKey}' is invalid. ${errorDetail}`);
super();
this.publicKey = publicKey;
this.name = 'InvalidPublicKeyError';
const baseMessage = `The public key '${publicKey}' is invalid.`;
this.message = errorDetail ? `${baseMessage} ${errorDetail}` : baseMessage;
}

@@ -161,5 +172,7 @@ }

constructor(signature, errorDetail) {
super(`The signature '${signature}' is invalid (${errorDetail})`);
super();
this.signature = signature;
this.name = 'InvalidSignatureError';
const baseMessage = `The signature '${signature}' is invalid.`;
this.message = errorDetail ? `${baseMessage} ${errorDetail}` : baseMessage;
}

@@ -173,6 +186,8 @@ }

constructor(msg, errorDetail) {
super(`The message '${msg}' is invalid. ${errorDetail}`);
super();
this.msg = msg;
this.errorDetail = errorDetail;
this.name = 'InvalidMessageError';
const baseMessage = `The message '${msg}' is invalid.`;
this.message = errorDetail ? `${baseMessage} ${errorDetail}` : baseMessage;
}

@@ -196,6 +211,8 @@ }

class InvalidAddressError extends Error {
constructor(address) {
super(`The address '${address}' is invalid`);
constructor(address, errorDetail) {
super();
this.address = address;
this.name = 'InvalidAddressError';
const baseMessage = `The address '${address}' is invalid.`;
this.message = errorDetail ? `${baseMessage} ${errorDetail}` : baseMessage;
}

@@ -301,2 +318,13 @@ }

}
/**
* @category Error
* @description Error that indicates an invalid hex string being passed or used
*/
class InvalidHexStringError extends Error {
constructor(message) {
super(message);
this.message = message;
this.name = 'InvalidHexStringError';
}
}

@@ -632,9 +660,40 @@ /**

}
/**
* @description Used to check if a spending key is valid.
* @returns 0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).
*
*/
function validateSpendingKey(value) {
return validatePrefixedValue(value, [Prefix.SASK]);
}
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
const VERSION = {
"commitHash": "6d90b3d5e616a6e9b9ad9dd8453b5068e7396fff",
"version": "13.0.1"
"commitHash": "8f69726d044c2033a3bd367fd7cbc593e5f036e2",
"version": "14.0.0-beta-RC.0"
};
const TZ_DECIMALS = 6;
const MTZ_DECIMALS = 3;
function getDecimal(format) {
switch (format) {
case 'tz':
return TZ_DECIMALS;
case 'mtz':
return MTZ_DECIMALS;
case 'mutez':
default:
return 0;
}
}
function format(from = 'mutez', to = 'mutez', amount) {
const bigNum = new BigNumber(amount);
if (bigNum.isNaN()) {
return amount;
}
return bigNum
.multipliedBy(Math.pow(10, getDecimal(from)))
.dividedBy(Math.pow(10, getDecimal(to)));
}
/**

@@ -941,4 +1000,68 @@ * @packageDocumentation

}
/**
*
* @description Convert hex string/UintArray/Buffer to bytes
*
* @param hex String value to convert to bytes
*/
function hex2Bytes(hex) {
if (!hex.match(/[\da-f]{2}/gi)) {
throw new InvalidHexStringError(`The hex string ${hex} does not have an even number of characters`);
}
return Buffer.from(hex, 'hex');
}
/**
*
* @description Converts a number or Bignumber to hexadecimal string
*
* @param val The value that will be converted to a hexadecimal string value
*/
function toHexBuf(val, bitLength = 8) {
return Buffer.from(num2PaddedHex(val, bitLength), 'hex');
}
/**
*
* @description Converts a number or BigNumber to a padded hexadecimal string
* @param val The value that will be converted into a padded hexadecimal string value
* @param bitLength The length of bits
*
*/
function num2PaddedHex(val, bitLength = 8) {
if (new BigNumber(val).isPositive()) {
const nibbleLength = Math.ceil(bitLength / 4);
const hex = val.toString(16);
// check whether nibble (4 bits) length is higher or lowerthan the current hex string length
let targetLength = hex.length >= nibbleLength ? hex.length : nibbleLength;
// make sure the hex string target length is even
targetLength = targetLength % 2 == 0 ? targetLength : targetLength + 1;
return padHexWithZero(hex, targetLength);
}
else {
const twosCompliment = new BigNumber(2)
.pow(bitLength)
.minus(new BigNumber(val).abs());
return twosCompliment.toString(16);
}
}
function padHexWithZero(hex, targetLength) {
const padString = '0';
if (hex.length >= targetLength) {
return hex;
}
else {
const padLength = targetLength - hex.length;
return padString.repeat(padLength) + hex;
}
}
/**
*
* @description Strips the first 2 characters of a hex string (0x)
*
* @param hex string to strip prefix from
*/
function stripHexPrefix(hex) {
return hex.startsWith('0x') ? hex.slice(2) : hex;
}
export { DeprecationError, InvalidAddressError, InvalidBlockHashError, InvalidChainIdError, InvalidContractAddressError, InvalidKeyError, InvalidKeyHashError, InvalidMessageError, InvalidOperationHashError, InvalidOperationKindError, InvalidProtocolHashError, InvalidPublicKeyError, InvalidSignatureError, Prefix, ProhibitedActionError, VERSION, ValidationResult, ValueConversionError, b58cdecode, b58cencode, b58decode, b58decodeL2Address, buf2hex, bytes2Char, char2Bytes, encodeExpr, encodeKey, encodeKeyHash, encodeL2Address, encodeOpHash, encodePubKey, getPkhfromPk, hex2buf, isValidPrefix, mergebuf, mic2arr, prefix, prefixLength, validateAddress, validateBlock, validateChain, validateContractAddress, validateKeyHash, validateOperation, validatePkAndExtractPrefix, validateProtocol, validatePublicKey, validateSignature, verifySignature };
export { DeprecationError, InvalidAddressError, InvalidBlockHashError, InvalidChainIdError, InvalidContractAddressError, InvalidHexStringError, InvalidKeyError, InvalidKeyHashError, InvalidMessageError, InvalidOperationHashError, InvalidOperationKindError, InvalidProtocolHashError, InvalidPublicKeyError, InvalidSignatureError, Prefix, ProhibitedActionError, VERSION, ValidationResult, ValueConversionError, b58cdecode, b58cencode, b58decode, b58decodeL2Address, buf2hex, bytes2Char, char2Bytes, encodeExpr, encodeKey, encodeKeyHash, encodeL2Address, encodeOpHash, encodePubKey, format, getPkhfromPk, hex2Bytes, hex2buf, isValidPrefix, mergebuf, mic2arr, num2PaddedHex, prefix, prefixLength, stripHexPrefix, toHexBuf, validateAddress, validateBlock, validateChain, validateContractAddress, validateKeyHash, validateOperation, validatePkAndExtractPrefix, validateProtocol, validatePublicKey, validateSignature, validateSpendingKey, verifySignature };
//# sourceMappingURL=taquito-utils.es6.js.map
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('buffer'), require('@stablelib/ed25519'), require('@stablelib/blake2b'), require('blakejs'), require('bs58check'), require('elliptic'), require('typedarray-to-buffer')) :
typeof define === 'function' && define.amd ? define(['exports', 'buffer', '@stablelib/ed25519', '@stablelib/blake2b', 'blakejs', 'bs58check', 'elliptic', 'typedarray-to-buffer'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.taquitoUtils = {}, global.buffer, global.ed25519, global.blake2b, global.blake, global.bs58check, global.elliptic, global.toBuffer));
})(this, (function (exports, buffer, ed25519, blake2b, blake, bs58check, elliptic, toBuffer) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('buffer'), require('@stablelib/ed25519'), require('@stablelib/blake2b'), require('blakejs'), require('bs58check'), require('bignumber.js'), require('elliptic'), require('typedarray-to-buffer')) :
typeof define === 'function' && define.amd ? define(['exports', 'buffer', '@stablelib/ed25519', '@stablelib/blake2b', 'blakejs', 'bs58check', 'bignumber.js', 'elliptic', 'typedarray-to-buffer'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.taquitoUtils = {}, global.buffer, global.ed25519, global.blake2b, global.blake, global.bs58check, global.BigNumber, global.elliptic, global.toBuffer));
})(this, (function (exports, buffer, ed25519, blake2b, blake, bs58check, BigNumber, elliptic, toBuffer) { 'use strict';

@@ -11,2 +11,3 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var bs58check__default = /*#__PURE__*/_interopDefaultLegacy(bs58check);
var BigNumber__default = /*#__PURE__*/_interopDefaultLegacy(BigNumber);
var elliptic__default = /*#__PURE__*/_interopDefaultLegacy(elliptic);

@@ -50,2 +51,4 @@ var toBuffer__default = /*#__PURE__*/_interopDefaultLegacy(toBuffer);

Prefix["VH"] = "vh";
Prefix["SASK"] = "sask";
Prefix["ZET1"] = "zet1";
//rollups

@@ -95,2 +98,4 @@ Prefix["TXR1"] = "txr1";

[exports.Prefix.VH]: new Uint8Array([1, 106, 242]),
[exports.Prefix.SASK]: new Uint8Array([11, 237, 20, 92]),
[exports.Prefix.ZET1]: new Uint8Array([18, 71, 40, 223]),
[exports.Prefix.TXR1]: new Uint8Array([1, 128, 120, 31]),

@@ -125,2 +130,4 @@ [exports.Prefix.TXI]: new Uint8Array([79, 148, 196]),

[exports.Prefix.VH]: 32,
[exports.Prefix.SASK]: 169,
[exports.Prefix.ZET1]: 43,
[exports.Prefix.TXR1]: 20,

@@ -141,6 +148,8 @@ [exports.Prefix.TXI]: 32,

constructor(key, errorDetail) {
super(`The key ${key} is invalid. ${errorDetail}`);
super();
this.key = key;
this.errorDetail = errorDetail;
this.name = 'InvalidKeyError';
const baseMessage = `The key ${key} is invalid.`;
this.message = errorDetail ? `${baseMessage} ${errorDetail}` : baseMessage;
}

@@ -154,5 +163,7 @@ }

constructor(publicKey, errorDetail) {
super(`The public key '${publicKey}' is invalid. ${errorDetail}`);
super();
this.publicKey = publicKey;
this.name = 'InvalidPublicKeyError';
const baseMessage = `The public key '${publicKey}' is invalid.`;
this.message = errorDetail ? `${baseMessage} ${errorDetail}` : baseMessage;
}

@@ -166,5 +177,7 @@ }

constructor(signature, errorDetail) {
super(`The signature '${signature}' is invalid (${errorDetail})`);
super();
this.signature = signature;
this.name = 'InvalidSignatureError';
const baseMessage = `The signature '${signature}' is invalid.`;
this.message = errorDetail ? `${baseMessage} ${errorDetail}` : baseMessage;
}

@@ -178,6 +191,8 @@ }

constructor(msg, errorDetail) {
super(`The message '${msg}' is invalid. ${errorDetail}`);
super();
this.msg = msg;
this.errorDetail = errorDetail;
this.name = 'InvalidMessageError';
const baseMessage = `The message '${msg}' is invalid.`;
this.message = errorDetail ? `${baseMessage} ${errorDetail}` : baseMessage;
}

@@ -201,6 +216,8 @@ }

class InvalidAddressError extends Error {
constructor(address) {
super(`The address '${address}' is invalid`);
constructor(address, errorDetail) {
super();
this.address = address;
this.name = 'InvalidAddressError';
const baseMessage = `The address '${address}' is invalid.`;
this.message = errorDetail ? `${baseMessage} ${errorDetail}` : baseMessage;
}

@@ -306,2 +323,13 @@ }

}
/**
* @category Error
* @description Error that indicates an invalid hex string being passed or used
*/
class InvalidHexStringError extends Error {
constructor(message) {
super(message);
this.message = message;
this.name = 'InvalidHexStringError';
}
}

@@ -637,9 +665,40 @@ /**

}
/**
* @description Used to check if a spending key is valid.
* @returns 0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).
*
*/
function validateSpendingKey(value) {
return validatePrefixedValue(value, [exports.Prefix.SASK]);
}
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
const VERSION = {
"commitHash": "6d90b3d5e616a6e9b9ad9dd8453b5068e7396fff",
"version": "13.0.1"
"commitHash": "8f69726d044c2033a3bd367fd7cbc593e5f036e2",
"version": "14.0.0-beta-RC.0"
};
const TZ_DECIMALS = 6;
const MTZ_DECIMALS = 3;
function getDecimal(format) {
switch (format) {
case 'tz':
return TZ_DECIMALS;
case 'mtz':
return MTZ_DECIMALS;
case 'mutez':
default:
return 0;
}
}
function format(from = 'mutez', to = 'mutez', amount) {
const bigNum = new BigNumber__default["default"](amount);
if (bigNum.isNaN()) {
return amount;
}
return bigNum
.multipliedBy(Math.pow(10, getDecimal(from)))
.dividedBy(Math.pow(10, getDecimal(to)));
}
/**

@@ -946,2 +1005,66 @@ * @packageDocumentation

}
/**
*
* @description Convert hex string/UintArray/Buffer to bytes
*
* @param hex String value to convert to bytes
*/
function hex2Bytes(hex) {
if (!hex.match(/[\da-f]{2}/gi)) {
throw new InvalidHexStringError(`The hex string ${hex} does not have an even number of characters`);
}
return buffer.Buffer.from(hex, 'hex');
}
/**
*
* @description Converts a number or Bignumber to hexadecimal string
*
* @param val The value that will be converted to a hexadecimal string value
*/
function toHexBuf(val, bitLength = 8) {
return buffer.Buffer.from(num2PaddedHex(val, bitLength), 'hex');
}
/**
*
* @description Converts a number or BigNumber to a padded hexadecimal string
* @param val The value that will be converted into a padded hexadecimal string value
* @param bitLength The length of bits
*
*/
function num2PaddedHex(val, bitLength = 8) {
if (new BigNumber__default["default"](val).isPositive()) {
const nibbleLength = Math.ceil(bitLength / 4);
const hex = val.toString(16);
// check whether nibble (4 bits) length is higher or lowerthan the current hex string length
let targetLength = hex.length >= nibbleLength ? hex.length : nibbleLength;
// make sure the hex string target length is even
targetLength = targetLength % 2 == 0 ? targetLength : targetLength + 1;
return padHexWithZero(hex, targetLength);
}
else {
const twosCompliment = new BigNumber__default["default"](2)
.pow(bitLength)
.minus(new BigNumber__default["default"](val).abs());
return twosCompliment.toString(16);
}
}
function padHexWithZero(hex, targetLength) {
const padString = '0';
if (hex.length >= targetLength) {
return hex;
}
else {
const padLength = targetLength - hex.length;
return padString.repeat(padLength) + hex;
}
}
/**
*
* @description Strips the first 2 characters of a hex string (0x)
*
* @param hex string to strip prefix from
*/
function stripHexPrefix(hex) {
return hex.startsWith('0x') ? hex.slice(2) : hex;
}

@@ -953,2 +1076,3 @@ exports.DeprecationError = DeprecationError;

exports.InvalidContractAddressError = InvalidContractAddressError;
exports.InvalidHexStringError = InvalidHexStringError;
exports.InvalidKeyError = InvalidKeyError;

@@ -978,3 +1102,5 @@ exports.InvalidKeyHashError = InvalidKeyHashError;

exports.encodePubKey = encodePubKey;
exports.format = format;
exports.getPkhfromPk = getPkhfromPk;
exports.hex2Bytes = hex2Bytes;
exports.hex2buf = hex2buf;

@@ -984,4 +1110,7 @@ exports.isValidPrefix = isValidPrefix;

exports.mic2arr = mic2arr;
exports.num2PaddedHex = num2PaddedHex;
exports.prefix = prefix;
exports.prefixLength = prefixLength;
exports.stripHexPrefix = stripHexPrefix;
exports.toHexBuf = toHexBuf;
exports.validateAddress = validateAddress;

@@ -997,2 +1126,3 @@ exports.validateBlock = validateBlock;

exports.validateSignature = validateSignature;
exports.validateSpendingKey = validateSpendingKey;
exports.verifySignature = verifySignature;

@@ -999,0 +1129,0 @@

@@ -35,2 +35,4 @@ export declare enum Prefix {

VH = "vh",
SASK = "sask",
ZET1 = "zet1",
TXR1 = "txr1",

@@ -78,2 +80,4 @@ TXI = "txi",

vh: Uint8Array;
sask: Uint8Array;
zet1: Uint8Array;
txr1: Uint8Array;

@@ -80,0 +84,0 @@ txi: Uint8Array;

@@ -55,3 +55,3 @@ /**

name: string;
constructor(address: string);
constructor(address: string, errorDetail?: string);
}

@@ -138,1 +138,10 @@ /**

}
/**
* @category Error
* @description Error that indicates an invalid hex string being passed or used
*/
export declare class InvalidHexStringError extends Error {
message: string;
name: string;
constructor(message: string);
}

@@ -5,3 +5,5 @@ /**

*/
/// <reference types="node" />
import { Buffer } from 'buffer';
import BigNumber from 'bignumber.js';
export * from './validators';

@@ -12,2 +14,3 @@ export { VERSION } from './version';

export * from './errors';
export { format } from './format';
/**

@@ -135,1 +138,30 @@ *

export declare function bytes2Char(hex: string): string;
/**
*
* @description Convert hex string/UintArray/Buffer to bytes
*
* @param hex String value to convert to bytes
*/
export declare function hex2Bytes(hex: string): Buffer;
/**
*
* @description Converts a number or Bignumber to hexadecimal string
*
* @param val The value that will be converted to a hexadecimal string value
*/
export declare function toHexBuf(val: number | BigNumber, bitLength?: number): Buffer;
/**
*
* @description Converts a number or BigNumber to a padded hexadecimal string
* @param val The value that will be converted into a padded hexadecimal string value
* @param bitLength The length of bits
*
*/
export declare function num2PaddedHex(val: number | BigNumber, bitLength?: number): string;
/**
*
* @description Strips the first 2 characters of a hex string (0x)
*
* @param hex string to strip prefix from
*/
export declare function stripHexPrefix(hex: string): string;

@@ -153,1 +153,7 @@ import { Prefix } from './constants';

export declare function validateBlock(value: string): ValidationResult;
/**
* @description Used to check if a spending key is valid.
* @returns 0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).
*
*/
export declare function validateSpendingKey(value: any): ValidationResult;
{
"name": "@taquito/utils",
"version": "13.0.1",
"version": "14.0.0-beta-RC.0",
"description": "converts michelson data and types into convenient JS/TS objects",

@@ -69,2 +69,3 @@ "keywords": [

"@types/bs58check": "^2.1.0",
"bignumber.js": "^9.0.2",
"blakejs": "^1.2.1",

@@ -105,3 +106,3 @@ "bs58check": "^2.1.2",

},
"gitHead": "6979668ac998ee33bfd4071482fa2bf605db8cde"
"gitHead": "5610002c69747ac5c13b018d12986e990126350f"
}

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