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

@liskhq/lisk-cryptography

Package Overview
Dependencies
Maintainers
3
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@liskhq/lisk-cryptography - npm Package Compare versions

Comparing version 2.5.0 to 3.0.0

dist-node/legacy_address.d.ts

1

dist-node/buffer.d.ts

@@ -5,5 +5,4 @@ /// <reference types="node" />

export declare const intToBuffer: (value: string | number, byteLength: number, endianness?: string, signed?: boolean) => Buffer;
export declare const bufferToIntAsString: (buffer: Buffer) => string;
export declare const bufferToHex: (buffer: Buffer) => string;
export declare const hexToBuffer: (hex: string, argumentName?: string) => Buffer;
export declare const stringToBuffer: (str: string) => Buffer;

@@ -49,12 +49,10 @@ "use strict";

};
exports.bufferToIntAsString = (buffer) => buffer.length <= MAX_NUMBER_BYTE_LENGTH
? buffer.readIntBE(0, buffer.length).toString()
: buffer.readBigUInt64BE().toString();
exports.bufferToHex = (buffer) => Buffer.from(buffer).toString('hex');
const hexRegex = /^[0-9a-f]+/i;
exports.hexToBuffer = (hex, argumentName = 'Argument') => {
var _a;
if (typeof hex !== 'string') {
throw new TypeError(`${argumentName} must be a string.`);
}
const matchedHex = (hex.match(hexRegex) || [])[0];
const matchedHex = ((_a = hex.match(hexRegex)) !== null && _a !== void 0 ? _a : [])[0];
if (!matchedHex || matchedHex.length !== hex.length) {

@@ -61,0 +59,0 @@ throw new TypeError(`${argumentName} must be a valid hex string.`);

export declare const SIGNED_MESSAGE_PREFIX = "Lisk Signed Message:\n";
export declare const BINARY_ADDRESS_LENGTH = 20;
export declare const DEFAULT_BASE32_ADDRESS_PREFIX = "lsk";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SIGNED_MESSAGE_PREFIX = 'Lisk Signed Message:\n';
exports.BINARY_ADDRESS_LENGTH = 20;
exports.DEFAULT_BASE32_ADDRESS_PREFIX = 'lsk';
//# sourceMappingURL=constants.js.map
/// <reference types="node" />
import * as ed2curve from 'ed2curve';
import { EncryptedPassphraseObject } from './encrypt';
export declare const convertUIntArray: (uintArray: number[], fromBits: number, toBits: number) => number[];
export declare const convertUInt5ToBase32: (uint5Array: number[]) => string;
export declare const getFirstEightBytesReversed: (input: string | Buffer) => Buffer;
export declare const toAddress: (buffer: Buffer) => string;
export declare const getAddressFromPublicKey: (publicKey: string) => string;
export declare const convertPublicKeyEd2Curve: typeof ed2curve.convertPublicKey;

@@ -8,0 +8,0 @@ export declare const convertPrivateKeyEd2Curve: typeof ed2curve.convertSecretKey;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const reverse = require("buffer-reverse");
const ed2curve = require("ed2curve");
const querystring = require("querystring");
const buffer_1 = require("./buffer");
const hash_1 = require("./hash");
const reverse = require("buffer-reverse");
const CHARSET = 'zxvcpmbn3465o978uyrtkqew2adsjhfg';
exports.convertUIntArray = (uintArray, fromBits, toBits) => {
const maxValue = (1 << toBits) - 1;
let accumulator = 0;
let bits = 0;
const result = [];
for (let p = 0; p < uintArray.length; p += 1) {
const byte = uintArray[p];
if (byte < 0 || byte >> fromBits !== 0) {
return [];
}
accumulator = (accumulator << fromBits) | byte;
bits += fromBits;
while (bits >= toBits) {
bits -= toBits;
result.push((accumulator >> bits) & maxValue);
}
}
return result;
};
exports.convertUInt5ToBase32 = (uint5Array) => uint5Array.map((val) => CHARSET[val]).join('');
exports.getFirstEightBytesReversed = (input) => {

@@ -15,17 +34,2 @@ const BUFFER_SIZE = 8;

};
exports.toAddress = (buffer) => {
const BUFFER_SIZE = 8;
if (!Buffer.from(buffer)
.slice(0, BUFFER_SIZE)
.equals(buffer)) {
throw new Error('The buffer for Lisk addresses must not have more than 8 bytes');
}
return `${buffer_1.bufferToIntAsString(buffer)}L`;
};
exports.getAddressFromPublicKey = (publicKey) => {
const publicKeyHash = hash_1.hash(publicKey, 'hex');
const publicKeyTransform = exports.getFirstEightBytesReversed(publicKeyHash);
const address = exports.toAddress(publicKeyTransform);
return address;
};
exports.convertPublicKeyEd2Curve = ed2curve.convertPublicKey;

@@ -32,0 +36,0 @@ exports.convertPrivateKeyEd2Curve = ed2curve.convertSecretKey;

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

/// <reference types="node" />
export interface EncryptedMessageWithNonce {

@@ -5,5 +6,6 @@ readonly encryptedMessage: string;

}
export declare const encryptMessageWithPassphrase: (message: string, passphrase: string, recipientPublicKey: string) => EncryptedMessageWithNonce;
export declare const decryptMessageWithPassphrase: (cipherHex: string, nonce: string, passphrase: string, senderPublicKey: string) => string;
export declare const encryptMessageWithPassphrase: (message: string, passphrase: string, recipientPublicKey: Buffer) => EncryptedMessageWithNonce;
export declare const decryptMessageWithPassphrase: (cipherHex: string, nonce: string, passphrase: string, senderPublicKey: Buffer) => string;
export interface EncryptedPassphraseObject {
readonly [key: string]: string | number | undefined;
readonly cipherText: string;

@@ -15,5 +17,4 @@ readonly iterations?: number;

readonly version: string;
readonly [key: string]: string | number | undefined;
}
export declare const encryptPassphraseWithPassword: (plainText: string, password: string, iterations?: number) => EncryptedPassphraseObject;
export declare const decryptPassphraseWithPassword: (encryptedPassphrase: EncryptedPassphraseObject, password: string) => string;

@@ -13,9 +13,8 @@ "use strict";

exports.encryptMessageWithPassphrase = (message, passphrase, recipientPublicKey) => {
const { privateKeyBytes: senderPrivateKeyBytes, } = keys_1.getPrivateAndPublicKeyBytesFromPassphrase(passphrase);
const { privateKey: senderPrivateKeyBytes } = keys_1.getPrivateAndPublicKeyFromPassphrase(passphrase);
const convertedPrivateKey = Buffer.from(convert_1.convertPrivateKeyEd2Curve(senderPrivateKeyBytes));
const recipientPublicKeyBytes = buffer_1.hexToBuffer(recipientPublicKey);
const messageInBytes = Buffer.from(message, 'utf8');
const nonceSize = 24;
const nonce = nacl_1.getRandomBytes(nonceSize);
const publicKeyUint8Array = convert_1.convertPublicKeyEd2Curve(recipientPublicKeyBytes);
const publicKeyUint8Array = convert_1.convertPublicKeyEd2Curve(recipientPublicKey);
if (publicKeyUint8Array === null) {

@@ -34,8 +33,7 @@ throw new Error('given public key is not a valid Ed25519 public key');

exports.decryptMessageWithPassphrase = (cipherHex, nonce, passphrase, senderPublicKey) => {
const { privateKeyBytes: recipientPrivateKeyBytes, } = keys_1.getPrivateAndPublicKeyBytesFromPassphrase(passphrase);
const { privateKey: recipientPrivateKeyBytes } = keys_1.getPrivateAndPublicKeyFromPassphrase(passphrase);
const convertedPrivateKey = Buffer.from(convert_1.convertPrivateKeyEd2Curve(recipientPrivateKeyBytes));
const senderPublicKeyBytes = buffer_1.hexToBuffer(senderPublicKey);
const cipherBytes = buffer_1.hexToBuffer(cipherHex);
const nonceBytes = buffer_1.hexToBuffer(nonce);
const publicKeyUint8Array = convert_1.convertPublicKeyEd2Curve(senderPublicKeyBytes);
const publicKeyUint8Array = convert_1.convertPublicKeyEd2Curve(senderPublicKey);
if (publicKeyUint8Array === null) {

@@ -50,3 +48,3 @@ throw new Error('given public key is not a valid Ed25519 public key');

catch (error) {
if (error.message.match(/bad nonce size|nonce must be a buffer of size crypto_box_NONCEBYTES/)) {
if (error.message.match(/bad nonce size|"n" must be crypto_box_NONCEBYTES bytes long/)) {
throw new Error('Expected nonce to be 24 bytes.');

@@ -86,3 +84,3 @@ }

const decryptAES256GCMWithPassword = (encryptedPassphrase, password) => {
const { iterations = PBKDF2_ITERATIONS, cipherText, iv, salt, tag, } = encryptedPassphrase;
const { iterations = PBKDF2_ITERATIONS, cipherText, iv, salt, tag } = encryptedPassphrase;
const tagBuffer = getTagBuffer(tag);

@@ -89,0 +87,0 @@ const key = getKeyFromPassword(password, buffer_1.hexToBuffer(salt, 'Salt'), iterations);

/// <reference types="node" />
export declare const hash: (data: string | Buffer, format?: string | undefined) => Buffer;
export declare const getNetworkIdentifier: (genesisBlockPayloadHash: string, communityIdentifier: string) => string;
export declare const getNetworkIdentifier: (genesisBlockID: Buffer, communityIdentifier: string) => Buffer;

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

}
throw new Error(`Unsupported data:${data} and format:${format}. Currently only Buffers or hex and utf8 strings are supported.`);
throw new Error(`Unsupported data:${data} and format:${format !== null && format !== void 0 ? format : 'undefined'}. Currently only Buffers or hex and utf8 strings are supported.`);
};
exports.getNetworkIdentifier = (genesisBlockPayloadHash, communityIdentifier) => exports.hash(genesisBlockPayloadHash + communityIdentifier, 'utf8').toString('hex');
exports.getNetworkIdentifier = (genesisBlockID, communityIdentifier) => exports.hash(Buffer.concat([genesisBlockID, Buffer.from(communityIdentifier, 'utf8')]));
//# sourceMappingURL=hash.js.map

@@ -7,2 +7,3 @@ import * as constants from './constants';

export * from './keys';
export * from './legacy_address';
export * from './sign';

@@ -9,0 +10,0 @@ export * from './hash_onion';

@@ -13,2 +13,3 @@ "use strict";

__export(require("./keys"));
__export(require("./legacy_address"));
__export(require("./sign"));

@@ -15,0 +16,0 @@ __export(require("./hash_onion"));

/// <reference types="node" />
export interface KeypairBytes {
readonly privateKeyBytes: Buffer;
readonly publicKeyBytes: Buffer;
}
export interface Keypair {
readonly privateKey: string;
readonly publicKey: string;
}
export declare const getPrivateAndPublicKeyBytesFromPassphrase: (passphrase: string) => KeypairBytes;
import { Keypair } from './types';
export declare const getPrivateAndPublicKeyFromPassphrase: (passphrase: string) => Keypair;
export declare const getKeys: (passphrase: string) => Keypair;
export declare const getAddressFromPublicKey: (publicKey: Buffer) => Buffer;
export declare const getAddressAndPublicKeyFromPassphrase: (passphrase: string) => {
readonly address: string;
readonly publicKey: string;
readonly address: Buffer;
readonly publicKey: Buffer;
};
export declare const getAddressFromPassphrase: (passphrase: string) => string;
export declare const getAddressFromPrivateKey: (privateKey: string) => string;
export declare const getAddressFromPassphrase: (passphrase: string) => Buffer;
export declare const getAddressFromPrivateKey: (privateKey: Buffer) => Buffer;
export declare const createChecksum: (uint5Array: number[]) => number[];
export declare const verifyChecksum: (integerSequence: number[]) => boolean;
export declare const getBase32AddressFromPublicKey: (publicKey: Buffer, prefix?: string) => string;
export declare const getBase32AddressFromPassphrase: (passphrase: string, prefix?: string) => string;
export declare const validateBase32Address: (address: string, prefix?: string) => boolean;
export declare const getAddressFromBase32Address: (base32Address: string, prefix?: string) => Buffer;
export declare const getBase32AddressFromAddress: (address: Buffer, prefix?: string) => string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const buffer_1 = require("./buffer");
const constants_1 = require("./constants");
const convert_1 = require("./convert");
const hash_1 = require("./hash");
const nacl_1 = require("./nacl");
exports.getPrivateAndPublicKeyBytesFromPassphrase = (passphrase) => {
exports.getPrivateAndPublicKeyFromPassphrase = (passphrase) => {
const hashed = hash_1.hash(passphrase, 'utf8');
const { publicKeyBytes, privateKeyBytes } = nacl_1.getKeyPair(hashed);
return {
privateKeyBytes,
publicKeyBytes,
};
return nacl_1.getKeyPair(hashed);
};
exports.getPrivateAndPublicKeyFromPassphrase = (passphrase) => {
const { privateKeyBytes, publicKeyBytes, } = exports.getPrivateAndPublicKeyBytesFromPassphrase(passphrase);
return {
privateKey: buffer_1.bufferToHex(privateKeyBytes),
publicKey: buffer_1.bufferToHex(publicKeyBytes),
};
exports.getKeys = exports.getPrivateAndPublicKeyFromPassphrase;
exports.getAddressFromPublicKey = (publicKey) => {
const buffer = hash_1.hash(publicKey);
const truncatedBuffer = buffer.slice(0, constants_1.BINARY_ADDRESS_LENGTH);
if (truncatedBuffer.length !== constants_1.BINARY_ADDRESS_LENGTH) {
throw new Error('The Lisk addresses must contains exactly 20 bytes');
}
return truncatedBuffer;
};
exports.getKeys = exports.getPrivateAndPublicKeyFromPassphrase;
exports.getAddressAndPublicKeyFromPassphrase = (passphrase) => {
const { publicKey } = exports.getKeys(passphrase);
const address = convert_1.getAddressFromPublicKey(publicKey);
const address = exports.getAddressFromPublicKey(publicKey);
return {

@@ -33,9 +30,75 @@ address,

const { publicKey } = exports.getKeys(passphrase);
return convert_1.getAddressFromPublicKey(publicKey);
return exports.getAddressFromPublicKey(publicKey);
};
exports.getAddressFromPrivateKey = (privateKey) => {
const publicKeyBytes = nacl_1.getPublicKey(buffer_1.hexToBuffer(privateKey));
const publicKey = buffer_1.bufferToHex(publicKeyBytes);
return convert_1.getAddressFromPublicKey(publicKey);
const publicKey = nacl_1.getPublicKey(privateKey);
return exports.getAddressFromPublicKey(publicKey);
};
const GENERATOR = [0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3];
const polymod = (uint5Array) => {
let chk = 1;
for (const value of uint5Array) {
const top = chk >> 25;
chk = ((chk & 0x1ffffff) << 5) ^ value;
for (let i = 0; i < 5; i += 1) {
if ((top >> i) & 1) {
chk ^= GENERATOR[i];
}
}
}
return chk;
};
exports.createChecksum = (uint5Array) => {
const values = uint5Array.concat([0, 0, 0, 0, 0, 0]);
const mod = polymod(values) ^ 1;
const result = [];
for (let p = 0; p < 6; p += 1) {
result.push((mod >> (5 * (5 - p))) & 31);
}
return result;
};
exports.verifyChecksum = (integerSequence) => polymod(integerSequence) === 1;
const addressToBase32 = (address) => {
const byteSequence = [];
for (const b of address) {
byteSequence.push(b);
}
const uint5Address = convert_1.convertUIntArray(byteSequence, 8, 5);
const uint5Checksum = exports.createChecksum(uint5Address);
return convert_1.convertUInt5ToBase32(uint5Address.concat(uint5Checksum));
};
exports.getBase32AddressFromPublicKey = (publicKey, prefix = constants_1.DEFAULT_BASE32_ADDRESS_PREFIX) => `${prefix}${addressToBase32(exports.getAddressFromPublicKey(publicKey))}`;
exports.getBase32AddressFromPassphrase = (passphrase, prefix = constants_1.DEFAULT_BASE32_ADDRESS_PREFIX) => {
const { publicKey } = exports.getAddressAndPublicKeyFromPassphrase(passphrase);
return exports.getBase32AddressFromPublicKey(publicKey, prefix);
};
const BASE32_ADDRESS_LENGTH = 41;
const BASE32_CHARSET = 'zxvcpmbn3465o978uyrtkqew2adsjhfg';
exports.validateBase32Address = (address, prefix = constants_1.DEFAULT_BASE32_ADDRESS_PREFIX) => {
if (address.length !== BASE32_ADDRESS_LENGTH) {
throw new Error('Address length does not match requirements. Expected 41 characters.');
}
const addressPrefix = address.substring(0, 3);
if (addressPrefix !== prefix) {
throw new Error(`Invalid prefix. Expected prefix: ${prefix}`);
}
const addressSubstringArray = address.substring(3).split('');
if (!addressSubstringArray.every(char => BASE32_CHARSET.includes(char))) {
throw new Error("Invalid character found in address. Only allow characters: 'abcdefghjkmnopqrstuvwxyz23456789'.");
}
const integerSequence = addressSubstringArray.map(char => BASE32_CHARSET.indexOf(char));
if (!exports.verifyChecksum(integerSequence)) {
throw new Error('Invalid checksum for address.');
}
return true;
};
exports.getAddressFromBase32Address = (base32Address, prefix = constants_1.DEFAULT_BASE32_ADDRESS_PREFIX) => {
exports.validateBase32Address(base32Address);
const base32AddressNoPrefixNoChecksum = base32Address.substring(prefix.length, base32Address.length - 6);
const addressArray = base32AddressNoPrefixNoChecksum.split('');
const integerSequence = addressArray.map(char => BASE32_CHARSET.indexOf(char));
const integerSequence8 = convert_1.convertUIntArray(integerSequence, 5, 8);
return Buffer.from(integerSequence8);
};
exports.getBase32AddressFromAddress = (address, prefix = constants_1.DEFAULT_BASE32_ADDRESS_PREFIX) => `${prefix}${addressToBase32(address)}`;
//# sourceMappingURL=keys.js.map

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

exports.getKeyPair = hashedSeed => {
const publicKeyBytes = Buffer.alloc(sodium.crypto_sign_PUBLICKEYBYTES);
const privateKeyBytes = Buffer.alloc(sodium.crypto_sign_SECRETKEYBYTES);
sodium.crypto_sign_seed_keypair(publicKeyBytes, privateKeyBytes, hashedSeed);
const publicKey = Buffer.alloc(sodium.crypto_sign_PUBLICKEYBYTES);
const privateKey = Buffer.alloc(sodium.crypto_sign_SECRETKEYBYTES);
sodium.crypto_sign_seed_keypair(publicKey, privateKey, hashedSeed);
return {
publicKeyBytes,
privateKeyBytes,
publicKey,
privateKey,
};

@@ -39,6 +39,5 @@ };

const publicKeyBytes = Buffer.alloc(sodium.crypto_sign_PUBLICKEYBYTES);
const privateKeyBytes = Buffer.alloc(sodium.crypto_sign_SECRETKEYBYTES);
sodium.crypto_sign_seed_keypair(publicKeyBytes, privateKeyBytes, privateKey);
sodium.crypto_sign_ed25519_sk_to_pk(publicKeyBytes, privateKey);
return publicKeyBytes;
};
//# sourceMappingURL=fast.js.map
/// <reference types="node" />
export declare const NACL_SIGN_PUBLICKEY_LENGTH = 32;
export declare const NACL_SIGN_SIGNATURE_LENGTH = 64;
export declare const box: (messageInBytes: Buffer, nonceInBytes: Buffer, convertedPublicKey: Buffer, convertedPrivateKey: Buffer) => Buffer, openBox: (cipherBytes: Buffer, nonceBytes: Buffer, convertedPublicKey: Buffer, convertedPrivateKey: Buffer) => Buffer, signDetached: (messageBytes: Buffer, privateKeyBytes: Buffer) => Buffer, verifyDetached: (messageBytes: Buffer, signatureBytes: Buffer, publicKeyBytes: Buffer) => boolean, getRandomBytes: (length: number) => Buffer, getKeyPair: (hashedSeed: Buffer) => import("..").KeypairBytes, getPublicKey: (privateKey: Buffer) => Buffer;
export declare const box: (messageInBytes: Buffer, nonceInBytes: Buffer, convertedPublicKey: Buffer, convertedPrivateKey: Buffer) => Buffer, openBox: (cipherBytes: Buffer, nonceBytes: Buffer, convertedPublicKey: Buffer, convertedPrivateKey: Buffer) => Buffer, signDetached: (messageBytes: Buffer, privateKeyBytes: Buffer) => Buffer, verifyDetached: (messageBytes: Buffer, signatureBytes: Buffer, publicKeyBytes: Buffer) => boolean, getRandomBytes: (length: number) => Buffer, getKeyPair: (hashedSeed: Buffer) => import("../types").Keypair, getPublicKey: (privateKey: Buffer) => Buffer;
/// <reference types="node" />
import { KeypairBytes } from '../keys';
import { Keypair } from '../types';
export interface NaclInterface {
box(messageInBytes: Buffer, nonceInBytes: Buffer, convertedPublicKey: Buffer, convertedPrivateKey: Buffer): Buffer;
getKeyPair(hashedSeed: Buffer): KeypairBytes;
getPublicKey(privateKey: Buffer): Buffer;
getRandomBytes(length: number): Buffer;
openBox(cipherBytes: Buffer, nonceBytes: Buffer, convertedPublicKey: Buffer, convertedPrivateKey: Buffer): Buffer;
signDetached(messageBytes: Buffer, privateKeyBytes: Buffer): Buffer;
verifyDetached(messageBytes: Buffer, signatureBytes: Buffer, publicKeyBytes: Buffer): boolean;
box: (messageInBytes: Buffer, nonceInBytes: Buffer, convertedPublicKey: Buffer, convertedPrivateKey: Buffer) => Buffer;
getKeyPair: (hashedSeed: Buffer) => Keypair;
getPublicKey: (privateKey: Buffer) => Buffer;
getRandomBytes: (length: number) => Buffer;
openBox: (cipherBytes: Buffer, nonceBytes: Buffer, convertedPublicKey: Buffer, convertedPrivateKey: Buffer) => Buffer;
signDetached: (messageBytes: Buffer, privateKeyBytes: Buffer) => Buffer;
verifyDetached: (messageBytes: Buffer, signatureBytes: Buffer, publicKeyBytes: Buffer) => boolean;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tweetnacl = require("tweetnacl");
exports.box = (messageInBytes, nonceInBytes, convertedPublicKey, convertedPrivateKey) => Buffer.from(tweetnacl.box(messageInBytes, nonceInBytes, convertedPublicKey, convertedPrivateKey));
exports.box = (messageInBytes, nonceInBytes, convertedPublicKey, convertedPrivateKey) => Buffer.from(tweetnacl.box(Uint8Array.from(messageInBytes), Uint8Array.from(nonceInBytes), Uint8Array.from(convertedPublicKey), Uint8Array.from(convertedPrivateKey)));
exports.openBox = (cipherBytes, nonceBytes, convertedPublicKey, convertedPrivateKey) => {
const originalMessage = tweetnacl.box.open(cipherBytes, nonceBytes, convertedPublicKey, convertedPrivateKey);
const originalMessage = tweetnacl.box.open(Uint8Array.from(cipherBytes), Uint8Array.from(nonceBytes), Uint8Array.from(convertedPublicKey), Uint8Array.from(convertedPrivateKey));
if (originalMessage === null) {

@@ -12,10 +12,10 @@ throw new Error('Failed to decrypt message');

};
exports.signDetached = (messageBytes, privateKeyBytes) => Buffer.from(tweetnacl.sign.detached(messageBytes, privateKeyBytes));
exports.verifyDetached = tweetnacl.sign.detached.verify;
exports.signDetached = (messageBytes, privateKeyBytes) => Buffer.from(tweetnacl.sign.detached(Uint8Array.from(messageBytes), Uint8Array.from(privateKeyBytes)));
exports.verifyDetached = (messageBytes, signatureBytes, publicKeyBytes) => tweetnacl.sign.detached.verify(Uint8Array.from(messageBytes), Uint8Array.from(signatureBytes), Uint8Array.from(publicKeyBytes));
exports.getRandomBytes = length => Buffer.from(tweetnacl.randomBytes(length));
exports.getKeyPair = hashedSeed => {
const { publicKey, secretKey } = tweetnacl.sign.keyPair.fromSeed(hashedSeed);
const { publicKey, secretKey } = tweetnacl.sign.keyPair.fromSeed(Uint8Array.from(hashedSeed));
return {
privateKeyBytes: Buffer.from(secretKey),
publicKeyBytes: Buffer.from(publicKey),
privateKey: Buffer.from(secretKey),
publicKey: Buffer.from(publicKey),
};

@@ -25,5 +25,5 @@ };

exports.getPublicKey = privateKey => {
const { publicKey } = tweetnacl.sign.keyPair.fromSeed(privateKey.slice(0, PRIVATE_KEY_LENGTH));
const { publicKey } = tweetnacl.sign.keyPair.fromSeed(Uint8Array.from(privateKey.slice(0, PRIVATE_KEY_LENGTH)));
return Buffer.from(publicKey);
};
//# sourceMappingURL=slow.js.map
/// <reference types="node" />
export interface SignedMessageWithOnePassphrase {
readonly message: string;
readonly publicKey: string;
readonly signature: string;
readonly publicKey: Buffer;
readonly signature: Buffer;
}

@@ -12,10 +12,10 @@ export declare const digestMessage: (message: string) => Buffer;

readonly message: string;
readonly publicKey: string;
readonly signature: string;
readonly publicKey: Buffer;
readonly signature: Buffer;
}
export declare const printSignedMessage: ({ message, signature, publicKey, }: SignedMessage) => string;
export declare const printSignedMessage: ({ message, signature, publicKey }: SignedMessage) => string;
export declare const signAndPrintMessage: (message: string, passphrase: string) => string;
export declare const signDataWithPrivateKey: (data: Buffer, privateKey: Buffer) => string;
export declare const signDataWithPassphrase: (data: Buffer, passphrase: string) => string;
export declare const signData: (data: Buffer, passphrase: string) => string;
export declare const verifyData: (data: Buffer, signature: string, publicKey: string) => boolean;
export declare const signDataWithPrivateKey: (data: Buffer, privateKey: Buffer) => Buffer;
export declare const signDataWithPassphrase: (data: Buffer, passphrase: string) => Buffer;
export declare const signData: (data: Buffer, passphrase: string) => Buffer;
export declare const verifyData: (data: Buffer, signature: Buffer, publicKey: Buffer) => boolean;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const varuint_bitcoin_1 = require("varuint-bitcoin");
const buffer_1 = require("./buffer");
const constants_1 = require("./constants");

@@ -30,8 +29,8 @@ const hash_1 = require("./hash");

const msgBytes = exports.digestMessage(message);
const { privateKeyBytes, publicKeyBytes, } = keys_1.getPrivateAndPublicKeyBytesFromPassphrase(passphrase);
const signature = nacl_1.signDetached(msgBytes, privateKeyBytes);
const { privateKey, publicKey } = keys_1.getPrivateAndPublicKeyFromPassphrase(passphrase);
const signature = nacl_1.signDetached(msgBytes, privateKey);
return {
message,
publicKey: buffer_1.bufferToHex(publicKeyBytes),
signature: buffer_1.bufferToHex(signature),
publicKey,
signature,
};

@@ -41,13 +40,11 @@ };

const msgBytes = exports.digestMessage(message);
const signatureBytes = buffer_1.hexToBuffer(signature);
const publicKeyBytes = buffer_1.hexToBuffer(publicKey);
if (publicKeyBytes.length !== nacl_1.NACL_SIGN_PUBLICKEY_LENGTH) {
throw new Error(`Invalid publicKey, expected ${nacl_1.NACL_SIGN_PUBLICKEY_LENGTH}-byte publicKey`);
if (publicKey.length !== nacl_1.NACL_SIGN_PUBLICKEY_LENGTH) {
throw new Error(`Invalid publicKey, expected ${nacl_1.NACL_SIGN_PUBLICKEY_LENGTH.toString()}-byte publicKey`);
}
if (signatureBytes.length !== nacl_1.NACL_SIGN_SIGNATURE_LENGTH) {
throw new Error(`Invalid signature length, expected ${nacl_1.NACL_SIGN_SIGNATURE_LENGTH}-byte signature`);
if (signature.length !== nacl_1.NACL_SIGN_SIGNATURE_LENGTH) {
throw new Error(`Invalid signature length, expected ${nacl_1.NACL_SIGN_SIGNATURE_LENGTH.toString()}-byte signature`);
}
return nacl_1.verifyDetached(msgBytes, signatureBytes, publicKeyBytes);
return nacl_1.verifyDetached(msgBytes, signature, publicKey);
};
exports.printSignedMessage = ({ message, signature, publicKey, }) => [
exports.printSignedMessage = ({ message, signature, publicKey }) => [
signedMessageHeader,

@@ -57,5 +54,5 @@ messageHeader,

publicKeyHeader,
publicKey,
publicKey.toString('hex'),
signatureHeader,
signature,
signature.toString('hex'),
signatureFooter,

@@ -69,12 +66,9 @@ ]

};
exports.signDataWithPrivateKey = (data, privateKey) => {
const signature = nacl_1.signDetached(data, privateKey);
return buffer_1.bufferToHex(signature);
};
exports.signDataWithPrivateKey = (data, privateKey) => nacl_1.signDetached(data, privateKey);
exports.signDataWithPassphrase = (data, passphrase) => {
const { privateKeyBytes } = keys_1.getPrivateAndPublicKeyBytesFromPassphrase(passphrase);
return exports.signDataWithPrivateKey(data, privateKeyBytes);
const { privateKey } = keys_1.getPrivateAndPublicKeyFromPassphrase(passphrase);
return exports.signDataWithPrivateKey(data, privateKey);
};
exports.signData = exports.signDataWithPassphrase;
exports.verifyData = (data, signature, publicKey) => nacl_1.verifyDetached(data, buffer_1.hexToBuffer(signature), buffer_1.hexToBuffer(publicKey));
exports.verifyData = (data, signature, publicKey) => nacl_1.verifyDetached(data, signature, publicKey);
//# sourceMappingURL=sign.js.map
{
"name": "@liskhq/lisk-cryptography",
"version": "2.5.0",
"version": "3.0.0",
"description": "General cryptographic functions for use with Lisk-related software",

@@ -27,5 +27,7 @@ "author": "Lisk Foundation <admin@lisk.io>, lightcurve GmbH <admin@lightcurve.io>",

"format": "prettier --write '**/*'",
"lint": "tslint --format verbose --project .",
"lint:fix": "npm run lint -- --fix",
"lint": "eslint --ext .js,.ts .",
"lint:fix": "eslint --fix --ext .js,.ts .",
"test": "jest",
"test:coverage": "jest --coverage=true --coverage-reporters=text",
"test:ci": "jest --coverage=true --coverage-reporters=json --verbose",
"test:watch": "npm test -- --watch",

@@ -44,21 +46,27 @@ "prebuild": "rm -r dist-node/* || mkdir dist-node || true",

"optionalDependencies": {
"sodium-native": "2.4.6"
"sodium-native": "3.2.0"
},
"devDependencies": {
"@types/ed2curve": "0.2.2",
"@types/jest": "25.1.3",
"@types/jest-when": "2.7.0",
"@types/jest": "26.0.13",
"@types/jest-when": "2.7.1",
"@types/node": "12.12.11",
"@typescript-eslint/eslint-plugin": "3.10.1",
"@typescript-eslint/parser": "3.10.1",
"benchmark": "2.1.4",
"jest": "25.1.0",
"eslint": "7.8.1",
"eslint-config-lisk-base": "1.2.2",
"eslint-config-prettier": "6.11.0",
"eslint-plugin-import": "2.22.0",
"eslint-plugin-jest": "24.0.0",
"jest": "26.4.2",
"jest-extended": "0.11.5",
"jest-when": "2.7.0",
"prettier": "1.19.1",
"source-map-support": "0.5.16",
"jest-when": "2.7.2",
"prettier": "2.0.5",
"source-map-support": "0.5.19",
"ts-jest": "26.3.0",
"ts-node": "8.6.2",
"tsconfig-paths": "3.9.0",
"tslint": "6.0.0",
"tslint-immutable": "6.0.1",
"typescript": "3.8.3"
}
}

@@ -38,3 +38,3 @@ # @liskhq/lisk-cryptography

Copyright 2016-2019 Lisk Foundation
Copyright 2016-2020 Lisk Foundation

@@ -41,0 +41,0 @@ Licensed under the Apache License, Version 2.0 (the "License");

{
"extends": "../../tsconfig",
"compilerOptions": {
"declaration": true,
"outDir": "dist-node",

@@ -6,0 +5,0 @@ "typeRoots": ["../../node_modules/@types", "./types", "node_modules/@types"]

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

// tslint:disable only-arrow-functions variable-name
declare module 'sodium-native' {

@@ -21,7 +20,3 @@ export const crypto_box_MACBYTES: number;

): boolean;
export function crypto_sign_detached(
signature: Buffer,
message: Buffer,
secretKey: Buffer,
): void;
export function crypto_sign_detached(signature: Buffer, message: Buffer, secretKey: Buffer): void;
export function crypto_sign_verify_detached(

@@ -33,2 +28,3 @@ signature: Buffer,

export function randombytes_buf(buffer: Buffer): void;
export function crypto_sign_ed25519_sk_to_pk(publicKey: Buffer, privateKey: Buffer): void;
export function crypto_sign_seed_keypair(

@@ -35,0 +31,0 @@ publicKey: Buffer,

@@ -1,4 +0,3 @@

// tslint:disable only-arrow-functions
declare module 'varuint-bitcoin' {
export function encode(num: number, buffer?: Buffer, offset?: number): Buffer;
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc