@airgap/coinlib-core 0.13.46 → 0.13.47
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/dependencies/src/axios-0.33.0/index.d.ts +345 -0
- package/dependencies/src/axios-0.33.0/lib/adapters/http.js +771 -0
- package/dependencies/src/axios-0.33.0/lib/adapters/xhr.js +305 -0
- package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/lib/axios.js +22 -7
- package/dependencies/src/axios-0.33.0/lib/cancel/CancelToken.js +118 -0
- package/dependencies/src/axios-0.33.0/lib/cancel/CanceledError.js +24 -0
- package/dependencies/src/axios-0.33.0/lib/core/Axios.js +178 -0
- package/dependencies/src/axios-0.33.0/lib/core/AxiosError.js +173 -0
- package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/lib/core/InterceptorManager.js +13 -2
- package/dependencies/src/axios-0.33.0/lib/core/buildFullPath.js +23 -0
- package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/lib/core/dispatchRequest.js +34 -16
- package/dependencies/src/axios-0.33.0/lib/core/mergeConfig.js +117 -0
- package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/lib/core/settle.js +4 -4
- package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/lib/core/transformData.js +5 -2
- package/dependencies/src/axios-0.33.0/lib/defaults/index.js +181 -0
- package/dependencies/src/axios-0.33.0/lib/defaults/transitional.js +7 -0
- package/dependencies/src/axios-0.33.0/lib/env/classes/FormData.js +2 -0
- package/dependencies/src/axios-0.33.0/lib/env/data.js +3 -0
- package/dependencies/src/axios-0.33.0/lib/helpers/AxiosURLSearchParams.js +50 -0
- package/dependencies/src/axios-0.33.0/lib/helpers/bind.js +7 -0
- package/dependencies/src/axios-0.33.0/lib/helpers/buildURL.js +63 -0
- package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/lib/helpers/combineURLs.js +1 -1
- package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/lib/helpers/cookies.js +15 -2
- package/dependencies/src/axios-0.33.0/lib/helpers/defaultRedactKeys.js +3 -0
- package/dependencies/src/axios-0.33.0/lib/helpers/estimateDataURLDecodedBytes.js +79 -0
- package/dependencies/src/axios-0.33.0/lib/helpers/formDataToJSON.js +91 -0
- package/dependencies/src/axios-0.33.0/lib/helpers/fromDataURI.js +51 -0
- package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/lib/helpers/isAbsoluteURL.js +1 -1
- package/dependencies/src/axios-0.33.0/lib/helpers/isAxiosError.js +13 -0
- package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/lib/helpers/isURLSameOrigin.js +12 -12
- package/dependencies/src/axios-0.33.0/lib/helpers/null.js +2 -0
- package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/lib/helpers/parseHeaders.js +2 -2
- package/dependencies/src/axios-0.33.0/lib/helpers/parseProtocol.js +6 -0
- package/dependencies/src/axios-0.33.0/lib/helpers/sanitizeHeaderValue.js +22 -0
- package/dependencies/src/axios-0.33.0/lib/helpers/shouldBypassProxy.js +187 -0
- package/dependencies/src/axios-0.33.0/lib/helpers/toFormData.js +212 -0
- package/dependencies/src/axios-0.33.0/lib/helpers/toURLEncodedForm.js +18 -0
- package/dependencies/src/axios-0.33.0/lib/helpers/validator.js +86 -0
- package/dependencies/src/axios-0.33.0/lib/platform/browser/classes/FormData.js +3 -0
- package/dependencies/src/axios-0.33.0/lib/platform/browser/classes/URLSearchParams.js +5 -0
- package/dependencies/src/axios-0.33.0/lib/platform/browser/index.js +11 -0
- package/dependencies/src/axios-0.33.0/lib/platform/index.js +3 -0
- package/dependencies/src/axios-0.33.0/lib/platform/node/classes/FormData.js +3 -0
- package/dependencies/src/axios-0.33.0/lib/platform/node/classes/URLSearchParams.js +5 -0
- package/dependencies/src/axios-0.33.0/lib/platform/node/index.js +11 -0
- package/dependencies/src/axios-0.33.0/lib/utils.js +565 -0
- package/dependencies/src/axios-0.33.0/package.json +100 -0
- package/dependencies/src/{bn.js-4.11.8 → bn.js-4.11.9}/lib/bn.js +7 -1
- package/dependencies/src/{elliptic-6.5.3 → elliptic-6.6.1}/lib/elliptic/curve/base.js +36 -31
- package/dependencies/src/{elliptic-6.5.1 → elliptic-6.6.1}/lib/elliptic/curve/edwards.js +13 -10
- package/dependencies/src/{elliptic-6.5.3 → elliptic-6.6.1}/lib/elliptic/curve/mont.js +1 -1
- package/dependencies/src/{elliptic-6.5.1 → elliptic-6.6.1}/lib/elliptic/curve/short.js +48 -47
- package/dependencies/src/{elliptic-6.5.3 → elliptic-6.6.1}/lib/elliptic/curves.js +21 -21
- package/dependencies/src/{elliptic-6.5.1 → elliptic-6.6.1}/lib/elliptic/ec/index.js +53 -16
- package/dependencies/src/{elliptic-6.5.3 → elliptic-6.6.1}/lib/elliptic/ec/key.js +8 -5
- package/dependencies/src/{elliptic-6.5.3 → elliptic-6.6.1}/lib/elliptic/ec/signature.js +11 -1
- package/dependencies/src/{elliptic-6.5.3 → elliptic-6.6.1}/lib/elliptic/eddsa/index.js +5 -2
- package/dependencies/src/{elliptic-6.5.3 → elliptic-6.6.1}/lib/elliptic/eddsa/signature.js +3 -2
- package/dependencies/src/{elliptic-6.5.1 → elliptic-6.6.1}/lib/elliptic/precomputed/secp256k1.js +197 -197
- package/dependencies/src/{elliptic-6.5.3 → elliptic-6.6.1}/lib/elliptic/utils.js +12 -9
- package/dependencies/src/{elliptic-6.5.1 → elliptic-6.6.1}/package.json +20 -22
- package/dependencies/src/ethereumjs-util-5.2.0/index.js +1 -1
- package/dependencies/src/follow-redirects-1.16.0/debug.js +15 -0
- package/dependencies/src/follow-redirects-1.16.0/index.js +709 -0
- package/dependencies/src/follow-redirects-1.16.0/package.json +58 -0
- package/dependencies/src/proxy-from-env-1.1.0/index.js +108 -0
- package/dependencies/src/proxy-from-env-1.1.0/package.json +34 -0
- package/dependencies/src/secp256k1-3.7.1/lib/elliptic/index.js +2 -2
- package/dependencies/src/secp256k1-4.0.2/lib/elliptic.js +1 -1
- package/dependencies/src/tiny-secp256k1-1.1.3/js.js +2 -2
- package/errors/index.d.ts +2 -2
- package/errors/index.js.map +1 -1
- package/package.json +2 -2
- package/utils/remote-data/HttpRemoteData.js +3 -8
- package/utils/remote-data/HttpRemoteData.js.map +1 -1
- package/utils/remote-data/IpfsRemoteData.js +13 -7
- package/utils/remote-data/IpfsRemoteData.js.map +1 -1
- package/utils/remote-data/Sha256RemoteData.js +5 -6
- package/utils/remote-data/Sha256RemoteData.js.map +1 -1
- package/utils/remote-data/remoteDataRequest.d.ts +16 -0
- package/utils/remote-data/remoteDataRequest.js +240 -0
- package/utils/remote-data/remoteDataRequest.js.map +1 -0
- package/dependencies/src/axios-0.19.0/index.d.ts +0 -152
- package/dependencies/src/axios-0.19.0/lib/adapters/http.js +0 -275
- package/dependencies/src/axios-0.19.0/lib/adapters/xhr.js +0 -174
- package/dependencies/src/axios-0.19.0/lib/cancel/Cancel.js +0 -19
- package/dependencies/src/axios-0.19.0/lib/cancel/CancelToken.js +0 -57
- package/dependencies/src/axios-0.19.0/lib/core/Axios.js +0 -86
- package/dependencies/src/axios-0.19.0/lib/core/createError.js +0 -18
- package/dependencies/src/axios-0.19.0/lib/core/enhanceError.js +0 -42
- package/dependencies/src/axios-0.19.0/lib/core/mergeConfig.js +0 -51
- package/dependencies/src/axios-0.19.0/lib/defaults.js +0 -98
- package/dependencies/src/axios-0.19.0/lib/helpers/bind.js +0 -11
- package/dependencies/src/axios-0.19.0/lib/helpers/buildURL.js +0 -71
- package/dependencies/src/axios-0.19.0/lib/utils.js +0 -334
- package/dependencies/src/axios-0.19.0/package.json +0 -85
- package/dependencies/src/elliptic-6.5.1/lib/elliptic/curve/base.js +0 -374
- package/dependencies/src/elliptic-6.5.1/lib/elliptic/curve/mont.js +0 -178
- package/dependencies/src/elliptic-6.5.1/lib/elliptic/curves.js +0 -206
- package/dependencies/src/elliptic-6.5.1/lib/elliptic/ec/key.js +0 -118
- package/dependencies/src/elliptic-6.5.1/lib/elliptic/ec/signature.js +0 -134
- package/dependencies/src/elliptic-6.5.1/lib/elliptic/eddsa/index.js +0 -118
- package/dependencies/src/elliptic-6.5.1/lib/elliptic/eddsa/signature.js +0 -65
- package/dependencies/src/elliptic-6.5.1/lib/elliptic/utils.js +0 -120
- package/dependencies/src/elliptic-6.5.3/lib/elliptic/curve/edwards.js +0 -432
- package/dependencies/src/elliptic-6.5.3/lib/elliptic/curve/index.js +0 -8
- package/dependencies/src/elliptic-6.5.3/lib/elliptic/curve/short.js +0 -937
- package/dependencies/src/elliptic-6.5.3/lib/elliptic/ec/index.js +0 -241
- package/dependencies/src/elliptic-6.5.3/lib/elliptic/eddsa/key.js +0 -95
- package/dependencies/src/elliptic-6.5.3/lib/elliptic/precomputed/secp256k1.js +0 -780
- package/dependencies/src/elliptic-6.5.3/lib/elliptic.js +0 -13
- package/dependencies/src/elliptic-6.5.3/package.json +0 -55
- package/dependencies/src/follow-redirects-1.5.10/index.js +0 -322
- package/dependencies/src/is-buffer-2.0.3/index.js +0 -11
- /package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/index.js +0 -0
- /package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/lib/cancel/isCancel.js +0 -0
- /package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/lib/helpers/deprecatedMethod.js +0 -0
- /package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/lib/helpers/normalizeHeaderName.js +0 -0
- /package/dependencies/src/{axios-0.19.0 → axios-0.33.0}/lib/helpers/spread.js +0 -0
- /package/dependencies/src/{elliptic-6.5.1 → elliptic-6.6.1}/lib/elliptic/curve/index.js +0 -0
- /package/dependencies/src/{elliptic-6.5.1 → elliptic-6.6.1}/lib/elliptic/eddsa/key.js +0 -0
- /package/dependencies/src/{elliptic-6.5.1 → elliptic-6.6.1}/lib/elliptic.js +0 -0
- /package/dependencies/src/{follow-redirects-1.5.10 → follow-redirects-1.16.0}/http.js +0 -0
- /package/dependencies/src/{follow-redirects-1.5.10 → follow-redirects-1.16.0}/https.js +0 -0
|
@@ -1,374 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var BN = require('../../../../bn.js-4.11.8/lib/bn');
|
|
4
|
-
var utils = require('../utils');
|
|
5
|
-
var getNAF = utils.getNAF;
|
|
6
|
-
var getJSF = utils.getJSF;
|
|
7
|
-
var assert = utils.assert;
|
|
8
|
-
|
|
9
|
-
function BaseCurve(type, conf) {
|
|
10
|
-
this.type = type;
|
|
11
|
-
this.p = new BN(conf.p, 16);
|
|
12
|
-
|
|
13
|
-
// Use Montgomery, when there is no fast reduction for the prime
|
|
14
|
-
this.red = conf.prime ? BN.red(conf.prime) : BN.mont(this.p);
|
|
15
|
-
|
|
16
|
-
// Useful for many curves
|
|
17
|
-
this.zero = new BN(0).toRed(this.red);
|
|
18
|
-
this.one = new BN(1).toRed(this.red);
|
|
19
|
-
this.two = new BN(2).toRed(this.red);
|
|
20
|
-
|
|
21
|
-
// Curve configuration, optional
|
|
22
|
-
this.n = conf.n && new BN(conf.n, 16);
|
|
23
|
-
this.g = conf.g && this.pointFromJSON(conf.g, conf.gRed);
|
|
24
|
-
|
|
25
|
-
// Temporary arrays
|
|
26
|
-
this._wnafT1 = new Array(4);
|
|
27
|
-
this._wnafT2 = new Array(4);
|
|
28
|
-
this._wnafT3 = new Array(4);
|
|
29
|
-
this._wnafT4 = new Array(4);
|
|
30
|
-
|
|
31
|
-
// Generalized Greg Maxwell's trick
|
|
32
|
-
var adjustCount = this.n && this.p.div(this.n);
|
|
33
|
-
if (!adjustCount || adjustCount.cmpn(100) > 0) {
|
|
34
|
-
this.redN = null;
|
|
35
|
-
} else {
|
|
36
|
-
this._maxwellTrick = true;
|
|
37
|
-
this.redN = this.n.toRed(this.red);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
module.exports = BaseCurve;
|
|
41
|
-
|
|
42
|
-
BaseCurve.prototype.point = function point() {
|
|
43
|
-
throw new Error('Not implemented');
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
BaseCurve.prototype.validate = function validate() {
|
|
47
|
-
throw new Error('Not implemented');
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
BaseCurve.prototype._fixedNafMul = function _fixedNafMul(p, k) {
|
|
51
|
-
assert(p.precomputed);
|
|
52
|
-
var doubles = p._getDoubles();
|
|
53
|
-
|
|
54
|
-
var naf = getNAF(k, 1);
|
|
55
|
-
var I = (1 << (doubles.step + 1)) - (doubles.step % 2 === 0 ? 2 : 1);
|
|
56
|
-
I /= 3;
|
|
57
|
-
|
|
58
|
-
// Translate into more windowed form
|
|
59
|
-
var repr = [];
|
|
60
|
-
for (var j = 0; j < naf.length; j += doubles.step) {
|
|
61
|
-
var nafW = 0;
|
|
62
|
-
for (var k = j + doubles.step - 1; k >= j; k--)
|
|
63
|
-
nafW = (nafW << 1) + naf[k];
|
|
64
|
-
repr.push(nafW);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
var a = this.jpoint(null, null, null);
|
|
68
|
-
var b = this.jpoint(null, null, null);
|
|
69
|
-
for (var i = I; i > 0; i--) {
|
|
70
|
-
for (var j = 0; j < repr.length; j++) {
|
|
71
|
-
var nafW = repr[j];
|
|
72
|
-
if (nafW === i)
|
|
73
|
-
b = b.mixedAdd(doubles.points[j]);
|
|
74
|
-
else if (nafW === -i)
|
|
75
|
-
b = b.mixedAdd(doubles.points[j].neg());
|
|
76
|
-
}
|
|
77
|
-
a = a.add(b);
|
|
78
|
-
}
|
|
79
|
-
return a.toP();
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
BaseCurve.prototype._wnafMul = function _wnafMul(p, k) {
|
|
83
|
-
var w = 4;
|
|
84
|
-
|
|
85
|
-
// Precompute window
|
|
86
|
-
var nafPoints = p._getNAFPoints(w);
|
|
87
|
-
w = nafPoints.wnd;
|
|
88
|
-
var wnd = nafPoints.points;
|
|
89
|
-
|
|
90
|
-
// Get NAF form
|
|
91
|
-
var naf = getNAF(k, w);
|
|
92
|
-
|
|
93
|
-
// Add `this`*(N+1) for every w-NAF index
|
|
94
|
-
var acc = this.jpoint(null, null, null);
|
|
95
|
-
for (var i = naf.length - 1; i >= 0; i--) {
|
|
96
|
-
// Count zeroes
|
|
97
|
-
for (var k = 0; i >= 0 && naf[i] === 0; i--)
|
|
98
|
-
k++;
|
|
99
|
-
if (i >= 0)
|
|
100
|
-
k++;
|
|
101
|
-
acc = acc.dblp(k);
|
|
102
|
-
|
|
103
|
-
if (i < 0)
|
|
104
|
-
break;
|
|
105
|
-
var z = naf[i];
|
|
106
|
-
assert(z !== 0);
|
|
107
|
-
if (p.type === 'affine') {
|
|
108
|
-
// J +- P
|
|
109
|
-
if (z > 0)
|
|
110
|
-
acc = acc.mixedAdd(wnd[(z - 1) >> 1]);
|
|
111
|
-
else
|
|
112
|
-
acc = acc.mixedAdd(wnd[(-z - 1) >> 1].neg());
|
|
113
|
-
} else {
|
|
114
|
-
// J +- J
|
|
115
|
-
if (z > 0)
|
|
116
|
-
acc = acc.add(wnd[(z - 1) >> 1]);
|
|
117
|
-
else
|
|
118
|
-
acc = acc.add(wnd[(-z - 1) >> 1].neg());
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return p.type === 'affine' ? acc.toP() : acc;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
BaseCurve.prototype._wnafMulAdd = function _wnafMulAdd(defW,
|
|
125
|
-
points,
|
|
126
|
-
coeffs,
|
|
127
|
-
len,
|
|
128
|
-
jacobianResult) {
|
|
129
|
-
var wndWidth = this._wnafT1;
|
|
130
|
-
var wnd = this._wnafT2;
|
|
131
|
-
var naf = this._wnafT3;
|
|
132
|
-
|
|
133
|
-
// Fill all arrays
|
|
134
|
-
var max = 0;
|
|
135
|
-
for (var i = 0; i < len; i++) {
|
|
136
|
-
var p = points[i];
|
|
137
|
-
var nafPoints = p._getNAFPoints(defW);
|
|
138
|
-
wndWidth[i] = nafPoints.wnd;
|
|
139
|
-
wnd[i] = nafPoints.points;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Comb small window NAFs
|
|
143
|
-
for (var i = len - 1; i >= 1; i -= 2) {
|
|
144
|
-
var a = i - 1;
|
|
145
|
-
var b = i;
|
|
146
|
-
if (wndWidth[a] !== 1 || wndWidth[b] !== 1) {
|
|
147
|
-
naf[a] = getNAF(coeffs[a], wndWidth[a]);
|
|
148
|
-
naf[b] = getNAF(coeffs[b], wndWidth[b]);
|
|
149
|
-
max = Math.max(naf[a].length, max);
|
|
150
|
-
max = Math.max(naf[b].length, max);
|
|
151
|
-
continue;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
var comb = [
|
|
155
|
-
points[a], /* 1 */
|
|
156
|
-
null, /* 3 */
|
|
157
|
-
null, /* 5 */
|
|
158
|
-
points[b] /* 7 */
|
|
159
|
-
];
|
|
160
|
-
|
|
161
|
-
// Try to avoid Projective points, if possible
|
|
162
|
-
if (points[a].y.cmp(points[b].y) === 0) {
|
|
163
|
-
comb[1] = points[a].add(points[b]);
|
|
164
|
-
comb[2] = points[a].toJ().mixedAdd(points[b].neg());
|
|
165
|
-
} else if (points[a].y.cmp(points[b].y.redNeg()) === 0) {
|
|
166
|
-
comb[1] = points[a].toJ().mixedAdd(points[b]);
|
|
167
|
-
comb[2] = points[a].add(points[b].neg());
|
|
168
|
-
} else {
|
|
169
|
-
comb[1] = points[a].toJ().mixedAdd(points[b]);
|
|
170
|
-
comb[2] = points[a].toJ().mixedAdd(points[b].neg());
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
var index = [
|
|
174
|
-
-3, /* -1 -1 */
|
|
175
|
-
-1, /* -1 0 */
|
|
176
|
-
-5, /* -1 1 */
|
|
177
|
-
-7, /* 0 -1 */
|
|
178
|
-
0, /* 0 0 */
|
|
179
|
-
7, /* 0 1 */
|
|
180
|
-
5, /* 1 -1 */
|
|
181
|
-
1, /* 1 0 */
|
|
182
|
-
3 /* 1 1 */
|
|
183
|
-
];
|
|
184
|
-
|
|
185
|
-
var jsf = getJSF(coeffs[a], coeffs[b]);
|
|
186
|
-
max = Math.max(jsf[0].length, max);
|
|
187
|
-
naf[a] = new Array(max);
|
|
188
|
-
naf[b] = new Array(max);
|
|
189
|
-
for (var j = 0; j < max; j++) {
|
|
190
|
-
var ja = jsf[0][j] | 0;
|
|
191
|
-
var jb = jsf[1][j] | 0;
|
|
192
|
-
|
|
193
|
-
naf[a][j] = index[(ja + 1) * 3 + (jb + 1)];
|
|
194
|
-
naf[b][j] = 0;
|
|
195
|
-
wnd[a] = comb;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
var acc = this.jpoint(null, null, null);
|
|
200
|
-
var tmp = this._wnafT4;
|
|
201
|
-
for (var i = max; i >= 0; i--) {
|
|
202
|
-
var k = 0;
|
|
203
|
-
|
|
204
|
-
while (i >= 0) {
|
|
205
|
-
var zero = true;
|
|
206
|
-
for (var j = 0; j < len; j++) {
|
|
207
|
-
tmp[j] = naf[j][i] | 0;
|
|
208
|
-
if (tmp[j] !== 0)
|
|
209
|
-
zero = false;
|
|
210
|
-
}
|
|
211
|
-
if (!zero)
|
|
212
|
-
break;
|
|
213
|
-
k++;
|
|
214
|
-
i--;
|
|
215
|
-
}
|
|
216
|
-
if (i >= 0)
|
|
217
|
-
k++;
|
|
218
|
-
acc = acc.dblp(k);
|
|
219
|
-
if (i < 0)
|
|
220
|
-
break;
|
|
221
|
-
|
|
222
|
-
for (var j = 0; j < len; j++) {
|
|
223
|
-
var z = tmp[j];
|
|
224
|
-
var p;
|
|
225
|
-
if (z === 0)
|
|
226
|
-
continue;
|
|
227
|
-
else if (z > 0)
|
|
228
|
-
p = wnd[j][(z - 1) >> 1];
|
|
229
|
-
else if (z < 0)
|
|
230
|
-
p = wnd[j][(-z - 1) >> 1].neg();
|
|
231
|
-
|
|
232
|
-
if (p.type === 'affine')
|
|
233
|
-
acc = acc.mixedAdd(p);
|
|
234
|
-
else
|
|
235
|
-
acc = acc.add(p);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
// Zeroify references
|
|
239
|
-
for (var i = 0; i < len; i++)
|
|
240
|
-
wnd[i] = null;
|
|
241
|
-
|
|
242
|
-
if (jacobianResult)
|
|
243
|
-
return acc;
|
|
244
|
-
else
|
|
245
|
-
return acc.toP();
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
function BasePoint(curve, type) {
|
|
249
|
-
this.curve = curve;
|
|
250
|
-
this.type = type;
|
|
251
|
-
this.precomputed = null;
|
|
252
|
-
}
|
|
253
|
-
BaseCurve.BasePoint = BasePoint;
|
|
254
|
-
|
|
255
|
-
BasePoint.prototype.eq = function eq(/*other*/) {
|
|
256
|
-
throw new Error('Not implemented');
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
BasePoint.prototype.validate = function validate() {
|
|
260
|
-
return this.curve.validate(this);
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
BaseCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
|
|
264
|
-
bytes = utils.toArray(bytes, enc);
|
|
265
|
-
|
|
266
|
-
var len = this.p.byteLength();
|
|
267
|
-
|
|
268
|
-
// uncompressed, hybrid-odd, hybrid-even
|
|
269
|
-
if ((bytes[0] === 0x04 || bytes[0] === 0x06 || bytes[0] === 0x07) &&
|
|
270
|
-
bytes.length - 1 === 2 * len) {
|
|
271
|
-
if (bytes[0] === 0x06)
|
|
272
|
-
assert(bytes[bytes.length - 1] % 2 === 0);
|
|
273
|
-
else if (bytes[0] === 0x07)
|
|
274
|
-
assert(bytes[bytes.length - 1] % 2 === 1);
|
|
275
|
-
|
|
276
|
-
var res = this.point(bytes.slice(1, 1 + len),
|
|
277
|
-
bytes.slice(1 + len, 1 + 2 * len));
|
|
278
|
-
|
|
279
|
-
return res;
|
|
280
|
-
} else if ((bytes[0] === 0x02 || bytes[0] === 0x03) &&
|
|
281
|
-
bytes.length - 1 === len) {
|
|
282
|
-
return this.pointFromX(bytes.slice(1, 1 + len), bytes[0] === 0x03);
|
|
283
|
-
}
|
|
284
|
-
throw new Error('Unknown point format');
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
BasePoint.prototype.encodeCompressed = function encodeCompressed(enc) {
|
|
288
|
-
return this.encode(enc, true);
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
BasePoint.prototype._encode = function _encode(compact) {
|
|
292
|
-
var len = this.curve.p.byteLength();
|
|
293
|
-
var x = this.getX().toArray('be', len);
|
|
294
|
-
|
|
295
|
-
if (compact)
|
|
296
|
-
return [ this.getY().isEven() ? 0x02 : 0x03 ].concat(x);
|
|
297
|
-
|
|
298
|
-
return [ 0x04 ].concat(x, this.getY().toArray('be', len)) ;
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
BasePoint.prototype.encode = function encode(enc, compact) {
|
|
302
|
-
return utils.encode(this._encode(compact), enc);
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
BasePoint.prototype.precompute = function precompute(power) {
|
|
306
|
-
if (this.precomputed)
|
|
307
|
-
return this;
|
|
308
|
-
|
|
309
|
-
var precomputed = {
|
|
310
|
-
doubles: null,
|
|
311
|
-
naf: null,
|
|
312
|
-
beta: null
|
|
313
|
-
};
|
|
314
|
-
precomputed.naf = this._getNAFPoints(8);
|
|
315
|
-
precomputed.doubles = this._getDoubles(4, power);
|
|
316
|
-
precomputed.beta = this._getBeta();
|
|
317
|
-
this.precomputed = precomputed;
|
|
318
|
-
|
|
319
|
-
return this;
|
|
320
|
-
};
|
|
321
|
-
|
|
322
|
-
BasePoint.prototype._hasDoubles = function _hasDoubles(k) {
|
|
323
|
-
if (!this.precomputed)
|
|
324
|
-
return false;
|
|
325
|
-
|
|
326
|
-
var doubles = this.precomputed.doubles;
|
|
327
|
-
if (!doubles)
|
|
328
|
-
return false;
|
|
329
|
-
|
|
330
|
-
return doubles.points.length >= Math.ceil((k.bitLength() + 1) / doubles.step);
|
|
331
|
-
};
|
|
332
|
-
|
|
333
|
-
BasePoint.prototype._getDoubles = function _getDoubles(step, power) {
|
|
334
|
-
if (this.precomputed && this.precomputed.doubles)
|
|
335
|
-
return this.precomputed.doubles;
|
|
336
|
-
|
|
337
|
-
var doubles = [ this ];
|
|
338
|
-
var acc = this;
|
|
339
|
-
for (var i = 0; i < power; i += step) {
|
|
340
|
-
for (var j = 0; j < step; j++)
|
|
341
|
-
acc = acc.dbl();
|
|
342
|
-
doubles.push(acc);
|
|
343
|
-
}
|
|
344
|
-
return {
|
|
345
|
-
step: step,
|
|
346
|
-
points: doubles
|
|
347
|
-
};
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
BasePoint.prototype._getNAFPoints = function _getNAFPoints(wnd) {
|
|
351
|
-
if (this.precomputed && this.precomputed.naf)
|
|
352
|
-
return this.precomputed.naf;
|
|
353
|
-
|
|
354
|
-
var res = [ this ];
|
|
355
|
-
var max = (1 << wnd) - 1;
|
|
356
|
-
var dbl = max === 1 ? null : this.dbl();
|
|
357
|
-
for (var i = 1; i < max; i++)
|
|
358
|
-
res[i] = res[i - 1].add(dbl);
|
|
359
|
-
return {
|
|
360
|
-
wnd: wnd,
|
|
361
|
-
points: res
|
|
362
|
-
};
|
|
363
|
-
};
|
|
364
|
-
|
|
365
|
-
BasePoint.prototype._getBeta = function _getBeta() {
|
|
366
|
-
return null;
|
|
367
|
-
};
|
|
368
|
-
|
|
369
|
-
BasePoint.prototype.dblp = function dblp(k) {
|
|
370
|
-
var r = this;
|
|
371
|
-
for (var i = 0; i < k; i++)
|
|
372
|
-
r = r.dbl();
|
|
373
|
-
return r;
|
|
374
|
-
};
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var BN = require('../../../../bn.js-4.11.8/lib/bn');
|
|
4
|
-
var inherits = require('../../../../inherits-2.0.4/inherits');
|
|
5
|
-
var Base = require('./base');
|
|
6
|
-
|
|
7
|
-
var utils = require('../utils');
|
|
8
|
-
|
|
9
|
-
function MontCurve(conf) {
|
|
10
|
-
Base.call(this, 'mont', conf);
|
|
11
|
-
|
|
12
|
-
this.a = new BN(conf.a, 16).toRed(this.red);
|
|
13
|
-
this.b = new BN(conf.b, 16).toRed(this.red);
|
|
14
|
-
this.i4 = new BN(4).toRed(this.red).redInvm();
|
|
15
|
-
this.two = new BN(2).toRed(this.red);
|
|
16
|
-
this.a24 = this.i4.redMul(this.a.redAdd(this.two));
|
|
17
|
-
}
|
|
18
|
-
inherits(MontCurve, Base);
|
|
19
|
-
module.exports = MontCurve;
|
|
20
|
-
|
|
21
|
-
MontCurve.prototype.validate = function validate(point) {
|
|
22
|
-
var x = point.normalize().x;
|
|
23
|
-
var x2 = x.redSqr();
|
|
24
|
-
var rhs = x2.redMul(x).redAdd(x2.redMul(this.a)).redAdd(x);
|
|
25
|
-
var y = rhs.redSqrt();
|
|
26
|
-
|
|
27
|
-
return y.redSqr().cmp(rhs) === 0;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
function Point(curve, x, z) {
|
|
31
|
-
Base.BasePoint.call(this, curve, 'projective');
|
|
32
|
-
if (x === null && z === null) {
|
|
33
|
-
this.x = this.curve.one;
|
|
34
|
-
this.z = this.curve.zero;
|
|
35
|
-
} else {
|
|
36
|
-
this.x = new BN(x, 16);
|
|
37
|
-
this.z = new BN(z, 16);
|
|
38
|
-
if (!this.x.red)
|
|
39
|
-
this.x = this.x.toRed(this.curve.red);
|
|
40
|
-
if (!this.z.red)
|
|
41
|
-
this.z = this.z.toRed(this.curve.red);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
inherits(Point, Base.BasePoint);
|
|
45
|
-
|
|
46
|
-
MontCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
|
|
47
|
-
return this.point(utils.toArray(bytes, enc), 1);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
MontCurve.prototype.point = function point(x, z) {
|
|
51
|
-
return new Point(this, x, z);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
MontCurve.prototype.pointFromJSON = function pointFromJSON(obj) {
|
|
55
|
-
return Point.fromJSON(this, obj);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
Point.prototype.precompute = function precompute() {
|
|
59
|
-
// No-op
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
Point.prototype._encode = function _encode() {
|
|
63
|
-
return this.getX().toArray('be', this.curve.p.byteLength());
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
Point.fromJSON = function fromJSON(curve, obj) {
|
|
67
|
-
return new Point(curve, obj[0], obj[1] || curve.one);
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
Point.prototype.inspect = function inspect() {
|
|
71
|
-
if (this.isInfinity())
|
|
72
|
-
return '<EC Point Infinity>';
|
|
73
|
-
return '<EC Point x: ' + this.x.fromRed().toString(16, 2) +
|
|
74
|
-
' z: ' + this.z.fromRed().toString(16, 2) + '>';
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
Point.prototype.isInfinity = function isInfinity() {
|
|
78
|
-
// XXX This code assumes that zero is always zero in red
|
|
79
|
-
return this.z.cmpn(0) === 0;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
Point.prototype.dbl = function dbl() {
|
|
83
|
-
// http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#doubling-dbl-1987-m-3
|
|
84
|
-
// 2M + 2S + 4A
|
|
85
|
-
|
|
86
|
-
// A = X1 + Z1
|
|
87
|
-
var a = this.x.redAdd(this.z);
|
|
88
|
-
// AA = A^2
|
|
89
|
-
var aa = a.redSqr();
|
|
90
|
-
// B = X1 - Z1
|
|
91
|
-
var b = this.x.redSub(this.z);
|
|
92
|
-
// BB = B^2
|
|
93
|
-
var bb = b.redSqr();
|
|
94
|
-
// C = AA - BB
|
|
95
|
-
var c = aa.redSub(bb);
|
|
96
|
-
// X3 = AA * BB
|
|
97
|
-
var nx = aa.redMul(bb);
|
|
98
|
-
// Z3 = C * (BB + A24 * C)
|
|
99
|
-
var nz = c.redMul(bb.redAdd(this.curve.a24.redMul(c)));
|
|
100
|
-
return this.curve.point(nx, nz);
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
Point.prototype.add = function add() {
|
|
104
|
-
throw new Error('Not supported on Montgomery curve');
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
Point.prototype.diffAdd = function diffAdd(p, diff) {
|
|
108
|
-
// http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#diffadd-dadd-1987-m-3
|
|
109
|
-
// 4M + 2S + 6A
|
|
110
|
-
|
|
111
|
-
// A = X2 + Z2
|
|
112
|
-
var a = this.x.redAdd(this.z);
|
|
113
|
-
// B = X2 - Z2
|
|
114
|
-
var b = this.x.redSub(this.z);
|
|
115
|
-
// C = X3 + Z3
|
|
116
|
-
var c = p.x.redAdd(p.z);
|
|
117
|
-
// D = X3 - Z3
|
|
118
|
-
var d = p.x.redSub(p.z);
|
|
119
|
-
// DA = D * A
|
|
120
|
-
var da = d.redMul(a);
|
|
121
|
-
// CB = C * B
|
|
122
|
-
var cb = c.redMul(b);
|
|
123
|
-
// X5 = Z1 * (DA + CB)^2
|
|
124
|
-
var nx = diff.z.redMul(da.redAdd(cb).redSqr());
|
|
125
|
-
// Z5 = X1 * (DA - CB)^2
|
|
126
|
-
var nz = diff.x.redMul(da.redISub(cb).redSqr());
|
|
127
|
-
return this.curve.point(nx, nz);
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
Point.prototype.mul = function mul(k) {
|
|
131
|
-
var t = k.clone();
|
|
132
|
-
var a = this; // (N / 2) * Q + Q
|
|
133
|
-
var b = this.curve.point(null, null); // (N / 2) * Q
|
|
134
|
-
var c = this; // Q
|
|
135
|
-
|
|
136
|
-
for (var bits = []; t.cmpn(0) !== 0; t.iushrn(1))
|
|
137
|
-
bits.push(t.andln(1));
|
|
138
|
-
|
|
139
|
-
for (var i = bits.length - 1; i >= 0; i--) {
|
|
140
|
-
if (bits[i] === 0) {
|
|
141
|
-
// N * Q + Q = ((N / 2) * Q + Q)) + (N / 2) * Q
|
|
142
|
-
a = a.diffAdd(b, c);
|
|
143
|
-
// N * Q = 2 * ((N / 2) * Q + Q))
|
|
144
|
-
b = b.dbl();
|
|
145
|
-
} else {
|
|
146
|
-
// N * Q = ((N / 2) * Q + Q) + ((N / 2) * Q)
|
|
147
|
-
b = a.diffAdd(b, c);
|
|
148
|
-
// N * Q + Q = 2 * ((N / 2) * Q + Q)
|
|
149
|
-
a = a.dbl();
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return b;
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
Point.prototype.mulAdd = function mulAdd() {
|
|
156
|
-
throw new Error('Not supported on Montgomery curve');
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
Point.prototype.jumlAdd = function jumlAdd() {
|
|
160
|
-
throw new Error('Not supported on Montgomery curve');
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
Point.prototype.eq = function eq(other) {
|
|
164
|
-
return this.getX().cmp(other.getX()) === 0;
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
Point.prototype.normalize = function normalize() {
|
|
168
|
-
this.x = this.x.redMul(this.z.redInvm());
|
|
169
|
-
this.z = this.curve.one;
|
|
170
|
-
return this;
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
Point.prototype.getX = function getX() {
|
|
174
|
-
// Normalize coordinates
|
|
175
|
-
this.normalize();
|
|
176
|
-
|
|
177
|
-
return this.x.fromRed();
|
|
178
|
-
};
|