@walletconnect/iso-crypto
Advanced tools
Comparing version 1.3.2-rc.2 to 1.3.2-rc.3
@@ -1,7 +0,6 @@ | ||
/// <reference types="node" /> | ||
import { IJsonRpcRequest, IJsonRpcResponseSuccess, IJsonRpcResponseError, IEncryptionPayload } from "@walletconnect/types"; | ||
export declare function generateKey(length?: number): Promise<ArrayBuffer>; | ||
export declare function verifyHmac(payload: IEncryptionPayload, key: Buffer): Promise<boolean>; | ||
export declare function verifyHmac(payload: IEncryptionPayload, key: Uint8Array): Promise<boolean>; | ||
export declare function encrypt(data: IJsonRpcRequest | IJsonRpcResponseSuccess | IJsonRpcResponseError, key: ArrayBuffer, providedIv?: ArrayBuffer): Promise<IEncryptionPayload>; | ||
export declare function decrypt(payload: IEncryptionPayload, key: ArrayBuffer): Promise<IJsonRpcRequest | IJsonRpcResponseSuccess | IJsonRpcResponseError | null>; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const eccryptoJS = tslib_1.__importStar(require("eccrypto-js")); | ||
const isoCrypto = tslib_1.__importStar(require("@pedrouid/iso-crypto")); | ||
const encUtils = tslib_1.__importStar(require("enc-utils")); | ||
const utils_1 = require("@walletconnect/utils"); | ||
@@ -9,4 +10,4 @@ function generateKey(length) { | ||
const _length = (length || 256) / 8; | ||
const buffer = eccryptoJS.randomBytes(_length); | ||
const result = utils_1.convertBufferToArrayBuffer(buffer); | ||
const bytes = isoCrypto.randomBytes(_length); | ||
const result = utils_1.convertBufferToArrayBuffer(encUtils.arrayToBuffer(bytes)); | ||
return result; | ||
@@ -18,10 +19,10 @@ }); | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const cipherText = utils_1.convertHexToBuffer(payload.data); | ||
const iv = utils_1.convertHexToBuffer(payload.iv); | ||
const hmac = utils_1.convertHexToBuffer(payload.hmac); | ||
const hmacHex = utils_1.convertBufferToHex(hmac, true); | ||
const unsigned = utils_1.concatBuffers(cipherText, iv); | ||
const chmac = yield eccryptoJS.hmacSha256Sign(key, unsigned); | ||
const chmacHex = utils_1.convertBufferToHex(chmac, true); | ||
if (utils_1.removeHexPrefix(hmacHex) === utils_1.removeHexPrefix(chmacHex)) { | ||
const cipherText = encUtils.hexToArray(payload.data); | ||
const iv = encUtils.hexToArray(payload.iv); | ||
const hmac = encUtils.hexToArray(payload.hmac); | ||
const hmacHex = encUtils.arrayToHex(hmac, false); | ||
const unsigned = encUtils.concatArrays(cipherText, iv); | ||
const chmac = yield isoCrypto.hmacSha256Sign(key, unsigned); | ||
const chmacHex = encUtils.arrayToHex(chmac, false); | ||
if (encUtils.removeHexPrefix(hmacHex) === encUtils.removeHexPrefix(chmacHex)) { | ||
return true; | ||
@@ -35,13 +36,13 @@ } | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const _key = utils_1.convertArrayBufferToBuffer(key); | ||
const _key = encUtils.bufferToArray(utils_1.convertArrayBufferToBuffer(key)); | ||
const ivArrayBuffer = providedIv || (yield generateKey(128)); | ||
const iv = utils_1.convertArrayBufferToBuffer(ivArrayBuffer); | ||
const ivHex = utils_1.convertBufferToHex(iv, true); | ||
const iv = encUtils.bufferToArray(utils_1.convertArrayBufferToBuffer(ivArrayBuffer)); | ||
const ivHex = encUtils.arrayToHex(iv, false); | ||
const contentString = JSON.stringify(data); | ||
const content = utils_1.convertUtf8ToBuffer(contentString); | ||
const cipherText = yield eccryptoJS.aesCbcEncrypt(iv, _key, content); | ||
const cipherTextHex = utils_1.convertBufferToHex(cipherText, true); | ||
const unsigned = utils_1.concatBuffers(cipherText, iv); | ||
const hmac = yield eccryptoJS.hmacSha256Sign(_key, unsigned); | ||
const hmacHex = utils_1.convertBufferToHex(hmac, true); | ||
const content = encUtils.utf8ToArray(contentString); | ||
const cipherText = yield isoCrypto.aesCbcEncrypt(iv, _key, content); | ||
const cipherTextHex = encUtils.arrayToHex(cipherText, false); | ||
const unsigned = encUtils.concatArrays(cipherText, iv); | ||
const hmac = yield isoCrypto.hmacSha256Sign(_key, unsigned); | ||
const hmacHex = encUtils.arrayToHex(hmac, false); | ||
return { | ||
@@ -57,3 +58,3 @@ data: cipherTextHex, | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const _key = utils_1.convertArrayBufferToBuffer(key); | ||
const _key = encUtils.bufferToArray(utils_1.convertArrayBufferToBuffer(key)); | ||
if (!_key) { | ||
@@ -66,6 +67,6 @@ throw new Error("Missing key: required for decryption"); | ||
} | ||
const cipherText = utils_1.convertHexToBuffer(payload.data); | ||
const iv = utils_1.convertHexToBuffer(payload.iv); | ||
const buffer = yield eccryptoJS.aesCbcDecrypt(iv, _key, cipherText); | ||
const utf8 = utils_1.convertBufferToUtf8(buffer); | ||
const cipherText = encUtils.hexToArray(payload.data); | ||
const iv = encUtils.hexToArray(payload.iv); | ||
const buffer = yield isoCrypto.aesCbcDecrypt(iv, _key, cipherText); | ||
const utf8 = encUtils.arrayToUtf8(buffer); | ||
let data; | ||
@@ -72,0 +73,0 @@ try { |
{ | ||
"name": "@walletconnect/iso-crypto", | ||
"version": "1.3.2-rc.2", | ||
"version": "1.3.2-rc.3", | ||
"description": "Isomorphic Crypto for WalletConnect", | ||
@@ -59,7 +59,7 @@ "scripts": { | ||
"dependencies": { | ||
"@walletconnect/types": "^1.3.2-rc.2", | ||
"@walletconnect/utils": "^1.3.2-rc.2", | ||
"eccrypto-js": "5.2.0" | ||
"@pedrouid/iso-crypto": "^1.0.0", | ||
"@walletconnect/types": "^1.3.2-rc.3", | ||
"@walletconnect/utils": "^1.3.2-rc.3" | ||
}, | ||
"gitHead": "165f7993c2acc907c653c02847fb02721052c6e7" | ||
} |
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 too big to display
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
2242
776641
+ Added@pedrouid/iso-crypto@^1.0.0
+ Added@pedrouid/environment@1.0.1(transitive)
+ Added@pedrouid/iso-crypto@1.1.0(transitive)
+ Added@pedrouid/iso-random@1.2.1(transitive)
+ Addedenc-utils@3.0.0(transitive)
- Removedeccrypto-js@5.2.0
- Removedbindings@1.5.0(transitive)
- Removedbip66@1.1.5(transitive)
- Removedbn.js@4.12.0(transitive)
- Removedbrorand@1.1.0(transitive)
- Removedbrowserify-aes@1.2.0(transitive)
- Removedbuffer-xor@1.0.3(transitive)
- Removedcipher-base@1.0.4(transitive)
- Removedcreate-hash@1.2.0(transitive)
- Removedcreate-hmac@1.1.7(transitive)
- Removeddrbg.js@1.0.1(transitive)
- Removedeccrypto-js@5.2.0(transitive)
- Removedelliptic@6.5.7(transitive)
- Removedenc-utils@2.1.0(transitive)
- Removedevp_bytestokey@1.0.3(transitive)
- Removedfile-uri-to-path@1.0.0(transitive)
- Removedhash-base@3.1.0(transitive)
- Removedhmac-drbg@1.0.1(transitive)
- Removedmd5.js@1.3.5(transitive)
- Removedminimalistic-crypto-utils@1.0.1(transitive)
- Removednan@2.20.0(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedripemd160@2.0.2(transitive)
- Removedsecp256k1@3.8.0(transitive)
- Removedsha.js@2.4.11(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedutil-deprecate@1.0.2(transitive)