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 11.1.0 to 11.2.0-beta-RC.0

dist/taquito-utils.es6.js

103

dist/lib/constants.js
"use strict";
var _a, _b;
Object.defineProperty(exports, "__esModule", { value: true });

@@ -28,3 +27,3 @@ exports.prefixLength = exports.prefix = exports.Prefix = void 0;

Prefix["NCE"] = "nce";
Prefix["B"] = "b";
Prefix["B"] = "B";
Prefix["O"] = "o";

@@ -39,53 +38,53 @@ Prefix["LO"] = "Lo";

})(Prefix = exports.Prefix || (exports.Prefix = {}));
exports.prefix = (_a = {},
_a[Prefix.TZ1] = new Uint8Array([6, 161, 159]),
_a[Prefix.TZ2] = new Uint8Array([6, 161, 161]),
_a[Prefix.TZ3] = new Uint8Array([6, 161, 164]),
_a[Prefix.KT] = new Uint8Array([2, 90, 121]),
_a[Prefix.KT1] = new Uint8Array([2, 90, 121]),
_a[Prefix.EDSK] = new Uint8Array([43, 246, 78, 7]),
_a[Prefix.EDSK2] = new Uint8Array([13, 15, 58, 7]),
_a[Prefix.SPSK] = new Uint8Array([17, 162, 224, 201]),
_a[Prefix.P2SK] = new Uint8Array([16, 81, 238, 189]),
_a[Prefix.EDPK] = new Uint8Array([13, 15, 37, 217]),
_a[Prefix.SPPK] = new Uint8Array([3, 254, 226, 86]),
_a[Prefix.P2PK] = new Uint8Array([3, 178, 139, 127]),
_a[Prefix.EDESK] = new Uint8Array([7, 90, 60, 179, 41]),
_a[Prefix.SPESK] = new Uint8Array([0x09, 0xed, 0xf1, 0xae, 0x96]),
_a[Prefix.P2ESK] = new Uint8Array([0x09, 0x30, 0x39, 0x73, 0xab]),
_a[Prefix.EDSIG] = new Uint8Array([9, 245, 205, 134, 18]),
_a[Prefix.SPSIG] = new Uint8Array([13, 115, 101, 19, 63]),
_a[Prefix.P2SIG] = new Uint8Array([54, 240, 44, 52]),
_a[Prefix.SIG] = new Uint8Array([4, 130, 43]),
_a[Prefix.NET] = new Uint8Array([87, 82, 0]),
_a[Prefix.NCE] = new Uint8Array([69, 220, 169]),
_a[Prefix.B] = new Uint8Array([1, 52]),
_a[Prefix.O] = new Uint8Array([5, 116]),
_a[Prefix.LO] = new Uint8Array([133, 233]),
_a[Prefix.LLO] = new Uint8Array([29, 159, 109]),
_a[Prefix.P] = new Uint8Array([2, 170]),
_a[Prefix.CO] = new Uint8Array([79, 179]),
_a[Prefix.ID] = new Uint8Array([153, 103]),
_a[Prefix.EXPR] = new Uint8Array([13, 44, 64, 27]),
exports.prefix = {
[Prefix.TZ1]: new Uint8Array([6, 161, 159]),
[Prefix.TZ2]: new Uint8Array([6, 161, 161]),
[Prefix.TZ3]: new Uint8Array([6, 161, 164]),
[Prefix.KT]: new Uint8Array([2, 90, 121]),
[Prefix.KT1]: new Uint8Array([2, 90, 121]),
[Prefix.EDSK]: new Uint8Array([43, 246, 78, 7]),
[Prefix.EDSK2]: new Uint8Array([13, 15, 58, 7]),
[Prefix.SPSK]: new Uint8Array([17, 162, 224, 201]),
[Prefix.P2SK]: new Uint8Array([16, 81, 238, 189]),
[Prefix.EDPK]: new Uint8Array([13, 15, 37, 217]),
[Prefix.SPPK]: new Uint8Array([3, 254, 226, 86]),
[Prefix.P2PK]: new Uint8Array([3, 178, 139, 127]),
[Prefix.EDESK]: new Uint8Array([7, 90, 60, 179, 41]),
[Prefix.SPESK]: new Uint8Array([0x09, 0xed, 0xf1, 0xae, 0x96]),
[Prefix.P2ESK]: new Uint8Array([0x09, 0x30, 0x39, 0x73, 0xab]),
[Prefix.EDSIG]: new Uint8Array([9, 245, 205, 134, 18]),
[Prefix.SPSIG]: new Uint8Array([13, 115, 101, 19, 63]),
[Prefix.P2SIG]: new Uint8Array([54, 240, 44, 52]),
[Prefix.SIG]: new Uint8Array([4, 130, 43]),
[Prefix.NET]: new Uint8Array([87, 82, 0]),
[Prefix.NCE]: new Uint8Array([69, 220, 169]),
[Prefix.B]: new Uint8Array([1, 52]),
[Prefix.O]: new Uint8Array([5, 116]),
[Prefix.LO]: new Uint8Array([133, 233]),
[Prefix.LLO]: new Uint8Array([29, 159, 109]),
[Prefix.P]: new Uint8Array([2, 170]),
[Prefix.CO]: new Uint8Array([79, 179]),
[Prefix.ID]: new Uint8Array([153, 103]),
[Prefix.EXPR]: new Uint8Array([13, 44, 64, 27]),
// Legacy prefix
_a[Prefix.TZ] = new Uint8Array([2, 90, 121]),
_a);
exports.prefixLength = (_b = {},
_b[Prefix.TZ1] = 20,
_b[Prefix.TZ2] = 20,
_b[Prefix.TZ3] = 20,
_b[Prefix.KT] = 20,
_b[Prefix.KT1] = 20,
_b[Prefix.EDPK] = 32,
_b[Prefix.SPPK] = 33,
_b[Prefix.P2PK] = 33,
_b[Prefix.EDSIG] = 64,
_b[Prefix.SPSIG] = 64,
_b[Prefix.P2SIG] = 64,
_b[Prefix.SIG] = 64,
_b[Prefix.NET] = 4,
_b[Prefix.B] = 32,
_b[Prefix.P] = 32,
_b[Prefix.O] = 32,
_b);
[Prefix.TZ]: new Uint8Array([2, 90, 121]),
};
exports.prefixLength = {
[Prefix.TZ1]: 20,
[Prefix.TZ2]: 20,
[Prefix.TZ3]: 20,
[Prefix.KT]: 20,
[Prefix.KT1]: 20,
[Prefix.EDPK]: 32,
[Prefix.SPPK]: 33,
[Prefix.P2PK]: 33,
[Prefix.EDSIG]: 64,
[Prefix.SPSIG]: 64,
[Prefix.P2SIG]: 64,
[Prefix.SIG]: 64,
[Prefix.NET]: 4,
[Prefix.B]: 32,
[Prefix.P]: 32,
[Prefix.O]: 32
};
//# sourceMappingURL=constants.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.InvalidMessageError = exports.InvalidSignatureError = exports.InvalidPublicKeyError = void 0;
var InvalidPublicKeyError = /** @class */ (function () {
function InvalidPublicKeyError(message) {
exports.InvalidOperationHashError = exports.InvalidProtocolHashError = exports.InvalidBlockHashError = exports.InvalidKeyHashError = exports.InvalidAddressError = exports.InvalidContractAddressError = exports.InvalidMessageError = exports.InvalidSignatureError = exports.InvalidPublicKeyError = void 0;
class InvalidPublicKeyError extends Error {
constructor(message) {
super(message);
this.message = message;
this.name = 'InvalidPublicKeyError';
}
return InvalidPublicKeyError;
}());
}
exports.InvalidPublicKeyError = InvalidPublicKeyError;
var InvalidSignatureError = /** @class */ (function () {
function InvalidSignatureError(message) {
class InvalidSignatureError extends Error {
constructor(message) {
super(message);
this.message = message;
this.name = 'InvalidSignatureError';
}
return InvalidSignatureError;
}());
}
exports.InvalidSignatureError = InvalidSignatureError;
var InvalidMessageError = /** @class */ (function () {
function InvalidMessageError(message) {
class InvalidMessageError extends Error {
constructor(message) {
super(message);
this.message = message;
this.name = 'InvalidMessageError';
}
return InvalidMessageError;
}());
}
exports.InvalidMessageError = InvalidMessageError;
class InvalidContractAddressError extends Error {
constructor(message) {
super(message);
this.message = message;
this.name = 'InvalidContractAddressError';
}
}
exports.InvalidContractAddressError = InvalidContractAddressError;
class InvalidAddressError extends Error {
constructor(message) {
super(message);
this.message = message;
this.name = 'InvalidAddressError';
}
}
exports.InvalidAddressError = InvalidAddressError;
class InvalidKeyHashError extends Error {
constructor(message) {
super(message);
this.message = message;
this.name = 'InvalidKeyHashError';
}
}
exports.InvalidKeyHashError = InvalidKeyHashError;
class InvalidBlockHashError extends Error {
constructor(message) {
super(message);
this.message = message;
this.name = 'InvalidBlockHashError';
}
}
exports.InvalidBlockHashError = InvalidBlockHashError;
class InvalidProtocolHashError extends Error {
constructor(message) {
super(message);
this.message = message;
this.name = 'InvalidProtocolHashError';
}
}
exports.InvalidProtocolHashError = InvalidProtocolHashError;
class InvalidOperationHashError extends Error {
constructor(message) {
super(message);
this.message = message;
this.name = 'InvalidOperationHashError';
}
}
exports.InvalidOperationHashError = InvalidOperationHashError;
//# sourceMappingURL=errors.js.map

@@ -23,8 +23,8 @@ "use strict";

*/
var buffer_1 = require("buffer");
var constants_1 = require("./constants");
var verify_signature_1 = require("./verify-signature");
var blake2b_1 = require("@stablelib/blake2b");
var blake = require('blakejs');
var bs58check = require('bs58check');
const buffer_1 = require("buffer");
const constants_1 = require("./constants");
const verify_signature_1 = require("./verify-signature");
const blake2b_1 = require("@stablelib/blake2b");
const blakejs_1 = require("blakejs");
const bs58check_1 = require("bs58check");
__exportStar(require("./validators"), exports);

@@ -40,2 +40,3 @@ var version_1 = require("./version");

Object.defineProperty(exports, "validatePkAndExtractPrefix", { enumerable: true, get: function () { return verify_signature_2.validatePkAndExtractPrefix; } });
__exportStar(require("./errors"), exports);
/**

@@ -48,3 +49,3 @@ *

function encodeExpr(value) {
var blakeHash = blake.blake2b(exports.hex2buf(value), null, 32);
const blakeHash = blakejs_1.default.blake2b(exports.hex2buf(value), undefined, 32);
return b58cencode(blakeHash, constants_1.prefix['expr']);

@@ -59,3 +60,3 @@ }

function encodeOpHash(value) {
var blakeHash = blake.blake2b(exports.hex2buf(value), null, 32);
const blakeHash = blakejs_1.default.blake2b(exports.hex2buf(value), undefined, 32);
return b58cencode(blakeHash, constants_1.prefix.o);

@@ -72,7 +73,7 @@ }

function b58cencode(value, prefix) {
var payloadAr = typeof value === 'string' ? Uint8Array.from(buffer_1.Buffer.from(value, 'hex')) : value;
var n = new Uint8Array(prefix.length + payloadAr.length);
const payloadAr = typeof value === 'string' ? Uint8Array.from(buffer_1.Buffer.from(value, 'hex')) : value;
const n = new Uint8Array(prefix.length + payloadAr.length);
n.set(prefix);
n.set(payloadAr, prefix.length);
return bs58check.encode(buffer_1.Buffer.from(n.buffer));
return bs58check_1.default.encode(buffer_1.Buffer.from(n.buffer));
}

@@ -87,5 +88,3 @@ exports.b58cencode = b58cencode;

*/
var b58cdecode = function (enc, prefixArg) {
return bs58check.decode(enc).slice(prefixArg.length);
};
const b58cdecode = (enc, prefixArg) => bs58check_1.default.decode(enc).slice(prefixArg.length);
exports.b58cdecode = b58cdecode;

@@ -99,13 +98,12 @@ /**

function b58decode(payload) {
var _a;
var buf = bs58check.decode(payload);
var prefixMap = (_a = {},
_a[constants_1.prefix.tz1.toString()] = '0000',
_a[constants_1.prefix.tz2.toString()] = '0001',
_a[constants_1.prefix.tz3.toString()] = '0002',
_a);
var pref = prefixMap[new Uint8Array(buf.slice(0, 3)).toString()];
const buf = bs58check_1.default.decode(payload);
const prefixMap = {
[constants_1.prefix.tz1.toString()]: '0000',
[constants_1.prefix.tz2.toString()]: '0001',
[constants_1.prefix.tz3.toString()]: '0002',
};
const pref = prefixMap[new Uint8Array(buf.slice(0, 3)).toString()];
if (pref) {
// tz addresses
var hex = exports.buf2hex(buf.slice(3));
const hex = exports.buf2hex(buf.slice(3));
return pref + hex;

@@ -121,9 +119,9 @@ }

*
* @description Base58 encode a public key using predefined prefix
* @description Base58 encode an address using predefined prefix
*
* @param value Public Key to base58 encode
* @param value Address to base58 encode (tz1, tz2, tz3 or KT1)
*/
function encodePubKey(value) {
if (value.substring(0, 2) === '00') {
var pref = {
const pref = {
'0000': constants_1.prefix.tz1,

@@ -146,3 +144,3 @@ '0001': constants_1.prefix.tz2,

if (value[0] === '0') {
var pref = {
const pref = {
'00': new Uint8Array([13, 15, 37, 217]),

@@ -160,7 +158,7 @@ '01': new Uint8Array([3, 254, 226, 86]),

*
* @param value Key to base58 encode
* @param value Key hash to base58 encode
*/
function encodeKeyHash(value) {
if (value[0] === '0') {
var pref = {
const pref = {
'00': new Uint8Array([6, 161, 159]),

@@ -180,4 +178,10 @@ '01': new Uint8Array([6, 161, 161]),

*/
var hex2buf = function (hex) {
return new Uint8Array(hex.match(/[\da-f]{2}/gi).map(function (h) { return parseInt(h, 16); }));
const hex2buf = (hex) => {
const match = hex.match(/[\da-f]{2}/gi);
if (match) {
return new Uint8Array(match.map((h) => parseInt(h, 16)));
}
else {
throw new Error(`Unable to convert ${hex} to a Uint8Array`);
}
};

@@ -192,4 +196,4 @@ exports.hex2buf = hex2buf;

*/
var mergebuf = function (b1, b2) {
var r = new Uint8Array(b1.length + b2.length);
const mergebuf = (b1, b2) => {
const r = new Uint8Array(b1.length + b2.length);
r.set(b1);

@@ -206,4 +210,4 @@ r.set(b2, b1.length);

*/
var mic2arr = function me2(s) {
var ret = [];
const mic2arr = function me2(s) {
let ret = [];
if (Object.prototype.hasOwnProperty.call(s, 'prim')) {

@@ -228,5 +232,5 @@ if (s.prim === 'Pair') {

else if (Array.isArray(s)) {
var sc = s.length;
for (var i = 0; i < sc; i++) {
var n = me2(s[i]);
const sc = s.length;
for (let i = 0; i < sc; i++) {
const n = me2(s[i]);
if (typeof n.key !== 'undefined') {

@@ -265,8 +269,8 @@ if (Array.isArray(ret)) {

*/
var buf2hex = function (buffer) {
var byteArray = new Uint8Array(buffer);
var hexParts = [];
byteArray.forEach(function (byte) {
var hex = byte.toString(16);
var paddedHex = ("00" + hex).slice(-2);
const buf2hex = (buffer) => {
const byteArray = new Uint8Array(buffer);
const hexParts = [];
byteArray.forEach((byte) => {
const hex = byte.toString(16);
const paddedHex = `00${hex}`.slice(-2);
hexParts.push(paddedHex);

@@ -284,7 +288,7 @@ });

*/
var getPkhfromPk = function (publicKey) {
var encodingPrefix;
var prefixLen;
var keyPrefix = verify_signature_1.validatePkAndExtractPrefix(publicKey);
var decoded = exports.b58cdecode(publicKey, constants_1.prefix[keyPrefix]);
const getPkhfromPk = (publicKey) => {
let encodingPrefix;
let prefixLen;
const keyPrefix = verify_signature_1.validatePkAndExtractPrefix(publicKey);
const decoded = exports.b58cdecode(publicKey, constants_1.prefix[keyPrefix]);
switch (keyPrefix) {

@@ -304,4 +308,4 @@ case constants_1.Prefix.EDPK:

}
var hashed = blake2b_1.hash(decoded, prefixLen);
var result = b58cencode(hashed, encodingPrefix);
const hashed = blake2b_1.hash(decoded, prefixLen);
const result = b58cencode(hashed, encodingPrefix);
return result;

@@ -308,0 +312,0 @@ };

"use strict";
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.validatePublicKey = exports.validateSignature = exports.validateKeyHash = exports.validateContractAddress = exports.validateChain = exports.validateAddress = exports.isValidPrefix = exports.ValidationResult = void 0;
var constants_1 = require("./constants");
var bs58check = require('bs58check');
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");
const bs58check_1 = require("bs58check");
var ValidationResult;

@@ -51,7 +31,7 @@ (function (ValidationResult) {

function validatePrefixedValue(value, prefixes) {
var match = new RegExp("^(" + prefixes.join('|') + ")").exec(value);
const match = new RegExp(`^(${prefixes.join('|')})`).exec(value);
if (!match || match.length === 0) {
return ValidationResult.NO_PREFIX_MATCHED;
}
var prefixKey = match[0];
const prefixKey = match[0];
if (!isValidPrefix(prefixKey)) {

@@ -61,3 +41,3 @@ return ValidationResult.NO_PREFIX_MATCHED;

// Remove annotation from contract address before doing the validation
var contractAddress = /^(KT1\w{33})(\%(.*))?/.exec(value);
const contractAddress = /^(KT1\w{33})(%(.*))?/.exec(value);
if (contractAddress) {

@@ -67,3 +47,3 @@ value = contractAddress[1];

// decodeUnsafe return undefined if decoding fail
var decoded = bs58check.decodeUnsafe(value);
let decoded = bs58check_1.default.decodeUnsafe(value);
if (!decoded) {

@@ -78,6 +58,9 @@ return ValidationResult.INVALID_CHECKSUM;

}
var implicitPrefix = [constants_1.Prefix.TZ1, constants_1.Prefix.TZ2, constants_1.Prefix.TZ3];
var contractPrefix = [constants_1.Prefix.KT1];
var signaturePrefix = [constants_1.Prefix.EDSIG, constants_1.Prefix.P2SIG, constants_1.Prefix.SPSIG, constants_1.Prefix.SIG];
var pkPrefix = [constants_1.Prefix.EDPK, constants_1.Prefix.SPPK, constants_1.Prefix.P2PK];
const implicitPrefix = [constants_1.Prefix.TZ1, constants_1.Prefix.TZ2, constants_1.Prefix.TZ3];
const contractPrefix = [constants_1.Prefix.KT1];
const signaturePrefix = [constants_1.Prefix.EDSIG, constants_1.Prefix.P2SIG, constants_1.Prefix.SPSIG, constants_1.Prefix.SIG];
const pkPrefix = [constants_1.Prefix.EDPK, constants_1.Prefix.SPPK, constants_1.Prefix.P2PK];
const operationPrefix = [constants_1.Prefix.O];
const protocolPrefix = [constants_1.Prefix.P];
const blockPrefix = [constants_1.Prefix.B];
/**

@@ -99,3 +82,3 @@ * @description Used to check if an address or a contract address is valid.

function validateAddress(value) {
return validatePrefixedValue(value, __spread(implicitPrefix, contractPrefix));
return validatePrefixedValue(value, [...implicitPrefix, ...contractPrefix]);
}

@@ -180,3 +163,3 @@ exports.validateAddress = validateAddress;

/**
* @description Used to check if a signature is valid.
* @description Used to check if a public key is valid.
*

@@ -199,2 +182,59 @@ * @returns

exports.validatePublicKey = validatePublicKey;
/**
* @description Used to check if an operation hash is valid.
*
* @returns
* 0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).
*
* @example
* ```
* import { validateOperation } from '@taquito/utils';
* const operationHash = 'oo6JPEAy8VuMRGaFuMmLNFFGdJgiaKfnmT1CpHJfKP3Ye5ZahiP'
* const validation = validateOperation(operationHash)
* console.log(validation)
* // This example return 3 which correspond to VALID
* ```
*/
function validateOperation(value) {
return validatePrefixedValue(value, operationPrefix);
}
exports.validateOperation = validateOperation;
/**
* @description Used to check if a protocol hash is valid.
*
* @returns
* 0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).
*
* @example
* ```
* import { validateProtocol } from '@taquito/utils';
* const protocolHash = 'PtHangz2aRngywmSRGGvrcTyMbbdpWdpFKuS4uMWxg2RaH9i1qx'
* const validation = validateProtocol(protocolHash)
* console.log(validation)
* // This example return 3 which correspond to VALID
* ```
*/
function validateProtocol(value) {
return validatePrefixedValue(value, protocolPrefix);
}
exports.validateProtocol = validateProtocol;
/**
* @description Used to check if a block hash is valid.
*
* @returns
* 0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).
*
* @example
* ```
* import { validateBlock } from '@taquito/utils';
* const blockHash = 'PtHangz2aRngywmSRGGvrcTyMbbdpWdpFKuS4uMWxg2RaH9i1qx'
* const validation = validateBlock(blockHash)
* console.log(validation)
* // This example return 3 which correspond to VALID
* ```
*/
function validateBlock(value) {
return validatePrefixedValue(value, blockPrefix);
}
exports.validateBlock = validateBlock;
//# sourceMappingURL=validators.js.map
"use strict";
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.validatePkAndExtractPrefix = exports.verifySignature = void 0;
var ed25519_1 = require("@stablelib/ed25519");
var blake2b_1 = require("@stablelib/blake2b");
var taquito_utils_1 = require("./taquito-utils");
var elliptic_1 = require("elliptic");
var typedarray_to_buffer_1 = require("typedarray-to-buffer");
var errors_1 = require("./errors");
const ed25519_1 = require("@stablelib/ed25519");
const blake2b_1 = require("@stablelib/blake2b");
const taquito_utils_1 = require("./taquito-utils");
const elliptic_1 = require("elliptic");
const typedarray_to_buffer_1 = require("typedarray-to-buffer");
const errors_1 = require("./errors");
/**

@@ -45,7 +29,7 @@ * @description Verify signature of a payload

function verifySignature(messageBytes, publicKey, signature) {
var pkPrefix = validatePkAndExtractPrefix(publicKey);
var sigPrefix = validateSigAndExtractPrefix(signature);
var decodedPublicKey = taquito_utils_1.b58cdecode(publicKey, taquito_utils_1.prefix[pkPrefix]);
var decodedSig = taquito_utils_1.b58cdecode(signature, taquito_utils_1.prefix[sigPrefix]);
var bytesHash = blake2b_1.hash(taquito_utils_1.hex2buf(validateMessageNotEmpty(messageBytes)), 32);
const pkPrefix = validatePkAndExtractPrefix(publicKey);
const sigPrefix = validateSigAndExtractPrefix(signature);
const decodedPublicKey = taquito_utils_1.b58cdecode(publicKey, taquito_utils_1.prefix[pkPrefix]);
const decodedSig = taquito_utils_1.b58cdecode(signature, taquito_utils_1.prefix[sigPrefix]);
const bytesHash = blake2b_1.hash(taquito_utils_1.hex2buf(validateMessageNotEmpty(messageBytes)), 32);
if (pkPrefix === taquito_utils_1.Prefix.EDPK) {

@@ -67,3 +51,3 @@ return verifyEdSignature(decodedSig, bytesHash, decodedPublicKey);

if (message === '') {
throw new errors_1.InvalidMessageError("The message provided for verifying signature cannot be empty.");
throw new errors_1.InvalidMessageError(`The message provided for verifying signature cannot be empty.`);
}

@@ -74,15 +58,15 @@ return message;

if (publicKey === '') {
throw new errors_1.InvalidPublicKeyError("The public key provided cannot be empty.");
throw new errors_1.InvalidPublicKeyError(`The public key provided cannot be empty.`);
}
var pkPrefix = publicKey.substring(0, 4);
var validation = taquito_utils_1.validatePublicKey(publicKey);
const pkPrefix = publicKey.substring(0, 4);
const validation = taquito_utils_1.validatePublicKey(publicKey);
if (validation !== taquito_utils_1.ValidationResult.VALID) {
if (validation === taquito_utils_1.ValidationResult.INVALID_CHECKSUM) {
throw new errors_1.InvalidPublicKeyError("The public key provided has an invalid checksum: " + publicKey);
throw new errors_1.InvalidPublicKeyError(`The public key provided has an invalid checksum: ${publicKey}`);
}
else if (validation === taquito_utils_1.ValidationResult.INVALID_LENGTH) {
throw new errors_1.InvalidPublicKeyError("The public key provided has an invalid length: " + publicKey);
throw new errors_1.InvalidPublicKeyError(`The public key provided has an invalid length: ${publicKey}`);
}
else if (validation === taquito_utils_1.ValidationResult.NO_PREFIX_MATCHED) {
throw new errors_1.InvalidPublicKeyError("The public key provided has an unsupported prefix: " + pkPrefix);
throw new errors_1.InvalidPublicKeyError(`The public key provided has an unsupported prefix: ${pkPrefix}`);
}

@@ -94,13 +78,13 @@ }

function validateSigAndExtractPrefix(signature) {
var signaturePrefix = signature.startsWith('sig') ? signature.substr(0, 3) : signature.substr(0, 5);
var validation = taquito_utils_1.validateSignature(signature);
const signaturePrefix = signature.startsWith('sig') ? signature.substr(0, 3) : signature.substr(0, 5);
const validation = taquito_utils_1.validateSignature(signature);
if (validation !== taquito_utils_1.ValidationResult.VALID) {
if (validation === taquito_utils_1.ValidationResult.INVALID_CHECKSUM) {
throw new errors_1.InvalidSignatureError("The signature provided has an invalid checksum: " + signature);
throw new errors_1.InvalidSignatureError(`The signature provided has an invalid checksum: ${signature}`);
}
else if (validation === taquito_utils_1.ValidationResult.INVALID_LENGTH) {
throw new errors_1.InvalidSignatureError("The signature provided has an invalid length: " + signature);
throw new errors_1.InvalidSignatureError(`The signature provided has an invalid length: ${signature}`);
}
else if (validation === taquito_utils_1.ValidationResult.NO_PREFIX_MATCHED) {
throw new errors_1.InvalidSignatureError("The signature provided has an unsupported prefix: " + signaturePrefix);
throw new errors_1.InvalidSignatureError(`The signature provided has an unsupported prefix: ${signaturePrefix}`);
}

@@ -119,16 +103,16 @@ }

function verifySpSignature(decodedSig, bytesHash, decodedPublicKey) {
var key = new elliptic_1.default.ec('secp256k1').keyFromPublic(decodedPublicKey);
const key = new elliptic_1.default.ec('secp256k1').keyFromPublic(decodedPublicKey);
return verifySpOrP2Sig(decodedSig, bytesHash, key);
}
function verifyP2Signature(decodedSig, bytesHash, decodedPublicKey) {
var key = new elliptic_1.default.ec('p256').keyFromPublic(decodedPublicKey);
const key = new elliptic_1.default.ec('p256').keyFromPublic(decodedPublicKey);
return verifySpOrP2Sig(decodedSig, bytesHash, key);
}
function verifySpOrP2Sig(decodedSig, bytesHash, key) {
var hexSig = taquito_utils_1.buf2hex(typedarray_to_buffer_1.default(decodedSig));
var match = hexSig.match(/([a-f\d]{64})/gi);
const hexSig = taquito_utils_1.buf2hex(typedarray_to_buffer_1.default(decodedSig));
const match = hexSig.match(/([a-f\d]{64})/gi);
if (match) {
try {
var _a = __read(match, 2), r = _a[0], s = _a[1];
return key.verify(bytesHash, { r: r, s: s });
const [r, s] = match;
return key.verify(bytesHash, { r, s });
}

@@ -135,0 +119,0 @@ catch (e) {

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

// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
/* tslint:disable */
exports.VERSION = {
"commitHash": "e1723ab725df70755b4cd73b75aa981f913d0d5c",
"version": "11.1.0"
"commitHash": "e03d983c780c7f96d8291ddd1251ea82f4581858",
"version": "11.2.0-beta-RC.0"
};
/* tslint:enable */
//# sourceMappingURL=version.js.map
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('buffer'), require('@stablelib/ed25519'), require('@stablelib/blake2b'), require('elliptic'), require('typedarray-to-buffer')) :
typeof define === 'function' && define.amd ? define(['exports', 'buffer', '@stablelib/ed25519', '@stablelib/blake2b', 'elliptic', 'typedarray-to-buffer'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.taquitoUtils = {}, global.buffer, global.ed25519, global.blake2b, global.elliptic, global.toBuffer));
}(this, (function (exports, buffer, ed25519, blake2b, 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('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';
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var blake__default = /*#__PURE__*/_interopDefaultLegacy(blake);
var bs58check__default = /*#__PURE__*/_interopDefaultLegacy(bs58check);
var elliptic__default = /*#__PURE__*/_interopDefaultLegacy(elliptic);
var toBuffer__default = /*#__PURE__*/_interopDefaultLegacy(toBuffer);
var _a, _b;
exports.Prefix = void 0;

@@ -36,3 +37,3 @@ (function (Prefix) {

Prefix["NCE"] = "nce";
Prefix["B"] = "b";
Prefix["B"] = "B";
Prefix["O"] = "o";

@@ -47,114 +48,117 @@ Prefix["LO"] = "Lo";

})(exports.Prefix || (exports.Prefix = {}));
var prefix = (_a = {},
_a[exports.Prefix.TZ1] = new Uint8Array([6, 161, 159]),
_a[exports.Prefix.TZ2] = new Uint8Array([6, 161, 161]),
_a[exports.Prefix.TZ3] = new Uint8Array([6, 161, 164]),
_a[exports.Prefix.KT] = new Uint8Array([2, 90, 121]),
_a[exports.Prefix.KT1] = new Uint8Array([2, 90, 121]),
_a[exports.Prefix.EDSK] = new Uint8Array([43, 246, 78, 7]),
_a[exports.Prefix.EDSK2] = new Uint8Array([13, 15, 58, 7]),
_a[exports.Prefix.SPSK] = new Uint8Array([17, 162, 224, 201]),
_a[exports.Prefix.P2SK] = new Uint8Array([16, 81, 238, 189]),
_a[exports.Prefix.EDPK] = new Uint8Array([13, 15, 37, 217]),
_a[exports.Prefix.SPPK] = new Uint8Array([3, 254, 226, 86]),
_a[exports.Prefix.P2PK] = new Uint8Array([3, 178, 139, 127]),
_a[exports.Prefix.EDESK] = new Uint8Array([7, 90, 60, 179, 41]),
_a[exports.Prefix.SPESK] = new Uint8Array([0x09, 0xed, 0xf1, 0xae, 0x96]),
_a[exports.Prefix.P2ESK] = new Uint8Array([0x09, 0x30, 0x39, 0x73, 0xab]),
_a[exports.Prefix.EDSIG] = new Uint8Array([9, 245, 205, 134, 18]),
_a[exports.Prefix.SPSIG] = new Uint8Array([13, 115, 101, 19, 63]),
_a[exports.Prefix.P2SIG] = new Uint8Array([54, 240, 44, 52]),
_a[exports.Prefix.SIG] = new Uint8Array([4, 130, 43]),
_a[exports.Prefix.NET] = new Uint8Array([87, 82, 0]),
_a[exports.Prefix.NCE] = new Uint8Array([69, 220, 169]),
_a[exports.Prefix.B] = new Uint8Array([1, 52]),
_a[exports.Prefix.O] = new Uint8Array([5, 116]),
_a[exports.Prefix.LO] = new Uint8Array([133, 233]),
_a[exports.Prefix.LLO] = new Uint8Array([29, 159, 109]),
_a[exports.Prefix.P] = new Uint8Array([2, 170]),
_a[exports.Prefix.CO] = new Uint8Array([79, 179]),
_a[exports.Prefix.ID] = new Uint8Array([153, 103]),
_a[exports.Prefix.EXPR] = new Uint8Array([13, 44, 64, 27]),
const prefix = {
[exports.Prefix.TZ1]: new Uint8Array([6, 161, 159]),
[exports.Prefix.TZ2]: new Uint8Array([6, 161, 161]),
[exports.Prefix.TZ3]: new Uint8Array([6, 161, 164]),
[exports.Prefix.KT]: new Uint8Array([2, 90, 121]),
[exports.Prefix.KT1]: new Uint8Array([2, 90, 121]),
[exports.Prefix.EDSK]: new Uint8Array([43, 246, 78, 7]),
[exports.Prefix.EDSK2]: new Uint8Array([13, 15, 58, 7]),
[exports.Prefix.SPSK]: new Uint8Array([17, 162, 224, 201]),
[exports.Prefix.P2SK]: new Uint8Array([16, 81, 238, 189]),
[exports.Prefix.EDPK]: new Uint8Array([13, 15, 37, 217]),
[exports.Prefix.SPPK]: new Uint8Array([3, 254, 226, 86]),
[exports.Prefix.P2PK]: new Uint8Array([3, 178, 139, 127]),
[exports.Prefix.EDESK]: new Uint8Array([7, 90, 60, 179, 41]),
[exports.Prefix.SPESK]: new Uint8Array([0x09, 0xed, 0xf1, 0xae, 0x96]),
[exports.Prefix.P2ESK]: new Uint8Array([0x09, 0x30, 0x39, 0x73, 0xab]),
[exports.Prefix.EDSIG]: new Uint8Array([9, 245, 205, 134, 18]),
[exports.Prefix.SPSIG]: new Uint8Array([13, 115, 101, 19, 63]),
[exports.Prefix.P2SIG]: new Uint8Array([54, 240, 44, 52]),
[exports.Prefix.SIG]: new Uint8Array([4, 130, 43]),
[exports.Prefix.NET]: new Uint8Array([87, 82, 0]),
[exports.Prefix.NCE]: new Uint8Array([69, 220, 169]),
[exports.Prefix.B]: new Uint8Array([1, 52]),
[exports.Prefix.O]: new Uint8Array([5, 116]),
[exports.Prefix.LO]: new Uint8Array([133, 233]),
[exports.Prefix.LLO]: new Uint8Array([29, 159, 109]),
[exports.Prefix.P]: new Uint8Array([2, 170]),
[exports.Prefix.CO]: new Uint8Array([79, 179]),
[exports.Prefix.ID]: new Uint8Array([153, 103]),
[exports.Prefix.EXPR]: new Uint8Array([13, 44, 64, 27]),
// Legacy prefix
_a[exports.Prefix.TZ] = new Uint8Array([2, 90, 121]),
_a);
var prefixLength = (_b = {},
_b[exports.Prefix.TZ1] = 20,
_b[exports.Prefix.TZ2] = 20,
_b[exports.Prefix.TZ3] = 20,
_b[exports.Prefix.KT] = 20,
_b[exports.Prefix.KT1] = 20,
_b[exports.Prefix.EDPK] = 32,
_b[exports.Prefix.SPPK] = 33,
_b[exports.Prefix.P2PK] = 33,
_b[exports.Prefix.EDSIG] = 64,
_b[exports.Prefix.SPSIG] = 64,
_b[exports.Prefix.P2SIG] = 64,
_b[exports.Prefix.SIG] = 64,
_b[exports.Prefix.NET] = 4,
_b[exports.Prefix.B] = 32,
_b[exports.Prefix.P] = 32,
_b[exports.Prefix.O] = 32,
_b);
[exports.Prefix.TZ]: new Uint8Array([2, 90, 121]),
};
const prefixLength = {
[exports.Prefix.TZ1]: 20,
[exports.Prefix.TZ2]: 20,
[exports.Prefix.TZ3]: 20,
[exports.Prefix.KT]: 20,
[exports.Prefix.KT1]: 20,
[exports.Prefix.EDPK]: 32,
[exports.Prefix.SPPK]: 33,
[exports.Prefix.P2PK]: 33,
[exports.Prefix.EDSIG]: 64,
[exports.Prefix.SPSIG]: 64,
[exports.Prefix.P2SIG]: 64,
[exports.Prefix.SIG]: 64,
[exports.Prefix.NET]: 4,
[exports.Prefix.B]: 32,
[exports.Prefix.P]: 32,
[exports.Prefix.O]: 32
};
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
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.
***************************************************************************** */
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
class InvalidPublicKeyError extends Error {
constructor(message) {
super(message);
this.message = message;
this.name = 'InvalidPublicKeyError';
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
class InvalidSignatureError extends Error {
constructor(message) {
super(message);
this.message = message;
this.name = 'InvalidSignatureError';
}
return ar;
}
/** @deprecated */
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
class InvalidMessageError extends Error {
constructor(message) {
super(message);
this.message = message;
this.name = 'InvalidMessageError';
}
}
var InvalidPublicKeyError = /** @class */ (function () {
function InvalidPublicKeyError(message) {
class InvalidContractAddressError extends Error {
constructor(message) {
super(message);
this.message = message;
this.name = 'InvalidPublicKeyError';
this.name = 'InvalidContractAddressError';
}
return InvalidPublicKeyError;
}());
var InvalidSignatureError = /** @class */ (function () {
function InvalidSignatureError(message) {
}
class InvalidAddressError extends Error {
constructor(message) {
super(message);
this.message = message;
this.name = 'InvalidSignatureError';
this.name = 'InvalidAddressError';
}
return InvalidSignatureError;
}());
var InvalidMessageError = /** @class */ (function () {
function InvalidMessageError(message) {
}
class InvalidKeyHashError extends Error {
constructor(message) {
super(message);
this.message = message;
this.name = 'InvalidMessageError';
this.name = 'InvalidKeyHashError';
}
return InvalidMessageError;
}());
}
class InvalidBlockHashError extends Error {
constructor(message) {
super(message);
this.message = message;
this.name = 'InvalidBlockHashError';
}
}
class InvalidProtocolHashError extends Error {
constructor(message) {
super(message);
this.message = message;
this.name = 'InvalidProtocolHashError';
}
}
class InvalidOperationHashError extends Error {
constructor(message) {
super(message);
this.message = message;
this.name = 'InvalidOperationHashError';
}
}

@@ -180,7 +184,7 @@ /**

function verifySignature(messageBytes, publicKey, signature) {
var pkPrefix = validatePkAndExtractPrefix(publicKey);
var sigPrefix = validateSigAndExtractPrefix(signature);
var decodedPublicKey = b58cdecode(publicKey, prefix[pkPrefix]);
var decodedSig = b58cdecode(signature, prefix[sigPrefix]);
var bytesHash = blake2b.hash(hex2buf(validateMessageNotEmpty(messageBytes)), 32);
const pkPrefix = validatePkAndExtractPrefix(publicKey);
const sigPrefix = validateSigAndExtractPrefix(signature);
const decodedPublicKey = b58cdecode(publicKey, prefix[pkPrefix]);
const decodedSig = b58cdecode(signature, prefix[sigPrefix]);
const bytesHash = blake2b.hash(hex2buf(validateMessageNotEmpty(messageBytes)), 32);
if (pkPrefix === exports.Prefix.EDPK) {

@@ -201,3 +205,3 @@ return verifyEdSignature(decodedSig, bytesHash, decodedPublicKey);

if (message === '') {
throw new InvalidMessageError("The message provided for verifying signature cannot be empty.");
throw new InvalidMessageError(`The message provided for verifying signature cannot be empty.`);
}

@@ -208,15 +212,15 @@ return message;

if (publicKey === '') {
throw new InvalidPublicKeyError("The public key provided cannot be empty.");
throw new InvalidPublicKeyError(`The public key provided cannot be empty.`);
}
var pkPrefix = publicKey.substring(0, 4);
var validation = validatePublicKey(publicKey);
const pkPrefix = publicKey.substring(0, 4);
const validation = validatePublicKey(publicKey);
if (validation !== exports.ValidationResult.VALID) {
if (validation === exports.ValidationResult.INVALID_CHECKSUM) {
throw new InvalidPublicKeyError("The public key provided has an invalid checksum: " + publicKey);
throw new InvalidPublicKeyError(`The public key provided has an invalid checksum: ${publicKey}`);
}
else if (validation === exports.ValidationResult.INVALID_LENGTH) {
throw new InvalidPublicKeyError("The public key provided has an invalid length: " + publicKey);
throw new InvalidPublicKeyError(`The public key provided has an invalid length: ${publicKey}`);
}
else if (validation === exports.ValidationResult.NO_PREFIX_MATCHED) {
throw new InvalidPublicKeyError("The public key provided has an unsupported prefix: " + pkPrefix);
throw new InvalidPublicKeyError(`The public key provided has an unsupported prefix: ${pkPrefix}`);
}

@@ -227,13 +231,13 @@ }

function validateSigAndExtractPrefix(signature) {
var signaturePrefix = signature.startsWith('sig') ? signature.substr(0, 3) : signature.substr(0, 5);
var validation = validateSignature(signature);
const signaturePrefix = signature.startsWith('sig') ? signature.substr(0, 3) : signature.substr(0, 5);
const validation = validateSignature(signature);
if (validation !== exports.ValidationResult.VALID) {
if (validation === exports.ValidationResult.INVALID_CHECKSUM) {
throw new InvalidSignatureError("The signature provided has an invalid checksum: " + signature);
throw new InvalidSignatureError(`The signature provided has an invalid checksum: ${signature}`);
}
else if (validation === exports.ValidationResult.INVALID_LENGTH) {
throw new InvalidSignatureError("The signature provided has an invalid length: " + signature);
throw new InvalidSignatureError(`The signature provided has an invalid length: ${signature}`);
}
else if (validation === exports.ValidationResult.NO_PREFIX_MATCHED) {
throw new InvalidSignatureError("The signature provided has an unsupported prefix: " + signaturePrefix);
throw new InvalidSignatureError(`The signature provided has an unsupported prefix: ${signaturePrefix}`);
}

@@ -252,16 +256,16 @@ }

function verifySpSignature(decodedSig, bytesHash, decodedPublicKey) {
var key = new elliptic__default['default'].ec('secp256k1').keyFromPublic(decodedPublicKey);
const key = new elliptic__default["default"].ec('secp256k1').keyFromPublic(decodedPublicKey);
return verifySpOrP2Sig(decodedSig, bytesHash, key);
}
function verifyP2Signature(decodedSig, bytesHash, decodedPublicKey) {
var key = new elliptic__default['default'].ec('p256').keyFromPublic(decodedPublicKey);
const key = new elliptic__default["default"].ec('p256').keyFromPublic(decodedPublicKey);
return verifySpOrP2Sig(decodedSig, bytesHash, key);
}
function verifySpOrP2Sig(decodedSig, bytesHash, key) {
var hexSig = buf2hex(toBuffer__default['default'](decodedSig));
var match = hexSig.match(/([a-f\d]{64})/gi);
const hexSig = buf2hex(toBuffer__default["default"](decodedSig));
const match = hexSig.match(/([a-f\d]{64})/gi);
if (match) {
try {
var _a = __read(match, 2), r = _a[0], s = _a[1];
return key.verify(bytesHash, { r: r, s: s });
const [r, s] = match;
return key.verify(bytesHash, { r, s });
}

@@ -275,3 +279,2 @@ catch (e) {

var bs58check$1 = require('bs58check');
exports.ValidationResult = void 0;

@@ -301,7 +304,7 @@ (function (ValidationResult) {

function validatePrefixedValue(value, prefixes) {
var match = new RegExp("^(" + prefixes.join('|') + ")").exec(value);
const match = new RegExp(`^(${prefixes.join('|')})`).exec(value);
if (!match || match.length === 0) {
return exports.ValidationResult.NO_PREFIX_MATCHED;
}
var prefixKey = match[0];
const prefixKey = match[0];
if (!isValidPrefix(prefixKey)) {

@@ -311,3 +314,3 @@ return exports.ValidationResult.NO_PREFIX_MATCHED;

// Remove annotation from contract address before doing the validation
var contractAddress = /^(KT1\w{33})(\%(.*))?/.exec(value);
const contractAddress = /^(KT1\w{33})(%(.*))?/.exec(value);
if (contractAddress) {

@@ -317,3 +320,3 @@ value = contractAddress[1];

// decodeUnsafe return undefined if decoding fail
var decoded = bs58check$1.decodeUnsafe(value);
let decoded = bs58check__default["default"].decodeUnsafe(value);
if (!decoded) {

@@ -328,6 +331,9 @@ return exports.ValidationResult.INVALID_CHECKSUM;

}
var implicitPrefix = [exports.Prefix.TZ1, exports.Prefix.TZ2, exports.Prefix.TZ3];
var contractPrefix = [exports.Prefix.KT1];
var signaturePrefix = [exports.Prefix.EDSIG, exports.Prefix.P2SIG, exports.Prefix.SPSIG, exports.Prefix.SIG];
var pkPrefix = [exports.Prefix.EDPK, exports.Prefix.SPPK, exports.Prefix.P2PK];
const implicitPrefix = [exports.Prefix.TZ1, exports.Prefix.TZ2, exports.Prefix.TZ3];
const contractPrefix = [exports.Prefix.KT1];
const signaturePrefix = [exports.Prefix.EDSIG, exports.Prefix.P2SIG, exports.Prefix.SPSIG, exports.Prefix.SIG];
const pkPrefix = [exports.Prefix.EDPK, exports.Prefix.SPPK, exports.Prefix.P2PK];
const operationPrefix = [exports.Prefix.O];
const protocolPrefix = [exports.Prefix.P];
const blockPrefix = [exports.Prefix.B];
/**

@@ -349,3 +355,3 @@ * @description Used to check if an address or a contract address is valid.

function validateAddress(value) {
return validatePrefixedValue(value, __spread(implicitPrefix, contractPrefix));
return validatePrefixedValue(value, [...implicitPrefix, ...contractPrefix]);
}

@@ -425,3 +431,3 @@ /**

/**
* @description Used to check if a signature is valid.
* @description Used to check if a public key is valid.
*

@@ -443,10 +449,62 @@ * @returns

}
/**
* @description Used to check if an operation hash is valid.
*
* @returns
* 0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).
*
* @example
* ```
* import { validateOperation } from '@taquito/utils';
* const operationHash = 'oo6JPEAy8VuMRGaFuMmLNFFGdJgiaKfnmT1CpHJfKP3Ye5ZahiP'
* const validation = validateOperation(operationHash)
* console.log(validation)
* // This example return 3 which correspond to VALID
* ```
*/
function validateOperation(value) {
return validatePrefixedValue(value, operationPrefix);
}
/**
* @description Used to check if a protocol hash is valid.
*
* @returns
* 0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).
*
* @example
* ```
* import { validateProtocol } from '@taquito/utils';
* const protocolHash = 'PtHangz2aRngywmSRGGvrcTyMbbdpWdpFKuS4uMWxg2RaH9i1qx'
* const validation = validateProtocol(protocolHash)
* console.log(validation)
* // This example return 3 which correspond to VALID
* ```
*/
function validateProtocol(value) {
return validatePrefixedValue(value, protocolPrefix);
}
/**
* @description Used to check if a block hash is valid.
*
* @returns
* 0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).
*
* @example
* ```
* import { validateBlock } from '@taquito/utils';
* const blockHash = 'PtHangz2aRngywmSRGGvrcTyMbbdpWdpFKuS4uMWxg2RaH9i1qx'
* const validation = validateBlock(blockHash)
* console.log(validation)
* // This example return 3 which correspond to VALID
* ```
*/
function validateBlock(value) {
return validatePrefixedValue(value, blockPrefix);
}
// IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
/* tslint:disable */
var VERSION = {
"commitHash": "e1723ab725df70755b4cd73b75aa981f913d0d5c",
"version": "11.1.0"
const VERSION = {
"commitHash": "e03d983c780c7f96d8291ddd1251ea82f4581858",
"version": "11.2.0-beta-RC.0"
};
/* tslint:enable */

@@ -457,4 +515,2 @@ /**

*/
var blake = require('blakejs');
var bs58check = require('bs58check');
/**

@@ -467,3 +523,3 @@ *

function encodeExpr(value) {
var blakeHash = blake.blake2b(hex2buf(value), null, 32);
const blakeHash = blake__default["default"].blake2b(hex2buf(value), undefined, 32);
return b58cencode(blakeHash, prefix['expr']);

@@ -477,3 +533,3 @@ }

function encodeOpHash(value) {
var blakeHash = blake.blake2b(hex2buf(value), null, 32);
const blakeHash = blake__default["default"].blake2b(hex2buf(value), undefined, 32);
return b58cencode(blakeHash, prefix.o);

@@ -489,7 +545,7 @@ }

function b58cencode(value, prefix) {
var payloadAr = typeof value === 'string' ? Uint8Array.from(buffer.Buffer.from(value, 'hex')) : value;
var n = new Uint8Array(prefix.length + payloadAr.length);
const payloadAr = typeof value === 'string' ? Uint8Array.from(buffer.Buffer.from(value, 'hex')) : value;
const n = new Uint8Array(prefix.length + payloadAr.length);
n.set(prefix);
n.set(payloadAr, prefix.length);
return bs58check.encode(buffer.Buffer.from(n.buffer));
return bs58check__default["default"].encode(buffer.Buffer.from(n.buffer));
}

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

*/
var b58cdecode = function (enc, prefixArg) {
return bs58check.decode(enc).slice(prefixArg.length);
};
const b58cdecode = (enc, prefixArg) => bs58check__default["default"].decode(enc).slice(prefixArg.length);
/**

@@ -514,13 +568,12 @@ *

function b58decode(payload) {
var _a;
var buf = bs58check.decode(payload);
var prefixMap = (_a = {},
_a[prefix.tz1.toString()] = '0000',
_a[prefix.tz2.toString()] = '0001',
_a[prefix.tz3.toString()] = '0002',
_a);
var pref = prefixMap[new Uint8Array(buf.slice(0, 3)).toString()];
const buf = bs58check__default["default"].decode(payload);
const prefixMap = {
[prefix.tz1.toString()]: '0000',
[prefix.tz2.toString()]: '0001',
[prefix.tz3.toString()]: '0002',
};
const pref = prefixMap[new Uint8Array(buf.slice(0, 3)).toString()];
if (pref) {
// tz addresses
var hex = buf2hex(buf.slice(3));
const hex = buf2hex(buf.slice(3));
return pref + hex;

@@ -535,9 +588,9 @@ }

*
* @description Base58 encode a public key using predefined prefix
* @description Base58 encode an address using predefined prefix
*
* @param value Public Key to base58 encode
* @param value Address to base58 encode (tz1, tz2, tz3 or KT1)
*/
function encodePubKey(value) {
if (value.substring(0, 2) === '00') {
var pref = {
const pref = {
'0000': prefix.tz1,

@@ -559,3 +612,3 @@ '0001': prefix.tz2,

if (value[0] === '0') {
var pref = {
const pref = {
'00': new Uint8Array([13, 15, 37, 217]),

@@ -572,7 +625,7 @@ '01': new Uint8Array([3, 254, 226, 86]),

*
* @param value Key to base58 encode
* @param value Key hash to base58 encode
*/
function encodeKeyHash(value) {
if (value[0] === '0') {
var pref = {
const pref = {
'00': new Uint8Array([6, 161, 159]),

@@ -591,4 +644,10 @@ '01': new Uint8Array([6, 161, 161]),

*/
var hex2buf = function (hex) {
return new Uint8Array(hex.match(/[\da-f]{2}/gi).map(function (h) { return parseInt(h, 16); }));
const hex2buf = (hex) => {
const match = hex.match(/[\da-f]{2}/gi);
if (match) {
return new Uint8Array(match.map((h) => parseInt(h, 16)));
}
else {
throw new Error(`Unable to convert ${hex} to a Uint8Array`);
}
};

@@ -602,4 +661,4 @@ /**

*/
var mergebuf = function (b1, b2) {
var r = new Uint8Array(b1.length + b2.length);
const mergebuf = (b1, b2) => {
const r = new Uint8Array(b1.length + b2.length);
r.set(b1);

@@ -615,4 +674,4 @@ r.set(b2, b1.length);

*/
var mic2arr = function me2(s) {
var ret = [];
const mic2arr = function me2(s) {
let ret = [];
if (Object.prototype.hasOwnProperty.call(s, 'prim')) {

@@ -637,5 +696,5 @@ if (s.prim === 'Pair') {

else if (Array.isArray(s)) {
var sc = s.length;
for (var i = 0; i < sc; i++) {
var n = me2(s[i]);
const sc = s.length;
for (let i = 0; i < sc; i++) {
const n = me2(s[i]);
if (typeof n.key !== 'undefined') {

@@ -673,8 +732,8 @@ if (Array.isArray(ret)) {

*/
var buf2hex = function (buffer) {
var byteArray = new Uint8Array(buffer);
var hexParts = [];
byteArray.forEach(function (byte) {
var hex = byte.toString(16);
var paddedHex = ("00" + hex).slice(-2);
const buf2hex = (buffer) => {
const byteArray = new Uint8Array(buffer);
const hexParts = [];
byteArray.forEach((byte) => {
const hex = byte.toString(16);
const paddedHex = `00${hex}`.slice(-2);
hexParts.push(paddedHex);

@@ -691,7 +750,7 @@ });

*/
var getPkhfromPk = function (publicKey) {
var encodingPrefix;
var prefixLen;
var keyPrefix = validatePkAndExtractPrefix(publicKey);
var decoded = b58cdecode(publicKey, prefix[keyPrefix]);
const getPkhfromPk = (publicKey) => {
let encodingPrefix;
let prefixLen;
const keyPrefix = validatePkAndExtractPrefix(publicKey);
const decoded = b58cdecode(publicKey, prefix[keyPrefix]);
switch (keyPrefix) {

@@ -711,4 +770,4 @@ case exports.Prefix.EDPK:

}
var hashed = blake2b.hash(decoded, prefixLen);
var result = b58cencode(hashed, encodingPrefix);
const hashed = blake2b.hash(decoded, prefixLen);
const result = b58cencode(hashed, encodingPrefix);
return result;

@@ -735,2 +794,11 @@ };

exports.InvalidAddressError = InvalidAddressError;
exports.InvalidBlockHashError = InvalidBlockHashError;
exports.InvalidContractAddressError = InvalidContractAddressError;
exports.InvalidKeyHashError = InvalidKeyHashError;
exports.InvalidMessageError = InvalidMessageError;
exports.InvalidOperationHashError = InvalidOperationHashError;
exports.InvalidProtocolHashError = InvalidProtocolHashError;
exports.InvalidPublicKeyError = InvalidPublicKeyError;
exports.InvalidSignatureError = InvalidSignatureError;
exports.VERSION = VERSION;

@@ -756,6 +824,9 @@ exports.b58cdecode = b58cdecode;

exports.validateAddress = validateAddress;
exports.validateBlock = validateBlock;
exports.validateChain = validateChain;
exports.validateContractAddress = validateContractAddress;
exports.validateKeyHash = validateKeyHash;
exports.validateOperation = validateOperation;
exports.validatePkAndExtractPrefix = validatePkAndExtractPrefix;
exports.validateProtocol = validateProtocol;
exports.validatePublicKey = validatePublicKey;

@@ -767,3 +838,3 @@ exports.validateSignature = validateSignature;

})));
}));
//# sourceMappingURL=taquito-utils.umd.js.map

@@ -23,3 +23,3 @@ export declare enum Prefix {

NCE = "nce",
B = "b",
B = "B",
O = "o",

@@ -56,3 +56,3 @@ LO = "Lo",

nce: Uint8Array;
b: Uint8Array;
B: Uint8Array;
o: Uint8Array;

@@ -59,0 +59,0 @@ Lo: Uint8Array;

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

export declare class InvalidPublicKeyError implements Error {
export declare class InvalidPublicKeyError extends Error {
message: string;

@@ -6,3 +6,3 @@ name: string;

}
export declare class InvalidSignatureError implements Error {
export declare class InvalidSignatureError extends Error {
message: string;

@@ -12,3 +12,3 @@ name: string;

}
export declare class InvalidMessageError implements Error {
export declare class InvalidMessageError extends Error {
message: string;

@@ -18,1 +18,31 @@ name: string;

}
export declare class InvalidContractAddressError extends Error {
message: string;
name: string;
constructor(message: string);
}
export declare class InvalidAddressError extends Error {
message: string;
name: string;
constructor(message: string);
}
export declare class InvalidKeyHashError extends Error {
message: string;
name: string;
constructor(message: string);
}
export declare class InvalidBlockHashError extends Error {
message: string;
name: string;
constructor(message: string);
}
export declare class InvalidProtocolHashError extends Error {
message: string;
name: string;
constructor(message: string);
}
export declare class InvalidOperationHashError extends Error {
message: string;
name: string;
constructor(message: string);
}

@@ -10,2 +10,3 @@ /**

export { verifySignature, validatePkAndExtractPrefix } from './verify-signature';
export * from './errors';
/**

@@ -17,3 +18,3 @@ *

*/
export declare function encodeExpr(value: string): any;
export declare function encodeExpr(value: string): string;
/**

@@ -24,3 +25,3 @@ *

*/
export declare function encodeOpHash(value: string): any;
export declare function encodeOpHash(value: string): string;
/**

@@ -33,3 +34,3 @@ *

*/
export declare function b58cencode(value: string | Uint8Array, prefix: Uint8Array): any;
export declare function b58cencode(value: string | Uint8Array, prefix: Uint8Array): string;
/**

@@ -52,7 +53,7 @@ *

*
* @description Base58 encode a public key using predefined prefix
* @description Base58 encode an address using predefined prefix
*
* @param value Public Key to base58 encode
* @param value Address to base58 encode (tz1, tz2, tz3 or KT1)
*/
export declare function encodePubKey(value: string): any;
export declare function encodePubKey(value: string): string;
/**

@@ -64,3 +65,3 @@ *

*/
export declare function encodeKey(value: string): any;
export declare function encodeKey(value: string): string | undefined;
/**

@@ -70,5 +71,5 @@ *

*
* @param value Key to base58 encode
* @param value Key hash to base58 encode
*/
export declare function encodeKeyHash(value: string): any;
export declare function encodeKeyHash(value: string): string | undefined;
/**

@@ -75,0 +76,0 @@ *

@@ -90,3 +90,3 @@ import { Prefix } from './constants';

/**
* @description Used to check if a signature is valid.
* @description Used to check if a public key is valid.
*

@@ -106,1 +106,49 @@ * @returns

export declare function validatePublicKey(value: any): ValidationResult;
/**
* @description Used to check if an operation hash is valid.
*
* @returns
* 0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).
*
* @example
* ```
* import { validateOperation } from '@taquito/utils';
* const operationHash = 'oo6JPEAy8VuMRGaFuMmLNFFGdJgiaKfnmT1CpHJfKP3Ye5ZahiP'
* const validation = validateOperation(operationHash)
* console.log(validation)
* // This example return 3 which correspond to VALID
* ```
*/
export declare function validateOperation(value: any): ValidationResult;
/**
* @description Used to check if a protocol hash is valid.
*
* @returns
* 0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).
*
* @example
* ```
* import { validateProtocol } from '@taquito/utils';
* const protocolHash = 'PtHangz2aRngywmSRGGvrcTyMbbdpWdpFKuS4uMWxg2RaH9i1qx'
* const validation = validateProtocol(protocolHash)
* console.log(validation)
* // This example return 3 which correspond to VALID
* ```
*/
export declare function validateProtocol(value: any): ValidationResult;
/**
* @description Used to check if a block hash is valid.
*
* @returns
* 0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).
*
* @example
* ```
* import { validateBlock } from '@taquito/utils';
* const blockHash = 'PtHangz2aRngywmSRGGvrcTyMbbdpWdpFKuS4uMWxg2RaH9i1qx'
* const validation = validateBlock(blockHash)
* console.log(validation)
* // This example return 3 which correspond to VALID
* ```
*/
export declare function validateBlock(value: any): ValidationResult;
{
"name": "@taquito/utils",
"version": "11.1.0",
"version": "11.2.0-beta-RC.0",
"description": "converts michelson data and types into convenient JS/TS objects",

@@ -12,3 +12,3 @@ "keywords": [

"main": "dist/taquito-utils.umd.js",
"module": "dist/taquito-utils.es5.js",
"module": "dist/taquito-utils.es6.js",
"typings": "dist/types/taquito-utils.d.ts",

@@ -36,4 +36,4 @@ "files": [

"version-stamp": "node ../taquito/version-stamping.js",
"build": "npm run version-stamp && tsc --project ./tsconfig.prod.json --module commonjs && rollup -c rollup.config.ts",
"start": "npm run version-stamp && rollup -c rollup.config.ts -w",
"build": "tsc --project ./tsconfig.prod.json --module commonjs && rollup -c rollup.config.ts",
"start": "rollup -c rollup.config.ts -w",
"test": "jest"

@@ -70,3 +70,4 @@ },

"@stablelib/ed25519": "^1.0.2",
"blakejs": "^1.1.0",
"@types/bs58check": "^2.1.0",
"blakejs": "^1.1.1",
"bs58check": "^2.1.2",

@@ -78,32 +79,32 @@ "buffer": "^6.0.3",

"devDependencies": {
"@types/bluebird": "^3.5.36",
"@types/elliptic": "^6.4.14",
"@types/jest": "^26.0.23",
"@types/node": "^15.12.2",
"@typescript-eslint/eslint-plugin": "^4.28.1",
"@typescript-eslint/parser": "^4.28.1",
"@types/node": "^17.0.0",
"@typescript-eslint/eslint-plugin": "^5.7.0",
"@typescript-eslint/parser": "^5.7.0",
"colors": "^1.4.0",
"coveralls": "^3.1.0",
"coveralls": "^3.1.1",
"cross-env": "^7.0.3",
"eslint": "^7.29.0",
"eslint": "^8.5.0",
"jest": "^26.6.3",
"jest-config": "^26.6.3",
"lint-staged": "^11.0.0",
"lint-staged": "^12.1.2",
"lodash.camelcase": "^4.3.0",
"prettier": "^2.3.1",
"prompt": "^1.1.0",
"replace-in-file": "^6.2.0",
"prettier": "^2.5.1",
"prompt": "^1.2.0",
"replace-in-file": "^6.3.2",
"rimraf": "^3.0.2",
"rollup": "^2.51.1",
"rollup": "^2.61.1",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-sourcemaps": "^0.6.3",
"rollup-plugin-typescript2": "^0.30.0",
"rollup-plugin-typescript2": "^0.31.1",
"shelljs": "^0.8.4",
"ts-jest": "^26.4.4",
"ts-node": "^10.0.0",
"tslint-config-prettier": "^1.18.0",
"tslint-config-standard": "^9.0.0",
"ts-node": "^10.4.0",
"ts-toolbelt": "^9.6.0",
"typedoc": "^0.20.36",
"typescript": "~4.1.5"
},
"gitHead": "b45707bca75a6a5163b6ef20c80db5975b02e894"
"gitHead": "7cc9152cdad01bacca4a1b682c7cb0a33a24f544"
}
# Taquito Utils package
*TypeDoc style documentation is available on-line [here](https://tezostaquito.io/typedoc/modules/_taquito_utils.html)*
`@taquito/utils` is an npm package that provides developers with utility functionality for Taquito.
## Install
```
npm i --save @taquito/utils
```
## Usage
### Validation functions
Taquito provides functions that allow seeing if an address, a chain, a key hash, a contract address, a public key, a signature, a block hash, an operation hash, or a protocol hash is valid based on checksums.
The `ValidationResult` returned by these functions is an enum that can take the following values:
```
0 = NO_PREFIX_MATCHED,
1 = INVALID_CHECKSUM,
2 = INVALID_LENGTH,
3 = VALID
```
**Address validation (tz1, tz2, tz3, KT1)**
```ts
import { char2Bytes } from '@taquito/utils'; // Convert a string to bytes
import { bytes2Char } from '@taquito/utils'; // Convert bytes to a string
import { buf2hex } from '@taquito/utils'; // Convert a buffer to an hex string
import { mergebuf } from '@taquito/utils'; // Merge 2 buffers together
import { hex2buf } from '@taquito/utils'; // Convert an hex string to a Uint8Array
import { encodeKeyHash } from '@taquito/utils'; // Base58 encode a key hash according to its prefix
import { encodeKey } from '@taquito/utils'; // Base58 encode a key according to its prefix
import { encodePubKey } from '@taquito/utils'; // Base58 encode a public key using predefined prefix
import { b58decode } from '@taquito/utils'; // Base58 decode a string with predefined prefix
import { b58cdecode } from '@taquito/utils'; // Base58 decode a string and remove the prefix from it
import { b58cencode } from '@taquito/utils'; // Base58 encode a string or a Uint8Array and append a prefix to it
import { encodeOpHash } from '@taquito/utils'; // Return the operation hash of a signed operation
import { encodeExpr } from '@taquito/utils'; // Hash a string using the BLAKE2b algorithm, base58 encode the hash obtained and appends the prefix 'expr' to it
import { getPkhfromPk } from '@taquito/utils'; // Returns Tezos address (PKH) of a given Public Key
import { validateAddress } from '@taquito/utils';
const pkh = 'tz1L9r8mWmRPndRhuvMCWESLGSVeFzQ9NAWx';
console.log(validateAddress(pkh));
// output: 3 which is valid
```
See the top-level [https://github.com/ecadlabs/taquito](https://github.com/ecadlabs/taquito) file for details on reporting issues, contributing and versioning.
**Key hash validation**
## API Documentation
```ts
import { validateKeyHash } from '@taquito/utils';
TypeDoc style documentation is available on-line [here](https://tezostaquito.io/typedoc/modules/_taquito_utils.html)
const keyHash = 'tz1L9r8mWmRPndRhuvMCWESLGSVeFzQ9NAWx';
console.log(validateKeyHash(keyHash));
// output: 3 which is valid
```
**Contract address validation**
```ts
import { validateContractAddress } from '@taquito/utils';
const contractAddress = 'KT1AfxAKKLnEg6rQ6kHdvCWwagjSaxEwURSJ';
console.log(validateContractAddress(contractAddress));
// output: 3 which is valid
```
**Chain id validation**
```ts
import { validateChain } from '@taquito/utils';
const chainId = 'NetXdQprcVkpaWU';
console.log(validateChain(chainId));
// output: 3 which is valid
```
**Public key validation**
```ts
import { validatePublicKey } from '@taquito/utils';
const publicKey = 'edpkvS5QFv7KRGfa3b87gg9DBpxSm3NpSwnjhUjNBQrRUUR66F7C9g';
console.log(validatePublicKey(publicKey));
// output: 3 which is valid
```
**Signature validation**
```ts
import { validateSignature } from '@taquito/utils';
const signature = 'edsigtkpiSSschcaCt9pUVrpNPf7TTcgvgDEDD6NCEHMy8NNQJCGnMfLZzYoQj74yLjo9wx6MPVV29CvVzgi7qEcEUok3k7AuMg';
console.log(validateSignature(signature));
// output: 3 which is valid
```
**Block hash validation**
```ts
import { validateBlock } from '@taquito/utils';
const block ='BLJjnzaPtSsxykZ9pLTFLSfsKuiN3z7SjSPDPWwbE4Q68u5EpBw';
console.log(validateBlock(block));
// output: 3 which is valid
```
**Operation hash validation**
```ts
import { validateOperation } from '@taquito/utils';
const operation ='ood2Y1FLHH9izvYghVcDGGAkvJFo1CgSEjPfWvGsaz3qypCmeUj';
console.log(validateOperation(operation));
// output: 3 which is valid
```
**Protocol hash validation**
```ts
import { validateProtocol } from '@taquito/utils';
//valid
const protocol ='PtHangz2aRngywmSRGGvrcTyMbbdpWdpFKuS4uMWxg2RaH9i1qx';
console.log(validateProtocol(protocol));
// output: 3 which is valid
```
### Verification of a signature
The function takes a message, a public key, and a signature as parameters and returns a boolean indicating if the signature matches.
```ts
import { verifySignature } from '@taquito/utils';
const message = '03d0c10e3ed11d7c6e3357f6ef335bab9e8f2bd54d0ce20c482e241191a6e4b8ce6c01be917311d9ac46959750e405d57e268e2ed9e174a80794fbd504e12a4a000141eb3781afed2f69679ff2bbe1c5375950b0e40d00ff000000005e05050505050507070100000024747a32526773486e74516b72794670707352466261313652546656503539684b72654a4d07070100000024747a315a6672455263414c42776d4171776f6e525859565142445439426a4e6a42484a750001';
const pk = 'sppk7c7hkPj47yjYFEHX85q46sFJGw6RBrqoVSHwAJAT4e14KJwzoey';
const sig = 'spsig1cdLkp1RLgUHAp13aRFkZ6MQDPp7xCnjAExGL3MBSdMDmT6JgQSX8cufyDgJRM3sinFtiCzLbsyP6d365EHoNevxhT47nx'
const isValid = verifySignature(message, pk, sig);
console.log(isValid);
// output: true
```
### Utility functions
**Conversion between hexadecimal and ASCII strings**
```ts
import { char2Bytes, bytes2Char } from '@taquito/utils';
const url = 'https://storage.googleapis.com/tzip-16/fa2-views.json';
const hex = '68747470733a2f2f73746f726167652e676f6f676c65617069732e636f6d2f747a69702d31362f6661322d76696577732e6a736f6e';
console.log(char2Bytes(url));
// output: 68747470733a2f2f73746f726167652e676f6f676c65617069732e636f6d2f747a69702d31362f6661322d76696577732e6a736f6e
console.log(bytes2Char(hex));
// output: https://storage.googleapis.com/tzip-16/fa2-views.json
```
**Conversion between buffer and hexadecimal strings**
```ts
import { buf2hex, hex2buf } from '@taquito/utils';
const buffer = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
const hex = '627566666572'
console.log(buf2hex(buffer));
// output: 627566666572
console.log(hex2buf(hex));
// output: Uint8Array(6) [ 98, 117, 102, 102, 101, 114 ]
```
**Merge 2 buffers together**
```ts
import { mergebuf } from '@taquito/utils';
const buff = new Uint8Array([1,2]);
const buff2 = new Uint8Array([3,4]);
console.log(mergebuf(buff, buff2));
// output: Uint8Array(4) [ 1, 2, 3, 4 ]
```
**Base58 encode a key hash according to its prefix**
```ts
import { encodeKeyHash } from '@taquito/utils';
console.log(encodeKeyHash('01106d79a502c4135b10e61e92f4c5a72ca740fb87'));
// output: tz29p6csejX9FcHXgQERr5sXsAinLvxmVerM
```
**Base58 encode a public key according to its prefix**
```ts
import { encodeKey } from '@taquito/utils';
console.log(encodeKey('0060842d4ba23a9940ef5dcf4404fdaa430cfaaccb5029fad06cb5ea894e4562ae'));
// output: edpkuNjKKT48xBoT5asPrWdmuM1Yw8D93MwgFgVvtca8jb5pstzaCh
```
**Base58 encode an address using a predefined prefix**
```ts
import { encodePubKey } from '@taquito/utils';
console.log(encodePubKey('0000e96b9f8b19af9c7ffa0c0480e1977b295850961f'));
// output: tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM
console.log(encodePubKey('01f9b689a478253793bd92357c5e08e5ebcd8db47600'));
// output: KT1XM8VUFBiM9AC5czWU15fEeE9nmuEYWt3Y
```
**Base58 decode a string with a predefined prefix**
```ts
import { b58decode } from '@taquito/utils';
console.log(b58decode('tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM'));
// output: 0000e96b9f8b19af9c7ffa0c0480e1977b295850961f
```
**Base58 decode a string and remove the prefix from it**
```ts
import { b58cdecode, prefix, Prefix } from '@taquito/utils';
console.log(b58cdecode('tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM', prefix[Prefix.TZ1]));
// output: <Buffer e9 6b 9f 8b 19 af 9c 7f fa 0c 04 80 e1 97 7b 29 58 50 96 1f>
```
**Base58 encode a string or a Uint8Array and append a prefix to it**
```ts
import { b58cencode } from '@taquito/utils';
console.log(b58cdecode('e96b9f8b19af9c7ffa0c0480e1977b295850961f', prefix[Prefix.TZ1]));
// output: tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM
```
**Return the operation hash of a signed operation**
```ts
import { encodeOpHash } from '@taquito/utils';
const opBytesSigned = '0f185d8a30061e8134c162dbb7a6c3ab8f5fdb153363ccd6149b49a33481156a6c00b2e19a9e74440d86c59f13dab8a18ff873e889eaa304ab05da13000001f1585a7384f36e45fb43dc37e8ce172bced3e05700ff0000000002002110c033f3a990c2e46a3d6054ecc2f74072aae7a34b5ac4d9ce9edc11c2410a97695682108951786f05b361da03b97245dc9897e1955e08b5b8d9e153b0bdeb0d';
console.log(encodeOpHash(opBytesSigned));
// output: opapqvVXmebRTCFd2GQFydr4tJj3V5QocQuTmuhbatcHm4Seo2t
```
**Generate expression hash**
Hash a string using the BLAKE2b algorithm, base58 encode the hash obtained and append the prefix 'expr' to it.
```ts
import { encodeExpr } from '@taquito/utils';
console.log(encodeExpr('050a000000160000b2e19a9e74440d86c59f13dab8a18ff873e889ea'));
// output: exprv6UsC1sN3Fk2XfgcJCL8NCerP5rCGy1PRESZAqr7L2JdzX55EN
```
**Obtain the public key hash given a public key**
```ts
import { getPkhfromPk } from '@taquito/utils';
const publicKey = 'sppk7czKu6So3zDWjhBPBv9wgCrBAfbEFoKYzEaKUsjhNr5Ug6E4Sn1';
console.log(getPkhfromPk(publicKey));
// output: 'tz2Gsf1Q857wUzkNGzHsJNC98z881UutMwjg
```
## Additional info
See the top-level [https://github.com/ecadlabs/taquito](https://github.com/ecadlabs/taquito) file for details on reporting issues, contributing, and versioning.
## Disclaimer
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

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