-
Notifications
You must be signed in to change notification settings - Fork 0
/
minimalHelper.js
46 lines (40 loc) · 958 Bytes
/
minimalHelper.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
define([], function () {
var chelper = {
getCurveName: function (curve) {
var curcurve;
for (curcurve in sjcl.ecc.curves) {
if (sjcl.ecc.curves.hasOwnProperty(curcurve)) {
if (sjcl.ecc.curves[curcurve] === curve) {
return curcurve;
}
}
}
throw "curve not existing";
},
getCurve: function (curveName) {
if (typeof curveName !== "string" || curveName.substr(0, 1) !== "c") {
curveName = "c" + curveName;
}
if (sjcl.ecc.curves[curveName]) {
return sjcl.ecc.curves[curveName];
}
throw new Error("invalid curve");
},
isHex: function (data) {
return (data && typeof data === "string" && !!data.match(/^[A-Fa-f0-9]*$/));
},
hex2bits: function (t) {
if (t instanceof Array) {
return t;
}
return sjcl.codec.hex.toBits(t);
},
bits2hex: function (t) {
if (typeof t === "string") {
return t;
}
return sjcl.codec.hex.fromBits(t);
}
};
return chelper;
});