@metamask/eth-sig-util
Advanced tools
Comparing version 7.0.1 to 7.0.2
@@ -27,4 +27,4 @@ "use strict"; | ||
exports.getEncryptionPublicKey = exports.decryptSafely = exports.decrypt = exports.encryptSafely = exports.encrypt = void 0; | ||
const base_1 = require("@scure/base"); | ||
const nacl = __importStar(require("tweetnacl")); | ||
const naclUtil = __importStar(require("tweetnacl-util")); | ||
const utils_1 = require("./utils"); | ||
@@ -60,3 +60,3 @@ /** | ||
try { | ||
pubKeyUInt8Array = naclUtil.decodeBase64(publicKey); | ||
pubKeyUInt8Array = base_1.base64.decode(publicKey); | ||
} | ||
@@ -66,3 +66,3 @@ catch (err) { | ||
} | ||
const msgParamsUInt8Array = naclUtil.decodeUTF8(data); | ||
const msgParamsUInt8Array = base_1.utf8.decode(data); | ||
const nonce = nacl.randomBytes(nacl.box.nonceLength); | ||
@@ -74,5 +74,5 @@ // encrypt | ||
version: 'x25519-xsalsa20-poly1305', | ||
nonce: naclUtil.encodeBase64(nonce), | ||
ephemPublicKey: naclUtil.encodeBase64(ephemeralKeyPair.publicKey), | ||
ciphertext: naclUtil.encodeBase64(encryptedMessage), | ||
nonce: base_1.base64.encode(nonce), | ||
ephemPublicKey: base_1.base64.encode(ephemeralKeyPair.publicKey), | ||
ciphertext: base_1.base64.encode(encryptedMessage), | ||
}; | ||
@@ -151,9 +151,8 @@ // return encrypted msg data | ||
case 'x25519-xsalsa20-poly1305': { | ||
// string to buffer to UInt8Array | ||
const receiverPrivateKeyUint8Array = naclDecodeHex(privateKey); | ||
const receiverPrivateKeyUint8Array = Buffer.from(privateKey, 'hex'); | ||
const receiverEncryptionPrivateKey = nacl.box.keyPair.fromSecretKey(receiverPrivateKeyUint8Array).secretKey; | ||
// assemble decryption parameters | ||
const nonce = naclUtil.decodeBase64(encryptedData.nonce); | ||
const ciphertext = naclUtil.decodeBase64(encryptedData.ciphertext); | ||
const ephemPublicKey = naclUtil.decodeBase64(encryptedData.ephemPublicKey); | ||
const nonce = base_1.base64.decode(encryptedData.nonce); | ||
const ciphertext = base_1.base64.decode(encryptedData.ciphertext); | ||
const ephemPublicKey = base_1.base64.decode(encryptedData.ephemPublicKey); | ||
// decrypt | ||
@@ -166,3 +165,3 @@ const decryptedMessage = nacl.box.open(ciphertext, nonce, ephemPublicKey, receiverEncryptionPrivateKey); | ||
} | ||
const output = naclUtil.encodeUTF8(decryptedMessage); | ||
const output = base_1.utf8.encode(decryptedMessage); | ||
// TODO: This is probably extraneous but was kept to minimize changes during refactor | ||
@@ -212,17 +211,7 @@ if (!output) { | ||
function getEncryptionPublicKey(privateKey) { | ||
const privateKeyUint8Array = naclDecodeHex(privateKey); | ||
const privateKeyUint8Array = Buffer.from(privateKey, 'hex'); | ||
const encryptionPublicKey = nacl.box.keyPair.fromSecretKey(privateKeyUint8Array).publicKey; | ||
return naclUtil.encodeBase64(encryptionPublicKey); | ||
return base_1.base64.encode(encryptionPublicKey); | ||
} | ||
exports.getEncryptionPublicKey = getEncryptionPublicKey; | ||
/** | ||
* Convert a hex string to the UInt8Array format used by nacl. | ||
* | ||
* @param msgHex - The string to convert. | ||
* @returns The converted string. | ||
*/ | ||
function naclDecodeHex(msgHex) { | ||
const msgBase64 = Buffer.from(msgHex, 'hex').toString('base64'); | ||
return naclUtil.decodeBase64(msgBase64); | ||
} | ||
//# sourceMappingURL=encryption.js.map |
{ | ||
"name": "@metamask/eth-sig-util", | ||
"version": "7.0.1", | ||
"version": "7.0.2", | ||
"description": "A few useful functions for signing ethereum data", | ||
@@ -50,5 +50,5 @@ "keywords": [ | ||
"@metamask/utils": "^8.1.0", | ||
"@scure/base": "~1.1.3", | ||
"ethereum-cryptography": "^2.1.2", | ||
"tweetnacl": "^1.0.3", | ||
"tweetnacl-util": "^0.15.1" | ||
"tweetnacl": "^1.0.3" | ||
}, | ||
@@ -55,0 +55,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
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
133129
1461
+ Added@scure/base@~1.1.3
- Removedtweetnacl-util@^0.15.1
- Removedtweetnacl-util@0.15.1(transitive)