eth-crypto-js
Advanced tools
Comparing version 0.1.12 to 0.1.13
@@ -30,3 +30,3 @@ /// <reference types="node" /> | ||
publicKeyByPrivateKey: typeof publicKeyByPrivateKey; | ||
createIdentity: (entropy?: Buffer | undefined) => import("./createIdentity").Identity; | ||
createIdentity: (entropy?: Buffer) => import("./createIdentity").Identity; | ||
sign: typeof sign; | ||
@@ -33,0 +33,0 @@ encryptWithPublicKey: typeof encryptWithPublicKey; |
@@ -1,201 +0,2 @@ | ||
import { keccak256, concat, randomBytes, Wallet, toUtf8Bytes } from 'ethers'; | ||
import { privateToPublic, toBuffer } from 'ethereumjs-util'; | ||
import { ecdsaSign, publicKeyConvert, ecdsaRecover } from 'secp256k1'; | ||
import { encrypt, decrypt } from 'eccrypto'; | ||
const MIN_ENTROPY_SIZE = 128; | ||
function createPrivateKey(entropy) { | ||
if (entropy) { | ||
if (!Buffer.isBuffer(entropy)) { | ||
throw new Error('WallabyCrypto.createPrivateKey(): given entropy is no Buffer'); | ||
} | ||
if (Buffer.byteLength(entropy, 'utf8') < MIN_ENTROPY_SIZE) { | ||
throw new Error(`WallabyCrypto.createPrivateKey(): Entropy-size must be at least ${MIN_ENTROPY_SIZE}`); | ||
} | ||
const outerHex = keccak256(entropy); | ||
return outerHex; | ||
} | ||
const innerHex = keccak256(concat([randomBytes(32), randomBytes(32)])); | ||
const middleHex = concat([concat([randomBytes(32), innerHex]), randomBytes(32)]); | ||
const outerHex = keccak256(middleHex); | ||
return outerHex; | ||
} | ||
function addLeading0x(str) { | ||
if (!str.startsWith('0x')) | ||
return '0x' + str; | ||
return str; | ||
} | ||
/** | ||
* Generate publicKey from the privateKey with leading 0x. | ||
* @returns {string} | ||
*/ | ||
function publicKeyByPrivateKey(privateKey) { | ||
const privateKeyWithLeading0x = addLeading0x(privateKey); | ||
const publicKeyBuffer = privateToPublic(toBuffer(privateKeyWithLeading0x)); | ||
return publicKeyBuffer.toString('hex'); | ||
} | ||
const createIdentity = (entropy) => { | ||
const privateKey = createPrivateKey(entropy); | ||
const wallet = new Wallet(privateKey); | ||
const identity = { | ||
privateKey: privateKey, | ||
publicKey: publicKeyByPrivateKey(privateKey), | ||
address: wallet.address, | ||
}; | ||
return identity; | ||
}; | ||
function removeLeading0x(str) { | ||
if (str.startsWith('0x')) | ||
return str.substring(2); | ||
return str; | ||
} | ||
/** | ||
* signs the given message | ||
* we do not use sign from eth-lib because the pure secp256k1-version is 90% faster | ||
* @param {string} privateKey | ||
* @param {string} hash | ||
* @return {string} hexString | ||
*/ | ||
function sign(privateKey, hash) { | ||
hash = addLeading0x(hash); | ||
if (hash.length !== 66) | ||
throw new Error('WallabyCrypto.sign(): Can only sign hashes, given: ' + hash); | ||
const sigObj = ecdsaSign(new Uint8Array(Buffer.from(removeLeading0x(hash), 'hex')), new Uint8Array(Buffer.from(removeLeading0x(privateKey), 'hex'))); | ||
const recoveryId = sigObj.recid === 1 ? '1c' : '1b'; | ||
const newSignature = '0x' + Buffer.from(sigObj.signature).toString('hex') + recoveryId; | ||
return newSignature; | ||
} | ||
function uint8ArrayToHex(arr) { | ||
return Buffer.from(arr).toString('hex'); | ||
} | ||
function hexToUnit8Array(str) { | ||
return new Uint8Array(Buffer.from(str, 'hex')); | ||
} | ||
function decompressPublicKey(startsWith02Or03) { | ||
// if already decompressed an not has trailing 04 | ||
const testBuffer = Buffer.from(startsWith02Or03, 'hex'); | ||
if (testBuffer.length === 64) | ||
startsWith02Or03 = '04' + startsWith02Or03; | ||
let decompressed = uint8ArrayToHex(publicKeyConvert(hexToUnit8Array(startsWith02Or03), false)); | ||
// remove trailing 04 | ||
decompressed = decompressed.substring(2); | ||
return decompressed; | ||
} | ||
async function encryptWithPublicKey(publicKey, message, opts = {}) { | ||
const decompressedPublicKey = decompressPublicKey(publicKey); | ||
const pubString = `04${decompressedPublicKey}`; | ||
return encrypt(Buffer.from(pubString, 'hex'), Buffer.from(message), opts).then((encryptedBuffers) => { | ||
const encrypted = { | ||
iv: encryptedBuffers.iv.toString('hex'), | ||
ephemPublicKey: encryptedBuffers.ephemPublicKey.toString('hex'), | ||
ciphertext: encryptedBuffers.ciphertext.toString('hex'), | ||
mac: encryptedBuffers.mac.toString('hex'), | ||
}; | ||
return encrypted; | ||
}); | ||
} | ||
function cipherParser(str) { | ||
if (typeof str !== 'string') { | ||
return str; | ||
} | ||
const buf = Buffer.from(str, 'hex'); | ||
const ret = { | ||
iv: buf.toString('hex', 0, 16), | ||
ephemPublicKey: buf.toString('hex', 16, 49), | ||
mac: buf.toString('hex', 49, 81), | ||
ciphertext: buf.toString('hex', 81, buf.length), | ||
}; | ||
ret.ephemPublicKey = `04${decompressPublicKey(ret.ephemPublicKey)}`; | ||
return ret; | ||
} | ||
async function decryptWithPrivateKey(privateKey, encrypted) { | ||
encrypted = cipherParser(encrypted); | ||
// remove trailing '0x' from privateKey | ||
const twoStripped = removeLeading0x(privateKey); | ||
const encryptedBuffer = { | ||
iv: Buffer.from(encrypted.iv, 'hex'), | ||
ephemPublicKey: Buffer.from(encrypted.ephemPublicKey, 'hex'), | ||
ciphertext: Buffer.from(encrypted.ciphertext, 'hex'), | ||
mac: Buffer.from(encrypted.mac, 'hex'), | ||
}; | ||
return decrypt(Buffer.from(twoStripped, 'hex'), encryptedBuffer).then((decryptedBuffer) => decryptedBuffer.toString()); | ||
} | ||
function recoverPublicKey(signature, hash) { | ||
signature = removeLeading0x(signature); | ||
// split into v-value and sig | ||
const sigOnly = signature.substring(0, signature.length - 2); // all but last 2 chars | ||
const vValue = signature.slice(-2); // last 2 chars | ||
const recoveryNumber = vValue === '1c' ? 1 : 0; | ||
let pubKey = uint8ArrayToHex(ecdsaRecover(hexToUnit8Array(sigOnly), recoveryNumber, hexToUnit8Array(removeLeading0x(hash)), false)); | ||
// remove trailing '04' | ||
pubKey = pubKey.slice(2); | ||
return pubKey; | ||
} | ||
function solidityKeccak256(str) { | ||
const hash = keccak256(toUtf8Bytes(str)); | ||
return hash; | ||
} | ||
function compressPublicKey(startsWith04) { | ||
// add trailing 04 if not done before | ||
const testBuffer = Buffer.from(startsWith04, 'hex'); | ||
if (testBuffer.length === 64) | ||
startsWith04 = '04' + startsWith04; | ||
return uint8ArrayToHex(publicKeyConvert(hexToUnit8Array(startsWith04), true)); | ||
} | ||
function cipherStringify(cipher) { | ||
if (typeof cipher === 'string') | ||
return cipher; | ||
const compressedKey = compressPublicKey(cipher.ephemPublicKey); | ||
const ret = Buffer.concat([ | ||
Buffer.from(cipher.iv, 'hex'), // 16bit | ||
Buffer.from(compressedKey, 'hex'), // 33bit | ||
Buffer.from(cipher.mac, 'hex'), // 32bit | ||
Buffer.from(cipher.ciphertext, 'hex'), // var bit | ||
]); | ||
return ret.toString('hex'); | ||
} | ||
const hash = { | ||
keccak256: solidityKeccak256, | ||
}; | ||
const publicKey = { | ||
compress: compressPublicKey, | ||
decomporess: decompressPublicKey, | ||
}; | ||
const cipher = { | ||
parse: cipherParser, | ||
stringify: cipherStringify, | ||
}; | ||
var index = { | ||
createPrivateKey, | ||
publicKeyByPrivateKey, | ||
createIdentity, | ||
sign, | ||
encryptWithPublicKey, | ||
decryptWithPrivateKey, | ||
recoverPublicKey, | ||
keccak256: solidityKeccak256, | ||
cipherParser, | ||
cipherStringify, | ||
hash, | ||
publicKey, | ||
cipher, | ||
}; | ||
export { cipher, cipherParser, cipherStringify, createIdentity, createPrivateKey, decryptWithPrivateKey, index as default, encryptWithPublicKey, hash, solidityKeccak256 as keccak256, publicKey, publicKeyByPrivateKey, recoverPublicKey, sign }; | ||
import{keccak256 as e,concat as r,randomBytes as t,Wallet as n,toUtf8Bytes as i}from"ethers";import{privateToPublic as f,toBuffer as o}from"ethereumjs-util";import{ecdsaSign as u,publicKeyConvert as c,ecdsaRecover as h}from"secp256k1";import{encrypt as a,decrypt as m}from"eccrypto";function s(n){if(n){if(!Buffer.isBuffer(n))throw new Error("WallabyCrypto.createPrivateKey(): given entropy is no Buffer");if(Buffer.byteLength(n,"utf8")<128)throw new Error("WallabyCrypto.createPrivateKey(): Entropy-size must be at least 128");return e(n)}var i=e(r([t(32),t(32)])),f=r([r([t(32),i]),t(32)]);return e(f)}function y(e){return e.startsWith("0x")?e:"0x"+e}function p(e){var r=y(e);return f(o(r)).toString("hex")}var x=function(e){var r=s(e),t=new n(r);return{privateKey:r,publicKey:p(r),address:t.address}};function g(e){return e.startsWith("0x")?e.substring(2):e}function l(e,r){if(66!==(r=y(r)).length)throw new Error("WallabyCrypto.sign(): Can only sign hashes, given: "+r);var t=u(new Uint8Array(Buffer.from(g(r),"hex")),new Uint8Array(Buffer.from(g(e),"hex"))),n=1===t.recid?"1c":"1b";return"0x"+Buffer.from(t.signature).toString("hex")+n}function v(e){return Buffer.from(e).toString("hex")}function B(e){return new Uint8Array(Buffer.from(e,"hex"))}function b(e){return 64===Buffer.from(e,"hex").length&&(e="04"+e),v(c(B(e),!1)).substring(2)}var P=function(e,r,t){void 0===t&&(t={});try{var n=b(e);return Promise.resolve(a(Buffer.from("04"+n,"hex"),Buffer.from(r),t).then(function(e){return{iv:e.iv.toString("hex"),ephemPublicKey:e.ephemPublicKey.toString("hex"),ciphertext:e.ciphertext.toString("hex"),mac:e.mac.toString("hex")}}))}catch(e){return Promise.reject(e)}};function K(e){if("string"!=typeof e)return e;var r=Buffer.from(e,"hex"),t={iv:r.toString("hex",0,16),ephemPublicKey:r.toString("hex",16,49),mac:r.toString("hex",49,81),ciphertext:r.toString("hex",81,r.length)};return t.ephemPublicKey="04"+b(t.ephemPublicKey),t}var S=function(e,r){try{r=K(r);var t=g(e),n={iv:Buffer.from(r.iv,"hex"),ephemPublicKey:Buffer.from(r.ephemPublicKey,"hex"),ciphertext:Buffer.from(r.ciphertext,"hex"),mac:Buffer.from(r.mac,"hex")};return Promise.resolve(m(Buffer.from(t,"hex"),n).then(function(e){return e.toString()}))}catch(e){return Promise.reject(e)}};function d(e,r){var t=(e=g(e)).substring(0,e.length-2),n="1c"===e.slice(-2)?1:0;return v(h(B(t),n,B(g(r)),!1)).slice(2)}function w(r){return e(i(r))}function k(e){return 64===Buffer.from(e,"hex").length&&(e="04"+e),v(c(B(e),!0))}function W(e){if("string"==typeof e)return e;var r=k(e.ephemPublicKey);return Buffer.concat([Buffer.from(e.iv,"hex"),Buffer.from(r,"hex"),Buffer.from(e.mac,"hex"),Buffer.from(e.ciphertext,"hex")]).toString("hex")}var C={keccak256:w},E={compress:k,decomporess:b},j={parse:K,stringify:W},A={createPrivateKey:s,publicKeyByPrivateKey:p,createIdentity:x,sign:l,encryptWithPublicKey:P,decryptWithPrivateKey:S,recoverPublicKey:d,keccak256:w,cipherParser:K,cipherStringify:W,hash:C,publicKey:E,cipher:j};export{j as cipher,K as cipherParser,W as cipherStringify,x as createIdentity,s as createPrivateKey,S as decryptWithPrivateKey,A as default,P as encryptWithPublicKey,C as hash,w as keccak256,E as publicKey,p as publicKeyByPrivateKey,d as recoverPublicKey,l as sign}; | ||
//# sourceMappingURL=index.esm.js.map |
@@ -1,201 +0,2 @@ | ||
import { keccak256, concat, randomBytes, Wallet, toUtf8Bytes } from 'ethers'; | ||
import { privateToPublic, toBuffer } from 'ethereumjs-util'; | ||
import { ecdsaSign, publicKeyConvert, ecdsaRecover } from 'secp256k1'; | ||
import { encrypt, decrypt } from 'eccrypto'; | ||
const MIN_ENTROPY_SIZE = 128; | ||
function createPrivateKey(entropy) { | ||
if (entropy) { | ||
if (!Buffer.isBuffer(entropy)) { | ||
throw new Error('WallabyCrypto.createPrivateKey(): given entropy is no Buffer'); | ||
} | ||
if (Buffer.byteLength(entropy, 'utf8') < MIN_ENTROPY_SIZE) { | ||
throw new Error(`WallabyCrypto.createPrivateKey(): Entropy-size must be at least ${MIN_ENTROPY_SIZE}`); | ||
} | ||
const outerHex = keccak256(entropy); | ||
return outerHex; | ||
} | ||
const innerHex = keccak256(concat([randomBytes(32), randomBytes(32)])); | ||
const middleHex = concat([concat([randomBytes(32), innerHex]), randomBytes(32)]); | ||
const outerHex = keccak256(middleHex); | ||
return outerHex; | ||
} | ||
function addLeading0x(str) { | ||
if (!str.startsWith('0x')) | ||
return '0x' + str; | ||
return str; | ||
} | ||
/** | ||
* Generate publicKey from the privateKey with leading 0x. | ||
* @returns {string} | ||
*/ | ||
function publicKeyByPrivateKey(privateKey) { | ||
const privateKeyWithLeading0x = addLeading0x(privateKey); | ||
const publicKeyBuffer = privateToPublic(toBuffer(privateKeyWithLeading0x)); | ||
return publicKeyBuffer.toString('hex'); | ||
} | ||
const createIdentity = (entropy) => { | ||
const privateKey = createPrivateKey(entropy); | ||
const wallet = new Wallet(privateKey); | ||
const identity = { | ||
privateKey: privateKey, | ||
publicKey: publicKeyByPrivateKey(privateKey), | ||
address: wallet.address, | ||
}; | ||
return identity; | ||
}; | ||
function removeLeading0x(str) { | ||
if (str.startsWith('0x')) | ||
return str.substring(2); | ||
return str; | ||
} | ||
/** | ||
* signs the given message | ||
* we do not use sign from eth-lib because the pure secp256k1-version is 90% faster | ||
* @param {string} privateKey | ||
* @param {string} hash | ||
* @return {string} hexString | ||
*/ | ||
function sign(privateKey, hash) { | ||
hash = addLeading0x(hash); | ||
if (hash.length !== 66) | ||
throw new Error('WallabyCrypto.sign(): Can only sign hashes, given: ' + hash); | ||
const sigObj = ecdsaSign(new Uint8Array(Buffer.from(removeLeading0x(hash), 'hex')), new Uint8Array(Buffer.from(removeLeading0x(privateKey), 'hex'))); | ||
const recoveryId = sigObj.recid === 1 ? '1c' : '1b'; | ||
const newSignature = '0x' + Buffer.from(sigObj.signature).toString('hex') + recoveryId; | ||
return newSignature; | ||
} | ||
function uint8ArrayToHex(arr) { | ||
return Buffer.from(arr).toString('hex'); | ||
} | ||
function hexToUnit8Array(str) { | ||
return new Uint8Array(Buffer.from(str, 'hex')); | ||
} | ||
function decompressPublicKey(startsWith02Or03) { | ||
// if already decompressed an not has trailing 04 | ||
const testBuffer = Buffer.from(startsWith02Or03, 'hex'); | ||
if (testBuffer.length === 64) | ||
startsWith02Or03 = '04' + startsWith02Or03; | ||
let decompressed = uint8ArrayToHex(publicKeyConvert(hexToUnit8Array(startsWith02Or03), false)); | ||
// remove trailing 04 | ||
decompressed = decompressed.substring(2); | ||
return decompressed; | ||
} | ||
async function encryptWithPublicKey(publicKey, message, opts = {}) { | ||
const decompressedPublicKey = decompressPublicKey(publicKey); | ||
const pubString = `04${decompressedPublicKey}`; | ||
return encrypt(Buffer.from(pubString, 'hex'), Buffer.from(message), opts).then((encryptedBuffers) => { | ||
const encrypted = { | ||
iv: encryptedBuffers.iv.toString('hex'), | ||
ephemPublicKey: encryptedBuffers.ephemPublicKey.toString('hex'), | ||
ciphertext: encryptedBuffers.ciphertext.toString('hex'), | ||
mac: encryptedBuffers.mac.toString('hex'), | ||
}; | ||
return encrypted; | ||
}); | ||
} | ||
function cipherParser(str) { | ||
if (typeof str !== 'string') { | ||
return str; | ||
} | ||
const buf = Buffer.from(str, 'hex'); | ||
const ret = { | ||
iv: buf.toString('hex', 0, 16), | ||
ephemPublicKey: buf.toString('hex', 16, 49), | ||
mac: buf.toString('hex', 49, 81), | ||
ciphertext: buf.toString('hex', 81, buf.length), | ||
}; | ||
ret.ephemPublicKey = `04${decompressPublicKey(ret.ephemPublicKey)}`; | ||
return ret; | ||
} | ||
async function decryptWithPrivateKey(privateKey, encrypted) { | ||
encrypted = cipherParser(encrypted); | ||
// remove trailing '0x' from privateKey | ||
const twoStripped = removeLeading0x(privateKey); | ||
const encryptedBuffer = { | ||
iv: Buffer.from(encrypted.iv, 'hex'), | ||
ephemPublicKey: Buffer.from(encrypted.ephemPublicKey, 'hex'), | ||
ciphertext: Buffer.from(encrypted.ciphertext, 'hex'), | ||
mac: Buffer.from(encrypted.mac, 'hex'), | ||
}; | ||
return decrypt(Buffer.from(twoStripped, 'hex'), encryptedBuffer).then((decryptedBuffer) => decryptedBuffer.toString()); | ||
} | ||
function recoverPublicKey(signature, hash) { | ||
signature = removeLeading0x(signature); | ||
// split into v-value and sig | ||
const sigOnly = signature.substring(0, signature.length - 2); // all but last 2 chars | ||
const vValue = signature.slice(-2); // last 2 chars | ||
const recoveryNumber = vValue === '1c' ? 1 : 0; | ||
let pubKey = uint8ArrayToHex(ecdsaRecover(hexToUnit8Array(sigOnly), recoveryNumber, hexToUnit8Array(removeLeading0x(hash)), false)); | ||
// remove trailing '04' | ||
pubKey = pubKey.slice(2); | ||
return pubKey; | ||
} | ||
function solidityKeccak256(str) { | ||
const hash = keccak256(toUtf8Bytes(str)); | ||
return hash; | ||
} | ||
function compressPublicKey(startsWith04) { | ||
// add trailing 04 if not done before | ||
const testBuffer = Buffer.from(startsWith04, 'hex'); | ||
if (testBuffer.length === 64) | ||
startsWith04 = '04' + startsWith04; | ||
return uint8ArrayToHex(publicKeyConvert(hexToUnit8Array(startsWith04), true)); | ||
} | ||
function cipherStringify(cipher) { | ||
if (typeof cipher === 'string') | ||
return cipher; | ||
const compressedKey = compressPublicKey(cipher.ephemPublicKey); | ||
const ret = Buffer.concat([ | ||
Buffer.from(cipher.iv, 'hex'), // 16bit | ||
Buffer.from(compressedKey, 'hex'), // 33bit | ||
Buffer.from(cipher.mac, 'hex'), // 32bit | ||
Buffer.from(cipher.ciphertext, 'hex'), // var bit | ||
]); | ||
return ret.toString('hex'); | ||
} | ||
const hash = { | ||
keccak256: solidityKeccak256, | ||
}; | ||
const publicKey = { | ||
compress: compressPublicKey, | ||
decomporess: decompressPublicKey, | ||
}; | ||
const cipher = { | ||
parse: cipherParser, | ||
stringify: cipherStringify, | ||
}; | ||
var index = { | ||
createPrivateKey, | ||
publicKeyByPrivateKey, | ||
createIdentity, | ||
sign, | ||
encryptWithPublicKey, | ||
decryptWithPrivateKey, | ||
recoverPublicKey, | ||
keccak256: solidityKeccak256, | ||
cipherParser, | ||
cipherStringify, | ||
hash, | ||
publicKey, | ||
cipher, | ||
}; | ||
export { cipher, cipherParser, cipherStringify, createIdentity, createPrivateKey, decryptWithPrivateKey, index as default, encryptWithPublicKey, hash, solidityKeccak256 as keccak256, publicKey, publicKeyByPrivateKey, recoverPublicKey, sign }; | ||
var e=require("ethers"),r=require("ethereumjs-util"),t=require("secp256k1"),i=require("eccrypto");function n(r){if(r){if(!Buffer.isBuffer(r))throw new Error("WallabyCrypto.createPrivateKey(): given entropy is no Buffer");if(Buffer.byteLength(r,"utf8")<128)throw new Error("WallabyCrypto.createPrivateKey(): Entropy-size must be at least 128");return e.keccak256(r)}var t=e.keccak256(e.concat([e.randomBytes(32),e.randomBytes(32)])),i=e.concat([e.concat([e.randomBytes(32),t]),e.randomBytes(32)]);return e.keccak256(i)}function c(e){return e.startsWith("0x")?e:"0x"+e}function o(e){var t=c(e);return r.privateToPublic(r.toBuffer(t)).toString("hex")}var f=function(r){var t=n(r),i=new e.Wallet(t);return{privateKey:t,publicKey:o(t),address:i.address}};function u(e){return e.startsWith("0x")?e.substring(2):e}function a(e,r){if(66!==(r=c(r)).length)throw new Error("WallabyCrypto.sign(): Can only sign hashes, given: "+r);var i=t.ecdsaSign(new Uint8Array(Buffer.from(u(r),"hex")),new Uint8Array(Buffer.from(u(e),"hex"))),n=1===i.recid?"1c":"1b";return"0x"+Buffer.from(i.signature).toString("hex")+n}function h(e){return Buffer.from(e).toString("hex")}function s(e){return new Uint8Array(Buffer.from(e,"hex"))}function y(e){return 64===Buffer.from(e,"hex").length&&(e="04"+e),h(t.publicKeyConvert(s(e),!1)).substring(2)}var p=function(e,r,t){void 0===t&&(t={});try{var n=y(e);return Promise.resolve(i.encrypt(Buffer.from("04"+n,"hex"),Buffer.from(r),t).then(function(e){return{iv:e.iv.toString("hex"),ephemPublicKey:e.ephemPublicKey.toString("hex"),ciphertext:e.ciphertext.toString("hex"),mac:e.mac.toString("hex")}}))}catch(e){return Promise.reject(e)}};function x(e){if("string"!=typeof e)return e;var r=Buffer.from(e,"hex"),t={iv:r.toString("hex",0,16),ephemPublicKey:r.toString("hex",16,49),mac:r.toString("hex",49,81),ciphertext:r.toString("hex",81,r.length)};return t.ephemPublicKey="04"+y(t.ephemPublicKey),t}var m=function(e,r){try{r=x(r);var t=u(e),n={iv:Buffer.from(r.iv,"hex"),ephemPublicKey:Buffer.from(r.ephemPublicKey,"hex"),ciphertext:Buffer.from(r.ciphertext,"hex"),mac:Buffer.from(r.mac,"hex")};return Promise.resolve(i.decrypt(Buffer.from(t,"hex"),n).then(function(e){return e.toString()}))}catch(e){return Promise.reject(e)}};function l(e,r){var i=(e=u(e)).substring(0,e.length-2),n="1c"===e.slice(-2)?1:0;return h(t.ecdsaRecover(s(i),n,s(u(r)),!1)).slice(2)}function v(r){return e.keccak256(e.toUtf8Bytes(r))}function g(e){return 64===Buffer.from(e,"hex").length&&(e="04"+e),h(t.publicKeyConvert(s(e),!0))}function B(e){if("string"==typeof e)return e;var r=g(e.ephemPublicKey);return Buffer.concat([Buffer.from(e.iv,"hex"),Buffer.from(r,"hex"),Buffer.from(e.mac,"hex"),Buffer.from(e.ciphertext,"hex")]).toString("hex")}var b={keccak256:v},K={compress:g,decomporess:y},P={parse:x,stringify:B},d={createPrivateKey:n,publicKeyByPrivateKey:o,createIdentity:f,sign:a,encryptWithPublicKey:p,decryptWithPrivateKey:m,recoverPublicKey:l,keccak256:v,cipherParser:x,cipherStringify:B,hash:b,publicKey:K,cipher:P};exports.cipher=P,exports.cipherParser=x,exports.cipherStringify=B,exports.createIdentity=f,exports.createPrivateKey=n,exports.decryptWithPrivateKey=m,exports.default=d,exports.encryptWithPublicKey=p,exports.hash=b,exports.keccak256=v,exports.publicKey=K,exports.publicKeyByPrivateKey=o,exports.recoverPublicKey=l,exports.sign=a; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "eth-crypto-js", | ||
"version": "0.1.12", | ||
"version": "0.1.13", | ||
"description": "Cryptographic javascript-functions for ethereum and tutorials on how to use them together with web3js and solidity", | ||
@@ -13,18 +13,15 @@ "author": "Olivier Esuka <oesukan@gmail.com> (https://oesukam.me)", | ||
"type": "git", | ||
"url": "git+https://github.com/eth-crypto-js/eth-crypto-js.git" | ||
"url": "git+https://github.com/eth-crypto-js/cheke.git" | ||
}, | ||
"main": "./dist/index.cjs.js", | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.esm.js", | ||
"commonjs": "./dist/index.cjs.js", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.esm.js", | ||
"require": "./dist/index.cjs.js", | ||
"types": "./dist/index.d.ts" | ||
}, | ||
"./package.json": "./package.json" | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.esm.js", | ||
"require": "./dist/index.js" | ||
}, | ||
"typings": "./dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
"./dist", | ||
"./src" | ||
], | ||
@@ -53,2 +50,3 @@ "engines": { | ||
"scripts": { | ||
"rimraf": "rimraf dist", | ||
"test": "jest", | ||
@@ -59,6 +57,4 @@ "test:watch": "jest --watch", | ||
"lint:fix": "npm run lint -- --fix", | ||
"prebuild": "rimraf dist", | ||
"build": "rollup --config --sourcemap --validate --bundleConfigAsCjs", | ||
"build:prod": "npm run build --compact --environment production", | ||
"build:dev": "rollup --config --bundleConfigAsCjs --watch", | ||
"build": "npm run rimraf && microbundle", | ||
"build:dev": "microbundle watch", | ||
"coveralls": "cat ./coverage/lcov.info | coveralls", | ||
@@ -70,10 +66,10 @@ "audit-ci": "audit-ci --config audit-ci.jsonc", | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^26.0.1", | ||
"@rollup/plugin-json": "^6.1.0", | ||
"@rollup/plugin-node-resolve": "^15.2.3", | ||
"@rollup/plugin-terser": "^0.4.4", | ||
"@rollup/plugin-typescript": "^11.1.6", | ||
"@types/eccrypto": "^1.1.6", | ||
"@types/jest": "^29.5.0", | ||
"@types/secp256k1": "^4.0.6", | ||
"@babel/core": "^7.24.7", | ||
"@babel/preset-env": "^7.24.7", | ||
"@babel/preset-typescript": "^7.24.7", | ||
"@eslint/js": "^9.5.0", | ||
"@types/jest": "^29.5.12", | ||
"@types/node": "^20.14.8", | ||
"@typescript-eslint/eslint-plugin": "^6.4.0", | ||
"audit-ci": "^7.0.1", | ||
"babel-jest": "^29.7.0", | ||
@@ -90,9 +86,5 @@ "coveralls": "^3.1.1", | ||
"jest": "^29.7.0", | ||
"jest-environment-jsdom": "^29.5.0", | ||
"microbundle": "^0.15.1", | ||
"prettier": "^3.3.2", | ||
"rimraf": "^5.0.7", | ||
"rollup": "^4.18.0", | ||
"rollup-plugin-node-builtins": "^2.0.0", | ||
"rollup-plugin-node-globals": "^1.4.0", | ||
"rollup-plugin-polyfill-node": "^0.13.0", | ||
"size-limit": "^8.2.4", | ||
"ts-jest": "^29.1.5", | ||
@@ -99,0 +91,0 @@ "ts-node": "^10.9.2", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
82200
25
65
569
3