@super-protocol/sdk-js 0.12.7-beta.1 → 0.12.7-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/crypto/nodejs/ECIES.js +11 -13
- package/package.json +1 -3
|
@@ -75,27 +75,25 @@ var ECIES = /** @class */ (function () {
|
|
|
75
75
|
};
|
|
76
76
|
ECIES.decrypt = function (encryption) {
|
|
77
77
|
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
-
var
|
|
78
|
+
var iv, epk, ct, mac, ecdh, pk, hash, cipherKey, macKey, m, decipher, pt, result;
|
|
79
79
|
return __generator(this, function (_a) {
|
|
80
80
|
if (!encryption.key)
|
|
81
81
|
throw Error("Decryption key is not provided");
|
|
82
|
-
|
|
83
|
-
iv: Buffer.from(encryption.iv, encryption.encoding),
|
|
84
|
-
epk: Buffer.from(encryption.ephemPublicKey, encryption.encoding),
|
|
85
|
-
ct: Buffer.from(encryption.ciphertext, encryption.encoding),
|
|
86
|
-
mac: Buffer.from(encryption.mac, encryption.encoding),
|
|
87
|
-
};
|
|
82
|
+
iv = Buffer.from(encryption.iv, encryption.encoding), epk = Buffer.from(encryption.ephemPublicKey, encryption.encoding), ct = Buffer.from(encryption.ciphertext, encryption.encoding), mac = Buffer.from(encryption.mac, encryption.encoding);
|
|
88
83
|
ecdh = crypto_1.default.createECDH("secp256k1");
|
|
89
84
|
ecdh.setPrivateKey(Buffer.from(encryption.key, encryption.encoding));
|
|
90
|
-
pk = ecdh.computeSecret(
|
|
85
|
+
pk = ecdh.computeSecret(epk);
|
|
91
86
|
hash = crypto_1.default.createHash("sha512").update(pk).digest();
|
|
92
87
|
cipherKey = hash.slice(0, 32), macKey = hash.slice(32);
|
|
93
|
-
m = crypto_1.default
|
|
94
|
-
|
|
95
|
-
|
|
88
|
+
m = crypto_1.default
|
|
89
|
+
.createHmac("sha256", macKey)
|
|
90
|
+
.update(Buffer.concat([iv, epk, ct]))
|
|
91
|
+
.digest();
|
|
92
|
+
if (m.compare(mac) !== 0 || mac.compare(m) !== 0) {
|
|
93
|
+
throw new Error("Corrupted Ecies body: unmatched authentication code");
|
|
96
94
|
}
|
|
97
|
-
decipher = crypto_1.default.createDecipheriv("aes-256-cbc", cipherKey,
|
|
98
|
-
pt = decipher.update(
|
|
95
|
+
decipher = crypto_1.default.createDecipheriv("aes-256-cbc", cipherKey, iv);
|
|
96
|
+
pt = decipher.update(ct);
|
|
99
97
|
result = Buffer.concat([pt, decipher.final()]);
|
|
100
98
|
return [2 /*return*/, result.toString("binary")];
|
|
101
99
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@super-protocol/sdk-js",
|
|
3
|
-
"version": "0.12.7-beta.
|
|
3
|
+
"version": "0.12.7-beta.2",
|
|
4
4
|
"main": "build/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -31,7 +31,6 @@
|
|
|
31
31
|
"dto:generate": "cd ./dto/src && protoc --plugin=../../node_modules/.bin/protoc-gen-ts_proto --ts_proto_opt=esModuleInterop=true --ts_proto_opt=unrecognizedEnum=false --ts_proto_out=../../src/proto ./*"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@types/eccrypto": "^1.1.3",
|
|
35
34
|
"@types/jest": "^27.0.3",
|
|
36
35
|
"@types/lodash": "^4.14.176",
|
|
37
36
|
"@types/node": "^17.0.0",
|
|
@@ -56,7 +55,6 @@
|
|
|
56
55
|
"@super-protocol/dto-js": "0.0.24",
|
|
57
56
|
"@super-protocol/tee-lib": "^0.1.2",
|
|
58
57
|
"@super-protocol/uplink-nodejs": "1.2.12",
|
|
59
|
-
"eccrypto": "^1.1.6",
|
|
60
58
|
"ethers": "^5.5.3",
|
|
61
59
|
"hybrid-crypto-js": "^0.2.4",
|
|
62
60
|
"lodash": "^4.17.21",
|