@ocap/mcrypto 1.18.50 → 1.18.52
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/lib/crypter/rsa-browserify.js +17 -34
- package/package.json +3 -3
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.RSABrowserCrypter = void 0;
|
|
13
4
|
// https://stackoverflow.com/questions/70056340/how-can-i-generate-an-rsa-pair-that-works-both-in-node-js-and-browser
|
|
@@ -19,34 +10,26 @@ const ab2str = (buffer) => String.fromCharCode.apply(null, new Uint8Array(buffer
|
|
|
19
10
|
const RSA_ALGORITHM = 'RSA-OAEP';
|
|
20
11
|
// RSA-OAEP
|
|
21
12
|
class RSABrowserCrypter {
|
|
22
|
-
genKeyPair(length = 2048) {
|
|
23
|
-
return
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}, true, ['encrypt', 'decrypt']);
|
|
30
|
-
});
|
|
13
|
+
async genKeyPair(length = 2048) {
|
|
14
|
+
return crypto.generateKey({
|
|
15
|
+
name: RSA_ALGORITHM,
|
|
16
|
+
modulusLength: length,
|
|
17
|
+
publicExponent: new Uint8Array([1, 0, 1]),
|
|
18
|
+
hash: 'SHA-256',
|
|
19
|
+
}, true, ['encrypt', 'decrypt']);
|
|
31
20
|
}
|
|
32
|
-
formatPublicKey(key) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return `-----BEGIN PUBLIC KEY-----\n${base64}\n-----END PUBLIC KEY-----`;
|
|
37
|
-
});
|
|
21
|
+
async formatPublicKey(key) {
|
|
22
|
+
const exported = await crypto.exportKey('spki', key);
|
|
23
|
+
const base64 = window.btoa(ab2str(exported));
|
|
24
|
+
return `-----BEGIN PUBLIC KEY-----\n${base64}\n-----END PUBLIC KEY-----`;
|
|
38
25
|
}
|
|
39
|
-
encrypt(message, key) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return (0, util_1.toBase58)(new Uint8Array(encrypted));
|
|
43
|
-
});
|
|
26
|
+
async encrypt(message, key) {
|
|
27
|
+
const encrypted = await crypto.encrypt({ name: RSA_ALGORITHM }, key, new TextEncoder().encode(message));
|
|
28
|
+
return (0, util_1.toBase58)(new Uint8Array(encrypted));
|
|
44
29
|
}
|
|
45
|
-
decrypt(message, key) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return Buffer.from(new Uint8Array(decrypted)).toString('utf8');
|
|
49
|
-
});
|
|
30
|
+
async decrypt(message, key) {
|
|
31
|
+
const decrypted = await crypto.decrypt({ name: RSA_ALGORITHM }, key, (0, util_1.fromBase58)(message));
|
|
32
|
+
return Buffer.from(new Uint8Array(decrypted)).toString('utf8');
|
|
50
33
|
}
|
|
51
34
|
}
|
|
52
35
|
exports.RSABrowserCrypter = RSABrowserCrypter;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ocap/mcrypto",
|
|
3
|
-
"version": "1.18.
|
|
3
|
+
"version": "1.18.52",
|
|
4
4
|
"description": "Crypto lib that provides signer,crypter,hasher interface",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"crypto",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"url": "https://github.com/ArcBlock/asset-chain/issues"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@ocap/util": "1.18.
|
|
59
|
+
"@ocap/util": "1.18.52",
|
|
60
60
|
"bn.js": "5.2.1",
|
|
61
61
|
"crypto-js": "^4.1.1",
|
|
62
62
|
"elliptic": "^6.5.4",
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
"bn.js": "5.2.1",
|
|
73
73
|
"elliptic": "6.5.3"
|
|
74
74
|
},
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "96239c70a503c2a045dbef508c3086251dee7ce5"
|
|
76
76
|
}
|