@liskhq/lisk-cryptography
Advanced tools
Comparing version 3.0.2 to 3.1.0
/// <reference types="node" /> | ||
export declare const BIG_ENDIAN = "big"; | ||
export declare const LITTLE_ENDIAN = "little"; | ||
export declare const intToBuffer: (value: string | number, byteLength: number, endianness?: string, signed?: boolean) => Buffer; | ||
export declare const intToBuffer: (value: number | string, byteLength: number, endianness?: string, signed?: boolean) => Buffer; | ||
export declare const bufferToHex: (buffer: Buffer) => string; | ||
export declare const hexToBuffer: (hex: string, argumentName?: string) => Buffer; | ||
export declare const stringToBuffer: (str: string) => Buffer; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.stringToBuffer = exports.hexToBuffer = exports.bufferToHex = exports.intToBuffer = exports.LITTLE_ENDIAN = exports.BIG_ENDIAN = void 0; | ||
exports.BIG_ENDIAN = 'big'; | ||
exports.LITTLE_ENDIAN = 'little'; | ||
const MAX_NUMBER_BYTE_LENGTH = 6; | ||
exports.intToBuffer = (value, byteLength, endianness = exports.BIG_ENDIAN, signed = false) => { | ||
const intToBuffer = (value, byteLength, endianness = exports.BIG_ENDIAN, signed = false) => { | ||
if (![exports.BIG_ENDIAN, exports.LITTLE_ENDIAN].includes(endianness)) { | ||
@@ -49,5 +50,7 @@ throw new Error(`Endianness must be either ${exports.BIG_ENDIAN} or ${exports.LITTLE_ENDIAN}`); | ||
}; | ||
exports.bufferToHex = (buffer) => Buffer.from(buffer).toString('hex'); | ||
exports.intToBuffer = intToBuffer; | ||
const bufferToHex = (buffer) => Buffer.from(buffer).toString('hex'); | ||
exports.bufferToHex = bufferToHex; | ||
const hexRegex = /^[0-9a-f]+/i; | ||
exports.hexToBuffer = (hex, argumentName = 'Argument') => { | ||
const hexToBuffer = (hex, argumentName = 'Argument') => { | ||
var _a; | ||
@@ -66,3 +69,5 @@ if (typeof hex !== 'string') { | ||
}; | ||
exports.stringToBuffer = (str) => Buffer.from(str, 'utf8'); | ||
exports.hexToBuffer = hexToBuffer; | ||
const stringToBuffer = (str) => Buffer.from(str, 'utf8'); | ||
exports.stringToBuffer = stringToBuffer; | ||
//# sourceMappingURL=buffer.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DEFAULT_BASE32_ADDRESS_PREFIX = exports.DEFAULT_LISK32_ADDRESS_PREFIX = exports.BINARY_ADDRESS_LENGTH = exports.SIGNED_MESSAGE_PREFIX = void 0; | ||
exports.SIGNED_MESSAGE_PREFIX = 'Lisk Signed Message:\n'; | ||
@@ -4,0 +5,0 @@ exports.BINARY_ADDRESS_LENGTH = 20; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseEncryptedPassphrase = exports.stringifyEncryptedPassphrase = exports.convertPrivateKeyEd2Curve = exports.convertPublicKeyEd2Curve = exports.getFirstEightBytesReversed = exports.convertUInt5ToBase32 = exports.convertUIntArray = void 0; | ||
const ed2curve = require("ed2curve"); | ||
@@ -7,3 +8,3 @@ const querystring = require("querystring"); | ||
const CHARSET = 'zxvcpmbn3465o978uyrtkqew2adsjhfg'; | ||
exports.convertUIntArray = (uintArray, fromBits, toBits) => { | ||
const convertUIntArray = (uintArray, fromBits, toBits) => { | ||
const maxValue = (1 << toBits) - 1; | ||
@@ -27,4 +28,6 @@ let accumulator = 0; | ||
}; | ||
exports.convertUInt5ToBase32 = (uint5Array) => uint5Array.map((val) => CHARSET[val]).join(''); | ||
exports.getFirstEightBytesReversed = (input) => { | ||
exports.convertUIntArray = convertUIntArray; | ||
const convertUInt5ToBase32 = (uint5Array) => uint5Array.map((val) => CHARSET[val]).join(''); | ||
exports.convertUInt5ToBase32 = convertUInt5ToBase32; | ||
const getFirstEightBytesReversed = (input) => { | ||
const BUFFER_SIZE = 8; | ||
@@ -36,5 +39,6 @@ if (typeof input === 'string') { | ||
}; | ||
exports.getFirstEightBytesReversed = getFirstEightBytesReversed; | ||
exports.convertPublicKeyEd2Curve = ed2curve.convertPublicKey; | ||
exports.convertPrivateKeyEd2Curve = ed2curve.convertSecretKey; | ||
exports.stringifyEncryptedPassphrase = (encryptedPassphrase) => { | ||
const stringifyEncryptedPassphrase = (encryptedPassphrase) => { | ||
if (typeof encryptedPassphrase !== 'object' || encryptedPassphrase === null) { | ||
@@ -54,2 +58,3 @@ throw new Error('Encrypted passphrase to stringify must be an object.'); | ||
}; | ||
exports.stringifyEncryptedPassphrase = stringifyEncryptedPassphrase; | ||
const parseIterations = (iterationsString) => { | ||
@@ -62,3 +67,3 @@ const iterations = iterationsString === undefined ? undefined : parseInt(iterationsString, 10); | ||
}; | ||
exports.parseEncryptedPassphrase = (encryptedPassphrase) => { | ||
const parseEncryptedPassphrase = (encryptedPassphrase) => { | ||
if (typeof encryptedPassphrase !== 'string') { | ||
@@ -86,2 +91,3 @@ throw new Error('Encrypted passphrase to parse must be a string.'); | ||
}; | ||
exports.parseEncryptedPassphrase = parseEncryptedPassphrase; | ||
//# sourceMappingURL=convert.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.decryptPassphraseWithPassword = exports.encryptPassphraseWithPassword = exports.decryptMessageWithPassphrase = exports.encryptMessageWithPassphrase = void 0; | ||
const crypto = require("crypto"); | ||
@@ -12,3 +13,3 @@ const buffer_1 = require("./buffer"); | ||
const ENCRYPTION_VERSION = '1'; | ||
exports.encryptMessageWithPassphrase = (message, passphrase, recipientPublicKey) => { | ||
const encryptMessageWithPassphrase = (message, passphrase, recipientPublicKey) => { | ||
const { privateKey: senderPrivateKeyBytes } = keys_1.getPrivateAndPublicKeyFromPassphrase(passphrase); | ||
@@ -32,3 +33,4 @@ const convertedPrivateKey = Buffer.from(convert_1.convertPrivateKeyEd2Curve(senderPrivateKeyBytes)); | ||
}; | ||
exports.decryptMessageWithPassphrase = (cipherHex, nonce, passphrase, senderPublicKey) => { | ||
exports.encryptMessageWithPassphrase = encryptMessageWithPassphrase; | ||
const decryptMessageWithPassphrase = (cipherHex, nonce, passphrase, senderPublicKey) => { | ||
const { privateKey: recipientPrivateKeyBytes } = keys_1.getPrivateAndPublicKeyFromPassphrase(passphrase); | ||
@@ -54,2 +56,3 @@ const convertedPrivateKey = Buffer.from(convert_1.convertPrivateKeyEd2Curve(recipientPrivateKeyBytes)); | ||
}; | ||
exports.decryptMessageWithPassphrase = decryptMessageWithPassphrase; | ||
const getKeyFromPassword = (password, salt, iterations) => crypto.pbkdf2Sync(password, salt, iterations, PBKDF2_KEYLEN, PBKDF2_HASH_FUNCTION); | ||
@@ -56,0 +59,0 @@ const encryptAES256GCMWithPassword = (plainText, password, iterations = PBKDF2_ITERATIONS) => { |
/// <reference types="node" /> | ||
export declare const generateHashOnionSeed: () => Buffer; | ||
export declare const hashOnion: (seed: Buffer, count?: number, distance?: number) => readonly Buffer[]; | ||
export declare const hashOnion: (seed: Buffer, count?: number, distance?: number) => ReadonlyArray<Buffer>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.hashOnion = exports.generateHashOnionSeed = void 0; | ||
const hash_1 = require("./hash"); | ||
@@ -9,4 +10,5 @@ const nacl_1 = require("./nacl"); | ||
const defaultDistance = 1000; | ||
exports.generateHashOnionSeed = () => hash_1.hash(nacl_1.getRandomBytes(INPUT_SIZE)).slice(0, HASH_SIZE); | ||
exports.hashOnion = (seed, count = defaultCount, distance = defaultDistance) => { | ||
const generateHashOnionSeed = () => hash_1.hash(nacl_1.getRandomBytes(INPUT_SIZE)).slice(0, HASH_SIZE); | ||
exports.generateHashOnionSeed = generateHashOnionSeed; | ||
const hashOnion = (seed, count = defaultCount, distance = defaultDistance) => { | ||
if (count < distance) { | ||
@@ -29,2 +31,3 @@ throw new Error('Invalid count or distance. Count must be greater than distance'); | ||
}; | ||
exports.hashOnion = hashOnion; | ||
//# sourceMappingURL=hash_onion.js.map |
/// <reference types="node" /> | ||
export declare const hash: (data: string | Buffer, format?: string | undefined) => Buffer; | ||
export declare const hash: (data: Buffer | string, format?: string | undefined) => Buffer; | ||
export declare const getNetworkIdentifier: (genesisBlockID: Buffer, communityIdentifier: string) => Buffer; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getNetworkIdentifier = exports.hash = void 0; | ||
const crypto = require("crypto"); | ||
@@ -10,3 +11,3 @@ const buffer_1 = require("./buffer"); | ||
}; | ||
exports.hash = (data, format) => { | ||
const hash = (data, format) => { | ||
if (Buffer.isBuffer(data)) { | ||
@@ -24,3 +25,5 @@ return cryptoHashSha256(data); | ||
}; | ||
exports.getNetworkIdentifier = (genesisBlockID, communityIdentifier) => exports.hash(Buffer.concat([genesisBlockID, Buffer.from(communityIdentifier, 'utf8')])); | ||
exports.hash = hash; | ||
const getNetworkIdentifier = (genesisBlockID, communityIdentifier) => exports.hash(Buffer.concat([genesisBlockID, Buffer.from(communityIdentifier, 'utf8')])); | ||
exports.getNetworkIdentifier = getNetworkIdentifier; | ||
//# sourceMappingURL=hash.js.map |
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.constants = exports.getRandomBytes = void 0; | ||
const constants = require("./constants"); | ||
exports.constants = constants; | ||
__export(require("./buffer")); | ||
__export(require("./convert")); | ||
__export(require("./encrypt")); | ||
__export(require("./hash")); | ||
__export(require("./keys")); | ||
__export(require("./legacy_address")); | ||
__export(require("./sign")); | ||
__export(require("./hash_onion")); | ||
__exportStar(require("./buffer"), exports); | ||
__exportStar(require("./convert"), exports); | ||
__exportStar(require("./encrypt"), exports); | ||
__exportStar(require("./hash"), exports); | ||
__exportStar(require("./keys"), exports); | ||
__exportStar(require("./legacy_address"), exports); | ||
__exportStar(require("./sign"), exports); | ||
__exportStar(require("./hash_onion"), exports); | ||
var nacl_1 = require("./nacl"); | ||
exports.getRandomBytes = nacl_1.getRandomBytes; | ||
Object.defineProperty(exports, "getRandomBytes", { enumerable: true, get: function () { return nacl_1.getRandomBytes; } }); | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getBase32AddressFromAddress = exports.getLisk32AddressFromAddress = exports.getAddressFromBase32Address = exports.getAddressFromLisk32Address = exports.validateBase32Address = exports.validateLisk32Address = exports.getBase32AddressFromPassphrase = exports.getLisk32AddressFromPassphrase = exports.getBase32AddressFromPublicKey = exports.getLisk32AddressFromPublicKey = exports.verifyChecksum = exports.createChecksum = exports.getAddressFromPrivateKey = exports.getAddressFromPassphrase = exports.getAddressAndPublicKeyFromPassphrase = exports.getAddressFromPublicKey = exports.getKeys = exports.getPrivateAndPublicKeyFromPassphrase = void 0; | ||
const constants_1 = require("./constants"); | ||
@@ -7,8 +8,9 @@ const convert_1 = require("./convert"); | ||
const nacl_1 = require("./nacl"); | ||
exports.getPrivateAndPublicKeyFromPassphrase = (passphrase) => { | ||
const getPrivateAndPublicKeyFromPassphrase = (passphrase) => { | ||
const hashed = hash_1.hash(passphrase, 'utf8'); | ||
return nacl_1.getKeyPair(hashed); | ||
}; | ||
exports.getPrivateAndPublicKeyFromPassphrase = getPrivateAndPublicKeyFromPassphrase; | ||
exports.getKeys = exports.getPrivateAndPublicKeyFromPassphrase; | ||
exports.getAddressFromPublicKey = (publicKey) => { | ||
const getAddressFromPublicKey = (publicKey) => { | ||
const buffer = hash_1.hash(publicKey); | ||
@@ -21,3 +23,4 @@ const truncatedBuffer = buffer.slice(0, constants_1.BINARY_ADDRESS_LENGTH); | ||
}; | ||
exports.getAddressAndPublicKeyFromPassphrase = (passphrase) => { | ||
exports.getAddressFromPublicKey = getAddressFromPublicKey; | ||
const getAddressAndPublicKeyFromPassphrase = (passphrase) => { | ||
const { publicKey } = exports.getKeys(passphrase); | ||
@@ -30,10 +33,13 @@ const address = exports.getAddressFromPublicKey(publicKey); | ||
}; | ||
exports.getAddressFromPassphrase = (passphrase) => { | ||
exports.getAddressAndPublicKeyFromPassphrase = getAddressAndPublicKeyFromPassphrase; | ||
const getAddressFromPassphrase = (passphrase) => { | ||
const { publicKey } = exports.getKeys(passphrase); | ||
return exports.getAddressFromPublicKey(publicKey); | ||
}; | ||
exports.getAddressFromPrivateKey = (privateKey) => { | ||
exports.getAddressFromPassphrase = getAddressFromPassphrase; | ||
const getAddressFromPrivateKey = (privateKey) => { | ||
const publicKey = nacl_1.getPublicKey(privateKey); | ||
return exports.getAddressFromPublicKey(publicKey); | ||
}; | ||
exports.getAddressFromPrivateKey = getAddressFromPrivateKey; | ||
const GENERATOR = [0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3]; | ||
@@ -53,3 +59,3 @@ const polymod = (uint5Array) => { | ||
}; | ||
exports.createChecksum = (uint5Array) => { | ||
const createChecksum = (uint5Array) => { | ||
const values = uint5Array.concat([0, 0, 0, 0, 0, 0]); | ||
@@ -63,3 +69,5 @@ const mod = polymod(values) ^ 1; | ||
}; | ||
exports.verifyChecksum = (integerSequence) => polymod(integerSequence) === 1; | ||
exports.createChecksum = createChecksum; | ||
const verifyChecksum = (integerSequence) => polymod(integerSequence) === 1; | ||
exports.verifyChecksum = verifyChecksum; | ||
const addressToLisk32 = (address) => { | ||
@@ -74,12 +82,14 @@ const byteSequence = []; | ||
}; | ||
exports.getLisk32AddressFromPublicKey = (publicKey, prefix = constants_1.DEFAULT_LISK32_ADDRESS_PREFIX) => `${prefix}${addressToLisk32(exports.getAddressFromPublicKey(publicKey))}`; | ||
const getLisk32AddressFromPublicKey = (publicKey, prefix = constants_1.DEFAULT_LISK32_ADDRESS_PREFIX) => `${prefix}${addressToLisk32(exports.getAddressFromPublicKey(publicKey))}`; | ||
exports.getLisk32AddressFromPublicKey = getLisk32AddressFromPublicKey; | ||
exports.getBase32AddressFromPublicKey = exports.getLisk32AddressFromPublicKey; | ||
exports.getLisk32AddressFromPassphrase = (passphrase, prefix = constants_1.DEFAULT_LISK32_ADDRESS_PREFIX) => { | ||
const getLisk32AddressFromPassphrase = (passphrase, prefix = constants_1.DEFAULT_LISK32_ADDRESS_PREFIX) => { | ||
const { publicKey } = exports.getAddressAndPublicKeyFromPassphrase(passphrase); | ||
return exports.getLisk32AddressFromPublicKey(publicKey, prefix); | ||
}; | ||
exports.getLisk32AddressFromPassphrase = getLisk32AddressFromPassphrase; | ||
exports.getBase32AddressFromPassphrase = exports.getLisk32AddressFromPassphrase; | ||
const LISK32_ADDRESS_LENGTH = 41; | ||
const LISK32_CHARSET = 'zxvcpmbn3465o978uyrtkqew2adsjhfg'; | ||
exports.validateLisk32Address = (address, prefix = constants_1.DEFAULT_LISK32_ADDRESS_PREFIX) => { | ||
const validateLisk32Address = (address, prefix = constants_1.DEFAULT_LISK32_ADDRESS_PREFIX) => { | ||
if (address.length !== LISK32_ADDRESS_LENGTH) { | ||
@@ -102,4 +112,5 @@ throw new Error('Address length does not match requirements. Expected 41 characters.'); | ||
}; | ||
exports.validateLisk32Address = validateLisk32Address; | ||
exports.validateBase32Address = exports.validateLisk32Address; | ||
exports.getAddressFromLisk32Address = (base32Address, prefix = constants_1.DEFAULT_LISK32_ADDRESS_PREFIX) => { | ||
const getAddressFromLisk32Address = (base32Address, prefix = constants_1.DEFAULT_LISK32_ADDRESS_PREFIX) => { | ||
exports.validateLisk32Address(base32Address, prefix); | ||
@@ -112,5 +123,7 @@ const base32AddressNoPrefixNoChecksum = base32Address.substring(prefix.length, base32Address.length - 6); | ||
}; | ||
exports.getAddressFromLisk32Address = getAddressFromLisk32Address; | ||
exports.getAddressFromBase32Address = exports.getAddressFromLisk32Address; | ||
exports.getLisk32AddressFromAddress = (address, prefix = constants_1.DEFAULT_LISK32_ADDRESS_PREFIX) => `${prefix}${addressToLisk32(address)}`; | ||
const getLisk32AddressFromAddress = (address, prefix = constants_1.DEFAULT_LISK32_ADDRESS_PREFIX) => `${prefix}${addressToLisk32(address)}`; | ||
exports.getLisk32AddressFromAddress = getLisk32AddressFromAddress; | ||
exports.getBase32AddressFromAddress = exports.getLisk32AddressFromAddress; | ||
//# sourceMappingURL=keys.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getLegacyAddressFromPrivateKey = exports.getLegacyAddressFromPassphrase = exports.getLegacyAddressAndPublicKeyFromPassphrase = exports.getLegacyAddressFromPublicKey = void 0; | ||
const hash_1 = require("./hash"); | ||
@@ -7,3 +8,3 @@ const keys_1 = require("./keys"); | ||
const nacl_1 = require("./nacl"); | ||
exports.getLegacyAddressFromPublicKey = (publicKey) => { | ||
const getLegacyAddressFromPublicKey = (publicKey) => { | ||
const publicKeyHash = hash_1.hash(publicKey); | ||
@@ -13,3 +14,4 @@ const publicKeyTransform = convert_1.getFirstEightBytesReversed(publicKeyHash); | ||
}; | ||
exports.getLegacyAddressAndPublicKeyFromPassphrase = (passphrase) => { | ||
exports.getLegacyAddressFromPublicKey = getLegacyAddressFromPublicKey; | ||
const getLegacyAddressAndPublicKeyFromPassphrase = (passphrase) => { | ||
const { publicKey } = keys_1.getKeys(passphrase); | ||
@@ -22,10 +24,13 @@ const address = exports.getLegacyAddressFromPublicKey(publicKey); | ||
}; | ||
exports.getLegacyAddressFromPassphrase = (passphrase) => { | ||
exports.getLegacyAddressAndPublicKeyFromPassphrase = getLegacyAddressAndPublicKeyFromPassphrase; | ||
const getLegacyAddressFromPassphrase = (passphrase) => { | ||
const { publicKey } = keys_1.getKeys(passphrase); | ||
return exports.getLegacyAddressFromPublicKey(publicKey); | ||
}; | ||
exports.getLegacyAddressFromPrivateKey = (privateKey) => { | ||
exports.getLegacyAddressFromPassphrase = getLegacyAddressFromPassphrase; | ||
const getLegacyAddressFromPrivateKey = (privateKey) => { | ||
const publicKey = nacl_1.getPublicKey(privateKey); | ||
return exports.getLegacyAddressFromPublicKey(publicKey); | ||
}; | ||
exports.getLegacyAddressFromPrivateKey = getLegacyAddressFromPrivateKey; | ||
//# sourceMappingURL=legacy_address.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getPublicKey = exports.getKeyPair = exports.getRandomBytes = exports.verifyDetached = exports.signDetached = exports.openBox = exports.box = void 0; | ||
const sodium = require("sodium-native"); | ||
exports.box = (messageInBytes, nonceInBytes, convertedPublicKey, convertedPrivateKey) => { | ||
const box = (messageInBytes, nonceInBytes, convertedPublicKey, convertedPrivateKey) => { | ||
const cipherBytes = Buffer.alloc(messageInBytes.length + sodium.crypto_box_MACBYTES); | ||
@@ -9,3 +10,4 @@ sodium.crypto_box_easy(cipherBytes, messageInBytes, nonceInBytes, convertedPublicKey, convertedPrivateKey); | ||
}; | ||
exports.openBox = (cipherBytes, nonceBytes, convertedPublicKey, convertedPrivateKey) => { | ||
exports.box = box; | ||
const openBox = (cipherBytes, nonceBytes, convertedPublicKey, convertedPrivateKey) => { | ||
const plainText = Buffer.alloc(cipherBytes.length - sodium.crypto_box_MACBYTES); | ||
@@ -17,3 +19,4 @@ if (!sodium.crypto_box_open_easy(plainText, cipherBytes, nonceBytes, convertedPublicKey, convertedPrivateKey)) { | ||
}; | ||
exports.signDetached = (messageBytes, privateKeyBytes) => { | ||
exports.openBox = openBox; | ||
const signDetached = (messageBytes, privateKeyBytes) => { | ||
const signatureBytes = Buffer.alloc(sodium.crypto_sign_BYTES); | ||
@@ -23,4 +26,6 @@ sodium.crypto_sign_detached(signatureBytes, messageBytes, privateKeyBytes); | ||
}; | ||
exports.verifyDetached = (messageBytes, signatureBytes, publicKeyBytes) => sodium.crypto_sign_verify_detached(signatureBytes, messageBytes, publicKeyBytes); | ||
exports.getRandomBytes = length => { | ||
exports.signDetached = signDetached; | ||
const verifyDetached = (messageBytes, signatureBytes, publicKeyBytes) => sodium.crypto_sign_verify_detached(signatureBytes, messageBytes, publicKeyBytes); | ||
exports.verifyDetached = verifyDetached; | ||
const getRandomBytes = length => { | ||
const nonce = Buffer.alloc(length); | ||
@@ -30,3 +35,4 @@ sodium.randombytes_buf(nonce); | ||
}; | ||
exports.getKeyPair = hashedSeed => { | ||
exports.getRandomBytes = getRandomBytes; | ||
const getKeyPair = hashedSeed => { | ||
const publicKey = Buffer.alloc(sodium.crypto_sign_PUBLICKEYBYTES); | ||
@@ -40,3 +46,4 @@ const privateKey = Buffer.alloc(sodium.crypto_sign_SECRETKEYBYTES); | ||
}; | ||
exports.getPublicKey = privateKey => { | ||
exports.getKeyPair = getKeyPair; | ||
const getPublicKey = privateKey => { | ||
const publicKeyBytes = Buffer.alloc(sodium.crypto_sign_PUBLICKEYBYTES); | ||
@@ -46,2 +53,3 @@ sodium.crypto_sign_ed25519_sk_to_pk(publicKeyBytes, privateKey); | ||
}; | ||
exports.getPublicKey = getPublicKey; | ||
//# sourceMappingURL=fast.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getPublicKey = exports.getKeyPair = exports.getRandomBytes = exports.verifyDetached = exports.signDetached = exports.openBox = exports.box = exports.NACL_SIGN_SIGNATURE_LENGTH = exports.NACL_SIGN_PUBLICKEY_LENGTH = void 0; | ||
let lib = require('./slow'); | ||
@@ -4,0 +5,0 @@ try { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getPublicKey = exports.getKeyPair = exports.getRandomBytes = exports.verifyDetached = exports.signDetached = exports.openBox = exports.box = void 0; | ||
const tweetnacl = require("tweetnacl"); | ||
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 box = (messageInBytes, nonceInBytes, convertedPublicKey, convertedPrivateKey) => Buffer.from(tweetnacl.box(Uint8Array.from(messageInBytes), Uint8Array.from(nonceInBytes), Uint8Array.from(convertedPublicKey), Uint8Array.from(convertedPrivateKey))); | ||
exports.box = box; | ||
const openBox = (cipherBytes, nonceBytes, convertedPublicKey, convertedPrivateKey) => { | ||
const originalMessage = tweetnacl.box.open(Uint8Array.from(cipherBytes), Uint8Array.from(nonceBytes), Uint8Array.from(convertedPublicKey), Uint8Array.from(convertedPrivateKey)); | ||
@@ -12,6 +14,10 @@ if (originalMessage === null) { | ||
}; | ||
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 => { | ||
exports.openBox = openBox; | ||
const signDetached = (messageBytes, privateKeyBytes) => Buffer.from(tweetnacl.sign.detached(Uint8Array.from(messageBytes), Uint8Array.from(privateKeyBytes))); | ||
exports.signDetached = signDetached; | ||
const verifyDetached = (messageBytes, signatureBytes, publicKeyBytes) => tweetnacl.sign.detached.verify(Uint8Array.from(messageBytes), Uint8Array.from(signatureBytes), Uint8Array.from(publicKeyBytes)); | ||
exports.verifyDetached = verifyDetached; | ||
const getRandomBytes = length => Buffer.from(tweetnacl.randomBytes(length)); | ||
exports.getRandomBytes = getRandomBytes; | ||
const getKeyPair = hashedSeed => { | ||
const { publicKey, secretKey } = tweetnacl.sign.keyPair.fromSeed(Uint8Array.from(hashedSeed)); | ||
@@ -23,7 +29,9 @@ return { | ||
}; | ||
exports.getKeyPair = getKeyPair; | ||
const PRIVATE_KEY_LENGTH = 32; | ||
exports.getPublicKey = privateKey => { | ||
const getPublicKey = privateKey => { | ||
const { publicKey } = tweetnacl.sign.keyPair.fromSeed(Uint8Array.from(privateKey.slice(0, PRIVATE_KEY_LENGTH))); | ||
return Buffer.from(publicKey); | ||
}; | ||
exports.getPublicKey = getPublicKey; | ||
//# sourceMappingURL=slow.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.verifyData = exports.signData = exports.signDataWithPassphrase = exports.signDataWithPrivateKey = exports.signAndPrintMessage = exports.printSignedMessage = exports.verifyMessageWithPublicKey = exports.signMessageWithPassphrase = exports.digestMessage = void 0; | ||
const varuint_bitcoin_1 = require("varuint-bitcoin"); | ||
@@ -16,3 +17,3 @@ const constants_1 = require("./constants"); | ||
const SIGNED_MESSAGE_PREFIX_LENGTH = varuint_bitcoin_1.encode(constants_1.SIGNED_MESSAGE_PREFIX.length); | ||
exports.digestMessage = (message) => { | ||
const digestMessage = (message) => { | ||
const msgBytes = Buffer.from(message, 'utf8'); | ||
@@ -28,3 +29,4 @@ const msgLenBytes = varuint_bitcoin_1.encode(message.length); | ||
}; | ||
exports.signMessageWithPassphrase = (message, passphrase) => { | ||
exports.digestMessage = digestMessage; | ||
const signMessageWithPassphrase = (message, passphrase) => { | ||
const msgBytes = exports.digestMessage(message); | ||
@@ -39,3 +41,4 @@ const { privateKey, publicKey } = keys_1.getPrivateAndPublicKeyFromPassphrase(passphrase); | ||
}; | ||
exports.verifyMessageWithPublicKey = ({ message, publicKey, signature, }) => { | ||
exports.signMessageWithPassphrase = signMessageWithPassphrase; | ||
const verifyMessageWithPublicKey = ({ message, publicKey, signature, }) => { | ||
const msgBytes = exports.digestMessage(message); | ||
@@ -50,3 +53,4 @@ if (publicKey.length !== nacl_1.NACL_SIGN_PUBLICKEY_LENGTH) { | ||
}; | ||
exports.printSignedMessage = ({ message, signature, publicKey }) => [ | ||
exports.verifyMessageWithPublicKey = verifyMessageWithPublicKey; | ||
const printSignedMessage = ({ message, signature, publicKey }) => [ | ||
signedMessageHeader, | ||
@@ -63,13 +67,18 @@ messageHeader, | ||
.join('\n'); | ||
exports.signAndPrintMessage = (message, passphrase) => { | ||
exports.printSignedMessage = printSignedMessage; | ||
const signAndPrintMessage = (message, passphrase) => { | ||
const signedMessage = exports.signMessageWithPassphrase(message, passphrase); | ||
return exports.printSignedMessage(signedMessage); | ||
}; | ||
exports.signDataWithPrivateKey = (data, privateKey) => nacl_1.signDetached(data, privateKey); | ||
exports.signDataWithPassphrase = (data, passphrase) => { | ||
exports.signAndPrintMessage = signAndPrintMessage; | ||
const signDataWithPrivateKey = (data, privateKey) => nacl_1.signDetached(data, privateKey); | ||
exports.signDataWithPrivateKey = signDataWithPrivateKey; | ||
const signDataWithPassphrase = (data, passphrase) => { | ||
const { privateKey } = keys_1.getPrivateAndPublicKeyFromPassphrase(passphrase); | ||
return exports.signDataWithPrivateKey(data, privateKey); | ||
}; | ||
exports.signDataWithPassphrase = signDataWithPassphrase; | ||
exports.signData = exports.signDataWithPassphrase; | ||
exports.verifyData = (data, signature, publicKey) => nacl_1.verifyDetached(data, signature, publicKey); | ||
const verifyData = (data, signature, publicKey) => nacl_1.verifyDetached(data, signature, publicKey); | ||
exports.verifyData = verifyData; | ||
//# sourceMappingURL=sign.js.map |
{ | ||
"name": "@liskhq/lisk-cryptography", | ||
"version": "3.0.2", | ||
"version": "3.1.0", | ||
"description": "General cryptographic functions for use with Lisk-related software", | ||
@@ -45,27 +45,26 @@ "author": "Lisk Foundation <admin@lisk.io>, lightcurve GmbH <admin@lightcurve.io>", | ||
"optionalDependencies": { | ||
"sodium-native": "3.2.0" | ||
"sodium-native": "3.2.1" | ||
}, | ||
"devDependencies": { | ||
"@types/ed2curve": "0.2.2", | ||
"@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", | ||
"@types/jest": "26.0.21", | ||
"@types/jest-when": "2.7.2", | ||
"@types/node": "12.20.6", | ||
"@typescript-eslint/eslint-plugin": "4.19.0", | ||
"@typescript-eslint/parser": "4.19.0", | ||
"benchmark": "2.1.4", | ||
"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", | ||
"eslint": "7.22.0", | ||
"eslint-config-lisk-base": "2.0.0", | ||
"eslint-plugin-import": "2.22.1", | ||
"eslint-plugin-jest": "24.3.2", | ||
"jest": "26.6.3", | ||
"jest-extended": "0.11.5", | ||
"jest-when": "2.7.2", | ||
"prettier": "2.0.5", | ||
"jest-when": "3.2.1", | ||
"prettier": "2.2.1", | ||
"source-map-support": "0.5.19", | ||
"ts-jest": "26.3.0", | ||
"ts-node": "8.6.2", | ||
"ts-jest": "26.5.4", | ||
"ts-node": "9.1.1", | ||
"tsconfig-paths": "3.9.0", | ||
"typescript": "3.8.3" | ||
"typescript": "4.2.3" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
83465
20
863