@arcblock/mcrypto
Advanced tools
Comparing version 0.38.4 to 0.38.5
@@ -1,5 +0,5 @@ | ||
const { toHex, toUint8Array, toBase58, toBuffer } = require('@arcblock/forge-util'); | ||
const { toHex, toUint8Array, toBase58, toBase64, toBuffer } = require('@arcblock/forge-util'); | ||
module.exports = function encode(data, encoding = 'hex') { | ||
if (encoding === 'hex') { | ||
if (['hex', 'base16'].includes(encoding)) { | ||
return toHex(data); | ||
@@ -9,16 +9,15 @@ } | ||
if (encoding === 'base58') { | ||
return toBase58(data, true); | ||
return toBase58(data); | ||
} | ||
// TODO: support this | ||
// if (encoding === 'base64') { | ||
// return toBase64(data); | ||
// } | ||
if (encoding === 'base64') { | ||
return toBase64(data); | ||
} | ||
if (encoding === 'Uint8Array') { | ||
return toUint8Array(data, true); | ||
return toUint8Array(data); | ||
} | ||
if (encoding === 'buffer') { | ||
return toBuffer(data, true); | ||
return toBuffer(data); | ||
} | ||
@@ -25,0 +24,0 @@ |
@@ -26,3 +26,3 @@ const sha3 = require('js-sha3'); | ||
try { | ||
input = toUint8Array(data, true); | ||
input = toUint8Array(data); | ||
} catch (err) { | ||
@@ -29,0 +29,0 @@ // Do nothing |
@@ -23,19 +23,19 @@ /* eslint-disable global-require */ | ||
const hashFn = (input, round) => { | ||
let inputBytes = input; | ||
try { | ||
inputBytes = toUint8Array(input); | ||
} catch (err) { | ||
// Do nothing | ||
} | ||
if (round === 1) { | ||
return `0x${hasher() | ||
.update(input) | ||
.update(inputBytes) | ||
.digest('hex')}`; | ||
} | ||
return hashFn(hashFn(input, 1), round - 1); | ||
return hashFn(hashFn(inputBytes, 1), round - 1); | ||
}; | ||
this[name] = (data, round = 2, encoding = 'hex') => { | ||
let input = data; | ||
try { | ||
input = toUint8Array(data, true); | ||
} catch (err) { | ||
// Do nothing | ||
} | ||
const res = hashFn(input, round); | ||
const res = hashFn(data, round); | ||
return encode(res, encoding); | ||
@@ -42,0 +42,0 @@ }; |
@@ -26,3 +26,3 @@ const sha3 = require('js-sha3'); | ||
try { | ||
input = toUint8Array(data, true); | ||
input = toUint8Array(data); | ||
} catch (err) { | ||
@@ -29,0 +29,0 @@ // Do nothing |
@@ -65,4 +65,4 @@ /* eslint-disable class-methods-use-this */ | ||
sign(message, sk, encoding = 'hex') { | ||
const skBytes = toUint8Array(sk, true); | ||
const messageBytes = toUint8Array(message, true); | ||
const skBytes = toUint8Array(sk); | ||
const messageBytes = toUint8Array(message); | ||
const signature = ed25519.detached(messageBytes, skBytes); | ||
@@ -81,5 +81,5 @@ return encode(signature, encoding); | ||
verify(message, signature, pk) { | ||
const pkBytes = toUint8Array(pk, true); | ||
const messageBytes = toUint8Array(message, true); | ||
const signatureBytes = toUint8Array(signature, true); | ||
const pkBytes = toUint8Array(pk); | ||
const messageBytes = toUint8Array(message); | ||
const signatureBytes = toUint8Array(signature); | ||
return ed25519.detached.verify(messageBytes, signatureBytes, pkBytes); | ||
@@ -86,0 +86,0 @@ } |
@@ -83,3 +83,3 @@ /* eslint-disable class-methods-use-this */ | ||
try { | ||
msg = toUint8Array(message, true); | ||
msg = toUint8Array(message); | ||
} catch (err) { | ||
@@ -107,3 +107,3 @@ // Do nothing; | ||
try { | ||
msg = toUint8Array(message, true); | ||
msg = toUint8Array(message); | ||
} catch (err) { | ||
@@ -110,0 +110,0 @@ // Do nothing; |
{ | ||
"name": "@arcblock/mcrypto", | ||
"version": "0.38.4", | ||
"version": "0.38.5", | ||
"description": "Crypto lib that provides signer,crypter,hasher interface", | ||
@@ -48,3 +48,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@arcblock/forge-util": "^0.38.4", | ||
"@arcblock/forge-util": "^0.38.5", | ||
"bn.js": "4.11.8", | ||
@@ -59,3 +59,3 @@ "crypto-js": "^3.1.9-1", | ||
}, | ||
"gitHead": "d9e6b54cbe74e3d682598f491e43f551d9e8c84d" | ||
"gitHead": "3cff060ab51b6868d77d95969f6a91db9cc57414" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27114
799
Updated@arcblock/forge-util@^0.38.5