-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (52 loc) · 1.37 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const Type = require('./src/type/index');
/**
* convert publicKey to DER format
* @param type secp256k1/secp384r1/secp521r1
* @param rawPublicKey
*/
function convertPublicKeyToDer(rawPublicKey) {
return convertPublicKey(rawPublicKey, 'DER');
}
/**
* convert publicKey to PEM format
* @param rawPublicKey
*/
function convertPublicKeyToPem(rawPublicKey) {
return convertPublicKey(rawPublicKey, 'PEM');
}
/**
* convert PrivateKey to DER format
* @param type secp256k1/secp384r1/secp521r1
* @param rawPrivateKey
*/
function convertPrivateKeyToDer(rawPrivateKey) {
return convertPrivateKey(rawPrivateKey, 'DER');
}
/**
* convert PrivateKey to PEM format
* @param type secp256k1/secp384r1/secp521r1
* @param rawPrivateKe
*/
function convertPrivateKeyToPem(rawPrivateKey) {
return convertPrivateKey(rawPrivateKey, 'PEM');
}
/**
*
* @param type secp256k1/secp256r1/secp384r1/secp521r1
*/
function handleKeyConvert(type) {
switch (type) {
case 'secp256k1':
return Type.secp256k1Type;
case 'secp256r1':
return Type.secp256r1Type;
case 'secp384r1':
return Type.secp384r1Type;
case 'secp521r1':
return Type.secp521r1Type;
}
throw new Error('Type is invalid or need support later')
}
module.exports = {
handleKeyConvert: handleKeyConvert
};