1 | module.exports =
|
2 | (function(modules) {
|
3 |
|
4 | var installedModules = {};
|
5 |
|
6 |
|
7 | function __webpack_require__(moduleId) {
|
8 |
|
9 |
|
10 | if(installedModules[moduleId]) {
|
11 | return installedModules[moduleId].exports;
|
12 | }
|
13 |
|
14 | var module = installedModules[moduleId] = {
|
15 | i: moduleId,
|
16 | l: false,
|
17 | exports: {}
|
18 | };
|
19 |
|
20 |
|
21 | modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
22 |
|
23 |
|
24 | module.l = true;
|
25 |
|
26 |
|
27 | return module.exports;
|
28 | }
|
29 |
|
30 |
|
31 |
|
32 | __webpack_require__.m = modules;
|
33 |
|
34 |
|
35 | __webpack_require__.c = installedModules;
|
36 |
|
37 |
|
38 | __webpack_require__.d = function(exports, name, getter) {
|
39 | if(!__webpack_require__.o(exports, name)) {
|
40 | Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
41 | }
|
42 | };
|
43 |
|
44 |
|
45 | __webpack_require__.r = function(exports) {
|
46 | if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
47 | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
48 | }
|
49 | Object.defineProperty(exports, '__esModule', { value: true });
|
50 | };
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | __webpack_require__.t = function(value, mode) {
|
58 | if(mode & 1) value = __webpack_require__(value);
|
59 | if(mode & 8) return value;
|
60 | if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
|
61 | var ns = Object.create(null);
|
62 | __webpack_require__.r(ns);
|
63 | Object.defineProperty(ns, 'default', { enumerable: true, value: value });
|
64 | if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
|
65 | return ns;
|
66 | };
|
67 |
|
68 |
|
69 | __webpack_require__.n = function(module) {
|
70 | var getter = module && module.__esModule ?
|
71 | function getDefault() { return module['default']; } :
|
72 | function getModuleExports() { return module; };
|
73 | __webpack_require__.d(getter, 'a', getter);
|
74 | return getter;
|
75 | };
|
76 |
|
77 |
|
78 | __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
79 |
|
80 |
|
81 | __webpack_require__.p = "";
|
82 |
|
83 |
|
84 |
|
85 | return __webpack_require__(__webpack_require__.s = 50);
|
86 | })
|
87 |
|
88 | ([
|
89 |
|
90 | (function(module, __webpack_exports__, __webpack_require__) {
|
91 |
|
92 | "use strict";
|
93 | __webpack_require__.r(__webpack_exports__);
|
94 | var consts_namespaceObject = {};
|
95 | __webpack_require__.r(consts_namespaceObject);
|
96 | __webpack_require__.d(consts_namespaceObject, "ADDR_VERSION", function() { return ADDR_VERSION; });
|
97 | __webpack_require__.d(consts_namespaceObject, "ASSETS", function() { return ASSETS; });
|
98 | __webpack_require__.d(consts_namespaceObject, "ASSET_ID", function() { return ASSET_ID; });
|
99 | __webpack_require__.d(consts_namespaceObject, "ASSET_TYPE", function() { return ASSET_TYPE; });
|
100 | __webpack_require__.d(consts_namespaceObject, "CONTRACTS", function() { return CONTRACTS; });
|
101 | __webpack_require__.d(consts_namespaceObject, "DEFAULT_RPC", function() { return DEFAULT_RPC; });
|
102 | __webpack_require__.d(consts_namespaceObject, "DEFAULT_REQ", function() { return DEFAULT_REQ; });
|
103 | __webpack_require__.d(consts_namespaceObject, "DEFAULT_SCRYPT", function() { return DEFAULT_SCRYPT; });
|
104 | __webpack_require__.d(consts_namespaceObject, "DEFAULT_SYSFEE", function() { return DEFAULT_SYSFEE; });
|
105 | __webpack_require__.d(consts_namespaceObject, "DEFAULT_WALLET", function() { return DEFAULT_WALLET; });
|
106 | __webpack_require__.d(consts_namespaceObject, "DEFAULT_ACCOUNT_CONTRACT", function() { return DEFAULT_ACCOUNT_CONTRACT; });
|
107 | __webpack_require__.d(consts_namespaceObject, "NEO_NETWORK", function() { return NEO_NETWORK; });
|
108 | __webpack_require__.d(consts_namespaceObject, "NEP_HEADER", function() { return NEP_HEADER; });
|
109 | __webpack_require__.d(consts_namespaceObject, "NEP_FLAG", function() { return NEP_FLAG; });
|
110 | __webpack_require__.d(consts_namespaceObject, "RPC_VERSION", function() { return RPC_VERSION; });
|
111 | __webpack_require__.d(consts_namespaceObject, "TX_VERSION", function() { return TX_VERSION; });
|
112 | var logging_namespaceObject = {};
|
113 | __webpack_require__.r(logging_namespaceObject);
|
114 | __webpack_require__.d(logging_namespaceObject, "setAll", function() { return setAll; });
|
115 | __webpack_require__.d(logging_namespaceObject, "default", function() { return logging; });
|
116 | __webpack_require__.d(logging_namespaceObject, "logger", function() { return logger; });
|
117 | var u_namespaceObject = {};
|
118 | __webpack_require__.r(u_namespaceObject);
|
119 | __webpack_require__.d(u_namespaceObject, "isHex", function() { return isHex; });
|
120 | __webpack_require__.d(u_namespaceObject, "ensureHex", function() { return ensureHex; });
|
121 | __webpack_require__.d(u_namespaceObject, "hexXor", function() { return hexXor; });
|
122 | __webpack_require__.d(u_namespaceObject, "reverseArray", function() { return reverseArray; });
|
123 | __webpack_require__.d(u_namespaceObject, "reverseHex", function() { return reverseHex; });
|
124 | __webpack_require__.d(u_namespaceObject, "ab2str", function() { return ab2str; });
|
125 | __webpack_require__.d(u_namespaceObject, "str2ab", function() { return str2ab; });
|
126 | __webpack_require__.d(u_namespaceObject, "hexstring2ab", function() { return hexstring2ab; });
|
127 | __webpack_require__.d(u_namespaceObject, "ab2hexstring", function() { return ab2hexstring; });
|
128 | __webpack_require__.d(u_namespaceObject, "str2hexstring", function() { return str2hexstring; });
|
129 | __webpack_require__.d(u_namespaceObject, "hexstring2str", function() { return hexstring2str; });
|
130 | __webpack_require__.d(u_namespaceObject, "int2hex", function() { return int2hex; });
|
131 | __webpack_require__.d(u_namespaceObject, "num2hexstring", function() { return num2hexstring; });
|
132 | __webpack_require__.d(u_namespaceObject, "num2fixed8", function() { return num2fixed8; });
|
133 | __webpack_require__.d(u_namespaceObject, "fixed82num", function() { return fixed82num; });
|
134 | __webpack_require__.d(u_namespaceObject, "num2VarInt", function() { return num2VarInt; });
|
135 | __webpack_require__.d(u_namespaceObject, "sha256", function() { return hash_sha256; });
|
136 | __webpack_require__.d(u_namespaceObject, "ripemd160", function() { return hash_ripemd160; });
|
137 | __webpack_require__.d(u_namespaceObject, "hash160", function() { return hash160; });
|
138 | __webpack_require__.d(u_namespaceObject, "hash256", function() { return hash256; });
|
139 | __webpack_require__.d(u_namespaceObject, "Fixed8", function() { return Fixed8_Fixed8; });
|
140 | __webpack_require__.d(u_namespaceObject, "StringStream", function() { return StringStream_StringStream; });
|
141 | __webpack_require__.d(u_namespaceObject, "generateRandomArray", function() { return generateRandomArray; });
|
142 | var sc_namespaceObject = {};
|
143 | __webpack_require__.r(sc_namespaceObject);
|
144 | __webpack_require__.d(sc_namespaceObject, "ContractParamType", function() { return ContractParamType; });
|
145 | __webpack_require__.d(sc_namespaceObject, "ContractParam", function() { return ContractParam_ContractParam; });
|
146 | __webpack_require__.d(sc_namespaceObject, "likeContractParam", function() { return likeContractParam; });
|
147 | __webpack_require__.d(sc_namespaceObject, "createScript", function() { return createScript; });
|
148 | __webpack_require__.d(sc_namespaceObject, "generateDeployScript", function() { return generateDeployScript; });
|
149 | __webpack_require__.d(sc_namespaceObject, "ScriptBuilder", function() { return ScriptBuilder_ScriptBuilder; });
|
150 | __webpack_require__.d(sc_namespaceObject, "StackItemType", function() { return StackItemType; });
|
151 | __webpack_require__.d(sc_namespaceObject, "hasChildren", function() { return hasChildren; });
|
152 | __webpack_require__.d(sc_namespaceObject, "StackItem", function() { return StackItem_StackItem; });
|
153 | __webpack_require__.d(sc_namespaceObject, "OpCode", function() { return OpCode; });
|
154 | var wallet_namespaceObject = {};
|
155 | __webpack_require__.r(wallet_namespaceObject);
|
156 | __webpack_require__.d(wallet_namespaceObject, "Account", function() { return Account_Account; });
|
157 | __webpack_require__.d(wallet_namespaceObject, "Balance", function() { return Balance_Balance; });
|
158 | __webpack_require__.d(wallet_namespaceObject, "Claims", function() { return Claims_Claims; });
|
159 | __webpack_require__.d(wallet_namespaceObject, "getPublicKeyEncoded", function() { return getPublicKeyEncoded; });
|
160 | __webpack_require__.d(wallet_namespaceObject, "getPublicKeyUnencoded", function() { return getPublicKeyUnencoded; });
|
161 | __webpack_require__.d(wallet_namespaceObject, "getPrivateKeyFromWIF", function() { return getPrivateKeyFromWIF; });
|
162 | __webpack_require__.d(wallet_namespaceObject, "getWIFFromPrivateKey", function() { return getWIFFromPrivateKey; });
|
163 | __webpack_require__.d(wallet_namespaceObject, "getPublicKeyFromPrivateKey", function() { return getPublicKeyFromPrivateKey; });
|
164 | __webpack_require__.d(wallet_namespaceObject, "getVerificationScriptFromPublicKey", function() { return getVerificationScriptFromPublicKey; });
|
165 | __webpack_require__.d(wallet_namespaceObject, "getScriptHashFromPublicKey", function() { return getScriptHashFromPublicKey; });
|
166 | __webpack_require__.d(wallet_namespaceObject, "getAddressFromScriptHash", function() { return getAddressFromScriptHash; });
|
167 | __webpack_require__.d(wallet_namespaceObject, "getScriptHashFromAddress", function() { return getScriptHashFromAddress; });
|
168 | __webpack_require__.d(wallet_namespaceObject, "generateSignature", function() { return generateSignature; });
|
169 | __webpack_require__.d(wallet_namespaceObject, "generatePrivateKey", function() { return generatePrivateKey; });
|
170 | __webpack_require__.d(wallet_namespaceObject, "encrypt", function() { return encrypt; });
|
171 | __webpack_require__.d(wallet_namespaceObject, "decrypt", function() { return decrypt; });
|
172 | __webpack_require__.d(wallet_namespaceObject, "isNEP2", function() { return isNEP2; });
|
173 | __webpack_require__.d(wallet_namespaceObject, "isWIF", function() { return isWIF; });
|
174 | __webpack_require__.d(wallet_namespaceObject, "isPrivateKey", function() { return isPrivateKey; });
|
175 | __webpack_require__.d(wallet_namespaceObject, "isPublicKey", function() { return isPublicKey; });
|
176 | __webpack_require__.d(wallet_namespaceObject, "isScriptHash", function() { return isScriptHash; });
|
177 | __webpack_require__.d(wallet_namespaceObject, "isAddress", function() { return isAddress; });
|
178 | __webpack_require__.d(wallet_namespaceObject, "curve", function() { return curve; });
|
179 | __webpack_require__.d(wallet_namespaceObject, "sign", function() { return sign; });
|
180 | __webpack_require__.d(wallet_namespaceObject, "verify", function() { return verify; });
|
181 | __webpack_require__.d(wallet_namespaceObject, "Wallet", function() { return Wallet_Wallet; });
|
182 | __webpack_require__.d(wallet_namespaceObject, "constructMultiSigVerificationScript", function() { return constructMultiSigVerificationScript; });
|
183 | __webpack_require__.d(wallet_namespaceObject, "getPublicKeysFromVerificationScript", function() { return getPublicKeysFromVerificationScript; });
|
184 | __webpack_require__.d(wallet_namespaceObject, "getSigningThresholdFromVerificationScript", function() { return getSigningThresholdFromVerificationScript; });
|
185 | __webpack_require__.d(wallet_namespaceObject, "getSignaturesFromInvocationScript", function() { return getSignaturesFromInvocationScript; });
|
186 | __webpack_require__.d(wallet_namespaceObject, "AssetBalance", function() { return AssetBalance_AssetBalance; });
|
187 | __webpack_require__.d(wallet_namespaceObject, "ClaimItem", function() { return ClaimItem_ClaimItem; });
|
188 | __webpack_require__.d(wallet_namespaceObject, "Coin", function() { return Coin_Coin; });
|
189 | var tx_namespaceObject = {};
|
190 | __webpack_require__.r(tx_namespaceObject);
|
191 | __webpack_require__.d(tx_namespaceObject, "defaultCalculationStrategy", function() { return defaultCalculationStrategy; });
|
192 | __webpack_require__.d(tx_namespaceObject, "smallestFirst", function() { return smallestFirst; });
|
193 | __webpack_require__.d(tx_namespaceObject, "biggestFirst", function() { return biggestFirst; });
|
194 | __webpack_require__.d(tx_namespaceObject, "balancedApproach", function() { return balancedApproach; });
|
195 | __webpack_require__.d(tx_namespaceObject, "TxAttrUsage", function() { return TxAttrUsage; });
|
196 | __webpack_require__.d(tx_namespaceObject, "TransactionAttribute", function() { return TransactionAttribute_TransactionAttribute; });
|
197 | __webpack_require__.d(tx_namespaceObject, "TransactionInput", function() { return TransactionInput_TransactionInput; });
|
198 | __webpack_require__.d(tx_namespaceObject, "TransactionOutput", function() { return TransactionOutput_TransactionOutput; });
|
199 | __webpack_require__.d(tx_namespaceObject, "Witness", function() { return Witness_Witness; });
|
200 | __webpack_require__.d(tx_namespaceObject, "StateType", function() { return StateType; });
|
201 | __webpack_require__.d(tx_namespaceObject, "StateDescriptor", function() { return StateDescriptor_StateDescriptor; });
|
202 | __webpack_require__.d(tx_namespaceObject, "BaseTransaction", function() { return BaseTransaction_BaseTransaction; });
|
203 | __webpack_require__.d(tx_namespaceObject, "Transaction", function() { return Transaction_Transaction; });
|
204 | __webpack_require__.d(tx_namespaceObject, "ClaimTransaction", function() { return ClaimTransaction_ClaimTransaction; });
|
205 | __webpack_require__.d(tx_namespaceObject, "ContractTransaction", function() { return ContractTransaction_ContractTransaction; });
|
206 | __webpack_require__.d(tx_namespaceObject, "InvocationTransaction", function() { return InvocationTransaction_InvocationTransaction; });
|
207 | __webpack_require__.d(tx_namespaceObject, "StateTransaction", function() { return StateTransaction_StateTransaction; });
|
208 | __webpack_require__.d(tx_namespaceObject, "MinerTransaction", function() { return MinerTransaction_MinerTransaction; });
|
209 | __webpack_require__.d(tx_namespaceObject, "IssueTransaction", function() { return IssueTransaction_IssueTransaction; });
|
210 | __webpack_require__.d(tx_namespaceObject, "RegisterTransaction", function() { return RegisterTransaction_RegisterTransaction; });
|
211 | __webpack_require__.d(tx_namespaceObject, "TransactionType", function() { return TransactionType; });
|
212 | __webpack_require__.d(tx_namespaceObject, "EnrollmentTransaction", function() { return EnrollmentTransaction_EnrollmentTransaction; });
|
213 | __webpack_require__.d(tx_namespaceObject, "PublishTransaction", function() { return PublishTransaction_PublishTransaction; });
|
214 | var settings_namespaceObject = {};
|
215 | __webpack_require__.r(settings_namespaceObject);
|
216 | __webpack_require__.d(settings_namespaceObject, "networks", function() { return networks; });
|
217 | __webpack_require__.d(settings_namespaceObject, "defaultCalculationStrategy", function() { return defaultCalculationStrategy; });
|
218 | __webpack_require__.d(settings_namespaceObject, "timeout", function() { return timeout; });
|
219 | var rpc_namespaceObject = {};
|
220 | __webpack_require__.r(rpc_namespaceObject);
|
221 | __webpack_require__.d(rpc_namespaceObject, "Network", function() { return Network_Network; });
|
222 | __webpack_require__.d(rpc_namespaceObject, "Protocol", function() { return Protocol_Protocol; });
|
223 | __webpack_require__.d(rpc_namespaceObject, "queryRPC", function() { return queryRPC; });
|
224 | __webpack_require__.d(rpc_namespaceObject, "Query", function() { return Query_Query; });
|
225 | __webpack_require__.d(rpc_namespaceObject, "RPCClient", function() { return RPCClient_RPCClient; });
|
226 | __webpack_require__.d(rpc_namespaceObject, "buildParser", function() { return buildParser; });
|
227 | __webpack_require__.d(rpc_namespaceObject, "NoOpParser", function() { return NoOpParser; });
|
228 | __webpack_require__.d(rpc_namespaceObject, "IntegerParser", function() { return IntegerParser; });
|
229 | __webpack_require__.d(rpc_namespaceObject, "StringParser", function() { return StringParser; });
|
230 | __webpack_require__.d(rpc_namespaceObject, "Fixed8Parser", function() { return Fixed8Parser; });
|
231 | __webpack_require__.d(rpc_namespaceObject, "SimpleParser", function() { return SimpleParser; });
|
232 |
|
233 |
|
234 | const ADDR_VERSION = "17";
|
235 | const ASSETS = {
|
236 | NEO: "NEO",
|
237 | c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b: "NEO",
|
238 | GAS: "GAS",
|
239 | "602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7": "GAS"
|
240 | };
|
241 | const ASSET_ID = {
|
242 | NEO: "c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b",
|
243 | GAS: "602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7"
|
244 | };
|
245 | const ASSET_TYPE = {
|
246 | CreditFlag: 0x40,
|
247 | DutyFlag: 0x80,
|
248 | GoverningToken: 0x00,
|
249 | UtilityToken: 0x01,
|
250 | Currency: 0x08,
|
251 | Share: 0x90,
|
252 | Invoice: 0x98,
|
253 | Token: 0x60
|
254 | };
|
255 | const CONTRACTS = {
|
256 | RPX: "ecc6b20d3ccac1ee9ef109af5a7cdb85706b1df9",
|
257 | TEST_RPX: "5b7074e873973a6ed3708862f219a6fbf4d1c411",
|
258 | TEST_LWTF: "d7678dd97c000be3f33e9362e673101bac4ca654",
|
259 | TEST_NXT: "0b6c1f919e95fe61c17a7612aebfaf4fda3a2214",
|
260 | TEST_RHTT4: "f9572c5b119a6b5775a6af07f1cef5d310038f55"
|
261 | };
|
262 | const DEFAULT_RPC = {
|
263 | MAIN: "https://seed11.ngd.network:10331",
|
264 | TEST: "https://seed11.ngd.network:20331"
|
265 | };
|
266 | const DEFAULT_REQ = {
|
267 | jsonrpc: "2.0",
|
268 | method: "getblockcount",
|
269 | params: [],
|
270 | id: 1234
|
271 | };
|
272 | const DEFAULT_SCRYPT = {
|
273 | n: 16384,
|
274 | r: 8,
|
275 | p: 8,
|
276 | size: 64
|
277 | };
|
278 | const DEFAULT_SYSFEE = {
|
279 | enrollmentTransaction: 1000,
|
280 | issueTransaction: 500,
|
281 | publishTransaction: 500,
|
282 | registerTransaction: 10000
|
283 | };
|
284 | const DEFAULT_WALLET = {
|
285 | name: "myWallet",
|
286 | version: "1.0",
|
287 | scrypt: DEFAULT_SCRYPT,
|
288 | extra: null
|
289 | };
|
290 | const DEFAULT_ACCOUNT_CONTRACT = {
|
291 | script: "",
|
292 | parameters: [
|
293 | {
|
294 | name: "signature",
|
295 | type: "Signature"
|
296 | }
|
297 | ],
|
298 | deployed: false
|
299 | };
|
300 | const NEO_NETWORK = {
|
301 | MAIN: "MainNet",
|
302 | TEST: "TestNet"
|
303 | };
|
304 |
|
305 | const NEP_HEADER = "0142";
|
306 | const NEP_FLAG = "e0";
|
307 | const RPC_VERSION = "2.3.2";
|
308 | const TX_VERSION = {
|
309 | CLAIM: 0,
|
310 | CONTRACT: 0,
|
311 | INVOCATION: 1,
|
312 | ISSUE: 0,
|
313 | STATE: 0,
|
314 | MINER: 0,
|
315 | ENROLLMENT: 0,
|
316 | PUBLISH: 0,
|
317 | REGISTER: 0
|
318 | };
|
319 |
|
320 |
|
321 | var loglevel = __webpack_require__(11);
|
322 | var loglevel_default = __webpack_require__.n(loglevel);
|
323 |
|
324 |
|
325 | var loglevel_plugin_prefix = __webpack_require__(23);
|
326 | var loglevel_plugin_prefix_default = __webpack_require__.n(loglevel_plugin_prefix);
|
327 |
|
328 |
|
329 |
|
330 |
|
331 | loglevel_plugin_prefix_default.a.reg(loglevel_default.a);
|
332 | loglevel_default.a.setDefaultLevel("silent");
|
333 | function setAll(lvl) {
|
334 | Object.keys(loglevel_default.a.getLoggers()).map(key => {
|
335 | const lg = loglevel_default.a.getLogger(key);
|
336 | lg.setLevel(lvl);
|
337 | });
|
338 | }
|
339 | const fn = (level, name, timestamp) => {
|
340 | const ts = timestamp ? timestamp : new Date().toUTCString();
|
341 | level = level.toUpperCase();
|
342 | return `[${ts}] (${name}) ${level}: `;
|
343 | };
|
344 | var logging = ((label) => {
|
345 | const l = loglevel_default.a.getLogger(label);
|
346 | loglevel_plugin_prefix_default.a.apply(l, { format: fn });
|
347 | return l;
|
348 | });
|
349 | const logger = loglevel_default.a;
|
350 |
|
351 |
|
352 | function compareNeonObjectArray(arr1, arr2 = []) {
|
353 | if (arr1.length !== arr2.length) {
|
354 | return false;
|
355 | }
|
356 | for (const c of arr1) {
|
357 | if (!arr2.find(cl => c.equals(c))) {
|
358 | return false;
|
359 | }
|
360 | }
|
361 | return true;
|
362 | }
|
363 | function compareObject(current, other) {
|
364 | const keys = Object.keys(current);
|
365 | const otherKeys = Object.keys(other);
|
366 | if (keys.length !== otherKeys.length) {
|
367 | return false;
|
368 | }
|
369 | for (const key of keys) {
|
370 | if (other[key] !== undefined && current[key] === other[key]) {
|
371 | continue;
|
372 | }
|
373 | return false;
|
374 | }
|
375 | return true;
|
376 | }
|
377 | function compareUnsortedPlainArrays(current, other) {
|
378 | if (!Array.isArray(current) ||
|
379 | !Array.isArray(other) ||
|
380 | current.length !== other.length) {
|
381 | return false;
|
382 | }
|
383 | for (let i = 0; i < current.length; i++) {
|
384 | if (current[i] !== other[i]) {
|
385 | return false;
|
386 | }
|
387 | }
|
388 | return true;
|
389 | }
|
390 | function compareArray(current, other) {
|
391 | if (current.length !== other.length) {
|
392 | return false;
|
393 | }
|
394 | for (let i = 0; i < current.length; i++) {
|
395 | if (typeof current[i] === "object" && typeof other[i] === "object") {
|
396 | const objectEquality = compareObject(current[i], other[i]);
|
397 | if (!objectEquality) {
|
398 | return false;
|
399 | }
|
400 | }
|
401 | if (current[i] !== other[i]) {
|
402 | return false;
|
403 | }
|
404 | }
|
405 | return true;
|
406 | }
|
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 | const log = logging("protocol");
|
413 | function compareArrays(current, other) {
|
414 | if (current.length !== other.length) {
|
415 | return false;
|
416 | }
|
417 | for (let i = 0; i < current.length; i++) {
|
418 | if (current[i] !== other[i]) {
|
419 | return false;
|
420 | }
|
421 | }
|
422 | return true;
|
423 | }
|
424 |
|
425 |
|
426 |
|
427 | class Protocol_Protocol {
|
428 | constructor(config = {}) {
|
429 | this.magic = config.magic || config.Magic || 0;
|
430 | this.addressVersion = config.addressVersion || config.AddressVersion || 23;
|
431 | this.standbyValidators =
|
432 | config.standbyValidators || config.StandbyValidators || [];
|
433 | this.seedList = config.seedList || config.SeedList || [];
|
434 | this.systemFee = Object.assign({}, config.systemFee || config.SystemFee || DEFAULT_SYSFEE);
|
435 | }
|
436 | get [Symbol.toStringTag]() {
|
437 | return "Protocol";
|
438 | }
|
439 | export() {
|
440 | return {
|
441 | Magic: this.magic,
|
442 | AddressVersion: this.addressVersion,
|
443 | StandbyValidators: this.standbyValidators,
|
444 | SeedList: this.seedList,
|
445 | SystemFee: this.systemFee
|
446 | };
|
447 | }
|
448 | equals(other) {
|
449 | return (this.magic === (other.magic || other.Magic) &&
|
450 | this.addressVersion === (other.addressVersion || other.AddressVersion) &&
|
451 | compareArrays(this.seedList, other.seedList || other.SeedList || []) &&
|
452 | compareArrays(this.standbyValidators, other.standbyValidators || other.StandbyValidators || []) &&
|
453 | compareObject(this.systemFee, other.systemFee || other.SystemFee || {}));
|
454 | }
|
455 | }
|
456 | var rpc_Protocol = (Protocol_Protocol);
|
457 |
|
458 |
|
459 |
|
460 |
|
461 |
|
462 | const Network_log = logging("protocol");
|
463 |
|
464 |
|
465 |
|
466 |
|
467 |
|
468 | class Network_Network {
|
469 | constructor(config = {}, name = null) {
|
470 | this.name = config.Name || config.name || name || "RandomNet";
|
471 | const protocolLike = Object.assign({}, config.protocol || config.ProtocolConfiguration || {});
|
472 | this.protocol = new rpc_Protocol(protocolLike);
|
473 | this.nodes = config.Nodes || config.nodes || [];
|
474 | this.extra = Object.assign({}, config.ExtraConfiguration || config.extra || {});
|
475 | }
|
476 | |
477 |
|
478 |
|
479 | export() {
|
480 | return {
|
481 | ProtocolConfiguration: this.protocol.export(),
|
482 | Name: this.name,
|
483 | ExtraConfiguration: this.extra,
|
484 | Nodes: this.nodes
|
485 | };
|
486 | }
|
487 | equals(other) {
|
488 | return (this.name === other.name &&
|
489 | this.protocol.equals(other.protocol || {}) &&
|
490 | compareUnsortedPlainArrays(this.nodes, other.nodes || []) &&
|
491 | compareObject(this.extra, other.extra || {}));
|
492 | }
|
493 | }
|
494 | var rpc_Network = (Network_Network);
|
495 |
|
496 |
|
497 | var axios = __webpack_require__(1);
|
498 | var axios_default = __webpack_require__.n(axios);
|
499 |
|
500 |
|
501 |
|
502 |
|
503 |
|
504 |
|
505 |
|
506 |
|
507 |
|
508 |
|
509 |
|
510 |
|
511 |
|
512 |
|
513 |
|
514 |
|
515 |
|
516 |
|
517 |
|
518 |
|
519 |
|
520 |
|
521 |
|
522 |
|
523 |
|
524 |
|
525 |
|
526 |
|
527 |
|
528 |
|
529 |
|
530 |
|
531 |
|
532 |
|
533 |
|
534 |
|
535 |
|
536 |
|
537 |
|
538 |
|
539 |
|
540 |
|
541 |
|
542 |
|
543 |
|
544 |
|
545 |
|
546 |
|
547 |
|
548 |
|
549 | var isNumeric = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,
|
550 |
|
551 | mathceil = Math.ceil,
|
552 | mathfloor = Math.floor,
|
553 |
|
554 | bignumberError = '[BigNumber Error] ',
|
555 | tooManyDigits = bignumberError + 'Number primitive has more than 15 significant digits: ',
|
556 |
|
557 | BASE = 1e14,
|
558 | LOG_BASE = 14,
|
559 | MAX_SAFE_INTEGER = 0x1fffffffffffff,
|
560 |
|
561 | POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13],
|
562 | SQRT_BASE = 1e7,
|
563 |
|
564 |
|
565 |
|
566 |
|
567 | MAX = 1E9;
|
568 |
|
569 |
|
570 |
|
571 |
|
572 |
|
573 | function clone(configObject) {
|
574 | var div, convertBase, parseNumeric,
|
575 | P = BigNumber.prototype = { constructor: BigNumber, toString: null, valueOf: null },
|
576 | ONE = new BigNumber(1),
|
577 |
|
578 |
|
579 |
|
580 |
|
581 |
|
582 |
|
583 |
|
584 |
|
585 |
|
586 | DECIMAL_PLACES = 20,
|
587 |
|
588 |
|
589 |
|
590 |
|
591 |
|
592 |
|
593 |
|
594 |
|
595 |
|
596 |
|
597 |
|
598 |
|
599 | ROUNDING_MODE = 4,
|
600 |
|
601 |
|
602 |
|
603 |
|
604 |
|
605 | TO_EXP_NEG = -7,
|
606 |
|
607 |
|
608 |
|
609 | TO_EXP_POS = 21,
|
610 |
|
611 |
|
612 |
|
613 |
|
614 |
|
615 | MIN_EXP = -1e7,
|
616 |
|
617 |
|
618 |
|
619 |
|
620 | MAX_EXP = 1e7,
|
621 |
|
622 |
|
623 | CRYPTO = false,
|
624 |
|
625 |
|
626 |
|
627 |
|
628 |
|
629 |
|
630 |
|
631 |
|
632 |
|
633 |
|
634 |
|
635 |
|
636 |
|
637 |
|
638 |
|
639 |
|
640 |
|
641 | MODULO_MODE = 1,
|
642 |
|
643 |
|
644 |
|
645 | POW_PRECISION = 0,
|
646 |
|
647 |
|
648 | FORMAT = {
|
649 | decimalSeparator: '.',
|
650 | groupSeparator: ',',
|
651 | groupSize: 3,
|
652 | secondaryGroupSize: 0,
|
653 | fractionGroupSeparator: '\xA0',
|
654 | fractionGroupSize: 0
|
655 | },
|
656 |
|
657 |
|
658 |
|
659 |
|
660 | ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyz';
|
661 |
|
662 |
|
663 |
|
664 |
|
665 |
|
666 |
|
667 |
|
668 |
|
669 | |
670 |
|
671 |
|
672 |
|
673 |
|
674 |
|
675 |
|
676 | function BigNumber(n, b) {
|
677 | var alphabet, c, caseChanged, e, i, isNum, len, str,
|
678 | x = this;
|
679 |
|
680 |
|
681 | if (!(x instanceof BigNumber)) {
|
682 |
|
683 |
|
684 |
|
685 |
|
686 | return new BigNumber(n, b);
|
687 | }
|
688 |
|
689 | if (b == null) {
|
690 |
|
691 |
|
692 | if (n instanceof BigNumber) {
|
693 | x.s = n.s;
|
694 | x.e = n.e;
|
695 | x.c = (n = n.c) ? n.slice() : n;
|
696 | return;
|
697 | }
|
698 |
|
699 | isNum = typeof n == 'number';
|
700 |
|
701 | if (isNum && n * 0 == 0) {
|
702 |
|
703 |
|
704 | x.s = 1 / n < 0 ? (n = -n, -1) : 1;
|
705 |
|
706 |
|
707 | if (n === ~~n) {
|
708 | for (e = 0, i = n; i >= 10; i /= 10, e++);
|
709 | x.e = e;
|
710 | x.c = [n];
|
711 | return;
|
712 | }
|
713 |
|
714 | str = n + '';
|
715 | } else {
|
716 | if (!isNumeric.test(str = n + '')) return parseNumeric(x, str, isNum);
|
717 | x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;
|
718 | }
|
719 |
|
720 |
|
721 | if ((e = str.indexOf('.')) > -1) str = str.replace('.', '');
|
722 |
|
723 |
|
724 | if ((i = str.search(/e/i)) > 0) {
|
725 |
|
726 |
|
727 | if (e < 0) e = i;
|
728 | e += +str.slice(i + 1);
|
729 | str = str.substring(0, i);
|
730 | } else if (e < 0) {
|
731 |
|
732 |
|
733 | e = str.length;
|
734 | }
|
735 |
|
736 | } else {
|
737 |
|
738 |
|
739 | intCheck(b, 2, ALPHABET.length, 'Base');
|
740 | str = n + '';
|
741 |
|
742 |
|
743 |
|
744 | if (b == 10) {
|
745 | x = new BigNumber(n instanceof BigNumber ? n : str);
|
746 | return round(x, DECIMAL_PLACES + x.e + 1, ROUNDING_MODE);
|
747 | }
|
748 |
|
749 | isNum = typeof n == 'number';
|
750 |
|
751 | if (isNum) {
|
752 |
|
753 |
|
754 | if (n * 0 != 0) return parseNumeric(x, str, isNum, b);
|
755 |
|
756 | x.s = 1 / n < 0 ? (str = str.slice(1), -1) : 1;
|
757 |
|
758 |
|
759 | if (BigNumber.DEBUG && str.replace(/^0\.0*|\./, '').length > 15) {
|
760 | throw Error
|
761 | (tooManyDigits + n);
|
762 | }
|
763 |
|
764 |
|
765 | isNum = false;
|
766 | } else {
|
767 | x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;
|
768 | }
|
769 |
|
770 | alphabet = ALPHABET.slice(0, b);
|
771 | e = i = 0;
|
772 |
|
773 |
|
774 |
|
775 | for (len = str.length; i < len; i++) {
|
776 | if (alphabet.indexOf(c = str.charAt(i)) < 0) {
|
777 | if (c == '.') {
|
778 |
|
779 |
|
780 | if (i > e) {
|
781 | e = len;
|
782 | continue;
|
783 | }
|
784 | } else if (!caseChanged) {
|
785 |
|
786 |
|
787 | if (str == str.toUpperCase() && (str = str.toLowerCase()) ||
|
788 | str == str.toLowerCase() && (str = str.toUpperCase())) {
|
789 | caseChanged = true;
|
790 | i = -1;
|
791 | e = 0;
|
792 | continue;
|
793 | }
|
794 | }
|
795 |
|
796 | return parseNumeric(x, n + '', isNum, b);
|
797 | }
|
798 | }
|
799 |
|
800 | str = convertBase(str, b, 10, x.s);
|
801 |
|
802 |
|
803 | if ((e = str.indexOf('.')) > -1) str = str.replace('.', '');
|
804 | else e = str.length;
|
805 | }
|
806 |
|
807 |
|
808 | for (i = 0; str.charCodeAt(i) === 48; i++);
|
809 |
|
810 |
|
811 | for (len = str.length; str.charCodeAt(--len) === 48;);
|
812 |
|
813 | str = str.slice(i, ++len);
|
814 |
|
815 | if (str) {
|
816 | len -= i;
|
817 |
|
818 |
|
819 | if (isNum && BigNumber.DEBUG &&
|
820 | len > 15 && (n > MAX_SAFE_INTEGER || n !== mathfloor(n))) {
|
821 | throw Error
|
822 | (tooManyDigits + (x.s * n));
|
823 | }
|
824 |
|
825 | e = e - i - 1;
|
826 |
|
827 |
|
828 | if (e > MAX_EXP) {
|
829 |
|
830 |
|
831 | x.c = x.e = null;
|
832 |
|
833 |
|
834 | } else if (e < MIN_EXP) {
|
835 |
|
836 |
|
837 | x.c = [x.e = 0];
|
838 | } else {
|
839 | x.e = e;
|
840 | x.c = [];
|
841 |
|
842 |
|
843 |
|
844 |
|
845 |
|
846 | i = (e + 1) % LOG_BASE;
|
847 | if (e < 0) i += LOG_BASE;
|
848 |
|
849 | if (i < len) {
|
850 | if (i) x.c.push(+str.slice(0, i));
|
851 |
|
852 | for (len -= LOG_BASE; i < len;) {
|
853 | x.c.push(+str.slice(i, i += LOG_BASE));
|
854 | }
|
855 |
|
856 | str = str.slice(i);
|
857 | i = LOG_BASE - str.length;
|
858 | } else {
|
859 | i -= len;
|
860 | }
|
861 |
|
862 | for (; i--; str += '0');
|
863 | x.c.push(+str);
|
864 | }
|
865 | } else {
|
866 |
|
867 |
|
868 | x.c = [x.e = 0];
|
869 | }
|
870 | }
|
871 |
|
872 |
|
873 |
|
874 |
|
875 |
|
876 | BigNumber.clone = clone;
|
877 |
|
878 | BigNumber.ROUND_UP = 0;
|
879 | BigNumber.ROUND_DOWN = 1;
|
880 | BigNumber.ROUND_CEIL = 2;
|
881 | BigNumber.ROUND_FLOOR = 3;
|
882 | BigNumber.ROUND_HALF_UP = 4;
|
883 | BigNumber.ROUND_HALF_DOWN = 5;
|
884 | BigNumber.ROUND_HALF_EVEN = 6;
|
885 | BigNumber.ROUND_HALF_CEIL = 7;
|
886 | BigNumber.ROUND_HALF_FLOOR = 8;
|
887 | BigNumber.EUCLID = 9;
|
888 |
|
889 |
|
890 | |
891 |
|
892 |
|
893 |
|
894 |
|
895 |
|
896 |
|
897 |
|
898 |
|
899 |
|
900 |
|
901 |
|
902 |
|
903 |
|
904 |
|
905 |
|
906 |
|
907 |
|
908 |
|
909 |
|
910 |
|
911 |
|
912 |
|
913 |
|
914 |
|
915 |
|
916 |
|
917 |
|
918 |
|
919 |
|
920 |
|
921 |
|
922 | BigNumber.config = BigNumber.set = function (obj) {
|
923 | var p, v;
|
924 |
|
925 | if (obj != null) {
|
926 |
|
927 | if (typeof obj == 'object') {
|
928 |
|
929 |
|
930 |
|
931 | if (obj.hasOwnProperty(p = 'DECIMAL_PLACES')) {
|
932 | v = obj[p];
|
933 | intCheck(v, 0, MAX, p);
|
934 | DECIMAL_PLACES = v;
|
935 | }
|
936 |
|
937 |
|
938 |
|
939 | if (obj.hasOwnProperty(p = 'ROUNDING_MODE')) {
|
940 | v = obj[p];
|
941 | intCheck(v, 0, 8, p);
|
942 | ROUNDING_MODE = v;
|
943 | }
|
944 |
|
945 |
|
946 |
|
947 |
|
948 |
|
949 | if (obj.hasOwnProperty(p = 'EXPONENTIAL_AT')) {
|
950 | v = obj[p];
|
951 | if (isArray(v)) {
|
952 | intCheck(v[0], -MAX, 0, p);
|
953 | intCheck(v[1], 0, MAX, p);
|
954 | TO_EXP_NEG = v[0];
|
955 | TO_EXP_POS = v[1];
|
956 | } else {
|
957 | intCheck(v, -MAX, MAX, p);
|
958 | TO_EXP_NEG = -(TO_EXP_POS = v < 0 ? -v : v);
|
959 | }
|
960 | }
|
961 |
|
962 |
|
963 |
|
964 |
|
965 | if (obj.hasOwnProperty(p = 'RANGE')) {
|
966 | v = obj[p];
|
967 | if (isArray(v)) {
|
968 | intCheck(v[0], -MAX, -1, p);
|
969 | intCheck(v[1], 1, MAX, p);
|
970 | MIN_EXP = v[0];
|
971 | MAX_EXP = v[1];
|
972 | } else {
|
973 | intCheck(v, -MAX, MAX, p);
|
974 | if (v) {
|
975 | MIN_EXP = -(MAX_EXP = v < 0 ? -v : v);
|
976 | } else {
|
977 | throw Error
|
978 | (bignumberError + p + ' cannot be zero: ' + v);
|
979 | }
|
980 | }
|
981 | }
|
982 |
|
983 |
|
984 |
|
985 |
|
986 | if (obj.hasOwnProperty(p = 'CRYPTO')) {
|
987 | v = obj[p];
|
988 | if (v === !!v) {
|
989 | if (v) {
|
990 | if (typeof crypto != 'undefined' && crypto &&
|
991 | (crypto.getRandomValues || crypto.randomBytes)) {
|
992 | CRYPTO = v;
|
993 | } else {
|
994 | CRYPTO = !v;
|
995 | throw Error
|
996 | (bignumberError + 'crypto unavailable');
|
997 | }
|
998 | } else {
|
999 | CRYPTO = v;
|
1000 | }
|
1001 | } else {
|
1002 | throw Error
|
1003 | (bignumberError + p + ' not true or false: ' + v);
|
1004 | }
|
1005 | }
|
1006 |
|
1007 |
|
1008 |
|
1009 | if (obj.hasOwnProperty(p = 'MODULO_MODE')) {
|
1010 | v = obj[p];
|
1011 | intCheck(v, 0, 9, p);
|
1012 | MODULO_MODE = v;
|
1013 | }
|
1014 |
|
1015 |
|
1016 |
|
1017 | if (obj.hasOwnProperty(p = 'POW_PRECISION')) {
|
1018 | v = obj[p];
|
1019 | intCheck(v, 0, MAX, p);
|
1020 | POW_PRECISION = v;
|
1021 | }
|
1022 |
|
1023 |
|
1024 |
|
1025 | if (obj.hasOwnProperty(p = 'FORMAT')) {
|
1026 | v = obj[p];
|
1027 | if (typeof v == 'object') FORMAT = v;
|
1028 | else throw Error
|
1029 | (bignumberError + p + ' not an object: ' + v);
|
1030 | }
|
1031 |
|
1032 |
|
1033 |
|
1034 | if (obj.hasOwnProperty(p = 'ALPHABET')) {
|
1035 | v = obj[p];
|
1036 |
|
1037 |
|
1038 | if (typeof v == 'string' && !/^.$|\.|(.).*\1/.test(v)) {
|
1039 | ALPHABET = v;
|
1040 | } else {
|
1041 | throw Error
|
1042 | (bignumberError + p + ' invalid: ' + v);
|
1043 | }
|
1044 | }
|
1045 |
|
1046 | } else {
|
1047 |
|
1048 |
|
1049 | throw Error
|
1050 | (bignumberError + 'Object expected: ' + obj);
|
1051 | }
|
1052 | }
|
1053 |
|
1054 | return {
|
1055 | DECIMAL_PLACES: DECIMAL_PLACES,
|
1056 | ROUNDING_MODE: ROUNDING_MODE,
|
1057 | EXPONENTIAL_AT: [TO_EXP_NEG, TO_EXP_POS],
|
1058 | RANGE: [MIN_EXP, MAX_EXP],
|
1059 | CRYPTO: CRYPTO,
|
1060 | MODULO_MODE: MODULO_MODE,
|
1061 | POW_PRECISION: POW_PRECISION,
|
1062 | FORMAT: FORMAT,
|
1063 | ALPHABET: ALPHABET
|
1064 | };
|
1065 | };
|
1066 |
|
1067 |
|
1068 | |
1069 |
|
1070 |
|
1071 |
|
1072 |
|
1073 | BigNumber.isBigNumber = function (v) {
|
1074 | return v instanceof BigNumber || v && v._isBigNumber === true || false;
|
1075 | };
|
1076 |
|
1077 |
|
1078 | |
1079 |
|
1080 |
|
1081 |
|
1082 |
|
1083 | BigNumber.maximum = BigNumber.max = function () {
|
1084 | return maxOrMin(arguments, P.lt);
|
1085 | };
|
1086 |
|
1087 |
|
1088 | |
1089 |
|
1090 |
|
1091 |
|
1092 |
|
1093 | BigNumber.minimum = BigNumber.min = function () {
|
1094 | return maxOrMin(arguments, P.gt);
|
1095 | };
|
1096 |
|
1097 |
|
1098 | |
1099 |
|
1100 |
|
1101 |
|
1102 |
|
1103 |
|
1104 |
|
1105 |
|
1106 |
|
1107 |
|
1108 | BigNumber.random = (function () {
|
1109 | var pow2_53 = 0x20000000000000;
|
1110 |
|
1111 |
|
1112 |
|
1113 |
|
1114 |
|
1115 | var random53bitInt = (Math.random() * pow2_53) & 0x1fffff
|
1116 | ? function () { return mathfloor(Math.random() * pow2_53); }
|
1117 | : function () { return ((Math.random() * 0x40000000 | 0) * 0x800000) +
|
1118 | (Math.random() * 0x800000 | 0); };
|
1119 |
|
1120 | return function (dp) {
|
1121 | var a, b, e, k, v,
|
1122 | i = 0,
|
1123 | c = [],
|
1124 | rand = new BigNumber(ONE);
|
1125 |
|
1126 | if (dp == null) dp = DECIMAL_PLACES;
|
1127 | else intCheck(dp, 0, MAX);
|
1128 |
|
1129 | k = mathceil(dp / LOG_BASE);
|
1130 |
|
1131 | if (CRYPTO) {
|
1132 |
|
1133 |
|
1134 | if (crypto.getRandomValues) {
|
1135 |
|
1136 | a = crypto.getRandomValues(new Uint32Array(k *= 2));
|
1137 |
|
1138 | for (; i < k;) {
|
1139 |
|
1140 |
|
1141 |
|
1142 |
|
1143 |
|
1144 |
|
1145 |
|
1146 | v = a[i] * 0x20000 + (a[i + 1] >>> 11);
|
1147 |
|
1148 |
|
1149 |
|
1150 |
|
1151 |
|
1152 | if (v >= 9e15) {
|
1153 | b = crypto.getRandomValues(new Uint32Array(2));
|
1154 | a[i] = b[0];
|
1155 | a[i + 1] = b[1];
|
1156 | } else {
|
1157 |
|
1158 |
|
1159 |
|
1160 | c.push(v % 1e14);
|
1161 | i += 2;
|
1162 | }
|
1163 | }
|
1164 | i = k / 2;
|
1165 |
|
1166 |
|
1167 | } else if (crypto.randomBytes) {
|
1168 |
|
1169 |
|
1170 | a = crypto.randomBytes(k *= 7);
|
1171 |
|
1172 | for (; i < k;) {
|
1173 |
|
1174 |
|
1175 |
|
1176 |
|
1177 |
|
1178 | v = ((a[i] & 31) * 0x1000000000000) + (a[i + 1] * 0x10000000000) +
|
1179 | (a[i + 2] * 0x100000000) + (a[i + 3] * 0x1000000) +
|
1180 | (a[i + 4] << 16) + (a[i + 5] << 8) + a[i + 6];
|
1181 |
|
1182 | if (v >= 9e15) {
|
1183 | crypto.randomBytes(7).copy(a, i);
|
1184 | } else {
|
1185 |
|
1186 |
|
1187 | c.push(v % 1e14);
|
1188 | i += 7;
|
1189 | }
|
1190 | }
|
1191 | i = k / 7;
|
1192 | } else {
|
1193 | CRYPTO = false;
|
1194 | throw Error
|
1195 | (bignumberError + 'crypto unavailable');
|
1196 | }
|
1197 | }
|
1198 |
|
1199 |
|
1200 | if (!CRYPTO) {
|
1201 |
|
1202 | for (; i < k;) {
|
1203 | v = random53bitInt();
|
1204 | if (v < 9e15) c[i++] = v % 1e14;
|
1205 | }
|
1206 | }
|
1207 |
|
1208 | k = c[--i];
|
1209 | dp %= LOG_BASE;
|
1210 |
|
1211 |
|
1212 | if (k && dp) {
|
1213 | v = POWS_TEN[LOG_BASE - dp];
|
1214 | c[i] = mathfloor(k / v) * v;
|
1215 | }
|
1216 |
|
1217 |
|
1218 | for (; c[i] === 0; c.pop(), i--);
|
1219 |
|
1220 |
|
1221 | if (i < 0) {
|
1222 | c = [e = 0];
|
1223 | } else {
|
1224 |
|
1225 |
|
1226 | for (e = -1 ; c[0] === 0; c.splice(0, 1), e -= LOG_BASE);
|
1227 |
|
1228 |
|
1229 | for (i = 1, v = c[0]; v >= 10; v /= 10, i++);
|
1230 |
|
1231 |
|
1232 | if (i < LOG_BASE) e -= LOG_BASE - i;
|
1233 | }
|
1234 |
|
1235 | rand.e = e;
|
1236 | rand.c = c;
|
1237 | return rand;
|
1238 | };
|
1239 | })();
|
1240 |
|
1241 |
|
1242 |
|
1243 |
|
1244 |
|
1245 |
|
1246 | convertBase = (function () {
|
1247 | var decimal = '0123456789';
|
1248 |
|
1249 | |
1250 |
|
1251 |
|
1252 |
|
1253 |
|
1254 | function toBaseOut(str, baseIn, baseOut, alphabet) {
|
1255 | var j,
|
1256 | arr = [0],
|
1257 | arrL,
|
1258 | i = 0,
|
1259 | len = str.length;
|
1260 |
|
1261 | for (; i < len;) {
|
1262 | for (arrL = arr.length; arrL--; arr[arrL] *= baseIn);
|
1263 |
|
1264 | arr[0] += alphabet.indexOf(str.charAt(i++));
|
1265 |
|
1266 | for (j = 0; j < arr.length; j++) {
|
1267 |
|
1268 | if (arr[j] > baseOut - 1) {
|
1269 | if (arr[j + 1] == null) arr[j + 1] = 0;
|
1270 | arr[j + 1] += arr[j] / baseOut | 0;
|
1271 | arr[j] %= baseOut;
|
1272 | }
|
1273 | }
|
1274 | }
|
1275 |
|
1276 | return arr.reverse();
|
1277 | }
|
1278 |
|
1279 |
|
1280 |
|
1281 |
|
1282 | return function (str, baseIn, baseOut, sign, callerIsToString) {
|
1283 | var alphabet, d, e, k, r, x, xc, y,
|
1284 | i = str.indexOf('.'),
|
1285 | dp = DECIMAL_PLACES,
|
1286 | rm = ROUNDING_MODE;
|
1287 |
|
1288 |
|
1289 | if (i >= 0) {
|
1290 | k = POW_PRECISION;
|
1291 |
|
1292 |
|
1293 | POW_PRECISION = 0;
|
1294 | str = str.replace('.', '');
|
1295 | y = new BigNumber(baseIn);
|
1296 | x = y.pow(str.length - i);
|
1297 | POW_PRECISION = k;
|
1298 |
|
1299 |
|
1300 |
|
1301 |
|
1302 | y.c = toBaseOut(toFixedPoint(coeffToString(x.c), x.e, '0'),
|
1303 | 10, baseOut, decimal);
|
1304 | y.e = y.c.length;
|
1305 | }
|
1306 |
|
1307 |
|
1308 |
|
1309 | xc = toBaseOut(str, baseIn, baseOut, callerIsToString
|
1310 | ? (alphabet = ALPHABET, decimal)
|
1311 | : (alphabet = decimal, ALPHABET));
|
1312 |
|
1313 |
|
1314 | e = k = xc.length;
|
1315 |
|
1316 |
|
1317 | for (; xc[--k] == 0; xc.pop());
|
1318 |
|
1319 |
|
1320 | if (!xc[0]) return alphabet.charAt(0);
|
1321 |
|
1322 |
|
1323 | if (i < 0) {
|
1324 | --e;
|
1325 | } else {
|
1326 | x.c = xc;
|
1327 | x.e = e;
|
1328 |
|
1329 |
|
1330 | x.s = sign;
|
1331 | x = div(x, y, dp, rm, baseOut);
|
1332 | xc = x.c;
|
1333 | r = x.r;
|
1334 | e = x.e;
|
1335 | }
|
1336 |
|
1337 |
|
1338 |
|
1339 |
|
1340 | d = e + dp + 1;
|
1341 |
|
1342 |
|
1343 | i = xc[d];
|
1344 |
|
1345 |
|
1346 |
|
1347 | k = baseOut / 2;
|
1348 | r = r || d < 0 || xc[d + 1] != null;
|
1349 |
|
1350 | r = rm < 4 ? (i != null || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2))
|
1351 | : i > k || i == k &&(rm == 4 || r || rm == 6 && xc[d - 1] & 1 ||
|
1352 | rm == (x.s < 0 ? 8 : 7));
|
1353 |
|
1354 |
|
1355 |
|
1356 |
|
1357 | if (d < 1 || !xc[0]) {
|
1358 |
|
1359 |
|
1360 | str = r ? toFixedPoint(alphabet.charAt(1), -dp, alphabet.charAt(0))
|
1361 | : alphabet.charAt(0);
|
1362 | } else {
|
1363 |
|
1364 |
|
1365 | xc.length = d;
|
1366 |
|
1367 |
|
1368 | if (r) {
|
1369 |
|
1370 |
|
1371 | for (--baseOut; ++xc[--d] > baseOut;) {
|
1372 | xc[d] = 0;
|
1373 |
|
1374 | if (!d) {
|
1375 | ++e;
|
1376 | xc = [1].concat(xc);
|
1377 | }
|
1378 | }
|
1379 | }
|
1380 |
|
1381 |
|
1382 | for (k = xc.length; !xc[--k];);
|
1383 |
|
1384 |
|
1385 | for (i = 0, str = ''; i <= k; str += alphabet.charAt(xc[i++]));
|
1386 |
|
1387 |
|
1388 | str = toFixedPoint(str, e, alphabet.charAt(0));
|
1389 | }
|
1390 |
|
1391 |
|
1392 | return str;
|
1393 | };
|
1394 | })();
|
1395 |
|
1396 |
|
1397 |
|
1398 | div = (function () {
|
1399 |
|
1400 |
|
1401 | function multiply(x, k, base) {
|
1402 | var m, temp, xlo, xhi,
|
1403 | carry = 0,
|
1404 | i = x.length,
|
1405 | klo = k % SQRT_BASE,
|
1406 | khi = k / SQRT_BASE | 0;
|
1407 |
|
1408 | for (x = x.slice(); i--;) {
|
1409 | xlo = x[i] % SQRT_BASE;
|
1410 | xhi = x[i] / SQRT_BASE | 0;
|
1411 | m = khi * xlo + xhi * klo;
|
1412 | temp = klo * xlo + ((m % SQRT_BASE) * SQRT_BASE) + carry;
|
1413 | carry = (temp / base | 0) + (m / SQRT_BASE | 0) + khi * xhi;
|
1414 | x[i] = temp % base;
|
1415 | }
|
1416 |
|
1417 | if (carry) x = [carry].concat(x);
|
1418 |
|
1419 | return x;
|
1420 | }
|
1421 |
|
1422 | function compare(a, b, aL, bL) {
|
1423 | var i, cmp;
|
1424 |
|
1425 | if (aL != bL) {
|
1426 | cmp = aL > bL ? 1 : -1;
|
1427 | } else {
|
1428 |
|
1429 | for (i = cmp = 0; i < aL; i++) {
|
1430 |
|
1431 | if (a[i] != b[i]) {
|
1432 | cmp = a[i] > b[i] ? 1 : -1;
|
1433 | break;
|
1434 | }
|
1435 | }
|
1436 | }
|
1437 |
|
1438 | return cmp;
|
1439 | }
|
1440 |
|
1441 | function subtract(a, b, aL, base) {
|
1442 | var i = 0;
|
1443 |
|
1444 |
|
1445 | for (; aL--;) {
|
1446 | a[aL] -= i;
|
1447 | i = a[aL] < b[aL] ? 1 : 0;
|
1448 | a[aL] = i * base + a[aL] - b[aL];
|
1449 | }
|
1450 |
|
1451 |
|
1452 | for (; !a[0] && a.length > 1; a.splice(0, 1));
|
1453 | }
|
1454 |
|
1455 |
|
1456 | return function (x, y, dp, rm, base) {
|
1457 | var cmp, e, i, more, n, prod, prodL, q, qc, rem, remL, rem0, xi, xL, yc0,
|
1458 | yL, yz,
|
1459 | s = x.s == y.s ? 1 : -1,
|
1460 | xc = x.c,
|
1461 | yc = y.c;
|
1462 |
|
1463 |
|
1464 | if (!xc || !xc[0] || !yc || !yc[0]) {
|
1465 |
|
1466 | return new BigNumber(
|
1467 |
|
1468 |
|
1469 | !x.s || !y.s || (xc ? yc && xc[0] == yc[0] : !yc) ? NaN :
|
1470 |
|
1471 |
|
1472 | xc && xc[0] == 0 || !yc ? s * 0 : s / 0
|
1473 | );
|
1474 | }
|
1475 |
|
1476 | q = new BigNumber(s);
|
1477 | qc = q.c = [];
|
1478 | e = x.e - y.e;
|
1479 | s = dp + e + 1;
|
1480 |
|
1481 | if (!base) {
|
1482 | base = BASE;
|
1483 | e = bitFloor(x.e / LOG_BASE) - bitFloor(y.e / LOG_BASE);
|
1484 | s = s / LOG_BASE | 0;
|
1485 | }
|
1486 |
|
1487 |
|
1488 |
|
1489 | for (i = 0; yc[i] == (xc[i] || 0); i++);
|
1490 |
|
1491 | if (yc[i] > (xc[i] || 0)) e--;
|
1492 |
|
1493 | if (s < 0) {
|
1494 | qc.push(1);
|
1495 | more = true;
|
1496 | } else {
|
1497 | xL = xc.length;
|
1498 | yL = yc.length;
|
1499 | i = 0;
|
1500 | s += 2;
|
1501 |
|
1502 |
|
1503 |
|
1504 | n = mathfloor(base / (yc[0] + 1));
|
1505 |
|
1506 |
|
1507 |
|
1508 | if (n > 1) {
|
1509 | yc = multiply(yc, n, base);
|
1510 | xc = multiply(xc, n, base);
|
1511 | yL = yc.length;
|
1512 | xL = xc.length;
|
1513 | }
|
1514 |
|
1515 | xi = yL;
|
1516 | rem = xc.slice(0, yL);
|
1517 | remL = rem.length;
|
1518 |
|
1519 |
|
1520 | for (; remL < yL; rem[remL++] = 0);
|
1521 | yz = yc.slice();
|
1522 | yz = [0].concat(yz);
|
1523 | yc0 = yc[0];
|
1524 | if (yc[1] >= base / 2) yc0++;
|
1525 |
|
1526 |
|
1527 |
|
1528 | do {
|
1529 | n = 0;
|
1530 |
|
1531 |
|
1532 | cmp = compare(yc, rem, yL, remL);
|
1533 |
|
1534 |
|
1535 | if (cmp < 0) {
|
1536 |
|
1537 |
|
1538 |
|
1539 | rem0 = rem[0];
|
1540 | if (yL != remL) rem0 = rem0 * base + (rem[1] || 0);
|
1541 |
|
1542 |
|
1543 | n = mathfloor(rem0 / yc0);
|
1544 |
|
1545 |
|
1546 |
|
1547 |
|
1548 |
|
1549 |
|
1550 |
|
1551 |
|
1552 |
|
1553 |
|
1554 |
|
1555 |
|
1556 | if (n > 1) {
|
1557 |
|
1558 |
|
1559 | if (n >= base) n = base - 1;
|
1560 |
|
1561 |
|
1562 | prod = multiply(yc, n, base);
|
1563 | prodL = prod.length;
|
1564 | remL = rem.length;
|
1565 |
|
1566 |
|
1567 |
|
1568 |
|
1569 |
|
1570 | while (compare(prod, rem, prodL, remL) == 1) {
|
1571 | n--;
|
1572 |
|
1573 |
|
1574 | subtract(prod, yL < prodL ? yz : yc, prodL, base);
|
1575 | prodL = prod.length;
|
1576 | cmp = 1;
|
1577 | }
|
1578 | } else {
|
1579 |
|
1580 |
|
1581 |
|
1582 |
|
1583 |
|
1584 | if (n == 0) {
|
1585 |
|
1586 |
|
1587 | cmp = n = 1;
|
1588 | }
|
1589 |
|
1590 |
|
1591 | prod = yc.slice();
|
1592 | prodL = prod.length;
|
1593 | }
|
1594 |
|
1595 | if (prodL < remL) prod = [0].concat(prod);
|
1596 |
|
1597 |
|
1598 | subtract(rem, prod, remL, base);
|
1599 | remL = rem.length;
|
1600 |
|
1601 |
|
1602 | if (cmp == -1) {
|
1603 |
|
1604 |
|
1605 |
|
1606 |
|
1607 |
|
1608 | while (compare(yc, rem, yL, remL) < 1) {
|
1609 | n++;
|
1610 |
|
1611 |
|
1612 | subtract(rem, yL < remL ? yz : yc, remL, base);
|
1613 | remL = rem.length;
|
1614 | }
|
1615 | }
|
1616 | } else if (cmp === 0) {
|
1617 | n++;
|
1618 | rem = [0];
|
1619 | }
|
1620 |
|
1621 |
|
1622 | qc[i++] = n;
|
1623 |
|
1624 |
|
1625 | if (rem[0]) {
|
1626 | rem[remL++] = xc[xi] || 0;
|
1627 | } else {
|
1628 | rem = [xc[xi]];
|
1629 | remL = 1;
|
1630 | }
|
1631 | } while ((xi++ < xL || rem[0] != null) && s--);
|
1632 |
|
1633 | more = rem[0] != null;
|
1634 |
|
1635 | // Leading zero?
|
1636 | if (!qc[0]) qc.splice(0, 1);
|
1637 | }
|
1638 |
|
1639 | if (base == BASE) {
|
1640 |
|
1641 | // To calculate q.e, first get the number of digits of qc[0].
|
1642 | for (i = 1, s = qc[0]; s >= 10; s /= 10, i++);
|
1643 |
|
1644 | round(q, dp + (q.e = i + e * LOG_BASE - 1) + 1, rm, more);
|
1645 |
|
1646 | // Caller is convertBase.
|
1647 | } else {
|
1648 | q.e = e;
|
1649 | q.r = +more;
|
1650 | }
|
1651 |
|
1652 | return q;
|
1653 | };
|
1654 | })();
|
1655 |
|
1656 |
|
1657 | /*
|
1658 | * Return a string representing the value of BigNumber n in fixed-point or exponential
|
1659 | * notation rounded to the specified decimal places or significant digits.
|
1660 | *
|
1661 | * n: a BigNumber.
|
1662 | * i: the index of the last digit required (i.e. the digit that may be rounded up).
|
1663 | * rm: the rounding mode.
|
1664 | * id: 1 (toExponential) or 2 (toPrecision).
|
1665 | */
|
1666 | function format(n, i, rm, id) {
|
1667 | var c0, e, ne, len, str;
|
1668 |
|
1669 | if (rm == null) rm = ROUNDING_MODE;
|
1670 | else intCheck(rm, 0, 8);
|
1671 |
|
1672 | if (!n.c) return n.toString();
|
1673 |
|
1674 | c0 = n.c[0];
|
1675 | ne = n.e;
|
1676 |
|
1677 | if (i == null) {
|
1678 | str = coeffToString(n.c);
|
1679 | str = id == 1 || id == 2 && ne <= TO_EXP_NEG
|
1680 | ? toExponential(str, ne)
|
1681 | : toFixedPoint(str, ne, '0');
|
1682 | } else {
|
1683 | n = round(new BigNumber(n), i, rm);
|
1684 |
|
1685 | // n.e may have changed if the value was rounded up.
|
1686 | e = n.e;
|
1687 |
|
1688 | str = coeffToString(n.c);
|
1689 | len = str.length;
|
1690 |
|
1691 | // toPrecision returns exponential notation if the number of significant digits
|
1692 | // specified is less than the number of digits necessary to represent the integer
|
1693 | // part of the value in fixed-point notation.
|
1694 |
|
1695 | // Exponential notation.
|
1696 | if (id == 1 || id == 2 && (i <= e || e <= TO_EXP_NEG)) {
|
1697 |
|
1698 | // Append zeros?
|
1699 | for (; len < i; str += '0', len++);
|
1700 | str = toExponential(str, e);
|
1701 |
|
1702 | // Fixed-point notation.
|
1703 | } else {
|
1704 | i -= ne;
|
1705 | str = toFixedPoint(str, e, '0');
|
1706 |
|
1707 | // Append zeros?
|
1708 | if (e + 1 > len) {
|
1709 | if (--i > 0) for (str += '.'; i--; str += '0');
|
1710 | } else {
|
1711 | i += e - len;
|
1712 | if (i > 0) {
|
1713 | if (e + 1 == len) str += '.';
|
1714 | for (; i--; str += '0');
|
1715 | }
|
1716 | }
|
1717 | }
|
1718 | }
|
1719 |
|
1720 | return n.s < 0 && c0 ? '-' + str : str;
|
1721 | }
|
1722 |
|
1723 |
|
1724 | // Handle BigNumber.max and BigNumber.min.
|
1725 | function maxOrMin(args, method) {
|
1726 | var m, n,
|
1727 | i = 0;
|
1728 |
|
1729 | if (isArray(args[0])) args = args[0];
|
1730 | m = new BigNumber(args[0]);
|
1731 |
|
1732 | for (; ++i < args.length;) {
|
1733 | n = new BigNumber(args[i]);
|
1734 |
|
1735 | // If any number is NaN, return NaN.
|
1736 | if (!n.s) {
|
1737 | m = n;
|
1738 | break;
|
1739 | } else if (method.call(m, n)) {
|
1740 | m = n;
|
1741 | }
|
1742 | }
|
1743 |
|
1744 | return m;
|
1745 | }
|
1746 |
|
1747 |
|
1748 | /*
|
1749 | * Strip trailing zeros, calculate base 10 exponent and check against MIN_EXP and MAX_EXP.
|
1750 | * Called by minus, plus and times.
|
1751 | */
|
1752 | function normalise(n, c, e) {
|
1753 | var i = 1,
|
1754 | j = c.length;
|
1755 |
|
1756 | // Remove trailing zeros.
|
1757 | for (; !c[--j]; c.pop());
|
1758 |
|
1759 | // Calculate the base 10 exponent. First get the number of digits of c[0].
|
1760 | for (j = c[0]; j >= 10; j /= 10, i++);
|
1761 |
|
1762 | // Overflow?
|
1763 | if ((e = i + e * LOG_BASE - 1) > MAX_EXP) {
|
1764 |
|
1765 | // Infinity.
|
1766 | n.c = n.e = null;
|
1767 |
|
1768 | // Underflow?
|
1769 | } else if (e < MIN_EXP) {
|
1770 |
|
1771 | // Zero.
|
1772 | n.c = [n.e = 0];
|
1773 | } else {
|
1774 | n.e = e;
|
1775 | n.c = c;
|
1776 | }
|
1777 |
|
1778 | return n;
|
1779 | }
|
1780 |
|
1781 |
|
1782 | // Handle values that fail the validity test in BigNumber.
|
1783 | parseNumeric = (function () {
|
1784 | var basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i,
|
1785 | dotAfter = /^([^.]+)\.$/,
|
1786 | dotBefore = /^\.([^.]+)$/,
|
1787 | isInfinityOrNaN = /^-?(Infinity|NaN)$/,
|
1788 | whitespaceOrPlus = /^\s*\+(?=[\w.])|^\s+|\s+$/g;
|
1789 |
|
1790 | return function (x, str, isNum, b) {
|
1791 | var base,
|
1792 | s = isNum ? str : str.replace(whitespaceOrPlus, '');
|
1793 |
|
1794 | // No exception on ±Infinity or NaN.
|
1795 | if (isInfinityOrNaN.test(s)) {
|
1796 | x.s = isNaN(s) ? null : s < 0 ? -1 : 1;
|
1797 | x.c = x.e = null;
|
1798 | } else {
|
1799 | if (!isNum) {
|
1800 |
|
1801 | // basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i
|
1802 | s = s.replace(basePrefix, function (m, p1, p2) {
|
1803 | base = (p2 = p2.toLowerCase()) == 'x' ? 16 : p2 == 'b' ? 2 : 8;
|
1804 | return !b || b == base ? p1 : m;
|
1805 | });
|
1806 |
|
1807 | if (b) {
|
1808 | base = b;
|
1809 |
|
1810 | // E.g. '1.' to '1', '.1' to '0.1'
|
1811 | s = s.replace(dotAfter, '$1').replace(dotBefore, '0.$1');
|
1812 | }
|
1813 |
|
1814 | if (str != s) return new BigNumber(s, base);
|
1815 | }
|
1816 |
|
1817 | // '[BigNumber Error] Not a number: {n}'
|
1818 | // '[BigNumber Error] Not a base {b} number: {n}'
|
1819 | if (BigNumber.DEBUG) {
|
1820 | throw Error
|
1821 | (bignumberError + 'Not a' + (b ? ' base ' + b : '') + ' number: ' + str);
|
1822 | }
|
1823 |
|
1824 | // NaN
|
1825 | x.c = x.e = x.s = null;
|
1826 | }
|
1827 | }
|
1828 | })();
|
1829 |
|
1830 |
|
1831 | /*
|
1832 | * Round x to sd significant digits using rounding mode rm. Check for over/under-flow.
|
1833 | * If r is truthy, it is known that there are more digits after the rounding digit.
|
1834 | */
|
1835 | function round(x, sd, rm, r) {
|
1836 | var d, i, j, k, n, ni, rd,
|
1837 | xc = x.c,
|
1838 | pows10 = POWS_TEN;
|
1839 |
|
1840 | // if x is not Infinity or NaN...
|
1841 | if (xc) {
|
1842 |
|
1843 | // rd is the rounding digit, i.e. the digit after the digit that may be rounded up.
|
1844 | // n is a base 1e14 number, the value of the element of array x.c containing rd.
|
1845 | // ni is the index of n within x.c.
|
1846 | // d is the number of digits of n.
|
1847 | // i is the index of rd within n including leading zeros.
|
1848 | // j is the actual index of rd within n (if < 0, rd is a leading zero).
|
1849 | out: {
|
1850 |
|
1851 | // Get the number of digits of the first element of xc.
|
1852 | for (d = 1, k = xc[0]; k >= 10; k /= 10, d++);
|
1853 | i = sd - d;
|
1854 |
|
1855 | // If the rounding digit is in the first element of xc...
|
1856 | if (i < 0) {
|
1857 | i += LOG_BASE;
|
1858 | j = sd;
|
1859 | n = xc[ni = 0];
|
1860 |
|
1861 | // Get the rounding digit at index j of n.
|
1862 | rd = n / pows10[d - j - 1] % 10 | 0;
|
1863 | } else {
|
1864 | ni = mathceil((i + 1) / LOG_BASE);
|
1865 |
|
1866 | if (ni >= xc.length) {
|
1867 |
|
1868 | if (r) {
|
1869 |
|
1870 | // Needed by sqrt.
|
1871 | for (; xc.length <= ni; xc.push(0));
|
1872 | n = rd = 0;
|
1873 | d = 1;
|
1874 | i %= LOG_BASE;
|
1875 | j = i - LOG_BASE + 1;
|
1876 | } else {
|
1877 | break out;
|
1878 | }
|
1879 | } else {
|
1880 | n = k = xc[ni];
|
1881 |
|
1882 | // Get the number of digits of n.
|
1883 | for (d = 1; k >= 10; k /= 10, d++);
|
1884 |
|
1885 | // Get the index of rd within n.
|
1886 | i %= LOG_BASE;
|
1887 |
|
1888 | // Get the index of rd within n, adjusted for leading zeros.
|
1889 | // The number of leading zeros of n is given by LOG_BASE - d.
|
1890 | j = i - LOG_BASE + d;
|
1891 |
|
1892 | // Get the rounding digit at index j of n.
|
1893 | rd = j < 0 ? 0 : n / pows10[d - j - 1] % 10 | 0;
|
1894 | }
|
1895 | }
|
1896 |
|
1897 | r = r || sd < 0 ||
|
1898 |
|
1899 | // Are there any non-zero digits after the rounding digit?
|
1900 | // The expression n % pows10[d - j - 1] returns all digits of n to the right
|
1901 | // of the digit at j, e.g. if n is 908714 and j is 2, the expression gives 714.
|
1902 | xc[ni + 1] != null || (j < 0 ? n : n % pows10[d - j - 1]);
|
1903 |
|
1904 | r = rm < 4
|
1905 | ? (rd || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2))
|
1906 | : rd > 5 || rd == 5 && (rm == 4 || r || rm == 6 &&
|
1907 |
|
1908 | // Check whether the digit to the left of the rounding digit is odd.
|
1909 | ((i > 0 ? j > 0 ? n / pows10[d - j] : 0 : xc[ni - 1]) % 10) & 1 ||
|
1910 | rm == (x.s < 0 ? 8 : 7));
|
1911 |
|
1912 | if (sd < 1 || !xc[0]) {
|
1913 | xc.length = 0;
|
1914 |
|
1915 | if (r) {
|
1916 |
|
1917 | // Convert sd to decimal places.
|
1918 | sd -= x.e + 1;
|
1919 |
|
1920 | // 1, 0.1, 0.01, 0.001, 0.0001 etc.
|
1921 | xc[0] = pows10[(LOG_BASE - sd % LOG_BASE) % LOG_BASE];
|
1922 | x.e = -sd || 0;
|
1923 | } else {
|
1924 |
|
1925 | // Zero.
|
1926 | xc[0] = x.e = 0;
|
1927 | }
|
1928 |
|
1929 | return x;
|
1930 | }
|
1931 |
|
1932 | // Remove excess digits.
|
1933 | if (i == 0) {
|
1934 | xc.length = ni;
|
1935 | k = 1;
|
1936 | ni--;
|
1937 | } else {
|
1938 | xc.length = ni + 1;
|
1939 | k = pows10[LOG_BASE - i];
|
1940 |
|
1941 | // E.g. 56700 becomes 56000 if 7 is the rounding digit.
|
1942 | // j > 0 means i > number of leading zeros of n.
|
1943 | xc[ni] = j > 0 ? mathfloor(n / pows10[d - j] % pows10[j]) * k : 0;
|
1944 | }
|
1945 |
|
1946 | // Round up?
|
1947 | if (r) {
|
1948 |
|
1949 | for (; ;) {
|
1950 |
|
1951 | // If the digit to be rounded up is in the first element of xc...
|
1952 | if (ni == 0) {
|
1953 |
|
1954 | // i will be the length of xc[0] before k is added.
|
1955 | for (i = 1, j = xc[0]; j >= 10; j /= 10, i++);
|
1956 | j = xc[0] += k;
|
1957 | for (k = 1; j >= 10; j /= 10, k++);
|
1958 |
|
1959 | // if i != k the length has increased.
|
1960 | if (i != k) {
|
1961 | x.e++;
|
1962 | if (xc[0] == BASE) xc[0] = 1;
|
1963 | }
|
1964 |
|
1965 | break;
|
1966 | } else {
|
1967 | xc[ni] += k;
|
1968 | if (xc[ni] != BASE) break;
|
1969 | xc[ni--] = 0;
|
1970 | k = 1;
|
1971 | }
|
1972 | }
|
1973 | }
|
1974 |
|
1975 | // Remove trailing zeros.
|
1976 | for (i = xc.length; xc[--i] === 0; xc.pop());
|
1977 | }
|
1978 |
|
1979 | // Overflow? Infinity.
|
1980 | if (x.e > MAX_EXP) {
|
1981 | x.c = x.e = null;
|
1982 |
|
1983 | // Underflow? Zero.
|
1984 | } else if (x.e < MIN_EXP) {
|
1985 | x.c = [x.e = 0];
|
1986 | }
|
1987 | }
|
1988 |
|
1989 | return x;
|
1990 | }
|
1991 |
|
1992 |
|
1993 | // PROTOTYPE/INSTANCE METHODS
|
1994 |
|
1995 |
|
1996 | /*
|
1997 | * Return a new BigNumber whose value is the absolute value of this BigNumber.
|
1998 | */
|
1999 | P.absoluteValue = P.abs = function () {
|
2000 | var x = new BigNumber(this);
|
2001 | if (x.s < 0) x.s = 1;
|
2002 | return x;
|
2003 | };
|
2004 |
|
2005 |
|
2006 | /*
|
2007 | * Return
|
2008 | * 1 if the value of this BigNumber is greater than the value of BigNumber(y, b),
|
2009 | * -1 if the value of this BigNumber is less than the value of BigNumber(y, b),
|
2010 | * 0 if they have the same value,
|
2011 | * or null if the value of either is NaN.
|
2012 | */
|
2013 | P.comparedTo = function (y, b) {
|
2014 | return compare(this, new BigNumber(y, b));
|
2015 | };
|
2016 |
|
2017 |
|
2018 | /*
|
2019 | * If dp is undefined or null or true or false, return the number of decimal places of the
|
2020 | * value of this BigNumber, or null if the value of this BigNumber is ±Infinity or NaN.
|
2021 | *
|
2022 | * Otherwise, if dp is a number, return a new BigNumber whose value is the value of this
|
2023 | * BigNumber rounded to a maximum of dp decimal places using rounding mode rm, or
|
2024 | * ROUNDING_MODE if rm is omitted.
|
2025 | *
|
2026 | * [dp] {number} Decimal places: integer, 0 to MAX inclusive.
|
2027 | * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
|
2028 | *
|
2029 | * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {dp|rm}'
|
2030 | */
|
2031 | P.decimalPlaces = P.dp = function (dp, rm) {
|
2032 | var c, n, v,
|
2033 | x = this;
|
2034 |
|
2035 | if (dp != null) {
|
2036 | intCheck(dp, 0, MAX);
|
2037 | if (rm == null) rm = ROUNDING_MODE;
|
2038 | else intCheck(rm, 0, 8);
|
2039 |
|
2040 | return round(new BigNumber(x), dp + x.e + 1, rm);
|
2041 | }
|
2042 |
|
2043 | if (!(c = x.c)) return null;
|
2044 | n = ((v = c.length - 1) - bitFloor(this.e / LOG_BASE)) * LOG_BASE;
|
2045 |
|
2046 | // Subtract the number of trailing zeros of the last number.
|
2047 | if (v = c[v]) for (; v % 10 == 0; v /= 10, n--);
|
2048 | if (n < 0) n = 0;
|
2049 |
|
2050 | return n;
|
2051 | };
|
2052 |
|
2053 |
|
2054 | /*
|
2055 | * n / 0 = I
|
2056 | * n / N = N
|
2057 | * n / I = 0
|
2058 | * 0 / n = 0
|
2059 | * 0 / 0 = N
|
2060 | * 0 / N = N
|
2061 | * 0 / I = 0
|
2062 | * N / n = N
|
2063 | * N / 0 = N
|
2064 | * N / N = N
|
2065 | * N / I = N
|
2066 | * I / n = I
|
2067 | * I / 0 = I
|
2068 | * I / N = N
|
2069 | * I / I = N
|
2070 | *
|
2071 | * Return a new BigNumber whose value is the value of this BigNumber divided by the value of
|
2072 | * BigNumber(y, b), rounded according to DECIMAL_PLACES and ROUNDING_MODE.
|
2073 | */
|
2074 | P.dividedBy = P.div = function (y, b) {
|
2075 | return div(this, new BigNumber(y, b), DECIMAL_PLACES, ROUNDING_MODE);
|
2076 | };
|
2077 |
|
2078 |
|
2079 | /*
|
2080 | * Return a new BigNumber whose value is the integer part of dividing the value of this
|
2081 | * BigNumber by the value of BigNumber(y, b).
|
2082 | */
|
2083 | P.dividedToIntegerBy = P.idiv = function (y, b) {
|
2084 | return div(this, new BigNumber(y, b), 0, 1);
|
2085 | };
|
2086 |
|
2087 |
|
2088 | /*
|
2089 | * Return a BigNumber whose value is the value of this BigNumber exponentiated by n.
|
2090 | *
|
2091 | * If m is present, return the result modulo m.
|
2092 | * If n is negative round according to DECIMAL_PLACES and ROUNDING_MODE.
|
2093 | * If POW_PRECISION is non-zero and m is not present, round to POW_PRECISION using ROUNDING_MODE.
|
2094 | *
|
2095 | * The modular power operation works efficiently when x, n, and m are integers, otherwise it
|
2096 | * is equivalent to calculating x.exponentiatedBy(n).modulo(m) with a POW_PRECISION of 0.
|
2097 | *
|
2098 | * n {number|string|BigNumber} The exponent. An integer.
|
2099 | * [m] {number|string|BigNumber} The modulus.
|
2100 | *
|
2101 | * '[BigNumber Error] Exponent not an integer: {n}'
|
2102 | */
|
2103 | P.exponentiatedBy = P.pow = function (n, m) {
|
2104 | var half, isModExp, k, more, nIsBig, nIsNeg, nIsOdd, y,
|
2105 | x = this;
|
2106 |
|
2107 | n = new BigNumber(n);
|
2108 |
|
2109 | // Allow NaN and ±Infinity, but not other non-integers.
|
2110 | if (n.c && !n.isInteger()) {
|
2111 | throw Error
|
2112 | (bignumberError + 'Exponent not an integer: ' + n);
|
2113 | }
|
2114 |
|
2115 | if (m != null) m = new BigNumber(m);
|
2116 |
|
2117 | // Exponent of MAX_SAFE_INTEGER is 15.
|
2118 | nIsBig = n.e > 14;
|
2119 |
|
2120 | // If x is NaN, ±Infinity, ±0 or ±1, or n is ±Infinity, NaN or ±0.
|
2121 | if (!x.c || !x.c[0] || x.c[0] == 1 && !x.e && x.c.length == 1 || !n.c || !n.c[0]) {
|
2122 |
|
2123 | // The sign of the result of pow when x is negative depends on the evenness of n.
|
2124 | // If +n overflows to ±Infinity, the evenness of n would be not be known.
|
2125 | y = new BigNumber(Math.pow(+x.valueOf(), nIsBig ? 2 - isOdd(n) : +n));
|
2126 | return m ? y.mod(m) : y;
|
2127 | }
|
2128 |
|
2129 | nIsNeg = n.s < 0;
|
2130 |
|
2131 | if (m) {
|
2132 |
|
2133 | // x % m returns NaN if abs(m) is zero, or m is NaN.
|
2134 | if (m.c ? !m.c[0] : !m.s) return new BigNumber(NaN);
|
2135 |
|
2136 | isModExp = !nIsNeg && x.isInteger() && m.isInteger();
|
2137 |
|
2138 | if (isModExp) x = x.mod(m);
|
2139 |
|
2140 | // Overflow to ±Infinity: >=2**1e10 or >=1.0000024**1e15.
|
2141 | // Underflow to ±0: <=0.79**1e10 or <=0.9999975**1e15.
|
2142 | } else if (n.e > 9 && (x.e > 0 || x.e < -1 || (x.e == 0
|
2143 | // [1, 240000000]
|
2144 | ? x.c[0] > 1 || nIsBig && x.c[1] >= 24e7
|
2145 | // [80000000000000] [99999750000000]
|
2146 | : x.c[0] < 8e13 || nIsBig && x.c[0] <= 9999975e7))) {
|
2147 |
|
2148 | // If x is negative and n is odd, k = -0, else k = 0.
|
2149 | k = x.s < 0 && isOdd(n) ? -0 : 0;
|
2150 |
|
2151 | // If x >= 1, k = ±Infinity.
|
2152 | if (x.e > -1) k = 1 / k;
|
2153 |
|
2154 | // If n is negative return ±0, else return ±Infinity.
|
2155 | return new BigNumber(nIsNeg ? 1 / k : k);
|
2156 |
|
2157 | } else if (POW_PRECISION) {
|
2158 |
|
2159 | // Truncating each coefficient array to a length of k after each multiplication
|
2160 | // equates to truncating significant digits to POW_PRECISION + [28, 41],
|
2161 | // i.e. there will be a minimum of 28 guard digits retained.
|
2162 | k = mathceil(POW_PRECISION / LOG_BASE + 2);
|
2163 | }
|
2164 |
|
2165 | if (nIsBig) {
|
2166 | half = new BigNumber(0.5);
|
2167 | nIsOdd = isOdd(n);
|
2168 | } else {
|
2169 | nIsOdd = n % 2;
|
2170 | }
|
2171 |
|
2172 | if (nIsNeg) n.s = 1;
|
2173 |
|
2174 | y = new BigNumber(ONE);
|
2175 |
|
2176 | // Performs 54 loop iterations for n of 9007199254740991.
|
2177 | for (; ;) {
|
2178 |
|
2179 | if (nIsOdd) {
|
2180 | y = y.times(x);
|
2181 | if (!y.c) break;
|
2182 |
|
2183 | if (k) {
|
2184 | if (y.c.length > k) y.c.length = k;
|
2185 | } else if (isModExp) {
|
2186 | y = y.mod(m); //y = y.minus(div(y, m, 0, MODULO_MODE).times(m));
|
2187 | }
|
2188 | }
|
2189 |
|
2190 | if (nIsBig) {
|
2191 | n = n.times(half);
|
2192 | round(n, n.e + 1, 1);
|
2193 | if (!n.c[0]) break;
|
2194 | nIsBig = n.e > 14;
|
2195 | nIsOdd = isOdd(n);
|
2196 | } else {
|
2197 | n = mathfloor(n / 2);
|
2198 | if (!n) break;
|
2199 | nIsOdd = n % 2;
|
2200 | }
|
2201 |
|
2202 | x = x.times(x);
|
2203 |
|
2204 | if (k) {
|
2205 | if (x.c && x.c.length > k) x.c.length = k;
|
2206 | } else if (isModExp) {
|
2207 | x = x.mod(m); //x = x.minus(div(x, m, 0, MODULO_MODE).times(m));
|
2208 | }
|
2209 | }
|
2210 |
|
2211 | if (isModExp) return y;
|
2212 | if (nIsNeg) y = ONE.div(y);
|
2213 |
|
2214 | return m ? y.mod(m) : k ? round(y, POW_PRECISION, ROUNDING_MODE, more) : y;
|
2215 | };
|
2216 |
|
2217 |
|
2218 | /*
|
2219 | * Return a new BigNumber whose value is the value of this BigNumber rounded to an integer
|
2220 | * using rounding mode rm, or ROUNDING_MODE if rm is omitted.
|
2221 | *
|
2222 | * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
|
2223 | *
|
2224 | * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {rm}'
|
2225 | */
|
2226 | P.integerValue = function (rm) {
|
2227 | var n = new BigNumber(this);
|
2228 | if (rm == null) rm = ROUNDING_MODE;
|
2229 | else intCheck(rm, 0, 8);
|
2230 | return round(n, n.e + 1, rm);
|
2231 | };
|
2232 |
|
2233 |
|
2234 | /*
|
2235 | * Return true if the value of this BigNumber is equal to the value of BigNumber(y, b),
|
2236 | * otherwise return false.
|
2237 | */
|
2238 | P.isEqualTo = P.eq = function (y, b) {
|
2239 | return compare(this, new BigNumber(y, b)) === 0;
|
2240 | };
|
2241 |
|
2242 |
|
2243 | /*
|
2244 | * Return true if the value of this BigNumber is a finite number, otherwise return false.
|
2245 | */
|
2246 | P.isFinite = function () {
|
2247 | return !!this.c;
|
2248 | };
|
2249 |
|
2250 |
|
2251 | /*
|
2252 | * Return true if the value of this BigNumber is greater than the value of BigNumber(y, b),
|
2253 | * otherwise return false.
|
2254 | */
|
2255 | P.isGreaterThan = P.gt = function (y, b) {
|
2256 | return compare(this, new BigNumber(y, b)) > 0;
|
2257 | };
|
2258 |
|
2259 |
|
2260 | /*
|
2261 | * Return true if the value of this BigNumber is greater than or equal to the value of
|
2262 | * BigNumber(y, b), otherwise return false.
|
2263 | */
|
2264 | P.isGreaterThanOrEqualTo = P.gte = function (y, b) {
|
2265 | return (b = compare(this, new BigNumber(y, b))) === 1 || b === 0;
|
2266 |
|
2267 | };
|
2268 |
|
2269 |
|
2270 | /*
|
2271 | * Return true if the value of this BigNumber is an integer, otherwise return false.
|
2272 | */
|
2273 | P.isInteger = function () {
|
2274 | return !!this.c && bitFloor(this.e / LOG_BASE) > this.c.length - 2;
|
2275 | };
|
2276 |
|
2277 |
|
2278 | /*
|
2279 | * Return true if the value of this BigNumber is less than the value of BigNumber(y, b),
|
2280 | * otherwise return false.
|
2281 | */
|
2282 | P.isLessThan = P.lt = function (y, b) {
|
2283 | return compare(this, new BigNumber(y, b)) < 0;
|
2284 | };
|
2285 |
|
2286 |
|
2287 | /*
|
2288 | * Return true if the value of this BigNumber is less than or equal to the value of
|
2289 | * BigNumber(y, b), otherwise return false.
|
2290 | */
|
2291 | P.isLessThanOrEqualTo = P.lte = function (y, b) {
|
2292 | return (b = compare(this, new BigNumber(y, b))) === -1 || b === 0;
|
2293 | };
|
2294 |
|
2295 |
|
2296 | /*
|
2297 | * Return true if the value of this BigNumber is NaN, otherwise return false.
|
2298 | */
|
2299 | P.isNaN = function () {
|
2300 | return !this.s;
|
2301 | };
|
2302 |
|
2303 |
|
2304 | /*
|
2305 | * Return true if the value of this BigNumber is negative, otherwise return false.
|
2306 | */
|
2307 | P.isNegative = function () {
|
2308 | return this.s < 0;
|
2309 | };
|
2310 |
|
2311 |
|
2312 | /*
|
2313 | * Return true if the value of this BigNumber is positive, otherwise return false.
|
2314 | */
|
2315 | P.isPositive = function () {
|
2316 | return this.s > 0;
|
2317 | };
|
2318 |
|
2319 |
|
2320 | /*
|
2321 | * Return true if the value of this BigNumber is 0 or -0, otherwise return false.
|
2322 | */
|
2323 | P.isZero = function () {
|
2324 | return !!this.c && this.c[0] == 0;
|
2325 | };
|
2326 |
|
2327 |
|
2328 | /*
|
2329 | * n - 0 = n
|
2330 | * n - N = N
|
2331 | * n - I = -I
|
2332 | * 0 - n = -n
|
2333 | * 0 - 0 = 0
|
2334 | * 0 - N = N
|
2335 | * 0 - I = -I
|
2336 | * N - n = N
|
2337 | * N - 0 = N
|
2338 | * N - N = N
|
2339 | * N - I = N
|
2340 | * I - n = I
|
2341 | * I - 0 = I
|
2342 | * I - N = N
|
2343 | * I - I = N
|
2344 | *
|
2345 | * Return a new BigNumber whose value is the value of this BigNumber minus the value of
|
2346 | * BigNumber(y, b).
|
2347 | */
|
2348 | P.minus = function (y, b) {
|
2349 | var i, j, t, xLTy,
|
2350 | x = this,
|
2351 | a = x.s;
|
2352 |
|
2353 | y = new BigNumber(y, b);
|
2354 | b = y.s;
|
2355 |
|
2356 | // Either NaN?
|
2357 | if (!a || !b) return new BigNumber(NaN);
|
2358 |
|
2359 | // Signs differ?
|
2360 | if (a != b) {
|
2361 | y.s = -b;
|
2362 | return x.plus(y);
|
2363 | }
|
2364 |
|
2365 | var xe = x.e / LOG_BASE,
|
2366 | ye = y.e / LOG_BASE,
|
2367 | xc = x.c,
|
2368 | yc = y.c;
|
2369 |
|
2370 | if (!xe || !ye) {
|
2371 |
|
2372 | // Either Infinity?
|
2373 | if (!xc || !yc) return xc ? (y.s = -b, y) : new BigNumber(yc ? x : NaN);
|
2374 |
|
2375 | // Either zero?
|
2376 | if (!xc[0] || !yc[0]) {
|
2377 |
|
2378 | // Return y if y is non-zero, x if x is non-zero, or zero if both are zero.
|
2379 | return yc[0] ? (y.s = -b, y) : new BigNumber(xc[0] ? x :
|
2380 |
|
2381 | // IEEE 754 (2008) 6.3: n - n = -0 when rounding to -Infinity
|
2382 | ROUNDING_MODE == 3 ? -0 : 0);
|
2383 | }
|
2384 | }
|
2385 |
|
2386 | xe = bitFloor(xe);
|
2387 | ye = bitFloor(ye);
|
2388 | xc = xc.slice();
|
2389 |
|
2390 | // Determine which is the bigger number.
|
2391 | if (a = xe - ye) {
|
2392 |
|
2393 | if (xLTy = a < 0) {
|
2394 | a = -a;
|
2395 | t = xc;
|
2396 | } else {
|
2397 | ye = xe;
|
2398 | t = yc;
|
2399 | }
|
2400 |
|
2401 | t.reverse();
|
2402 |
|
2403 | // Prepend zeros to equalise exponents.
|
2404 | for (b = a; b--; t.push(0));
|
2405 | t.reverse();
|
2406 | } else {
|
2407 |
|
2408 | // Exponents equal. Check digit by digit.
|
2409 | j = (xLTy = (a = xc.length) < (b = yc.length)) ? a : b;
|
2410 |
|
2411 | for (a = b = 0; b < j; b++) {
|
2412 |
|
2413 | if (xc[b] != yc[b]) {
|
2414 | xLTy = xc[b] < yc[b];
|
2415 | break;
|
2416 | }
|
2417 | }
|
2418 | }
|
2419 |
|
2420 | // x < y? Point xc to the array of the bigger number.
|
2421 | if (xLTy) t = xc, xc = yc, yc = t, y.s = -y.s;
|
2422 |
|
2423 | b = (j = yc.length) - (i = xc.length);
|
2424 |
|
2425 | // Append zeros to xc if shorter.
|
2426 | // No need to add zeros to yc if shorter as subtract only needs to start at yc.length.
|
2427 | if (b > 0) for (; b--; xc[i++] = 0);
|
2428 | b = BASE - 1;
|
2429 |
|
2430 | // Subtract yc from xc.
|
2431 | for (; j > a;) {
|
2432 |
|
2433 | if (xc[--j] < yc[j]) {
|
2434 | for (i = j; i && !xc[--i]; xc[i] = b);
|
2435 | --xc[i];
|
2436 | xc[j] += BASE;
|
2437 | }
|
2438 |
|
2439 | xc[j] -= yc[j];
|
2440 | }
|
2441 |
|
2442 | // Remove leading zeros and adjust exponent accordingly.
|
2443 | for (; xc[0] == 0; xc.splice(0, 1), --ye);
|
2444 |
|
2445 | // Zero?
|
2446 | if (!xc[0]) {
|
2447 |
|
2448 | // Following IEEE 754 (2008) 6.3,
|
2449 | // n - n = +0 but n - n = -0 when rounding towards -Infinity.
|
2450 | y.s = ROUNDING_MODE == 3 ? -1 : 1;
|
2451 | y.c = [y.e = 0];
|
2452 | return y;
|
2453 | }
|
2454 |
|
2455 | // No need to check for Infinity as +x - +y != Infinity && -x - -y != Infinity
|
2456 | // for finite x and y.
|
2457 | return normalise(y, xc, ye);
|
2458 | };
|
2459 |
|
2460 |
|
2461 | /*
|
2462 | * n % 0 = N
|
2463 | * n % N = N
|
2464 | * n % I = n
|
2465 | * 0 % n = 0
|
2466 | * -0 % n = -0
|
2467 | * 0 % 0 = N
|
2468 | * 0 % N = N
|
2469 | * 0 % I = 0
|
2470 | * N % n = N
|
2471 | * N % 0 = N
|
2472 | * N % N = N
|
2473 | * N % I = N
|
2474 | * I % n = N
|
2475 | * I % 0 = N
|
2476 | * I % N = N
|
2477 | * I % I = N
|
2478 | *
|
2479 | * Return a new BigNumber whose value is the value of this BigNumber modulo the value of
|
2480 | * BigNumber(y, b). The result depends on the value of MODULO_MODE.
|
2481 | */
|
2482 | P.modulo = P.mod = function (y, b) {
|
2483 | var q, s,
|
2484 | x = this;
|
2485 |
|
2486 | y = new BigNumber(y, b);
|
2487 |
|
2488 | // Return NaN if x is Infinity or NaN, or y is NaN or zero.
|
2489 | if (!x.c || !y.s || y.c && !y.c[0]) {
|
2490 | return new BigNumber(NaN);
|
2491 |
|
2492 | // Return x if y is Infinity or x is zero.
|
2493 | } else if (!y.c || x.c && !x.c[0]) {
|
2494 | return new BigNumber(x);
|
2495 | }
|
2496 |
|
2497 | if (MODULO_MODE == 9) {
|
2498 |
|
2499 | // Euclidian division: q = sign(y) * floor(x / abs(y))
|
2500 | // r = x - qy where 0 <= r < abs(y)
|
2501 | s = y.s;
|
2502 | y.s = 1;
|
2503 | q = div(x, y, 0, 3);
|
2504 | y.s = s;
|
2505 | q.s *= s;
|
2506 | } else {
|
2507 | q = div(x, y, 0, MODULO_MODE);
|
2508 | }
|
2509 |
|
2510 | y = x.minus(q.times(y));
|
2511 |
|
2512 | // To match JavaScript %, ensure sign of zero is sign of dividend.
|
2513 | if (!y.c[0] && MODULO_MODE == 1) y.s = x.s;
|
2514 |
|
2515 | return y;
|
2516 | };
|
2517 |
|
2518 |
|
2519 | /*
|
2520 | * n * 0 = 0
|
2521 | * n * N = N
|
2522 | * n * I = I
|
2523 | * 0 * n = 0
|
2524 | * 0 * 0 = 0
|
2525 | * 0 * N = N
|
2526 | * 0 * I = N
|
2527 | * N * n = N
|
2528 | * N * 0 = N
|
2529 | * N * N = N
|
2530 | * N * I = N
|
2531 | * I * n = I
|
2532 | * I * 0 = N
|
2533 | * I * N = N
|
2534 | * I * I = I
|
2535 | *
|
2536 | * Return a new BigNumber whose value is the value of this BigNumber multiplied by the value
|
2537 | * of BigNumber(y, b).
|
2538 | */
|
2539 | P.multipliedBy = P.times = function (y, b) {
|
2540 | var c, e, i, j, k, m, xcL, xlo, xhi, ycL, ylo, yhi, zc,
|
2541 | base, sqrtBase,
|
2542 | x = this,
|
2543 | xc = x.c,
|
2544 | yc = (y = new BigNumber(y, b)).c;
|
2545 |
|
2546 | // Either NaN, ±Infinity or ±0?
|
2547 | if (!xc || !yc || !xc[0] || !yc[0]) {
|
2548 |
|
2549 | // Return NaN if either is NaN, or one is 0 and the other is Infinity.
|
2550 | if (!x.s || !y.s || xc && !xc[0] && !yc || yc && !yc[0] && !xc) {
|
2551 | y.c = y.e = y.s = null;
|
2552 | } else {
|
2553 | y.s *= x.s;
|
2554 |
|
2555 | // Return ±Infinity if either is ±Infinity.
|
2556 | if (!xc || !yc) {
|
2557 | y.c = y.e = null;
|
2558 |
|
2559 | // Return ±0 if either is ±0.
|
2560 | } else {
|
2561 | y.c = [0];
|
2562 | y.e = 0;
|
2563 | }
|
2564 | }
|
2565 |
|
2566 | return y;
|
2567 | }
|
2568 |
|
2569 | e = bitFloor(x.e / LOG_BASE) + bitFloor(y.e / LOG_BASE);
|
2570 | y.s *= x.s;
|
2571 | xcL = xc.length;
|
2572 | ycL = yc.length;
|
2573 |
|
2574 | // Ensure xc points to longer array and xcL to its length.
|
2575 | if (xcL < ycL) zc = xc, xc = yc, yc = zc, i = xcL, xcL = ycL, ycL = i;
|
2576 |
|
2577 | // Initialise the result array with zeros.
|
2578 | for (i = xcL + ycL, zc = []; i--; zc.push(0));
|
2579 |
|
2580 | base = BASE;
|
2581 | sqrtBase = SQRT_BASE;
|
2582 |
|
2583 | for (i = ycL; --i >= 0;) {
|
2584 | c = 0;
|
2585 | ylo = yc[i] % sqrtBase;
|
2586 | yhi = yc[i] / sqrtBase | 0;
|
2587 |
|
2588 | for (k = xcL, j = i + k; j > i;) {
|
2589 | xlo = xc[--k] % sqrtBase;
|
2590 | xhi = xc[k] / sqrtBase | 0;
|
2591 | m = yhi * xlo + xhi * ylo;
|
2592 | xlo = ylo * xlo + ((m % sqrtBase) * sqrtBase) + zc[j] + c;
|
2593 | c = (xlo / base | 0) + (m / sqrtBase | 0) + yhi * xhi;
|
2594 | zc[j--] = xlo % base;
|
2595 | }
|
2596 |
|
2597 | zc[j] = c;
|
2598 | }
|
2599 |
|
2600 | if (c) {
|
2601 | ++e;
|
2602 | } else {
|
2603 | zc.splice(0, 1);
|
2604 | }
|
2605 |
|
2606 | return normalise(y, zc, e);
|
2607 | };
|
2608 |
|
2609 |
|
2610 | /*
|
2611 | * Return a new BigNumber whose value is the value of this BigNumber negated,
|
2612 | * i.e. multiplied by -1.
|
2613 | */
|
2614 | P.negated = function () {
|
2615 | var x = new BigNumber(this);
|
2616 | x.s = -x.s || null;
|
2617 | return x;
|
2618 | };
|
2619 |
|
2620 |
|
2621 | /*
|
2622 | * n + 0 = n
|
2623 | * n + N = N
|
2624 | * n + I = I
|
2625 | * 0 + n = n
|
2626 | * 0 + 0 = 0
|
2627 | * 0 + N = N
|
2628 | * 0 + I = I
|
2629 | * N + n = N
|
2630 | * N + 0 = N
|
2631 | * N + N = N
|
2632 | * N + I = N
|
2633 | * I + n = I
|
2634 | * I + 0 = I
|
2635 | * I + N = N
|
2636 | * I + I = I
|
2637 | *
|
2638 | * Return a new BigNumber whose value is the value of this BigNumber plus the value of
|
2639 | * BigNumber(y, b).
|
2640 | */
|
2641 | P.plus = function (y, b) {
|
2642 | var t,
|
2643 | x = this,
|
2644 | a = x.s;
|
2645 |
|
2646 | y = new BigNumber(y, b);
|
2647 | b = y.s;
|
2648 |
|
2649 | // Either NaN?
|
2650 | if (!a || !b) return new BigNumber(NaN);
|
2651 |
|
2652 | // Signs differ?
|
2653 | if (a != b) {
|
2654 | y.s = -b;
|
2655 | return x.minus(y);
|
2656 | }
|
2657 |
|
2658 | var xe = x.e / LOG_BASE,
|
2659 | ye = y.e / LOG_BASE,
|
2660 | xc = x.c,
|
2661 | yc = y.c;
|
2662 |
|
2663 | if (!xe || !ye) {
|
2664 |
|
2665 | // Return ±Infinity if either ±Infinity.
|
2666 | if (!xc || !yc) return new BigNumber(a / 0);
|
2667 |
|
2668 | // Either zero?
|
2669 | // Return y if y is non-zero, x if x is non-zero, or zero if both are zero.
|
2670 | if (!xc[0] || !yc[0]) return yc[0] ? y : new BigNumber(xc[0] ? x : a * 0);
|
2671 | }
|
2672 |
|
2673 | xe = bitFloor(xe);
|
2674 | ye = bitFloor(ye);
|
2675 | xc = xc.slice();
|
2676 |
|
2677 | // Prepend zeros to equalise exponents. Faster to use reverse then do unshifts.
|
2678 | if (a = xe - ye) {
|
2679 | if (a > 0) {
|
2680 | ye = xe;
|
2681 | t = yc;
|
2682 | } else {
|
2683 | a = -a;
|
2684 | t = xc;
|
2685 | }
|
2686 |
|
2687 | t.reverse();
|
2688 | for (; a--; t.push(0));
|
2689 | t.reverse();
|
2690 | }
|
2691 |
|
2692 | a = xc.length;
|
2693 | b = yc.length;
|
2694 |
|
2695 | // Point xc to the longer array, and b to the shorter length.
|
2696 | if (a - b < 0) t = yc, yc = xc, xc = t, b = a;
|
2697 |
|
2698 | // Only start adding at yc.length - 1 as the further digits of xc can be ignored.
|
2699 | for (a = 0; b;) {
|
2700 | a = (xc[--b] = xc[b] + yc[b] + a) / BASE | 0;
|
2701 | xc[b] = BASE === xc[b] ? 0 : xc[b] % BASE;
|
2702 | }
|
2703 |
|
2704 | if (a) {
|
2705 | xc = [a].concat(xc);
|
2706 | ++ye;
|
2707 | }
|
2708 |
|
2709 | // No need to check for zero, as +x + +y != 0 && -x + -y != 0
|
2710 | // ye = MAX_EXP + 1 possible
|
2711 | return normalise(y, xc, ye);
|
2712 | };
|
2713 |
|
2714 |
|
2715 | /*
|
2716 | * If sd is undefined or null or true or false, return the number of significant digits of
|
2717 | * the value of this BigNumber, or null if the value of this BigNumber is ±Infinity or NaN.
|
2718 | * If sd is true include integer-part trailing zeros in the count.
|
2719 | *
|
2720 | * Otherwise, if sd is a number, return a new BigNumber whose value is the value of this
|
2721 | * BigNumber rounded to a maximum of sd significant digits using rounding mode rm, or
|
2722 | * ROUNDING_MODE if rm is omitted.
|
2723 | *
|
2724 | * sd {number|boolean} number: significant digits: integer, 1 to MAX inclusive.
|
2725 | * boolean: whether to count integer-part trailing zeros: true or false.
|
2726 | * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
|
2727 | *
|
2728 | * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {sd|rm}'
|
2729 | */
|
2730 | P.precision = P.sd = function (sd, rm) {
|
2731 | var c, n, v,
|
2732 | x = this;
|
2733 |
|
2734 | if (sd != null && sd !== !!sd) {
|
2735 | intCheck(sd, 1, MAX);
|
2736 | if (rm == null) rm = ROUNDING_MODE;
|
2737 | else intCheck(rm, 0, 8);
|
2738 |
|
2739 | return round(new BigNumber(x), sd, rm);
|
2740 | }
|
2741 |
|
2742 | if (!(c = x.c)) return null;
|
2743 | v = c.length - 1;
|
2744 | n = v * LOG_BASE + 1;
|
2745 |
|
2746 | if (v = c[v]) {
|
2747 |
|
2748 | // Subtract the number of trailing zeros of the last element.
|
2749 | for (; v % 10 == 0; v /= 10, n--);
|
2750 |
|
2751 | // Add the number of digits of the first element.
|
2752 | for (v = c[0]; v >= 10; v /= 10, n++);
|
2753 | }
|
2754 |
|
2755 | if (sd && x.e + 1 > n) n = x.e + 1;
|
2756 |
|
2757 | return n;
|
2758 | };
|
2759 |
|
2760 |
|
2761 | /*
|
2762 | * Return a new BigNumber whose value is the value of this BigNumber shifted by k places
|
2763 | * (powers of 10). Shift to the right if n > 0, and to the left if n < 0.
|
2764 | *
|
2765 | * k {number} Integer, -MAX_SAFE_INTEGER to MAX_SAFE_INTEGER inclusive.
|
2766 | *
|
2767 | * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {k}'
|
2768 | */
|
2769 | P.shiftedBy = function (k) {
|
2770 | intCheck(k, -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
|
2771 | return this.times('1e' + k);
|
2772 | };
|
2773 |
|
2774 |
|
2775 | /*
|
2776 | * sqrt(-n) = N
|
2777 | * sqrt(N) = N
|
2778 | * sqrt(-I) = N
|
2779 | * sqrt(I) = I
|
2780 | * sqrt(0) = 0
|
2781 | * sqrt(-0) = -0
|
2782 | *
|
2783 | * Return a new BigNumber whose value is the square root of the value of this BigNumber,
|
2784 | * rounded according to DECIMAL_PLACES and ROUNDING_MODE.
|
2785 | */
|
2786 | P.squareRoot = P.sqrt = function () {
|
2787 | var m, n, r, rep, t,
|
2788 | x = this,
|
2789 | c = x.c,
|
2790 | s = x.s,
|
2791 | e = x.e,
|
2792 | dp = DECIMAL_PLACES + 4,
|
2793 | half = new BigNumber('0.5');
|
2794 |
|
2795 | // Negative/NaN/Infinity/zero?
|
2796 | if (s !== 1 || !c || !c[0]) {
|
2797 | return new BigNumber(!s || s < 0 && (!c || c[0]) ? NaN : c ? x : 1 / 0);
|
2798 | }
|
2799 |
|
2800 | // Initial estimate.
|
2801 | s = Math.sqrt(+x);
|
2802 |
|
2803 | // Math.sqrt underflow/overflow?
|
2804 | // Pass x to Math.sqrt as integer, then adjust the exponent of the result.
|
2805 | if (s == 0 || s == 1 / 0) {
|
2806 | n = coeffToString(c);
|
2807 | if ((n.length + e) % 2 == 0) n += '0';
|
2808 | s = Math.sqrt(n);
|
2809 | e = bitFloor((e + 1) / 2) - (e < 0 || e % 2);
|
2810 |
|
2811 | if (s == 1 / 0) {
|
2812 | n = '1e' + e;
|
2813 | } else {
|
2814 | n = s.toExponential();
|
2815 | n = n.slice(0, n.indexOf('e') + 1) + e;
|
2816 | }
|
2817 |
|
2818 | r = new BigNumber(n);
|
2819 | } else {
|
2820 | r = new BigNumber(s + '');
|
2821 | }
|
2822 |
|
2823 | // Check for zero.
|
2824 | // r could be zero if MIN_EXP is changed after the this value was created.
|
2825 | // This would cause a division by zero (x/t) and hence Infinity below, which would cause
|
2826 | // coeffToString to throw.
|
2827 | if (r.c[0]) {
|
2828 | e = r.e;
|
2829 | s = e + dp;
|
2830 | if (s < 3) s = 0;
|
2831 |
|
2832 | // Newton-Raphson iteration.
|
2833 | for (; ;) {
|
2834 | t = r;
|
2835 | r = half.times(t.plus(div(x, t, dp, 1)));
|
2836 |
|
2837 | if (coeffToString(t.c ).slice(0, s) === (n =
|
2838 | coeffToString(r.c)).slice(0, s)) {
|
2839 |
|
2840 | // The exponent of r may here be one less than the final result exponent,
|
2841 | // e.g 0.0009999 (e-4) --> 0.001 (e-3), so adjust s so the rounding digits
|
2842 | // are indexed correctly.
|
2843 | if (r.e < e) --s;
|
2844 | n = n.slice(s - 3, s + 1);
|
2845 |
|
2846 | // The 4th rounding digit may be in error by -1 so if the 4 rounding digits
|
2847 | // are 9999 or 4999 (i.e. approaching a rounding boundary) continue the
|
2848 | // iteration.
|
2849 | if (n == '9999' || !rep && n == '4999') {
|
2850 |
|
2851 | // On the first iteration only, check to see if rounding up gives the
|
2852 | // exact result as the nines may infinitely repeat.
|
2853 | if (!rep) {
|
2854 | round(t, t.e + DECIMAL_PLACES + 2, 0);
|
2855 |
|
2856 | if (t.times(t).eq(x)) {
|
2857 | r = t;
|
2858 | break;
|
2859 | }
|
2860 | }
|
2861 |
|
2862 | dp += 4;
|
2863 | s += 4;
|
2864 | rep = 1;
|
2865 | } else {
|
2866 |
|
2867 | // If rounding digits are null, 0{0,4} or 50{0,3}, check for exact
|
2868 | // result. If not, then there are further digits and m will be truthy.
|
2869 | if (!+n || !+n.slice(1) && n.charAt(0) == '5') {
|
2870 |
|
2871 | // Truncate to the first rounding digit.
|
2872 | round(r, r.e + DECIMAL_PLACES + 2, 1);
|
2873 | m = !r.times(r).eq(x);
|
2874 | }
|
2875 |
|
2876 | break;
|
2877 | }
|
2878 | }
|
2879 | }
|
2880 | }
|
2881 |
|
2882 | return round(r, r.e + DECIMAL_PLACES + 1, ROUNDING_MODE, m);
|
2883 | };
|
2884 |
|
2885 |
|
2886 | /*
|
2887 | * Return a string representing the value of this BigNumber in exponential notation and
|
2888 | * rounded using ROUNDING_MODE to dp fixed decimal places.
|
2889 | *
|
2890 | * [dp] {number} Decimal places. Integer, 0 to MAX inclusive.
|
2891 | * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
|
2892 | *
|
2893 | * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {dp|rm}'
|
2894 | */
|
2895 | P.toExponential = function (dp, rm) {
|
2896 | if (dp != null) {
|
2897 | intCheck(dp, 0, MAX);
|
2898 | dp++;
|
2899 | }
|
2900 | return format(this, dp, rm, 1);
|
2901 | };
|
2902 |
|
2903 |
|
2904 | /*
|
2905 | * Return a string representing the value of this BigNumber in fixed-point notation rounding
|
2906 | * to dp fixed decimal places using rounding mode rm, or ROUNDING_MODE if rm is omitted.
|
2907 | *
|
2908 | * Note: as with JavaScript's number type, (-0).toFixed(0) is '0',
|
2909 | * but e.g. (-0.00001).toFixed(0) is '-0'.
|
2910 | *
|
2911 | * [dp] {number} Decimal places. Integer, 0 to MAX inclusive.
|
2912 | * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
|
2913 | *
|
2914 | * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {dp|rm}'
|
2915 | */
|
2916 | P.toFixed = function (dp, rm) {
|
2917 | if (dp != null) {
|
2918 | intCheck(dp, 0, MAX);
|
2919 | dp = dp + this.e + 1;
|
2920 | }
|
2921 | return format(this, dp, rm);
|
2922 | };
|
2923 |
|
2924 |
|
2925 | /*
|
2926 | * Return a string representing the value of this BigNumber in fixed-point notation rounded
|
2927 | * using rm or ROUNDING_MODE to dp decimal places, and formatted according to the properties
|
2928 | * of the FORMAT object (see BigNumber.set).
|
2929 | *
|
2930 | * FORMAT = {
|
2931 | * decimalSeparator : '.',
|
2932 | * groupSeparator : ',',
|
2933 | * groupSize : 3,
|
2934 | * secondaryGroupSize : 0,
|
2935 | * fractionGroupSeparator : '\xA0', // non-breaking space
|
2936 | * fractionGroupSize : 0
|
2937 | * };
|
2938 | *
|
2939 | * [dp] {number} Decimal places. Integer, 0 to MAX inclusive.
|
2940 | * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
|
2941 | *
|
2942 | * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {dp|rm}'
|
2943 | */
|
2944 | P.toFormat = function (dp, rm) {
|
2945 | var str = this.toFixed(dp, rm);
|
2946 |
|
2947 | if (this.c) {
|
2948 | var i,
|
2949 | arr = str.split('.'),
|
2950 | g1 = +FORMAT.groupSize,
|
2951 | g2 = +FORMAT.secondaryGroupSize,
|
2952 | groupSeparator = FORMAT.groupSeparator,
|
2953 | intPart = arr[0],
|
2954 | fractionPart = arr[1],
|
2955 | isNeg = this.s < 0,
|
2956 | intDigits = isNeg ? intPart.slice(1) : intPart,
|
2957 | len = intDigits.length;
|
2958 |
|
2959 | if (g2) i = g1, g1 = g2, g2 = i, len -= i;
|
2960 |
|
2961 | if (g1 > 0 && len > 0) {
|
2962 | i = len % g1 || g1;
|
2963 | intPart = intDigits.substr(0, i);
|
2964 |
|
2965 | for (; i < len; i += g1) {
|
2966 | intPart += groupSeparator + intDigits.substr(i, g1);
|
2967 | }
|
2968 |
|
2969 | if (g2 > 0) intPart += groupSeparator + intDigits.slice(i);
|
2970 | if (isNeg) intPart = '-' + intPart;
|
2971 | }
|
2972 |
|
2973 | str = fractionPart
|
2974 | ? intPart + FORMAT.decimalSeparator + ((g2 = +FORMAT.fractionGroupSize)
|
2975 | ? fractionPart.replace(new RegExp('\\d{' + g2 + '}\\B', 'g'),
|
2976 | '$&' + FORMAT.fractionGroupSeparator)
|
2977 | : fractionPart)
|
2978 | : intPart;
|
2979 | }
|
2980 |
|
2981 | return str;
|
2982 | };
|
2983 |
|
2984 |
|
2985 | /*
|
2986 | * Return a string array representing the value of this BigNumber as a simple fraction with
|
2987 | * an integer numerator and an integer denominator. The denominator will be a positive
|
2988 | * non-zero value less than or equal to the specified maximum denominator. If a maximum
|
2989 | * denominator is not specified, the denominator will be the lowest value necessary to
|
2990 | * represent the number exactly.
|
2991 | *
|
2992 | * [md] {number|string|BigNumber} Integer >= 1, or Infinity. The maximum denominator.
|
2993 | *
|
2994 | * '[BigNumber Error] Argument {not an integer|out of range} : {md}'
|
2995 | */
|
2996 | P.toFraction = function (md) {
|
2997 | var arr, d, d0, d1, d2, e, exp, n, n0, n1, q, s,
|
2998 | x = this,
|
2999 | xc = x.c;
|
3000 |
|
3001 | if (md != null) {
|
3002 | n = new BigNumber(md);
|
3003 |
|
3004 | // Throw if md is less than one or is not an integer, unless it is Infinity.
|
3005 | if (!n.isInteger() && (n.c || n.s !== 1) || n.lt(ONE)) {
|
3006 | throw Error
|
3007 | (bignumberError + 'Argument ' +
|
3008 | (n.isInteger() ? 'out of range: ' : 'not an integer: ') + md);
|
3009 | }
|
3010 | }
|
3011 |
|
3012 | if (!xc) return x.toString();
|
3013 |
|
3014 | d = new BigNumber(ONE);
|
3015 | n1 = d0 = new BigNumber(ONE);
|
3016 | d1 = n0 = new BigNumber(ONE);
|
3017 | s = coeffToString(xc);
|
3018 |
|
3019 | // Determine initial denominator.
|
3020 | // d is a power of 10 and the minimum max denominator that specifies the value exactly.
|
3021 | e = d.e = s.length - x.e - 1;
|
3022 | d.c[0] = POWS_TEN[(exp = e % LOG_BASE) < 0 ? LOG_BASE + exp : exp];
|
3023 | md = !md || n.comparedTo(d) > 0 ? (e > 0 ? d : n1) : n;
|
3024 |
|
3025 | exp = MAX_EXP;
|
3026 | MAX_EXP = 1 / 0;
|
3027 | n = new BigNumber(s);
|
3028 |
|
3029 | // n0 = d1 = 0
|
3030 | n0.c[0] = 0;
|
3031 |
|
3032 | for (; ;) {
|
3033 | q = div(n, d, 0, 1);
|
3034 | d2 = d0.plus(q.times(d1));
|
3035 | if (d2.comparedTo(md) == 1) break;
|
3036 | d0 = d1;
|
3037 | d1 = d2;
|
3038 | n1 = n0.plus(q.times(d2 = n1));
|
3039 | n0 = d2;
|
3040 | d = n.minus(q.times(d2 = d));
|
3041 | n = d2;
|
3042 | }
|
3043 |
|
3044 | d2 = div(md.minus(d0), d1, 0, 1);
|
3045 | n0 = n0.plus(d2.times(n1));
|
3046 | d0 = d0.plus(d2.times(d1));
|
3047 | n0.s = n1.s = x.s;
|
3048 | e *= 2;
|
3049 |
|
3050 | // Determine which fraction is closer to x, n0/d0 or n1/d1
|
3051 | arr = div(n1, d1, e, ROUNDING_MODE).minus(x).abs().comparedTo(
|
3052 | div(n0, d0, e, ROUNDING_MODE).minus(x).abs()) < 1
|
3053 | ? [n1.toString(), d1.toString()]
|
3054 | : [n0.toString(), d0.toString()];
|
3055 |
|
3056 | MAX_EXP = exp;
|
3057 | return arr;
|
3058 | };
|
3059 |
|
3060 |
|
3061 | /*
|
3062 | * Return the value of this BigNumber converted to a number primitive.
|
3063 | */
|
3064 | P.toNumber = function () {
|
3065 | return +this;
|
3066 | };
|
3067 |
|
3068 |
|
3069 | /*
|
3070 | * Return a string representing the value of this BigNumber rounded to sd significant digits
|
3071 | * using rounding mode rm or ROUNDING_MODE. If sd is less than the number of digits
|
3072 | * necessary to represent the integer part of the value in fixed-point notation, then use
|
3073 | * exponential notation.
|
3074 | *
|
3075 | * [sd] {number} Significant digits. Integer, 1 to MAX inclusive.
|
3076 | * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
|
3077 | *
|
3078 | * '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {sd|rm}'
|
3079 | */
|
3080 | P.toPrecision = function (sd, rm) {
|
3081 | if (sd != null) intCheck(sd, 1, MAX);
|
3082 | return format(this, sd, rm, 2);
|
3083 | };
|
3084 |
|
3085 |
|
3086 | /*
|
3087 | * Return a string representing the value of this BigNumber in base b, or base 10 if b is
|
3088 | * omitted. If a base is specified, including base 10, round according to DECIMAL_PLACES and
|
3089 | * ROUNDING_MODE. If a base is not specified, and this BigNumber has a positive exponent
|
3090 | * that is equal to or greater than TO_EXP_POS, or a negative exponent equal to or less than
|
3091 | * TO_EXP_NEG, return exponential notation.
|
3092 | *
|
3093 | * [b] {number} Integer, 2 to ALPHABET.length inclusive.
|
3094 | *
|
3095 | * '[BigNumber Error] Base {not a primitive number|not an integer|out of range}: {b}'
|
3096 | */
|
3097 | P.toString = function (b) {
|
3098 | var str,
|
3099 | n = this,
|
3100 | s = n.s,
|
3101 | e = n.e;
|
3102 |
|
3103 | // Infinity or NaN?
|
3104 | if (e === null) {
|
3105 |
|
3106 | if (s) {
|
3107 | str = 'Infinity';
|
3108 | if (s < 0) str = '-' + str;
|
3109 | } else {
|
3110 | str = 'NaN';
|
3111 | }
|
3112 | } else {
|
3113 | str = coeffToString(n.c);
|
3114 |
|
3115 | if (b == null) {
|
3116 | str = e <= TO_EXP_NEG || e >= TO_EXP_POS
|
3117 | ? toExponential(str, e)
|
3118 | : toFixedPoint(str, e, '0');
|
3119 | } else {
|
3120 | intCheck(b, 2, ALPHABET.length, 'Base');
|
3121 | str = convertBase(toFixedPoint(str, e, '0'), 10, b, s, true);
|
3122 | }
|
3123 |
|
3124 | if (s < 0 && n.c[0]) str = '-' + str;
|
3125 | }
|
3126 |
|
3127 | return str;
|
3128 | };
|
3129 |
|
3130 |
|
3131 | /*
|
3132 | * Return as toString, but do not accept a base argument, and include the minus sign for
|
3133 | * negative zero.
|
3134 | */
|
3135 | P.valueOf = P.toJSON = function () {
|
3136 | var str,
|
3137 | n = this,
|
3138 | e = n.e;
|
3139 |
|
3140 | if (e === null) return n.toString();
|
3141 |
|
3142 | str = coeffToString(n.c);
|
3143 |
|
3144 | str = e <= TO_EXP_NEG || e >= TO_EXP_POS
|
3145 | ? toExponential(str, e)
|
3146 | : toFixedPoint(str, e, '0');
|
3147 |
|
3148 | return n.s < 0 ? '-' + str : str;
|
3149 | };
|
3150 |
|
3151 |
|
3152 | P._isBigNumber = true;
|
3153 |
|
3154 | if (configObject != null) BigNumber.set(configObject);
|
3155 |
|
3156 | return BigNumber;
|
3157 | }
|
3158 |
|
3159 |
|
3160 | // PRIVATE HELPER FUNCTIONS
|
3161 |
|
3162 |
|
3163 | function bitFloor(n) {
|
3164 | var i = n | 0;
|
3165 | return n > 0 || n === i ? i : i - 1;
|
3166 | }
|
3167 |
|
3168 |
|
3169 | // Return a coefficient array as a string of base 10 digits.
|
3170 | function coeffToString(a) {
|
3171 | var s, z,
|
3172 | i = 1,
|
3173 | j = a.length,
|
3174 | r = a[0] + '';
|
3175 |
|
3176 | for (; i < j;) {
|
3177 | s = a[i++] + '';
|
3178 | z = LOG_BASE - s.length;
|
3179 | for (; z--; s = '0' + s);
|
3180 | r += s;
|
3181 | }
|
3182 |
|
3183 | // Determine trailing zeros.
|
3184 | for (j = r.length; r.charCodeAt(--j) === 48;);
|
3185 | return r.slice(0, j + 1 || 1);
|
3186 | }
|
3187 |
|
3188 |
|
3189 | // Compare the value of BigNumbers x and y.
|
3190 | function compare(x, y) {
|
3191 | var a, b,
|
3192 | xc = x.c,
|
3193 | yc = y.c,
|
3194 | i = x.s,
|
3195 | j = y.s,
|
3196 | k = x.e,
|
3197 | l = y.e;
|
3198 |
|
3199 | // Either NaN?
|
3200 | if (!i || !j) return null;
|
3201 |
|
3202 | a = xc && !xc[0];
|
3203 | b = yc && !yc[0];
|
3204 |
|
3205 | // Either zero?
|
3206 | if (a || b) return a ? b ? 0 : -j : i;
|
3207 |
|
3208 | // Signs differ?
|
3209 | if (i != j) return i;
|
3210 |
|
3211 | a = i < 0;
|
3212 | b = k == l;
|
3213 |
|
3214 | // Either Infinity?
|
3215 | if (!xc || !yc) return b ? 0 : !xc ^ a ? 1 : -1;
|
3216 |
|
3217 | // Compare exponents.
|
3218 | if (!b) return k > l ^ a ? 1 : -1;
|
3219 |
|
3220 | j = (k = xc.length) < (l = yc.length) ? k : l;
|
3221 |
|
3222 | // Compare digit by digit.
|
3223 | for (i = 0; i < j; i++) if (xc[i] != yc[i]) return xc[i] > yc[i] ^ a ? 1 : -1;
|
3224 |
|
3225 | // Compare lengths.
|
3226 | return k == l ? 0 : k > l ^ a ? 1 : -1;
|
3227 | }
|
3228 |
|
3229 |
|
3230 | /*
|
3231 | * Check that n is a primitive number, an integer, and in range, otherwise throw.
|
3232 | */
|
3233 | function intCheck(n, min, max, name) {
|
3234 | if (n < min || n > max || n !== (n < 0 ? mathceil(n) : mathfloor(n))) {
|
3235 | throw Error
|
3236 | (bignumberError + (name || 'Argument') + (typeof n == 'number'
|
3237 | ? n < min || n > max ? ' out of range: ' : ' not an integer: '
|
3238 | : ' not a primitive number: ') + n);
|
3239 | }
|
3240 | }
|
3241 |
|
3242 |
|
3243 | function isArray(obj) {
|
3244 | return Object.prototype.toString.call(obj) == '[object Array]';
|
3245 | }
|
3246 |
|
3247 |
|
3248 | // Assumes finite n.
|
3249 | function isOdd(n) {
|
3250 | var k = n.c.length - 1;
|
3251 | return bitFloor(n.e / LOG_BASE) == k && n.c[k] % 2 != 0;
|
3252 | }
|
3253 |
|
3254 |
|
3255 | function toExponential(str, e) {
|
3256 | return (str.length > 1 ? str.charAt(0) + '.' + str.slice(1) : str) +
|
3257 | (e < 0 ? 'e' : 'e+') + e;
|
3258 | }
|
3259 |
|
3260 |
|
3261 | function toFixedPoint(str, e, z) {
|
3262 | var len, zs;
|
3263 |
|
3264 | // Negative exponent?
|
3265 | if (e < 0) {
|
3266 |
|
3267 | // Prepend zeros.
|
3268 | for (zs = z + '.'; ++e; zs += z);
|
3269 | str = zs + str;
|
3270 |
|
3271 | // Positive exponent
|
3272 | } else {
|
3273 | len = str.length;
|
3274 |
|
3275 | // Append zeros.
|
3276 | if (++e > len) {
|
3277 | for (zs = z, e -= len; --e; zs += z);
|
3278 | str += zs;
|
3279 | } else if (e < len) {
|
3280 | str = str.slice(0, e) + '.' + str.slice(e);
|
3281 | }
|
3282 | }
|
3283 |
|
3284 | return str;
|
3285 | }
|
3286 |
|
3287 |
|
3288 | // EXPORTS
|
3289 |
|
3290 |
|
3291 | var BigNumber = clone();
|
3292 |
|
3293 | /* harmony default export */ var bignumber = (BigNumber);
|
3294 |
|
3295 | // CONCATENATED MODULE: ../neon-core/lib/u/Fixed8.js
|
3296 |
|
3297 |
|
3298 | const DECIMALS = 100000000;
|
3299 | // This is the maximum hex integer 0x7fffffffffffffff (= 9223372036854775807)
|
3300 | // that can be converted to Fixed8 by dividing by the 10^8.
|
3301 | const MAX_FIXED8_HEX = new bignumber(2).pow(63).minus(1);
|
3302 | // This is the minimum hex integer 0x8000000000000000 (= -9223372036854775808)
|
3303 | // that can be converted to Fixed8 by dividing by the 10^8.
|
3304 | const MIN_FIXED8_HEX = new bignumber(2).pow(63).negated();
|
3305 | // Total number of Fixed8 available. This includes negative and positive
|
3306 | // Fixed8 numbers.
|
3307 | const TOTAL_FIXED8_HEX = new bignumber(2).pow(64);
|
3308 | /**
|
3309 | * A fixed point notation used widely in the NEO system for representing decimals.
|
3310 | * It is basically a hexideciaml integer that is divided by the 10^8.
|
3311 | * Supports up to 8 decimals and is 8 bytes long.
|
3312 | * @extends BN
|
3313 | */
|
3314 | class Fixed8_Fixed8 extends bignumber {
|
3315 | constructor(input, base = 10) {
|
3316 | if (!input) {
|
3317 | input = "0";
|
3318 | }
|
3319 | if (typeof input === "number") {
|
3320 | input = input.toFixed(8);
|
3321 | }
|
3322 | super(input, base);
|
3323 | if (this.isGreaterThan(Fixed8_Fixed8.MAX_VALUE)) {
|
3324 | throw new Error(`expected input to be less than ${Fixed8_Fixed8.MAX_VALUE}. Got input = ${this}`);
|
3325 | }
|
3326 | if (this.isLessThan(Fixed8_Fixed8.MIN_VALUE)) {
|
3327 | throw new Error(`expected input to be greater than ${Fixed8_Fixed8.MIN_VALUE}. Got input = ${this}`);
|
3328 | }
|
3329 | Object.setPrototypeOf(this, Fixed8_Fixed8.prototype);
|
3330 | }
|
3331 | static fromHex(hex) {
|
3332 | if (hex.length > 16) {
|
3333 | throw new Error(`expected hex string to have length less or equal than 16: got ${hex.length} for hex = ${hex}`);
|
3334 | }
|
3335 | let n = new bignumber(hex, 16);
|
3336 | if (n.isGreaterThan(MAX_FIXED8_HEX)) {
|
3337 | // convert n to two complement
|
3338 | n = n.minus(TOTAL_FIXED8_HEX);
|
3339 | }
|
3340 | n = n.div(DECIMALS);
|
3341 | return new Fixed8_Fixed8(n, 10);
|
3342 | }
|
3343 | static fromReverseHex(hex) {
|
3344 | return this.fromHex(reverseHex(hex));
|
3345 | }
|
3346 | toHex() {
|
3347 | let hexstring = "";
|
3348 | const num = this.toRawNumber();
|
3349 | hexstring = num.isLessThan(0)
|
3350 | ? TOTAL_FIXED8_HEX.plus(num).toString(16) // convert num to two complement
|
3351 | : num.toString(16);
|
3352 | return "0".repeat(16 - hexstring.length) + hexstring;
|
3353 | }
|
3354 | toReverseHex() {
|
3355 | return reverseHex(this.toHex());
|
3356 | }
|
3357 | /**
|
3358 | * Returns a raw number represetation of Fixed8.
|
3359 | */
|
3360 | toRawNumber() {
|
3361 | return super.times(DECIMALS);
|
3362 | }
|
3363 | /**
|
3364 | * Returns a Fixed8 whose value is rounded upwards to the next whole number.
|
3365 | */
|
3366 | ceil() {
|
3367 | return new Fixed8_Fixed8(super.decimalPlaces(0, bignumber.ROUND_CEIL));
|
3368 | }
|
3369 | /**
|
3370 | * Returns a Fixed8 whose value is rounded downwards to the previous whole number.
|
3371 | */
|
3372 | floor() {
|
3373 | return new Fixed8_Fixed8(super.decimalPlaces(0, bignumber.ROUND_FLOOR));
|
3374 | }
|
3375 | /**
|
3376 | * Returns true if the value is equivalent.
|
3377 | */
|
3378 | equals(other) {
|
3379 | return super.eq(other);
|
3380 | }
|
3381 | /**
|
3382 | * Returns a Fixed8 rounded to the nearest dp decimal places according to rounding mode rm.
|
3383 | * If dp is null, round to whole number.
|
3384 | * If rm is null, round according to default rounding mode.
|
3385 | * @param dp
|
3386 | * @param rm
|
3387 | * @return {Fixed8}
|
3388 | */
|
3389 | round(dp = 0, rm) {
|
3390 | return new Fixed8_Fixed8(super.decimalPlaces(dp, rm));
|
3391 | }
|
3392 | /**
|
3393 | * Returns a Fixed8 whose value is the value of this Fixed8 divided by `n`
|
3394 | * @alias div
|
3395 | */
|
3396 | dividedBy(n, base) {
|
3397 | return new Fixed8_Fixed8(super.dividedBy(n, base));
|
3398 | }
|
3399 | div(n, base) {
|
3400 | return this.dividedBy(n, base);
|
3401 | }
|
3402 | /**
|
3403 | * Returns a Fixed8 whose value is the value of this Fixed8 multipled by `n`
|
3404 | * @alias mul
|
3405 | */
|
3406 | times(n, base) {
|
3407 | return new Fixed8_Fixed8(super.times(n, base));
|
3408 | }
|
3409 | mul(n, base) {
|
3410 | return this.times(n, base);
|
3411 | }
|
3412 | /**
|
3413 | * Returns a Fixed8 whose value is the value of this Fixed8 plus `n`
|
3414 | * @alias add
|
3415 | */
|
3416 | plus(n, base) {
|
3417 | return new Fixed8_Fixed8(super.plus(n, base));
|
3418 | }
|
3419 | add(n, base) {
|
3420 | return this.plus(n, base);
|
3421 | }
|
3422 | /**
|
3423 | * Returns a Fixed8 whose value is the value of this Fixed8 minus `n`
|
3424 | * @alias sub
|
3425 | */
|
3426 | minus(n, base) {
|
3427 | return new Fixed8_Fixed8(super.minus(n, base));
|
3428 | }
|
3429 | sub(n, base) {
|
3430 | return this.minus(n, base);
|
3431 | }
|
3432 | }
|
3433 | // The maximum Fixed8 is obtained by dividing 0x7fffffffffffffff (= 9223372036854775807) with 10^8.
|
3434 | Fixed8_Fixed8.MAX_VALUE = new Fixed8_Fixed8(MAX_FIXED8_HEX.div(DECIMALS));
|
3435 | // The minimum Fixed8 is obtained by dividing 0x8000000000000000 (= -9223372036854775808) with 10^8.
|
3436 | Fixed8_Fixed8.MIN_VALUE = new Fixed8_Fixed8(MIN_FIXED8_HEX.div(DECIMALS));
|
3437 | /* harmony default export */ var u_Fixed8 = (Fixed8_Fixed8);
|
3438 | //# sourceMappingURL=Fixed8.js.map
|
3439 | // CONCATENATED MODULE: ../neon-core/lib/u/convert.js
|
3440 |
|
3441 |
|
3442 | /**
|
3443 | * @param buf ArrayBuffer
|
3444 | * @returns ASCII string
|
3445 | */
|
3446 | function ab2str(buf) {
|
3447 | return String.fromCharCode.apply(null, Array.from(new Uint8Array(buf)));
|
3448 | }
|
3449 | /**
|
3450 | * @param str ASCII string
|
3451 | * @returns
|
3452 | */
|
3453 | function str2ab(str) {
|
3454 | if (typeof str !== "string") {
|
3455 | throw new Error(`str2ab expected a string but got ${typeof str} instead.`);
|
3456 | }
|
3457 | const result = new Uint8Array(str.length);
|
3458 | for (let i = 0, strLen = str.length; i < strLen; i++) {
|
3459 | result[i] = str.charCodeAt(i);
|
3460 | }
|
3461 | return result;
|
3462 | }
|
3463 | /**
|
3464 | * @param str HEX string
|
3465 | * @returns
|
3466 | */
|
3467 | function hexstring2ab(str) {
|
3468 | ensureHex(str);
|
3469 | if (!str.length) {
|
3470 | return new Uint8Array(0);
|
3471 | }
|
3472 | const iters = str.length / 2;
|
3473 | const result = new Uint8Array(iters);
|
3474 | for (let i = 0; i < iters; i++) {
|
3475 | result[i] = parseInt(str.substring(0, 2), 16);
|
3476 | str = str.substring(2);
|
3477 | }
|
3478 | return result;
|
3479 | }
|
3480 | /**
|
3481 | * @param arr
|
3482 | * @returns HEX string
|
3483 | */
|
3484 | function ab2hexstring(arr) {
|
3485 | if (typeof arr !== "object") {
|
3486 | throw new Error(`ab2hexstring expects an array. Input was ${arr}`);
|
3487 | }
|
3488 | let result = "";
|
3489 | const intArray = new Uint8Array(arr);
|
3490 | for (const i of intArray) {
|
3491 | let str = i.toString(16);
|
3492 | str = str.length === 0 ? "00" : str.length === 1 ? "0" + str : str;
|
3493 | result += str;
|
3494 | }
|
3495 | return result;
|
3496 | }
|
3497 | /**
|
3498 | * @param str ASCII string
|
3499 | * @returns HEX string
|
3500 | */
|
3501 | function str2hexstring(str) {
|
3502 | return ab2hexstring(str2ab(str));
|
3503 | }
|
3504 | /**
|
3505 | * @param hexstring HEX string
|
3506 | * @returns ASCII string
|
3507 | */
|
3508 | function hexstring2str(hexstring) {
|
3509 | return ab2str(hexstring2ab(hexstring));
|
3510 | }
|
3511 | /**
|
3512 | * convert an integer to big endian hex and add leading zeros
|
3513 | * @param num Integer.
|
3514 | */
|
3515 | function int2hex(num) {
|
3516 | if (typeof num !== "number") {
|
3517 | throw new Error(`int2hex expected a number but got ${typeof num} instead.`);
|
3518 | }
|
3519 | const h = num.toString(16);
|
3520 | return h.length % 2 ? "0" + h : h;
|
3521 | }
|
3522 | /**
|
3523 | * Converts a number to a big endian hexstring of a suitable size, optionally little endian
|
3524 | * @param num A positive integer.
|
3525 | * @param size The required size in bytes, eg 1 for Uint8, 2 for Uint16. Defaults to 1.
|
3526 | * @param littleEndian Encode the hex in little endian form
|
3527 | */
|
3528 | function num2hexstring(num, size = 1, littleEndian = false) {
|
3529 | if (typeof num !== "number") {
|
3530 | throw new Error(`num2hexstring expected a number but got ${typeof num} instead.`);
|
3531 | }
|
3532 | if (num < 0) {
|
3533 | throw new RangeError(`num2hexstring expected a positive integer but got ${num} instead.`);
|
3534 | }
|
3535 | if (size % 1 !== 0) {
|
3536 | throw new Error(`num2hexstring expected a positive integer but got ${num} instead.`);
|
3537 | }
|
3538 | if (!Number.isSafeInteger(num)) {
|
3539 | throw new RangeError(`num2hexstring expected a safe integer but got ${num} instead.`);
|
3540 | }
|
3541 | size = size * 2;
|
3542 | let hexstring = num.toString(16);
|
3543 | hexstring =
|
3544 | hexstring.length % size === 0
|
3545 | ? hexstring
|
3546 | : ("0".repeat(size) + hexstring).substring(hexstring.length);
|
3547 | if (littleEndian) {
|
3548 | hexstring = reverseHex(hexstring);
|
3549 | }
|
3550 | return hexstring;
|
3551 | }
|
3552 | /**
|
3553 | * Converts a number to a Fixed8 format hex string
|
3554 | * @param num
|
3555 | * @param size output size in bytes
|
3556 | * @return number in Fixed8 representation.
|
3557 | */
|
3558 | function num2fixed8(num, size = 8) {
|
3559 | if (typeof num !== "number") {
|
3560 | throw new Error(`num2fixed8 expected a number but got ${typeof num} instead.`);
|
3561 | }
|
3562 | if (size % 1 !== 0) {
|
3563 | throw new Error(`num2fixed expected an integer for argument size but got ${size} instead.`);
|
3564 | }
|
3565 | const i = new u_Fixed8(num);
|
3566 | return new u_Fixed8(num).toReverseHex().slice(0, size * 2);
|
3567 | }
|
3568 | /**
|
3569 | * Converts a Fixed8 hex string to its original number
|
3570 | * @param fixed8hex number in Fixed8 representation
|
3571 | */
|
3572 | function fixed82num(fixed8hex) {
|
3573 | ensureHex(fixed8hex);
|
3574 | if (fixed8hex === "") {
|
3575 | return 0;
|
3576 | }
|
3577 | return u_Fixed8.fromReverseHex(fixed8hex).toNumber();
|
3578 | }
|
3579 | /**
|
3580 | * Converts a number to a variable length Int. Used for array length header
|
3581 | * @param num
|
3582 | * @returns hexstring of int.
|
3583 | */
|
3584 | function num2VarInt(num) {
|
3585 | if (num < 0xfd) {
|
3586 | return num2hexstring(num);
|
3587 | }
|
3588 | else if (num <= 0xffff) {
|
3589 | // uint16
|
3590 | return "fd" + num2hexstring(num, 2, true);
|
3591 | }
|
3592 | else if (num <= 0xffffffff) {
|
3593 | // uint32
|
3594 | return "fe" + num2hexstring(num, 4, true);
|
3595 | }
|
3596 | else {
|
3597 | // uint64
|
3598 | return "ff" + num2hexstring(num, 8, true);
|
3599 | }
|
3600 | }
|
3601 | //# sourceMappingURL=convert.js.map
|
3602 | // CONCATENATED MODULE: ../neon-core/lib/u/misc.js
|
3603 |
|
3604 | const hexRegex = /^([0-9A-Fa-f]{2})*$/;
|
3605 | /**
|
3606 | * Checks if input is a hexstring. Empty string is considered a hexstring.
|
3607 | */
|
3608 | function isHex(str) {
|
3609 | try {
|
3610 | return hexRegex.test(str);
|
3611 | }
|
3612 | catch (err) {
|
3613 | return false;
|
3614 | }
|
3615 | }
|
3616 | /**
|
3617 | * Throws an error if input is not hexstring.
|
3618 | */
|
3619 | function ensureHex(str) {
|
3620 | if (!isHex(str)) {
|
3621 | throw new Error(`Expected a hexstring but got ${str}`);
|
3622 | }
|
3623 | }
|
3624 | /**
|
3625 | * XORs two hexstrings
|
3626 | * @param str1 HEX string
|
3627 | * @param str2 HEX string
|
3628 | * @returns XOR output as a HEX string
|
3629 | */
|
3630 | function hexXor(str1, str2) {
|
3631 | ensureHex(str1);
|
3632 | ensureHex(str2);
|
3633 | if (str1.length !== str2.length) {
|
3634 | throw new Error(`strings are disparate lengths. Inputs are of length ${str1.length} and ${str2.length}`);
|
3635 | }
|
3636 | const result = [];
|
3637 | for (let i = 0; i < str1.length; i += 2) {
|
3638 | result.push(
|
3639 | // tslint:disable-next-line:no-bitwise
|
3640 | parseInt(str1.substr(i, 2), 16) ^ parseInt(str2.substr(i, 2), 16));
|
3641 | }
|
3642 | return ab2hexstring(result);
|
3643 | }
|
3644 | /**
|
3645 | * Reverses an array.
|
3646 | * @example
|
3647 | * reverseArray('abcd') = 'cdba'
|
3648 | */
|
3649 | function reverseArray(arr) {
|
3650 | if (typeof arr !== "object" || !arr.length) {
|
3651 | throw new Error("reverseArray expects an array");
|
3652 | }
|
3653 | const result = new Array(arr.length);
|
3654 | for (let i = 0; i < arr.length; i++) {
|
3655 | result[i] = arr[arr.length - 1 - i];
|
3656 | }
|
3657 | return result;
|
3658 | }
|
3659 | /**
|
3660 | * Reverses a HEX string, treating 2 chars as a byte.
|
3661 | * @example
|
3662 | * reverseHex('abcdef') = 'efcdab'
|
3663 | */
|
3664 | function reverseHex(hex) {
|
3665 | ensureHex(hex);
|
3666 | let out = "";
|
3667 | for (let i = hex.length - 2; i >= 0; i -= 2) {
|
3668 | out += hex.substr(i, 2);
|
3669 | }
|
3670 | return out;
|
3671 | }
|
3672 | //# sourceMappingURL=misc.js.map
|
3673 | // EXTERNAL MODULE: /home/circleci/repo/node_modules/crypto-js/enc-hex.js
|
3674 | var enc_hex = __webpack_require__(14);
|
3675 | var enc_hex_default = /*#__PURE__*/__webpack_require__.n(enc_hex);
|
3676 |
|
3677 | // EXTERNAL MODULE: /home/circleci/repo/node_modules/crypto-js/ripemd160.js
|
3678 | var ripemd160 = __webpack_require__(45);
|
3679 | var ripemd160_default = /*#__PURE__*/__webpack_require__.n(ripemd160);
|
3680 |
|
3681 | // EXTERNAL MODULE: /home/circleci/repo/node_modules/crypto-js/sha256.js
|
3682 | var sha256 = __webpack_require__(10);
|
3683 | var sha256_default = /*#__PURE__*/__webpack_require__.n(sha256);
|
3684 |
|
3685 | // CONCATENATED MODULE: ../neon-core/lib/u/hash.js
|
3686 |
|
3687 |
|
3688 |
|
3689 | function hash_hash(hex, hashingFunction) {
|
3690 | const hexEncoded = enc_hex_default.a.parse(hex);
|
3691 | const result = hashingFunction(hexEncoded);
|
3692 | return result.toString(enc_hex_default.a);
|
3693 | }
|
3694 | /**
|
3695 | * Performs a single SHA256.
|
3696 | */
|
3697 | function hash_sha256(hex) {
|
3698 | return hash_hash(hex, sha256_default.a);
|
3699 | }
|
3700 | /**
|
3701 | * Performs a single RIPEMD160.
|
3702 | */
|
3703 | function hash_ripemd160(hex) {
|
3704 | return hash_hash(hex, ripemd160_default.a);
|
3705 | }
|
3706 | /**
|
3707 | * Performs a SHA256 followed by a RIPEMD160.
|
3708 | */
|
3709 | function hash160(hex) {
|
3710 | const sha = hash_sha256(hex);
|
3711 | return hash_ripemd160(sha);
|
3712 | // const hexEncoded = safeParseHex(hex);
|
3713 | // const ProgramSha256 = SHA256(hexEncoded);
|
3714 | // return RIPEMD160(ProgramSha256.toString()).toString();
|
3715 | }
|
3716 | /**
|
3717 | * Performs 2 SHA256.
|
3718 | */
|
3719 | function hash256(hex) {
|
3720 | const firstSha = hash_sha256(hex);
|
3721 | return hash_sha256(firstSha);
|
3722 | // const hexEncoded = safeParseHex(hex);
|
3723 | // const ProgramSha256 = SHA256(hexEncoded);
|
3724 | // return SHA256(ProgramSha256).toString();
|
3725 | }
|
3726 | //# sourceMappingURL=hash.js.map
|
3727 | // CONCATENATED MODULE: ../neon-core/lib/u/StringStream.js
|
3728 |
|
3729 | /**
|
3730 | * A simple string stream that allows user to read a string byte by byte using read().
|
3731 | * @param str - The string to read as a stream.
|
3732 | */
|
3733 | class StringStream_StringStream {
|
3734 | /**
|
3735 | * Initializes the stream with given string and pointer at position 0.
|
3736 | */
|
3737 | constructor(str = "") {
|
3738 | this.str = str;
|
3739 | this.pter = 0;
|
3740 | }
|
3741 | /**
|
3742 | * Checks if reached the end of the stream. Does not mean stream is actually empty (this.str is not empty).
|
3743 | * @example
|
3744 | * const ss = new StringStream("01020304");
|
3745 | * ss.isEmpty(); // false
|
3746 | * ss.pter = 3;
|
3747 | * ss.isEmpty(); // true
|
3748 | */
|
3749 | isEmpty() {
|
3750 | return this.pter >= this.str.length;
|
3751 | }
|
3752 | /**
|
3753 | * Peek at the next bytes on the string. May return less than intended bytes if reaching end of stream.
|
3754 | * @example
|
3755 | * const ss = new StringStream("0102");
|
3756 | * ss.peek(); // "01"
|
3757 | * ss.peek(5); // "0102"
|
3758 | */
|
3759 | peek(bytes = 1) {
|
3760 | if (this.isEmpty()) {
|
3761 | return "";
|
3762 | }
|
3763 | return this.str.substr(this.pter, bytes * 2);
|
3764 | }
|
3765 | /**
|
3766 | * Reads some bytes off the stream.
|
3767 | * @param bytes Number of bytes to read
|
3768 | * @example
|
3769 | * const ss = new StringStream("01020304");
|
3770 | * ss.read(); // "01"
|
3771 | * ss.read(2); // "0203"
|
3772 | */
|
3773 | read(bytes = 1) {
|
3774 | if (this.isEmpty()) {
|
3775 | throw new Error("Reached the end of the stream!");
|
3776 | }
|
3777 | const out = this.str.substr(this.pter, bytes * 2);
|
3778 | this.pter += bytes * 2;
|
3779 | return out;
|
3780 | }
|
3781 | /**
|
3782 | * Reads some bytes off the stream.
|
3783 | * A variable-length integer is first read off the stream and then bytes equal to the integer is read off and returned.
|
3784 | */
|
3785 | readVarBytes() {
|
3786 | return this.read(this.readVarInt());
|
3787 | }
|
3788 | /**
|
3789 | * Reads an integer of variable bytelength. May consume up to 9 bytes.
|
3790 | * The first byte read indicates if more bytes need to be read off.
|
3791 | */
|
3792 | readVarInt() {
|
3793 | let len = parseInt(this.read(1), 16);
|
3794 | if (len === 0xfd) {
|
3795 | len = parseInt(reverseHex(this.read(2)), 16);
|
3796 | }
|
3797 | else if (len === 0xfe) {
|
3798 | len = parseInt(reverseHex(this.read(4)), 16);
|
3799 | }
|
3800 | else if (len === 0xff) {
|
3801 | len = parseInt(reverseHex(this.read(8)), 16);
|
3802 | }
|
3803 | return len;
|
3804 | }
|
3805 | /**
|
3806 | * Resets the pointer to start of string.
|
3807 | * @example
|
3808 | * const ss = new StringStream("010203");
|
3809 | * ss.read(); //"01"
|
3810 | * ss.reset();
|
3811 | * ss.read(); // "01"
|
3812 | */
|
3813 | reset() {
|
3814 | this.pter = 0;
|
3815 | }
|
3816 | /**
|
3817 | * Returns a printable string of the characters around the pointer.
|
3818 | * Used for debugging.
|
3819 | */
|
3820 | context() {
|
3821 | const before = this.pter > 10
|
3822 | ? this.str.slice(this.pter - 10, this.pter)
|
3823 | : this.str.slice(0, this.pter);
|
3824 | const current = this.read(1);
|
3825 | const after = this.peek(5);
|
3826 | this.pter -= 2;
|
3827 | return `${before}|${current}|${after}`;
|
3828 | }
|
3829 | }
|
3830 | /* harmony default export */ var u_StringStream = (StringStream_StringStream);
|
3831 | //# sourceMappingURL=StringStream.js.map
|
3832 | // EXTERNAL MODULE: /home/circleci/repo/node_modules/secure-random/lib/secure-random.js
|
3833 | var secure_random = __webpack_require__(46);
|
3834 | var secure_random_default = /*#__PURE__*/__webpack_require__.n(secure_random);
|
3835 |
|
3836 | // CONCATENATED MODULE: ../neon-core/lib/u/random.js
|
3837 |
|
3838 | /**
|
3839 | * Generates a arrayBuffer filled with random bits.
|
3840 | * @param length Length of buffer.
|
3841 | */
|
3842 | const generateRandomArray = (length) => {
|
3843 | return secure_random_default()(length);
|
3844 | };
|
3845 | //# sourceMappingURL=random.js.map
|
3846 | // CONCATENATED MODULE: ../neon-core/lib/u/index.js
|
3847 |
|
3848 |
|
3849 |
|
3850 |
|
3851 |
|
3852 |
|
3853 | //# sourceMappingURL=index.js.map
|
3854 | // CONCATENATED MODULE: ../neon-core/lib/tx/txAttrUsage.js
|
3855 | /**
|
3856 | * Enum for TransactionAttributeUsage
|
3857 | * @enum {number}
|
3858 | */
|
3859 | var TxAttrUsage;
|
3860 | (function (TxAttrUsage) {
|
3861 | TxAttrUsage[TxAttrUsage["ContractHash"] = 0] = "ContractHash";
|
3862 | TxAttrUsage[TxAttrUsage["ECDH02"] = 2] = "ECDH02";
|
3863 | TxAttrUsage[TxAttrUsage["ECDH03"] = 3] = "ECDH03";
|
3864 | TxAttrUsage[TxAttrUsage["Script"] = 32] = "Script";
|
3865 | TxAttrUsage[TxAttrUsage["Vote"] = 48] = "Vote";
|
3866 | TxAttrUsage[TxAttrUsage["DescriptionUrl"] = 129] = "DescriptionUrl";
|
3867 | TxAttrUsage[TxAttrUsage["Description"] = 144] = "Description";
|
3868 | TxAttrUsage[TxAttrUsage["Hash1"] = 161] = "Hash1";
|
3869 | TxAttrUsage[TxAttrUsage["Hash2"] = 162] = "Hash2";
|
3870 | TxAttrUsage[TxAttrUsage["Hash3"] = 163] = "Hash3";
|
3871 | TxAttrUsage[TxAttrUsage["Hash4"] = 164] = "Hash4";
|
3872 | TxAttrUsage[TxAttrUsage["Hash5"] = 165] = "Hash5";
|
3873 | TxAttrUsage[TxAttrUsage["Hash6"] = 166] = "Hash6";
|
3874 | TxAttrUsage[TxAttrUsage["Hash7"] = 167] = "Hash7";
|
3875 | TxAttrUsage[TxAttrUsage["Hash8"] = 168] = "Hash8";
|
3876 | TxAttrUsage[TxAttrUsage["Hash9"] = 169] = "Hash9";
|
3877 | TxAttrUsage[TxAttrUsage["Hash10"] = 170] = "Hash10";
|
3878 | TxAttrUsage[TxAttrUsage["Hash11"] = 171] = "Hash11";
|
3879 | TxAttrUsage[TxAttrUsage["Hash12"] = 172] = "Hash12";
|
3880 | TxAttrUsage[TxAttrUsage["Hash13"] = 173] = "Hash13";
|
3881 | TxAttrUsage[TxAttrUsage["Hash14"] = 174] = "Hash14";
|
3882 | TxAttrUsage[TxAttrUsage["Hash15"] = 175] = "Hash15";
|
3883 | TxAttrUsage[TxAttrUsage["Remark"] = 240] = "Remark";
|
3884 | TxAttrUsage[TxAttrUsage["Remark1"] = 241] = "Remark1";
|
3885 | TxAttrUsage[TxAttrUsage["Remark2"] = 242] = "Remark2";
|
3886 | TxAttrUsage[TxAttrUsage["Remark3"] = 243] = "Remark3";
|
3887 | TxAttrUsage[TxAttrUsage["Remark4"] = 244] = "Remark4";
|
3888 | TxAttrUsage[TxAttrUsage["Remark5"] = 245] = "Remark5";
|
3889 | TxAttrUsage[TxAttrUsage["Remark6"] = 246] = "Remark6";
|
3890 | TxAttrUsage[TxAttrUsage["Remark7"] = 247] = "Remark7";
|
3891 | TxAttrUsage[TxAttrUsage["Remark8"] = 248] = "Remark8";
|
3892 | TxAttrUsage[TxAttrUsage["Remark9"] = 249] = "Remark9";
|
3893 | TxAttrUsage[TxAttrUsage["Remark10"] = 250] = "Remark10";
|
3894 | TxAttrUsage[TxAttrUsage["Remark11"] = 251] = "Remark11";
|
3895 | TxAttrUsage[TxAttrUsage["Remark12"] = 252] = "Remark12";
|
3896 | TxAttrUsage[TxAttrUsage["Remark13"] = 253] = "Remark13";
|
3897 | TxAttrUsage[TxAttrUsage["Remark14"] = 254] = "Remark14";
|
3898 | TxAttrUsage[TxAttrUsage["Remark15"] = 255] = "Remark15";
|
3899 | })(TxAttrUsage || (TxAttrUsage = {}));
|
3900 | /* harmony default export */ var txAttrUsage = (TxAttrUsage);
|
3901 | //# sourceMappingURL=txAttrUsage.js.map
|
3902 | // CONCATENATED MODULE: ../neon-core/lib/tx/components/TransactionAttribute.js
|
3903 |
|
3904 |
|
3905 | const maxTransactionAttributeSize = 65535;
|
3906 | function toTxAttrUsage(type) {
|
3907 | if (typeof type === "string") {
|
3908 | if (type in TxAttrUsage) {
|
3909 | return TxAttrUsage[type];
|
3910 | }
|
3911 | throw new Error(`${type} not found in TxAttrUsage!`);
|
3912 | }
|
3913 | return type;
|
3914 | }
|
3915 | /**
|
3916 | * An attribute that is used to decorate the transaction.
|
3917 | * Used for appending additional information to the transaction.
|
3918 | *
|
3919 | * For example, a remark is attached as an attribute.
|
3920 | */
|
3921 | class TransactionAttribute_TransactionAttribute {
|
3922 | static deserialize(hex) {
|
3923 | const ss = new StringStream_StringStream(hex);
|
3924 | return this.fromStream(ss);
|
3925 | }
|
3926 | static fromStream(ss) {
|
3927 | const usage = parseInt(ss.read(1), 16);
|
3928 | let data;
|
3929 | if (usage === 0x00 || usage === 0x30 || (usage >= 0xa1 && usage <= 0xaf)) {
|
3930 | data = ss.read(32);
|
3931 | }
|
3932 | else if (usage === 0x02 || usage === 0x03) {
|
3933 | data = num2hexstring(usage) + ss.read(32);
|
3934 | }
|
3935 | else if (usage === 0x20) {
|
3936 | data = ss.read(20);
|
3937 | }
|
3938 | else if (usage === 0x81) {
|
3939 | data = ss.read(parseInt(ss.read(1), 16));
|
3940 | }
|
3941 | else if (usage === 0x90 || usage >= 0xf0) {
|
3942 | data = ss.readVarBytes();
|
3943 | }
|
3944 | else {
|
3945 | throw new Error(`Unknown usage type: ${usage}. Context: ${ss.context()}`);
|
3946 | }
|
3947 | return new TransactionAttribute_TransactionAttribute({ usage, data });
|
3948 | }
|
3949 | constructor(obj) {
|
3950 | if (!obj || obj.usage === undefined || obj.data === undefined) {
|
3951 | throw new Error("TransactionAttribute requires usage and data fields");
|
3952 | }
|
3953 | this.usage = toTxAttrUsage(obj.usage);
|
3954 | this.data = obj.data;
|
3955 | }
|
3956 | get [Symbol.toStringTag]() {
|
3957 | return "TransactionAttribute";
|
3958 | }
|
3959 | serialize() {
|
3960 | if (this.data.length > maxTransactionAttributeSize) {
|
3961 | throw new Error(`Data size too big!`);
|
3962 | }
|
3963 | let out = num2hexstring(this.usage);
|
3964 | if (this.usage === 0x81) {
|
3965 | out += num2hexstring(this.data.length / 2);
|
3966 | }
|
3967 | else if (this.usage === 0x90 || this.usage >= 0xf0) {
|
3968 | out += num2VarInt(this.data.length / 2);
|
3969 | }
|
3970 | if (this.usage === 0x02 || this.usage === 0x03) {
|
3971 | out += this.data.substr(2, 64);
|
3972 | }
|
3973 | else {
|
3974 | out += this.data;
|
3975 | }
|
3976 | return out;
|
3977 | }
|
3978 | export() {
|
3979 | return {
|
3980 | usage: this.usage,
|
3981 | data: this.data
|
3982 | };
|
3983 | }
|
3984 | equals(other) {
|
3985 | return (this.usage === toTxAttrUsage(other.usage) && this.data === other.data);
|
3986 | }
|
3987 | }
|
3988 | /* harmony default export */ var components_TransactionAttribute = (TransactionAttribute_TransactionAttribute);
|
3989 | //# sourceMappingURL=TransactionAttribute.js.map
|
3990 | // CONCATENATED MODULE: ../neon-core/lib/tx/components/TransactionInput.js
|
3991 |
|
3992 | /**
|
3993 | * A reference to a TransactionOutput in another confirmed transaction.
|
3994 | * This is used to denote UTXO that will be spent in this transaction.
|
3995 | */
|
3996 | class TransactionInput_TransactionInput {
|
3997 | static deserialize(hex) {
|
3998 | const ss = new StringStream_StringStream(hex);
|
3999 | return this.fromStream(ss);
|
4000 | }
|
4001 | static fromStream(ss) {
|
4002 | const prevHash = reverseHex(ss.read(32));
|
4003 | const prevIndex = parseInt(reverseHex(ss.read(2)), 16);
|
4004 | return new TransactionInput_TransactionInput({ prevHash, prevIndex });
|
4005 | }
|
4006 | constructor(obj) {
|
4007 | if (!obj || obj.prevHash === undefined || obj.prevIndex === undefined) {
|
4008 | throw new Error("TransactionInput requires prevHash and prevIndex fields");
|
4009 | }
|
4010 | this.prevHash = obj.prevHash;
|
4011 | this.prevIndex = obj.prevIndex;
|
4012 | }
|
4013 | serialize() {
|
4014 | return (reverseHex(this.prevHash) + reverseHex(num2hexstring(this.prevIndex, 2)));
|
4015 | }
|
4016 | export() {
|
4017 | return {
|
4018 | prevHash: this.prevHash,
|
4019 | prevIndex: this.prevIndex
|
4020 | };
|
4021 | }
|
4022 | equals(other) {
|
4023 | return (this.prevHash === other.prevHash && this.prevIndex === other.prevIndex);
|
4024 | }
|
4025 | }
|
4026 | /* harmony default export */ var components_TransactionInput = (TransactionInput_TransactionInput);
|
4027 | //# sourceMappingURL=TransactionInput.js.map
|
4028 | // EXTERNAL MODULE: external "util"
|
4029 | var external_util_ = __webpack_require__(12);
|
4030 | var external_util_default = /*#__PURE__*/__webpack_require__.n(external_util_);
|
4031 |
|
4032 | // EXTERNAL MODULE: /home/circleci/repo/node_modules/bs58/index.js
|
4033 | var bs58 = __webpack_require__(7);
|
4034 | var bs58_default = /*#__PURE__*/__webpack_require__.n(bs58);
|
4035 |
|
4036 | // EXTERNAL MODULE: external "buffer"
|
4037 | var external_buffer_ = __webpack_require__(9);
|
4038 |
|
4039 | // EXTERNAL MODULE: /home/circleci/repo/node_modules/wif/index.js
|
4040 | var node_modules_wif = __webpack_require__(24);
|
4041 | var wif_default = /*#__PURE__*/__webpack_require__.n(node_modules_wif);
|
4042 |
|
4043 | // EXTERNAL MODULE: /home/circleci/repo/node_modules/bn.js/lib/bn.js
|
4044 | var lib_bn = __webpack_require__(3);
|
4045 | var bn_default = /*#__PURE__*/__webpack_require__.n(lib_bn);
|
4046 |
|
4047 | // EXTERNAL MODULE: /home/circleci/repo/node_modules/elliptic/lib/elliptic.js
|
4048 | var elliptic = __webpack_require__(5);
|
4049 |
|
4050 | // CONCATENATED MODULE: ../neon-core/lib/wallet/verify.js
|
4051 | /**
|
4052 | * Verification methods on the various key formats.
|
4053 | * Useful for identification and ensuring key is valid.
|
4054 | *
|
4055 | * Methods are named as is<Format> where:
|
4056 | * <Format> is the key format to check.
|
4057 | *
|
4058 | * All methods take in Big-Endian strings and return boolean.
|
4059 | */
|
4060 |
|
4061 |
|
4062 |
|
4063 | /**
|
4064 | * Verifies a NEP2. This merely verifies the format. It is unable to verify if it is has been tampered with.
|
4065 | */
|
4066 | function isNEP2(nep2) {
|
4067 | try {
|
4068 | if (nep2.length !== 58) {
|
4069 | return false;
|
4070 | }
|
4071 | const hexStr = ab2hexstring(bs58_default.a.decode(nep2));
|
4072 | if (!hexStr || hexStr.length !== 86) {
|
4073 | return false;
|
4074 | }
|
4075 | if (hexStr.substr(0, 2) !== "01") {
|
4076 | return false;
|
4077 | }
|
4078 | if (hexStr.substr(2, 2) !== "42") {
|
4079 | return false;
|
4080 | }
|
4081 | if (hexStr.substr(4, 2) !== "e0") {
|
4082 | return false;
|
4083 | }
|
4084 | return true;
|
4085 | }
|
4086 | catch (e) {
|
4087 | return false;
|
4088 | }
|
4089 | }
|
4090 | /**
|
4091 | * Verifies a WIF using its checksum.
|
4092 | */
|
4093 | function isWIF(wif) {
|
4094 | try {
|
4095 | if (wif.length !== 52) {
|
4096 | return false;
|
4097 | }
|
4098 | const hexStr = ab2hexstring(bs58_default.a.decode(wif));
|
4099 | const shaChecksum = hash256(hexStr.substr(0, hexStr.length - 8)).substr(0, 8);
|
4100 | return shaChecksum === hexStr.substr(hexStr.length - 8, 8);
|
4101 | }
|
4102 | catch (e) {
|
4103 | return false;
|
4104 | }
|
4105 | }
|
4106 | /**
|
4107 | * Checks if hexstring is a valid Private Key. Any hexstring of 64 chars is a valid private key.
|
4108 | */
|
4109 | function isPrivateKey(key) {
|
4110 | return /^[0-9A-Fa-f]{64}$/.test(key);
|
4111 | }
|
4112 | /**
|
4113 | * Checks if hexstring is a valid Public Key. Accepts both encoded and unencoded forms.
|
4114 | * @param key
|
4115 | * @param encoded Optional parameter to specify for a specific form. If this is omitted, this function will return true for both forms. If this parameter is provided, this function will only return true for the specific form.
|
4116 | */
|
4117 | function isPublicKey(key, encoded) {
|
4118 | try {
|
4119 | let encodedKey;
|
4120 | switch (key.substr(0, 2)) {
|
4121 | case "04":
|
4122 | if (encoded === true) {
|
4123 | return false;
|
4124 | }
|
4125 | // Encode key
|
4126 | encodedKey = getPublicKeyEncoded(key);
|
4127 | break;
|
4128 | case "02":
|
4129 | case "03":
|
4130 | if (encoded === false) {
|
4131 | return false;
|
4132 | }
|
4133 | encodedKey = key;
|
4134 | break;
|
4135 | default:
|
4136 | return false;
|
4137 | }
|
4138 | const unencoded = getPublicKeyUnencoded(encodedKey);
|
4139 | const tail = parseInt(unencoded.substr(unencoded.length - 2, 2), 16);
|
4140 | if (encodedKey.substr(0, 2) === "02" && tail % 2 === 0) {
|
4141 | return true;
|
4142 | }
|
4143 | if (encodedKey.substr(0, 2) === "03" && tail % 2 === 1) {
|
4144 | return true;
|
4145 | }
|
4146 | return false;
|
4147 | }
|
4148 | catch (e) {
|
4149 | return false;
|
4150 | }
|
4151 | }
|
4152 | /**
|
4153 | * Verifies if string is a scripthash. Any 20 byte hexstring is a valid scriptHash.
|
4154 | */
|
4155 | function isScriptHash(scriptHash) {
|
4156 | return isHex(scriptHash) && scriptHash.length === 40;
|
4157 | }
|
4158 | /**
|
4159 | * Verifies an address using its checksum.
|
4160 | */
|
4161 | function isAddress(address) {
|
4162 | try {
|
4163 | const programHash = ab2hexstring(bs58_default.a.decode(address));
|
4164 | const shaChecksum = hash256(programHash.slice(0, 42)).substr(0, 8);
|
4165 | // We use the checksum to verify the address
|
4166 | if (shaChecksum !== programHash.substr(42, 8)) {
|
4167 | return false;
|
4168 | }
|
4169 | // As other chains use similar checksum methods, we need to attempt to transform the programHash back into the address
|
4170 | const scriptHash = reverseHex(programHash.slice(2, 42));
|
4171 | if (getAddressFromScriptHash(scriptHash) !== address) {
|
4172 | // address is not valid Neo address, could be btc, ltc etc.
|
4173 | return false;
|
4174 | }
|
4175 | return true;
|
4176 | }
|
4177 | catch (e) {
|
4178 | return false;
|
4179 | }
|
4180 | }
|
4181 | //# sourceMappingURL=verify.js.map
|
4182 | // CONCATENATED MODULE: ../neon-core/lib/wallet/signing.js
|
4183 |
|
4184 |
|
4185 |
|
4186 |
|
4187 |
|
4188 | const curve = new elliptic["ec"]("p256");
|
4189 | /**
|
4190 | * Converts signatureHex to a signature object with r & s.
|
4191 | */
|
4192 | function getSignatureFromHex(signatureHex) {
|
4193 | const signatureBuffer = Buffer.from(signatureHex, "hex");
|
4194 | const r = new bn_default.a(signatureBuffer.slice(0, 32).toString("hex"), 16, "be");
|
4195 | const s = new bn_default.a(signatureBuffer.slice(32).toString("hex"), 16, "be");
|
4196 | return { r, s };
|
4197 | }
|
4198 | /**
|
4199 | * Generates a ECDSA signature from a hexstring using the given private key.
|
4200 | * @param hex Hexstring to hash.
|
4201 | * @param privateKey Hexstring or WIF format.
|
4202 | */
|
4203 | function sign(hex, privateKey) {
|
4204 | if (isWIF(privateKey)) {
|
4205 | privateKey = getPrivateKeyFromWIF(privateKey);
|
4206 | }
|
4207 | const msgHash = hash_sha256(hex);
|
4208 | const msgHashHex = Buffer.from(msgHash, "hex");
|
4209 | const privateKeyBuffer = Buffer.from(privateKey, "hex");
|
4210 | const sig = curve.sign(msgHashHex, privateKeyBuffer);
|
4211 | return sig.r.toString("hex", 32) + sig.s.toString("hex", 32);
|
4212 | }
|
4213 | /**
|
4214 | * Verifies that the message, signature and signing key matches.
|
4215 | * @param hex Message that was signed.
|
4216 | * @param sig ECDSA signature.
|
4217 | * @param publicKey encoded/unencoded public key of the signing key.
|
4218 | */
|
4219 | function verify(hex, sig, publicKey) {
|
4220 | if (!isPublicKey(publicKey)) {
|
4221 | throw new Error("Invalid public key");
|
4222 | }
|
4223 | if (!isPublicKey(publicKey, true)) {
|
4224 | publicKey = getPublicKeyUnencoded(publicKey);
|
4225 | }
|
4226 | const sigObj = getSignatureFromHex(sig);
|
4227 | const messageHash = hash_sha256(hex);
|
4228 | const publicKeyBuffer = Buffer.from(publicKey, "hex");
|
4229 | return curve.verify(messageHash, sigObj, publicKeyBuffer, "hex");
|
4230 | }
|
4231 | //# sourceMappingURL=signing.js.map
|
4232 | // CONCATENATED MODULE: ../neon-core/lib/wallet/core.js
|
4233 | /**
|
4234 | * @file Core methods for manipulating keys
|
4235 | * NEP2 <=> WIF <=> Private => Public => ScriptHash <=> Address
|
4236 | * Keys are arranged in order of derivation.
|
4237 | * Arrows determine the direction.
|
4238 | *
|
4239 | * NEP2 methods are found within NEP2 standard.
|
4240 | * All methods take in Big-Endian strings and return Big-Endian strings.
|
4241 | */
|
4242 |
|
4243 |
|
4244 |
|
4245 |
|
4246 |
|
4247 |
|
4248 |
|
4249 | /**
|
4250 | * Encodes a public key.
|
4251 | * @param unencodedKey unencoded public key
|
4252 | * @return encoded public key
|
4253 | */
|
4254 | function getPublicKeyEncoded(unencodedKey) {
|
4255 | const publicKeyArray = new Uint8Array(hexstring2ab(unencodedKey));
|
4256 | if (publicKeyArray[64] % 2 === 1) {
|
4257 | return "03" + ab2hexstring(publicKeyArray.slice(1, 33));
|
4258 | }
|
4259 | else {
|
4260 | return "02" + ab2hexstring(publicKeyArray.slice(1, 33));
|
4261 | }
|
4262 | }
|
4263 | /**
|
4264 | * Unencodes a public key.
|
4265 | * @param publicKey Encoded public key
|
4266 | * @return decoded public key
|
4267 | */
|
4268 | function getPublicKeyUnencoded(publicKey) {
|
4269 | const publicKeyBuffer = external_buffer_["Buffer"].from(publicKey, "hex");
|
4270 | const keyPair = curve.keyFromPublic(publicKeyBuffer, "hex");
|
4271 | return keyPair.getPublic().encode("hex", false);
|
4272 | }
|
4273 | /**
|
4274 | * Converts a WIF to private key.
|
4275 | */
|
4276 | function getPrivateKeyFromWIF(wif) {
|
4277 | return ab2hexstring(wif_default.a.decode(wif, 128).privateKey);
|
4278 | }
|
4279 | /**
|
4280 | * Converts a private key to WIF.
|
4281 | */
|
4282 | function getWIFFromPrivateKey(privateKey) {
|
4283 | return wif_default.a.encode(128, external_buffer_["Buffer"].from(privateKey, "hex"), true);
|
4284 | }
|
4285 | /**
|
4286 | * Converts a private key to public key.
|
4287 | * @param privateKey
|
4288 | * @param encode Returns the encoded form if true.
|
4289 | */
|
4290 | function getPublicKeyFromPrivateKey(privateKey, encode = true) {
|
4291 | const privateKeyBuffer = external_buffer_["Buffer"].from(privateKey, "hex");
|
4292 | const keypair = curve.keyFromPrivate(privateKeyBuffer, "hex");
|
4293 | const unencodedPubKey = keypair.getPublic().encode("hex", false);
|
4294 | if (encode) {
|
4295 | const tail = parseInt(unencodedPubKey.substr(64 * 2, 2), 16);
|
4296 | if (tail % 2 === 1) {
|
4297 | return "03" + unencodedPubKey.substr(2, 64);
|
4298 | }
|
4299 | else {
|
4300 | return "02" + unencodedPubKey.substr(2, 64);
|
4301 | }
|
4302 | }
|
4303 | else {
|
4304 | return unencodedPubKey;
|
4305 | }
|
4306 | }
|
4307 | /**
|
4308 | * Converts a public key to verification script form.
|
4309 | * VerificationScript serves a very niche purpose.
|
4310 | * It is attached as part of the signature when signing a transaction.
|
4311 | * Thus, the name 'scriptHash' instead of 'keyHash' is because we are hashing the verificationScript and not the PublicKey.
|
4312 | */
|
4313 | const getVerificationScriptFromPublicKey = (publicKey) => {
|
4314 | return "21" + publicKey + "ac";
|
4315 | };
|
4316 | /**
|
4317 | * Converts a public key to scripthash.
|
4318 | */
|
4319 | const getScriptHashFromPublicKey = (publicKey) => {
|
4320 | // if unencoded
|
4321 | if (publicKey.substring(0, 2) === "04") {
|
4322 | publicKey = getPublicKeyEncoded(publicKey);
|
4323 | }
|
4324 | const verificationScript = getVerificationScriptFromPublicKey(publicKey);
|
4325 | return reverseHex(hash160(verificationScript));
|
4326 | };
|
4327 | /**
|
4328 | * Converts a scripthash to address.
|
4329 | */
|
4330 | const getAddressFromScriptHash = (scriptHash) => {
|
4331 | scriptHash = reverseHex(scriptHash);
|
4332 | const shaChecksum = hash256(ADDR_VERSION + scriptHash).substr(0, 8);
|
4333 | return bs58_default.a.encode(external_buffer_["Buffer"].from(ADDR_VERSION + scriptHash + shaChecksum, "hex"));
|
4334 | };
|
4335 | /**
|
4336 | * Converts an address to scripthash.
|
4337 | */
|
4338 | const getScriptHashFromAddress = (address) => {
|
4339 | const hash = ab2hexstring(bs58_default.a.decode(address));
|
4340 | return reverseHex(hash.substr(2, 40));
|
4341 | };
|
4342 | /**
|
4343 | * Generates a signature of the transaction based on given private key.
|
4344 | * @param tx Serialized unsigned transaction.
|
4345 | * @param privateKey Private Key.
|
4346 | * @return Signature. Does not include tx.
|
4347 | */
|
4348 | const generateSignature = (tx, privateKey) => {
|
4349 | return sign(tx, privateKey);
|
4350 | };
|
4351 | /**
|
4352 | * Generates a random private key.
|
4353 | */
|
4354 | const generatePrivateKey = () => {
|
4355 | return ab2hexstring(generateRandomArray(32));
|
4356 | };
|
4357 | //# sourceMappingURL=core.js.map
|
4358 | // CONCATENATED MODULE: ../neon-core/lib/sc/ContractParam.js
|
4359 |
|
4360 |
|
4361 | var ContractParamType;
|
4362 | (function (ContractParamType) {
|
4363 | ContractParamType[ContractParamType["Signature"] = 0] = "Signature";
|
4364 | ContractParamType[ContractParamType["Boolean"] = 1] = "Boolean";
|
4365 | ContractParamType[ContractParamType["Integer"] = 2] = "Integer";
|
4366 | ContractParamType[ContractParamType["Hash160"] = 3] = "Hash160";
|
4367 | ContractParamType[ContractParamType["Hash256"] = 4] = "Hash256";
|
4368 | ContractParamType[ContractParamType["ByteArray"] = 5] = "ByteArray";
|
4369 | ContractParamType[ContractParamType["PublicKey"] = 6] = "PublicKey";
|
4370 | ContractParamType[ContractParamType["String"] = 7] = "String";
|
4371 | ContractParamType[ContractParamType["Array"] = 16] = "Array";
|
4372 | ContractParamType[ContractParamType["InteropInterface"] = 240] = "InteropInterface";
|
4373 | ContractParamType[ContractParamType["Void"] = 255] = "Void";
|
4374 | })(ContractParamType || (ContractParamType = {}));
|
4375 | function toContractParamType(type) {
|
4376 | if (typeof type === "string") {
|
4377 | if (type in ContractParamType) {
|
4378 | return ContractParamType[type];
|
4379 | }
|
4380 | throw new Error(`${type} not found in ContractParamType!`);
|
4381 | }
|
4382 | return type;
|
4383 | }
|
4384 | /**
|
4385 | * Contract input parameters.
|
4386 | * These are mainly used as parameters to pass in for RPC test invokes.
|
4387 | */
|
4388 | class ContractParam_ContractParam {
|
4389 | /**
|
4390 | * Creates a String ContractParam.
|
4391 | */
|
4392 | static string(value) {
|
4393 | return new ContractParam_ContractParam(ContractParamType.String, value);
|
4394 | }
|
4395 | /**
|
4396 | * Creates a Boolean ContractParam. Does basic checks to convert value into a boolean.
|
4397 | */
|
4398 | static boolean(value) {
|
4399 | return new ContractParam_ContractParam(ContractParamType.Boolean, !!value);
|
4400 | }
|
4401 | /**
|
4402 | * Creates a Hash160 ContractParam. This is used for containing a scriptHash. Do not reverse the input if using this format.
|
4403 | * @param {string} value - A 40 character long hexstring. Automatically converts an address to scripthash if provided.
|
4404 | * @return {ContractParam}
|
4405 | */
|
4406 | static hash160(value) {
|
4407 | if (typeof value !== "string") {
|
4408 | throw new Error(`hash160 expected a string but got ${typeof value} instead.`);
|
4409 | }
|
4410 | if (isAddress(value)) {
|
4411 | value = getScriptHashFromAddress(value);
|
4412 | }
|
4413 | if (value.length !== 40) {
|
4414 | throw new Error(`hash160 expected a 40 character string but got ${value.length} chars instead.`);
|
4415 | }
|
4416 | return new ContractParam_ContractParam(ContractParamType.Hash160, value);
|
4417 | }
|
4418 | /**
|
4419 | * Creates an Integer ContractParam. This is converted into an BigInteger in NeoVM.
|
4420 | * @param {string | number } value - A value that can be parsed to an BigInteger. Numbers or numeric strings are accepted.
|
4421 | * @example
|
4422 | * ContractParam.integer(128)
|
4423 | * ContractParam.integer("128")
|
4424 | */
|
4425 | static integer(value) {
|
4426 | const num = typeof value === "string"
|
4427 | ? value.split(".")[0]
|
4428 | : Math.round(value).toString();
|
4429 | return new ContractParam_ContractParam(ContractParamType.Integer, num);
|
4430 | }
|
4431 | /**
|
4432 | * Creates a ByteArray ContractParam.
|
4433 | * @param value
|
4434 | * @param format The format that this value represents. Different formats are parsed differently.
|
4435 | * @param args Additional arguments such as decimal precision
|
4436 | */
|
4437 | static byteArray(value, format, ...args) {
|
4438 | if (format) {
|
4439 | format = format.toLowerCase();
|
4440 | }
|
4441 | if (format === "address") {
|
4442 | return new ContractParam_ContractParam(ContractParamType.ByteArray, reverseHex(getScriptHashFromAddress(value)));
|
4443 | }
|
4444 | else if (format === "fixed8") {
|
4445 | let decimals = 8;
|
4446 | if (args.length === 1) {
|
4447 | decimals = args[0];
|
4448 | }
|
4449 | if (!isFinite(value)) {
|
4450 | throw new Error(`Input should be number!`);
|
4451 | }
|
4452 | const divisor = new Fixed8_Fixed8(Math.pow(10, 8 - decimals));
|
4453 | const fixed8Value = new Fixed8_Fixed8(value);
|
4454 | const adjustedValue = fixed8Value.times(Math.pow(10, decimals));
|
4455 | const modValue = adjustedValue.mod(1);
|
4456 | if (!modValue.isZero()) {
|
4457 | throw new Error(`wrong precision: expected ${decimals}`);
|
4458 | }
|
4459 | value = fixed8Value.div(divisor);
|
4460 | return new ContractParam_ContractParam(ContractParamType.ByteArray, value.toReverseHex().slice(0, 16));
|
4461 | }
|
4462 | else {
|
4463 | return new ContractParam_ContractParam(ContractParamType.ByteArray, value);
|
4464 | }
|
4465 | }
|
4466 | /**
|
4467 | * Creates an Array ContractParam.
|
4468 | * @param params params to be encapsulated in an array.
|
4469 | */
|
4470 | static array(...params) {
|
4471 | return new ContractParam_ContractParam(ContractParamType.Array, params);
|
4472 | }
|
4473 | constructor(type, value) {
|
4474 | if (typeof type === "object") {
|
4475 | this.type = toContractParamType(type.type);
|
4476 | this.value = type.value;
|
4477 | }
|
4478 | else if (type !== undefined) {
|
4479 | this.type = toContractParamType(type);
|
4480 | this.value = value;
|
4481 | }
|
4482 | else {
|
4483 | throw new Error("No constructor arguments provided!");
|
4484 | }
|
4485 | }
|
4486 | get [Symbol.toStringTag]() {
|
4487 | return "ContractParam:" + ContractParamType[this.type];
|
4488 | }
|
4489 | export() {
|
4490 | const exportedValue = Array.isArray(this.value)
|
4491 | ? this.value.map(cp => cp.export())
|
4492 | : this.value;
|
4493 | return { type: ContractParamType[this.type], value: this.value };
|
4494 | }
|
4495 | equal(other) {
|
4496 | if (this.type === toContractParamType(other.type) &&
|
4497 | Array.isArray(this.value) &&
|
4498 | Array.isArray(other.value) &&
|
4499 | this.value.length === other.value.length) {
|
4500 | return this.value.every((cp, i) => cp.equal(other.value[i]));
|
4501 | }
|
4502 | return false;
|
4503 | }
|
4504 | }
|
4505 | /* harmony default export */ var sc_ContractParam = (ContractParam_ContractParam);
|
4506 | function likeContractParam(cp) {
|
4507 | if (cp === null || cp === undefined) {
|
4508 | return false;
|
4509 | }
|
4510 | if (cp instanceof ContractParam_ContractParam) {
|
4511 | return true;
|
4512 | }
|
4513 | return (cp.type in ContractParamType &&
|
4514 | cp.value !== null &&
|
4515 | cp.value !== undefined);
|
4516 | }
|
4517 | //# sourceMappingURL=ContractParam.js.map
|
4518 | // CONCATENATED MODULE: ../neon-core/lib/sc/OpCode.js
|
4519 | var OpCode;
|
4520 | (function (OpCode) {
|
4521 | OpCode[OpCode["PUSH0"] = 0] = "PUSH0";
|
4522 | OpCode[OpCode["PUSHF"] = 0] = "PUSHF";
|
4523 | OpCode[OpCode["PUSHBYTES1"] = 1] = "PUSHBYTES1";
|
4524 | OpCode[OpCode["PUSHBYTES75"] = 75] = "PUSHBYTES75";
|
4525 | OpCode[OpCode["PUSHDATA1"] = 76] = "PUSHDATA1";
|
4526 | OpCode[OpCode["PUSHDATA2"] = 77] = "PUSHDATA2";
|
4527 | OpCode[OpCode["PUSHDATA4"] = 78] = "PUSHDATA4";
|
4528 | OpCode[OpCode["PUSHM1"] = 79] = "PUSHM1";
|
4529 | OpCode[OpCode["PUSH1"] = 81] = "PUSH1";
|
4530 | OpCode[OpCode["PUSHT"] = 81] = "PUSHT";
|
4531 | OpCode[OpCode["PUSH2"] = 82] = "PUSH2";
|
4532 | OpCode[OpCode["PUSH3"] = 83] = "PUSH3";
|
4533 | OpCode[OpCode["PUSH4"] = 84] = "PUSH4";
|
4534 | OpCode[OpCode["PUSH5"] = 85] = "PUSH5";
|
4535 | OpCode[OpCode["PUSH6"] = 86] = "PUSH6";
|
4536 | OpCode[OpCode["PUSH7"] = 87] = "PUSH7";
|
4537 | OpCode[OpCode["PUSH8"] = 88] = "PUSH8";
|
4538 | OpCode[OpCode["PUSH9"] = 89] = "PUSH9";
|
4539 | OpCode[OpCode["PUSH10"] = 90] = "PUSH10";
|
4540 | OpCode[OpCode["PUSH11"] = 91] = "PUSH11";
|
4541 | OpCode[OpCode["PUSH12"] = 92] = "PUSH12";
|
4542 | OpCode[OpCode["PUSH13"] = 93] = "PUSH13";
|
4543 | OpCode[OpCode["PUSH14"] = 94] = "PUSH14";
|
4544 | OpCode[OpCode["PUSH15"] = 95] = "PUSH15";
|
4545 | OpCode[OpCode["PUSH16"] = 96] = "PUSH16";
|
4546 | OpCode[OpCode["NOP"] = 97] = "NOP";
|
4547 | OpCode[OpCode["JMP"] = 98] = "JMP";
|
4548 | OpCode[OpCode["JMPIF"] = 99] = "JMPIF";
|
4549 | OpCode[OpCode["JMPIFNOT"] = 100] = "JMPIFNOT";
|
4550 | OpCode[OpCode["CALL"] = 101] = "CALL";
|
4551 | OpCode[OpCode["RET"] = 102] = "RET";
|
4552 | OpCode[OpCode["APPCALL"] = 103] = "APPCALL";
|
4553 | OpCode[OpCode["SYSCALL"] = 104] = "SYSCALL";
|
4554 | OpCode[OpCode["TAILCALL"] = 105] = "TAILCALL";
|
4555 | OpCode[OpCode["DUPFROMALTSTACK"] = 106] = "DUPFROMALTSTACK";
|
4556 | OpCode[OpCode["TOALTSTACK"] = 107] = "TOALTSTACK";
|
4557 | OpCode[OpCode["FROMALTSTACK"] = 108] = "FROMALTSTACK";
|
4558 | OpCode[OpCode["XDROP"] = 109] = "XDROP";
|
4559 | OpCode[OpCode["XSWAP"] = 114] = "XSWAP";
|
4560 | OpCode[OpCode["XTUCK"] = 115] = "XTUCK";
|
4561 | OpCode[OpCode["DEPTH"] = 116] = "DEPTH";
|
4562 | OpCode[OpCode["DROP"] = 117] = "DROP";
|
4563 | OpCode[OpCode["DUP"] = 118] = "DUP";
|
4564 | OpCode[OpCode["NIP"] = 119] = "NIP";
|
4565 | OpCode[OpCode["OVER"] = 120] = "OVER";
|
4566 | OpCode[OpCode["PICK"] = 121] = "PICK";
|
4567 | OpCode[OpCode["ROLL"] = 122] = "ROLL";
|
4568 | OpCode[OpCode["ROT"] = 123] = "ROT";
|
4569 | OpCode[OpCode["SWAP"] = 124] = "SWAP";
|
4570 | OpCode[OpCode["TUCK"] = 125] = "TUCK";
|
4571 | OpCode[OpCode["CAT"] = 126] = "CAT";
|
4572 | OpCode[OpCode["SUBSTR"] = 127] = "SUBSTR";
|
4573 | OpCode[OpCode["LEFT"] = 128] = "LEFT";
|
4574 | OpCode[OpCode["RIGHT"] = 129] = "RIGHT";
|
4575 | OpCode[OpCode["SIZE"] = 130] = "SIZE";
|
4576 | OpCode[OpCode["INVERT"] = 131] = "INVERT";
|
4577 | OpCode[OpCode["AND"] = 132] = "AND";
|
4578 | OpCode[OpCode["OR"] = 133] = "OR";
|
4579 | OpCode[OpCode["XOR"] = 134] = "XOR";
|
4580 | OpCode[OpCode["EQUAL"] = 135] = "EQUAL";
|
4581 | OpCode[OpCode["INC"] = 139] = "INC";
|
4582 | OpCode[OpCode["DEC"] = 140] = "DEC";
|
4583 | OpCode[OpCode["SIGN"] = 141] = "SIGN";
|
4584 | OpCode[OpCode["NEGATE"] = 143] = "NEGATE";
|
4585 | OpCode[OpCode["ABS"] = 144] = "ABS";
|
4586 | OpCode[OpCode["NOT"] = 145] = "NOT";
|
4587 | OpCode[OpCode["NZ"] = 146] = "NZ";
|
4588 | OpCode[OpCode["ADD"] = 147] = "ADD";
|
4589 | OpCode[OpCode["SUB"] = 148] = "SUB";
|
4590 | OpCode[OpCode["MUL"] = 149] = "MUL";
|
4591 | OpCode[OpCode["DIV"] = 150] = "DIV";
|
4592 | OpCode[OpCode["MOD"] = 151] = "MOD";
|
4593 | OpCode[OpCode["SHL"] = 152] = "SHL";
|
4594 | OpCode[OpCode["SHR"] = 153] = "SHR";
|
4595 | OpCode[OpCode["BOOLAND"] = 154] = "BOOLAND";
|
4596 | OpCode[OpCode["BOOLOR"] = 155] = "BOOLOR";
|
4597 | OpCode[OpCode["NUMEQUAL"] = 156] = "NUMEQUAL";
|
4598 | OpCode[OpCode["NUMNOTEQUAL"] = 158] = "NUMNOTEQUAL";
|
4599 | OpCode[OpCode["LT"] = 159] = "LT";
|
4600 | OpCode[OpCode["GT"] = 160] = "GT";
|
4601 | OpCode[OpCode["LTE"] = 161] = "LTE";
|
4602 | OpCode[OpCode["GTE"] = 162] = "GTE";
|
4603 | OpCode[OpCode["MIN"] = 163] = "MIN";
|
4604 | OpCode[OpCode["MAX"] = 164] = "MAX";
|
4605 | OpCode[OpCode["WITHIN"] = 165] = "WITHIN";
|
4606 | OpCode[OpCode["SHA1"] = 167] = "SHA1";
|
4607 | OpCode[OpCode["SHA256"] = 168] = "SHA256";
|
4608 | OpCode[OpCode["HASH160"] = 169] = "HASH160";
|
4609 | OpCode[OpCode["HASH256"] = 170] = "HASH256";
|
4610 | OpCode[OpCode["CHECKSIG"] = 172] = "CHECKSIG";
|
4611 | OpCode[OpCode["VERIFY"] = 173] = "VERIFY";
|
4612 | OpCode[OpCode["CHECKMULTISIG"] = 174] = "CHECKMULTISIG";
|
4613 | OpCode[OpCode["ARRAYSIZE"] = 192] = "ARRAYSIZE";
|
4614 | OpCode[OpCode["PACK"] = 193] = "PACK";
|
4615 | OpCode[OpCode["UNPACK"] = 194] = "UNPACK";
|
4616 | OpCode[OpCode["PICKITEM"] = 195] = "PICKITEM";
|
4617 | OpCode[OpCode["SETITEM"] = 196] = "SETITEM";
|
4618 | OpCode[OpCode["NEWARRAY"] = 197] = "NEWARRAY";
|
4619 | OpCode[OpCode["NEWSTRUCT"] = 198] = "NEWSTRUCT";
|
4620 | OpCode[OpCode["NEWMAP"] = 199] = "NEWMAP";
|
4621 | OpCode[OpCode["APPEND"] = 200] = "APPEND";
|
4622 | OpCode[OpCode["REVERSE"] = 201] = "REVERSE";
|
4623 | OpCode[OpCode["REMOVE"] = 202] = "REMOVE";
|
4624 | OpCode[OpCode["HASKEY"] = 203] = "HASKEY";
|
4625 | OpCode[OpCode["KEYS"] = 204] = "KEYS";
|
4626 | OpCode[OpCode["VALUES"] = 205] = "VALUES";
|
4627 | OpCode[OpCode["CALL_I"] = 224] = "CALL_I";
|
4628 | OpCode[OpCode["CALL_E"] = 225] = "CALL_E";
|
4629 | OpCode[OpCode["CALL_ED"] = 226] = "CALL_ED";
|
4630 | OpCode[OpCode["CALL_ET"] = 227] = "CALL_ET";
|
4631 | OpCode[OpCode["CALL_EDT"] = 228] = "CALL_EDT";
|
4632 | OpCode[OpCode["THROW"] = 240] = "THROW";
|
4633 | OpCode[OpCode["THROWIFNOT"] = 241] = "THROWIFNOT";
|
4634 | })(OpCode || (OpCode = {}));
|
4635 | /* harmony default export */ var sc_OpCode = (OpCode);
|
4636 | //# sourceMappingURL=OpCode.js.map
|
4637 | // CONCATENATED MODULE: ../neon-core/lib/sc/ScriptBuilder.js
|
4638 |
|
4639 |
|
4640 |
|
4641 |
|
4642 | function isValidValue(value) {
|
4643 | if (value) {
|
4644 | return true;
|
4645 | }
|
4646 | else if (value === 0) {
|
4647 | return true;
|
4648 | }
|
4649 | else if (value === "") {
|
4650 | return true;
|
4651 | }
|
4652 | return false;
|
4653 | }
|
4654 | /**
|
4655 | * Retrieves a single AppCall from a ScriptBuilder object.
|
4656 | * Returns ScriptIntents starting from the beginning of the script.
|
4657 | * This is based off the pointer in the stream.
|
4658 | * @param sb
|
4659 | * @returns A single ScriptIntent if available.
|
4660 | */
|
4661 | function retrieveAppCall(sb) {
|
4662 | const output = {
|
4663 | scriptHash: "",
|
4664 | args: []
|
4665 | };
|
4666 | while (!sb.isEmpty()) {
|
4667 | const b = sb.read();
|
4668 | const n = parseInt(b, 16);
|
4669 | switch (true) {
|
4670 | case n === 0:
|
4671 | output.args.unshift(0);
|
4672 | break;
|
4673 | case n < 75:
|
4674 | output.args.unshift(sb.read(n));
|
4675 | break;
|
4676 | case n >= 81 && n <= 96:
|
4677 | output.args.unshift(n - 80);
|
4678 | break;
|
4679 | case n === 193:
|
4680 | const len = output.args.shift();
|
4681 | const cache = [];
|
4682 | for (let i = 0; i < len; i++) {
|
4683 | cache.unshift(output.args.shift());
|
4684 | }
|
4685 | output.args.unshift(cache);
|
4686 | break;
|
4687 | case n === 102:
|
4688 | sb.pter = sb.str.length;
|
4689 | break;
|
4690 | case n === 103:
|
4691 | output.scriptHash = reverseHex(sb.read(20));
|
4692 | output.useTailCall = false;
|
4693 | return output;
|
4694 | case n === 105:
|
4695 | output.scriptHash = reverseHex(sb.read(20));
|
4696 | output.useTailCall = true;
|
4697 | return output;
|
4698 | case n === 241:
|
4699 | break;
|
4700 | default:
|
4701 | throw new Error(`Encounter unknown byte: ${b}`);
|
4702 | }
|
4703 | }
|
4704 | if (output.scriptHash === "") {
|
4705 | return null;
|
4706 | }
|
4707 | return output;
|
4708 | }
|
4709 | /**
|
4710 | * Builds a VM script in hexstring. Used for constructing smart contract method calls.
|
4711 | * @extends StringStream
|
4712 | */
|
4713 | class ScriptBuilder_ScriptBuilder extends StringStream_StringStream {
|
4714 | /**
|
4715 | * Appends an Opcode, followed by args
|
4716 | */
|
4717 | emit(op, args) {
|
4718 | this.str += num2hexstring(op);
|
4719 | if (args) {
|
4720 | this.str += args;
|
4721 | }
|
4722 | return this;
|
4723 | }
|
4724 | /**
|
4725 | * Appends args, operation and scriptHash
|
4726 | * @param scriptHash Hexstring(BE)
|
4727 | * @param operation ASCII, defaults to null
|
4728 | * @param args any
|
4729 | * @param useTailCall Use TailCall instead of AppCall
|
4730 | * @return this
|
4731 | */
|
4732 | emitAppCall(scriptHash, operation = null, args, useTailCall = false) {
|
4733 | this.emitPush(args);
|
4734 | if (operation) {
|
4735 | let hexOp = "";
|
4736 | for (let i = 0; i < operation.length; i++) {
|
4737 | hexOp += num2hexstring(operation.charCodeAt(i));
|
4738 | }
|
4739 | this.emitPush(hexOp);
|
4740 | }
|
4741 | this._emitAppCall(scriptHash, useTailCall);
|
4742 | return this;
|
4743 | }
|
4744 | /**
|
4745 | * Appends a SysCall
|
4746 | * @param api api of SysCall
|
4747 | * @return this
|
4748 | */
|
4749 | emitSysCall(api) {
|
4750 | if (!api) {
|
4751 | throw new Error("Invalid SysCall API");
|
4752 | }
|
4753 | const apiBytes = str2hexstring(api);
|
4754 | const length = int2hex(apiBytes.length / 2);
|
4755 | if (length.length !== 2) {
|
4756 | throw new Error("Invalid length for SysCall API");
|
4757 | }
|
4758 | const out = length + apiBytes;
|
4759 | return this.emit(sc_OpCode.SYSCALL, out);
|
4760 | }
|
4761 | /**
|
4762 | * Appends data depending on type. Used to append params/array lengths.
|
4763 | * @param data
|
4764 | * @return this
|
4765 | */
|
4766 | emitPush(data) {
|
4767 | switch (typeof data) {
|
4768 | case "boolean":
|
4769 | return this.emit(data ? sc_OpCode.PUSHT : sc_OpCode.PUSHF);
|
4770 | case "string":
|
4771 | return this._emitString(data);
|
4772 | case "number":
|
4773 | return this._emitNum(data);
|
4774 | case "undefined":
|
4775 | return this.emitPush(false);
|
4776 | case "object":
|
4777 | if (Array.isArray(data)) {
|
4778 | return this._emitArray(data);
|
4779 | }
|
4780 | else if (likeContractParam(data)) {
|
4781 | return this._emitParam(new sc_ContractParam(data));
|
4782 | }
|
4783 | else if (data === null) {
|
4784 | return this.emitPush(false);
|
4785 | }
|
4786 | throw new Error(`Unidentified object: ${data}`);
|
4787 | default:
|
4788 | throw new Error();
|
4789 | }
|
4790 | }
|
4791 | /**
|
4792 | * Reverse engineer a script back to its params.
|
4793 | * A script may have multiple invocations so a list is always returned.
|
4794 | * @return A list of ScriptIntents[].
|
4795 | */
|
4796 | toScriptParams() {
|
4797 | this.reset();
|
4798 | const scripts = [];
|
4799 | while (!this.isEmpty()) {
|
4800 | const a = retrieveAppCall(this);
|
4801 | if (a) {
|
4802 | scripts.push(a);
|
4803 | }
|
4804 | }
|
4805 | return scripts;
|
4806 | }
|
4807 | /**
|
4808 | * Appends a AppCall and scriptHash. Used to end off a script.
|
4809 | * @param scriptHash Hexstring(BE)
|
4810 | * @param useTailCall Defaults to false
|
4811 | */
|
4812 | _emitAppCall(scriptHash, useTailCall = false) {
|
4813 | ensureHex(scriptHash);
|
4814 | if (scriptHash.length !== 40) {
|
4815 | throw new Error("ScriptHash should be 20 bytes long!");
|
4816 | }
|
4817 | return this.emit(useTailCall ? sc_OpCode.TAILCALL : sc_OpCode.APPCALL, reverseHex(scriptHash));
|
4818 | }
|
4819 | /**
|
4820 | * Private method to append an array
|
4821 | * @private
|
4822 | */
|
4823 | _emitArray(arr) {
|
4824 | for (let i = arr.length - 1; i >= 0; i--) {
|
4825 | this.emitPush(arr[i]);
|
4826 | }
|
4827 | return this.emitPush(arr.length).emit(sc_OpCode.PACK);
|
4828 | }
|
4829 | /**
|
4830 | * Private method to append a hexstring.
|
4831 | * @private
|
4832 | * @param hexstring Hexstring(BE)
|
4833 | * @return this
|
4834 | */
|
4835 | _emitString(hexstring) {
|
4836 | ensureHex(hexstring);
|
4837 | const size = hexstring.length / 2;
|
4838 | if (size <= sc_OpCode.PUSHBYTES75) {
|
4839 | this.str += num2hexstring(size);
|
4840 | this.str += hexstring;
|
4841 | }
|
4842 | else if (size < 0x100) {
|
4843 | this.emit(sc_OpCode.PUSHDATA1);
|
4844 | this.str += num2hexstring(size);
|
4845 | this.str += hexstring;
|
4846 | }
|
4847 | else if (size < 0x10000) {
|
4848 | this.emit(sc_OpCode.PUSHDATA2);
|
4849 | this.str += num2hexstring(size, 2, true);
|
4850 | this.str += hexstring;
|
4851 | }
|
4852 | else if (size < 0x100000000) {
|
4853 | this.emit(sc_OpCode.PUSHDATA4);
|
4854 | this.str += num2hexstring(size, 4, true);
|
4855 | this.str += hexstring;
|
4856 | }
|
4857 | else {
|
4858 | throw new Error(`String too big to emit!`);
|
4859 | }
|
4860 | return this;
|
4861 | }
|
4862 | /**
|
4863 | * Private method to append a number.
|
4864 | * @private
|
4865 | * @param num
|
4866 | * @return this
|
4867 | */
|
4868 | _emitNum(num) {
|
4869 | const bn = new bn_default.a(num);
|
4870 | if (bn.eqn(-1)) {
|
4871 | return this.emit(sc_OpCode.PUSHM1);
|
4872 | }
|
4873 | if (bn.eqn(0)) {
|
4874 | return this.emit(sc_OpCode.PUSH0);
|
4875 | }
|
4876 | if (bn.gtn(0) && bn.lten(16)) {
|
4877 | return this.emit(sc_OpCode.PUSH1 - 1 + bn.toNumber());
|
4878 | }
|
4879 | const msbSet = bn.testn(bn.byteLength() * 8 - 1);
|
4880 | const hex = bn
|
4881 | .toTwos(bn.byteLength() * 8)
|
4882 | .toString(16, bn.byteLength() * 2);
|
4883 | const paddedHex = !bn.isNeg() && msbSet ? "00" + hex : hex;
|
4884 | return this.emitPush(reverseHex(paddedHex));
|
4885 | }
|
4886 | /**
|
4887 | * Private method to append a ContractParam
|
4888 | * @private
|
4889 | */
|
4890 | _emitParam(param) {
|
4891 | if (!param.type) {
|
4892 | throw new Error("No type available!");
|
4893 | }
|
4894 | if (!isValidValue(param.value)) {
|
4895 | throw new Error("Invalid value provided!");
|
4896 | }
|
4897 | switch (param.type) {
|
4898 | case ContractParamType.String:
|
4899 | return this._emitString(str2hexstring(param.value));
|
4900 | case ContractParamType.Boolean:
|
4901 | return this.emit(param.value ? sc_OpCode.PUSHT : sc_OpCode.PUSHF);
|
4902 | case ContractParamType.Integer:
|
4903 | return this._emitNum(param.value);
|
4904 | case ContractParamType.ByteArray:
|
4905 | return this._emitString(param.value);
|
4906 | case ContractParamType.Array:
|
4907 | return this._emitArray(param.value);
|
4908 | case ContractParamType.Hash160:
|
4909 | return this._emitString(reverseHex(param.value));
|
4910 | default:
|
4911 | throw new Error(`Unaccounted ContractParamType!: ${param.type}`);
|
4912 | }
|
4913 | }
|
4914 | }
|
4915 | /* harmony default export */ var sc_ScriptBuilder = (ScriptBuilder_ScriptBuilder);
|
4916 | //# sourceMappingURL=ScriptBuilder.js.map
|
4917 | // CONCATENATED MODULE: ../neon-core/lib/sc/core.js
|
4918 |
|
4919 |
|
4920 | /**
|
4921 | * Translates a ScriptIntent / array of ScriptIntents into hexstring.
|
4922 | */
|
4923 | function createScript(...intents) {
|
4924 | const sb = new sc_ScriptBuilder();
|
4925 | for (const scriptIntent of intents) {
|
4926 | if (typeof scriptIntent === "string") {
|
4927 | sb.str += scriptIntent;
|
4928 | continue;
|
4929 | }
|
4930 | if (!scriptIntent.scriptHash) {
|
4931 | throw new Error("No scriptHash found!");
|
4932 | }
|
4933 | const { scriptHash, operation, args, useTailCall } = Object.assign({ operation: null, args: undefined, useTailCall: false }, scriptIntent);
|
4934 | sb.emitAppCall(scriptHash, operation, args, useTailCall);
|
4935 | }
|
4936 | return sb.str;
|
4937 | }
|
4938 | /**
|
4939 | * Generates script for deploying contract
|
4940 | */
|
4941 | function generateDeployScript(params) {
|
4942 | const sb = new sc_ScriptBuilder();
|
4943 | sb.emitPush(str2hexstring(params.description))
|
4944 | .emitPush(str2hexstring(params.email))
|
4945 | .emitPush(str2hexstring(params.author))
|
4946 | .emitPush(str2hexstring(params.version))
|
4947 | .emitPush(str2hexstring(params.name))
|
4948 | .emitPush(params.needsStorage || false)
|
4949 | .emitPush(params.returnType || "ff00")
|
4950 | .emitPush(params.parameterList)
|
4951 | .emitPush(params.script)
|
4952 | .emitSysCall("Neo.Contract.Create");
|
4953 | return sb;
|
4954 | }
|
4955 | //# sourceMappingURL=core.js.map
|
4956 | // CONCATENATED MODULE: ../neon-core/lib/sc/StackItem.js
|
4957 |
|
4958 | var StackItemType;
|
4959 | (function (StackItemType) {
|
4960 | StackItemType[StackItemType["ByteArray"] = 0] = "ByteArray";
|
4961 | StackItemType[StackItemType["Boolean"] = 1] = "Boolean";
|
4962 | StackItemType[StackItemType["Integer"] = 2] = "Integer";
|
4963 | StackItemType[StackItemType["InteropInterface"] = 4] = "InteropInterface";
|
4964 | StackItemType[StackItemType["Array"] = 128] = "Array";
|
4965 | StackItemType[StackItemType["Struct"] = 129] = "Struct";
|
4966 | StackItemType[StackItemType["Map"] = 130] = "Map";
|
4967 | })(StackItemType || (StackItemType = {}));
|
4968 | function toStackItemType(type) {
|
4969 | if (typeof type === "string") {
|
4970 | return StackItemType[type];
|
4971 | }
|
4972 | return type;
|
4973 | }
|
4974 | /**
|
4975 | * Determine if there's a nested set based on type
|
4976 | */
|
4977 | function hasChildren(type) {
|
4978 | if (type === StackItemType.Array ||
|
4979 | type === StackItemType.Struct ||
|
4980 | type === StackItemType.Map) {
|
4981 | return true;
|
4982 | }
|
4983 | return false;
|
4984 | }
|
4985 | function getDefaultValue(type) {
|
4986 | switch (type) {
|
4987 | case StackItemType.Array:
|
4988 | case StackItemType.Struct:
|
4989 | case StackItemType.Map:
|
4990 | return [];
|
4991 | case StackItemType.Boolean:
|
4992 | return false;
|
4993 | default:
|
4994 | return "";
|
4995 | }
|
4996 | }
|
4997 | /**
|
4998 | * Object returned as a result of executing a script in the VM.
|
4999 | */
|
5000 | class StackItem_StackItem {
|
5001 | static deserialize(hex) {
|
5002 | const ss = new StringStream_StringStream(hex);
|
5003 | return this._deserialize(ss);
|
5004 | }
|
5005 | static _deserialize(ss) {
|
5006 | const item = new StackItem_StackItem({ type: parseInt(ss.read(), 16) });
|
5007 | const l = ss.readVarInt();
|
5008 | if (l === 0) {
|
5009 | item.value = getDefaultValue(item.type);
|
5010 | return item;
|
5011 | }
|
5012 | switch (item.type) {
|
5013 | case StackItemType.Array:
|
5014 | case StackItemType.Struct:
|
5015 | item.value = [];
|
5016 | for (let i = 0; i < l; i++) {
|
5017 | item.value.push(this._deserialize(ss));
|
5018 | }
|
5019 | break;
|
5020 | case StackItemType.Map:
|
5021 | item.value = [];
|
5022 | for (let i = 0; i < l; i++) {
|
5023 | item.value.push({
|
5024 | key: this._deserialize(ss),
|
5025 | value: this._deserialize(ss)
|
5026 | });
|
5027 | }
|
5028 | break;
|
5029 | case StackItemType.Boolean:
|
5030 | item.value = parseInt(ss.read(), 16) > 0;
|
5031 | break;
|
5032 | default:
|
5033 | item.value = ss.read(l);
|
5034 | }
|
5035 | return item;
|
5036 | }
|
5037 | constructor(obj) {
|
5038 | if (obj.type === undefined) {
|
5039 | throw new Error(`Invalid type provided: ${obj.type}`);
|
5040 | }
|
5041 | this.type = toStackItemType(obj.type);
|
5042 | if (obj.value === undefined) {
|
5043 | this.value = getDefaultValue(this.type);
|
5044 | }
|
5045 | else if (Array.isArray(obj.value)) {
|
5046 | if (this.type === StackItemType.Array) {
|
5047 | this.value = obj.value.map(v => new StackItem_StackItem(v));
|
5048 | }
|
5049 | else if (this.type === StackItemType.Map) {
|
5050 | this.value = obj.value.map(v => ({
|
5051 | key: new StackItem_StackItem(v.key),
|
5052 | value: new StackItem_StackItem(v.value)
|
5053 | }));
|
5054 | }
|
5055 | throw new Error(`Encountered array for value but invalid type`);
|
5056 | }
|
5057 | else {
|
5058 | this.value = obj.value;
|
5059 | }
|
5060 | }
|
5061 | export() {
|
5062 | const type = StackItemType[this.type];
|
5063 | switch (this.type) {
|
5064 | case StackItemType.Array:
|
5065 | case StackItemType.Struct:
|
5066 | return {
|
5067 | type,
|
5068 | value: this.value.map(i => i.export())
|
5069 | };
|
5070 | case StackItemType.Map:
|
5071 | return {
|
5072 | type,
|
5073 | value: this.value.map(kv => ({
|
5074 | key: kv.key.export(),
|
5075 | value: kv.value.export()
|
5076 | }))
|
5077 | };
|
5078 | default:
|
5079 | return { type, value: this.value };
|
5080 | }
|
5081 | }
|
5082 | }
|
5083 | /* harmony default export */ var sc_StackItem = (StackItem_StackItem);
|
5084 | //# sourceMappingURL=StackItem.js.map
|
5085 | // CONCATENATED MODULE: ../neon-core/lib/sc/index.js
|
5086 |
|
5087 |
|
5088 |
|
5089 |
|
5090 |
|
5091 | //# sourceMappingURL=index.js.map
|
5092 | // CONCATENATED MODULE: ../neon-core/lib/wallet/multisig.js
|
5093 |
|
5094 |
|
5095 |
|
5096 | function constructMultiSigVerificationScript(signingThreshold, keys) {
|
5097 | if (signingThreshold > keys.length) {
|
5098 | throw new Error("signingThreshold must be smaller than or equal to number of keys");
|
5099 | }
|
5100 | const ss = new ScriptBuilder_ScriptBuilder();
|
5101 | ss.emitPush(signingThreshold);
|
5102 | keys.forEach(k => {
|
5103 | if (!isPublicKey(k, true)) {
|
5104 | throw new Error(`${k} is not a valid encoded public key`);
|
5105 | }
|
5106 | ss.emitPush(k);
|
5107 | });
|
5108 | ss.emitPush(keys.length);
|
5109 | ss.emit(OpCode.CHECKMULTISIG);
|
5110 | return ss.str;
|
5111 | }
|
5112 | /**
|
5113 | * Returns the list of public keys found in the verification script.
|
5114 | * @param verificationScript Verification Script of an Account.
|
5115 | */
|
5116 | function getPublicKeysFromVerificationScript(verificationScript) {
|
5117 | const ss = new StringStream_StringStream(verificationScript);
|
5118 | const keys = [];
|
5119 | while (!ss.isEmpty()) {
|
5120 | const byte = ss.read();
|
5121 | if (byte === "21") {
|
5122 | keys.push(ss.read(33));
|
5123 | }
|
5124 | }
|
5125 | return keys;
|
5126 | }
|
5127 | /**
|
5128 | * Returns the number of signatures required for signing for a verification Script.
|
5129 | * @param verificationScript Verification Script of a multi-sig Account.
|
5130 | */
|
5131 | function getSigningThresholdFromVerificationScript(verificationScript) {
|
5132 | const checkSigOpCode = verificationScript.slice(verificationScript.length - 2);
|
5133 | if (checkSigOpCode === "ac") {
|
5134 | return 1;
|
5135 | }
|
5136 | else if (checkSigOpCode === "ae") {
|
5137 | const ss = new StringStream_StringStream(verificationScript);
|
5138 | const byte = parseInt(ss.peek(), 16);
|
5139 | if (byte < 80) {
|
5140 | const hexNum = reverseHex(ss.readVarBytes());
|
5141 | return parseInt(hexNum, 16);
|
5142 | }
|
5143 | else {
|
5144 | return parseInt(ss.read(), 16) - 80;
|
5145 | }
|
5146 | }
|
5147 | else {
|
5148 | throw new Error("VerificationScript does not call CHECKSIG or CHECKMULTISIG.");
|
5149 | }
|
5150 | }
|
5151 | /**
|
5152 | * Extract signatures from invocationScript
|
5153 | * @param invocationScript InvocationScript of a Witness.
|
5154 | */
|
5155 | function getSignaturesFromInvocationScript(invocationScript) {
|
5156 | const ss = new StringStream_StringStream(invocationScript);
|
5157 | const sigs = [];
|
5158 | while (!ss.isEmpty()) {
|
5159 | const byte = parseInt(ss.peek(), 16);
|
5160 | if (byte > 80) {
|
5161 | continue;
|
5162 | }
|
5163 | else if (byte === 4 * 16) {
|
5164 | sigs.push(ss.readVarBytes());
|
5165 | }
|
5166 | }
|
5167 | return sigs;
|
5168 | }
|
5169 | //# sourceMappingURL=multisig.js.map
|
5170 | // EXTERNAL MODULE: /home/circleci/repo/node_modules/bs58check/index.js
|
5171 | var bs58check = __webpack_require__(17);
|
5172 | var bs58check_default = /*#__PURE__*/__webpack_require__.n(bs58check);
|
5173 |
|
5174 | // EXTERNAL MODULE: /home/circleci/repo/node_modules/crypto-js/aes.js
|
5175 | var aes = __webpack_require__(25);
|
5176 | var aes_default = /*#__PURE__*/__webpack_require__.n(aes);
|
5177 |
|
5178 | // EXTERNAL MODULE: /home/circleci/repo/node_modules/crypto-js/enc-latin1.js
|
5179 | var enc_latin1 = __webpack_require__(47);
|
5180 | var enc_latin1_default = /*#__PURE__*/__webpack_require__.n(enc_latin1);
|
5181 |
|
5182 | // EXTERNAL MODULE: /home/circleci/repo/node_modules/crypto-js/mode-ecb.js
|
5183 | var mode_ecb = __webpack_require__(48);
|
5184 | var mode_ecb_default = /*#__PURE__*/__webpack_require__.n(mode_ecb);
|
5185 |
|
5186 | // EXTERNAL MODULE: /home/circleci/repo/node_modules/crypto-js/pad-nopadding.js
|
5187 | var pad_nopadding = __webpack_require__(49);
|
5188 | var pad_nopadding_default = /*#__PURE__*/__webpack_require__.n(pad_nopadding);
|
5189 |
|
5190 | // EXTERNAL MODULE: /home/circleci/repo/node_modules/scrypt-js/scrypt.js
|
5191 | var scrypt = __webpack_require__(26);
|
5192 | var scrypt_default = /*#__PURE__*/__webpack_require__.n(scrypt);
|
5193 |
|
5194 | // CONCATENATED MODULE: ../neon-core/lib/wallet/nep2.js
|
5195 | /**
|
5196 | * NEP2 - Private Key Encryption based on AES.
|
5197 | * This encrypts your private key with a passphrase, protecting your private key from being stolen and used.
|
5198 | * It is useful for storing private keys in a JSON file securely or to mask the key before printing it.
|
5199 | */
|
5200 | // This is importable because WIF specifies it as a dependency.
|
5201 |
|
5202 |
|
5203 |
|
5204 |
|
5205 |
|
5206 |
|
5207 |
|
5208 |
|
5209 |
|
5210 |
|
5211 |
|
5212 | const enc = {
|
5213 | Latin1: enc_latin1_default.a,
|
5214 | Hex: enc_hex_default.a
|
5215 | };
|
5216 | const AES_OPTIONS = { mode: mode_ecb_default.a, padding: pad_nopadding_default.a };
|
5217 | const nep2_log = logging("wallet");
|
5218 | /**
|
5219 | * Encrypts a WIF key using a given keyphrase under NEP-2 Standard.
|
5220 | * @param wifKey WIF key to encrypt (52 chars long).
|
5221 | * @param keyphrase The password will be encoded as UTF-8 and normalized using Unicode Normalization Form C (NFC).
|
5222 | * @param scryptParams Optional parameters for Scrypt. Defaults to NEP2 specified parameters.
|
5223 | * @returns The encrypted key in Base58 (Case sensitive).
|
5224 | */
|
5225 | function encrypt(wifKey, keyphrase, scryptParams = DEFAULT_SCRYPT) {
|
5226 | return new Promise((resolve, reject) => {
|
5227 | const { n, r, p } = scryptParams;
|
5228 | const account = new wallet_Account(wifKey);
|
5229 | // SHA Salt (use the first 4 bytes)
|
5230 | const firstSha = sha256_default()(enc.Latin1.parse(account.address));
|
5231 | const addressHash = sha256_default()(firstSha)
|
5232 | .toString()
|
5233 | .slice(0, 8);
|
5234 | scrypt_default()(Buffer.from(keyphrase.normalize("NFC"), "utf8"), Buffer.from(addressHash, "hex"), n, r, p, 64, (error, _, key) => {
|
5235 | if (error != null) {
|
5236 | reject(error);
|
5237 | }
|
5238 | else if (key) {
|
5239 | const derived = Buffer.from(key).toString("hex");
|
5240 | const derived1 = derived.slice(0, 64);
|
5241 | const derived2 = derived.slice(64);
|
5242 | // AES Encrypt
|
5243 | const xor = hexXor(account.privateKey, derived1);
|
5244 | const encrypted = aes_default.a.encrypt(enc.Hex.parse(xor), enc.Hex.parse(derived2), AES_OPTIONS);
|
5245 | const assembled = NEP_HEADER +
|
5246 | NEP_FLAG +
|
5247 | addressHash +
|
5248 | encrypted.ciphertext.toString();
|
5249 | const encryptedKey = bs58check_default.a.encode(Buffer.from(assembled, "hex"));
|
5250 | nep2_log.info(`Successfully encrypted key to ${encryptedKey}`);
|
5251 | resolve(encryptedKey);
|
5252 | }
|
5253 | });
|
5254 | });
|
5255 | }
|
5256 | /**
|
5257 | * Decrypts an encrypted key using a given keyphrase under NEP-2 Standard.
|
5258 | * @param encryptedKey The encrypted key (58 chars long).
|
5259 | * @param keyphrase The password will be encoded as UTF-8 and normalized using Unicode Normalization Form C (NFC).
|
5260 | * @param scryptParams Parameters for Scrypt. Defaults to NEP2 specified parameters.
|
5261 | * @returns The decrypted WIF key.
|
5262 | */
|
5263 | function decrypt(encryptedKey, keyphrase, scryptParams = DEFAULT_SCRYPT) {
|
5264 | return new Promise((resolve, reject) => {
|
5265 | const { n, r, p } = scryptParams;
|
5266 | const assembled = ab2hexstring(bs58check_default.a.decode(encryptedKey));
|
5267 | const addressHash = assembled.substr(6, 8);
|
5268 | const encrypted = assembled.substr(-64);
|
5269 | scrypt_default()(Buffer.from(keyphrase.normalize("NFC"), "utf8"), Buffer.from(addressHash, "hex"), n, r, p, 64, (error, _, key) => {
|
5270 | if (error != null) {
|
5271 | reject(error);
|
5272 | }
|
5273 | else if (key) {
|
5274 | const derived = Buffer.from(key).toString("hex");
|
5275 | const derived1 = derived.slice(0, 64);
|
5276 | const derived2 = derived.slice(64);
|
5277 | const ciphertext = {
|
5278 | ciphertext: enc.Hex.parse(encrypted),
|
5279 | salt: "",
|
5280 | iv: ""
|
5281 | };
|
5282 | const decrypted = aes_default.a.decrypt(ciphertext, enc.Hex.parse(derived2), AES_OPTIONS);
|
5283 | const privateKey = hexXor(decrypted.toString(), derived1);
|
5284 | const account = new wallet_Account(privateKey);
|
5285 | const newAddressHash = sha256_default()(sha256_default()(enc.Latin1.parse(account.address)))
|
5286 | .toString()
|
5287 | .slice(0, 8);
|
5288 | if (addressHash !== newAddressHash) {
|
5289 | reject(new Error("Wrong password or scrypt parameters!"));
|
5290 | }
|
5291 | nep2_log.info(`Successfully decrypted ${encryptedKey}`);
|
5292 | resolve(account.WIF);
|
5293 | }
|
5294 | });
|
5295 | });
|
5296 | }
|
5297 | //# sourceMappingURL=nep2.js.map
|
5298 | // CONCATENATED MODULE: ../neon-core/lib/wallet/Account.js
|
5299 |
|
5300 |
|
5301 |
|
5302 |
|
5303 |
|
5304 |
|
5305 |
|
5306 |
|
5307 | const Account_log = logging("wallet");
|
5308 | const inspect = external_util_default.a.inspect.custom;
|
5309 | /**
|
5310 | * This allows for simple utilisation and manipulating of keys without need the long access methods.
|
5311 | *
|
5312 | * Key formats are derived from each other lazily and stored for future access.
|
5313 | * If the previous key (one level higher) is not found, it will attempt to generate it or throw an Error if insufficient information was provided (eg. trying to generate private key when only address was given.)
|
5314 | *
|
5315 | * NEP2 <=> WIF <=> Private => Public => ScriptHash <=> Address
|
5316 | *
|
5317 | * @param str WIF/ Private Key / Public Key / Address or a Wallet Account object.
|
5318 | * @example
|
5319 | * const acct = new Account("L1QqQJnpBwbsPGAuutuzPTac8piqvbR1HRjrY5qHup48TBCBFe4g");
|
5320 | * acct.address; // "ALq7AWrhAueN6mJNqk6FHJjnsEoPRytLdW"
|
5321 | */
|
5322 | class Account_Account {
|
5323 | /**
|
5324 | * Create a multi-sig account from a list of public keys
|
5325 | * @param signingThreshold Minimum number of signatures required for verification. Must be larger than 0 and less than number of keys provided.
|
5326 | * @param publicKeys List of public keys to form the account. 2-16 keys allowed. Order is important.
|
5327 | * @example
|
5328 | * const threshold = 2;
|
5329 | * const publicKeys = [
|
5330 | * "02028a99826edc0c97d18e22b6932373d908d323aa7f92656a77ec26e8861699ef",
|
5331 | * "031d8e1630ce640966967bc6d95223d21f44304133003140c3b52004dc981349c9",
|
5332 | * "02232ce8d2e2063dce0451131851d47421bfc4fc1da4db116fca5302c0756462fa"
|
5333 | * ];
|
5334 | * const acct = Account.createMultiSig(threshold, publicKeys);
|
5335 | */
|
5336 | static createMultiSig(signingThreshold, publicKeys) {
|
5337 | const verificationScript = constructMultiSigVerificationScript(signingThreshold, publicKeys);
|
5338 | return new Account_Account({
|
5339 | contract: {
|
5340 | script: verificationScript,
|
5341 | parameters: Array(signingThreshold).map((_, i) => ({
|
5342 | name: `signature${i}`,
|
5343 | type: "Signature"
|
5344 | })),
|
5345 | deployed: false
|
5346 | }
|
5347 | });
|
5348 | }
|
5349 | // tslint:enables:variable-name
|
5350 | constructor(str = "") {
|
5351 | this.extra = {};
|
5352 | this.label = "";
|
5353 | this.isDefault = false;
|
5354 | this.lock = false;
|
5355 | this.contract = Object.assign({}, DEFAULT_ACCOUNT_CONTRACT);
|
5356 | if (!str) {
|
5357 | this._privateKey = generatePrivateKey();
|
5358 | }
|
5359 | else if (typeof str === "object") {
|
5360 | this._encrypted = str.key;
|
5361 | this._address = str.address;
|
5362 | this.label = str.label || "";
|
5363 | this.extra = str.extra || {};
|
5364 | this.isDefault = str.isDefault || false;
|
5365 | this.lock = str.lock || false;
|
5366 | this.contract =
|
5367 | str.contract || Object.assign({}, DEFAULT_ACCOUNT_CONTRACT);
|
5368 | }
|
5369 | else if (isPrivateKey(str)) {
|
5370 | this._privateKey = str;
|
5371 | }
|
5372 | else if (isPublicKey(str, false)) {
|
5373 | this._publicKey = getPublicKeyEncoded(str);
|
5374 | }
|
5375 | else if (isPublicKey(str, true)) {
|
5376 | this._publicKey = str;
|
5377 | }
|
5378 | else if (isScriptHash(str)) {
|
5379 | this._scriptHash = str;
|
5380 | }
|
5381 | else if (isAddress(str)) {
|
5382 | this._address = str;
|
5383 | }
|
5384 | else if (isWIF(str)) {
|
5385 | this._privateKey = getPrivateKeyFromWIF(str);
|
5386 | this._WIF = str;
|
5387 | }
|
5388 | else if (isNEP2(str)) {
|
5389 | this._encrypted = str;
|
5390 | }
|
5391 | else {
|
5392 | throw new ReferenceError(`Invalid input: ${str}`);
|
5393 | }
|
5394 | this._updateContractScript();
|
5395 | // Attempts to make address the default label of the Account.
|
5396 | if (!this.label) {
|
5397 | try {
|
5398 | this.label = this.address;
|
5399 | }
|
5400 | catch (err) {
|
5401 | this.label = "";
|
5402 | }
|
5403 | }
|
5404 | }
|
5405 | get [Symbol.toStringTag]() {
|
5406 | return "Account";
|
5407 | }
|
5408 | [inspect]() {
|
5409 | return `[Account: ${this.label}]`;
|
5410 | }
|
5411 | get isMultiSig() {
|
5412 | return (this.contract &&
|
5413 | this.contract.script &&
|
5414 | this.contract.script.slice(this.contract.script.length - 2) === "ae");
|
5415 | }
|
5416 | /**
|
5417 | * Key encrypted according to NEP2 standard.
|
5418 | * @example 6PYLHmDf6AjF4AsVtosmxHuPYeuyJL3SLuw7J1U8i7HxKAnYNsp61HYRfF
|
5419 | */
|
5420 | get encrypted() {
|
5421 | if (this._encrypted) {
|
5422 | return this._encrypted;
|
5423 | }
|
5424 | else {
|
5425 | throw new Error("No encrypted key found");
|
5426 | }
|
5427 | }
|
5428 | /**
|
5429 | * Case sensitive key of 52 characters long.
|
5430 | * @example L1QqQJnpBwbsPGAuutuzPTac8piqvbR1HRjrY5qHup48TBCBFe4g
|
5431 | */
|
5432 | get WIF() {
|
5433 | if (this._WIF) {
|
5434 | return this._WIF;
|
5435 | }
|
5436 | else {
|
5437 | this._WIF = getWIFFromPrivateKey(this.privateKey);
|
5438 | return this._WIF;
|
5439 | }
|
5440 | }
|
5441 | /**
|
5442 | * Key of 64 hex characters.
|
5443 | * @example 7d128a6d096f0c14c3a25a2b0c41cf79661bfcb4a8cc95aaaea28bde4d732344
|
5444 | */
|
5445 | get privateKey() {
|
5446 | if (this._privateKey) {
|
5447 | return this._privateKey;
|
5448 | }
|
5449 | else if (this._WIF) {
|
5450 | this._privateKey = getPrivateKeyFromWIF(this._WIF);
|
5451 | return this._privateKey;
|
5452 | }
|
5453 | else if (this._encrypted) {
|
5454 | throw new ReferenceError("Private Key encrypted!");
|
5455 | }
|
5456 | else {
|
5457 | throw new ReferenceError("No Private Key provided!");
|
5458 | }
|
5459 | }
|
5460 | /**
|
5461 | * Returns the public key in encoded form. This is the form that is the short version (starts with 02 or 03). If you require the unencoded form, do use the publicKey method instead of this getter.
|
5462 | * @example 02028a99826edc0c97d18e22b6932373d908d323aa7f92656a77ec26e8861699ef
|
5463 | */
|
5464 | get publicKey() {
|
5465 | if (this._publicKey) {
|
5466 | return this._publicKey;
|
5467 | }
|
5468 | else {
|
5469 | this._publicKey = getPublicKeyFromPrivateKey(this.privateKey);
|
5470 | return this._publicKey;
|
5471 | }
|
5472 | }
|
5473 | /** Retrieves the Public Key in encoded / unencoded form.
|
5474 | * @param encoded Encoded or unencoded.
|
5475 | */
|
5476 | getPublicKey(encoded = true) {
|
5477 | return encoded
|
5478 | ? this.publicKey
|
5479 | : getPublicKeyUnencoded(this.publicKey);
|
5480 | }
|
5481 | /**
|
5482 | * Script hash of the key. This format is usually used in the code instead of address as this is a hexstring.
|
5483 | */
|
5484 | get scriptHash() {
|
5485 | if (this._scriptHash) {
|
5486 | return this._scriptHash;
|
5487 | }
|
5488 | else {
|
5489 | if (this._address) {
|
5490 | this._scriptHash = getScriptHashFromAddress(this.address);
|
5491 | return this._scriptHash;
|
5492 | }
|
5493 | else if (this.contract.script) {
|
5494 | this._scriptHash = this._getScriptHashFromVerificationScript();
|
5495 | return this._scriptHash;
|
5496 | }
|
5497 | else {
|
5498 | this._scriptHash = getScriptHashFromPublicKey(this.publicKey);
|
5499 | return this._scriptHash;
|
5500 | }
|
5501 | }
|
5502 | }
|
5503 | /**
|
5504 | * Public address used to receive transactions. Case sensitive.
|
5505 | * @example ALq7AWrhAueN6mJNqk6FHJjnsEoPRytLdW
|
5506 | */
|
5507 | get address() {
|
5508 | if (this._address) {
|
5509 | return this._address;
|
5510 | }
|
5511 | else {
|
5512 | this._address = getAddressFromScriptHash(this.scriptHash);
|
5513 | return this._address;
|
5514 | }
|
5515 | }
|
5516 | /**
|
5517 | * This is the safe way to get a key without it throwing an error.
|
5518 | */
|
5519 | tryGet(keyType) {
|
5520 | switch (keyType) {
|
5521 | case "encrypted":
|
5522 | return this._encrypted || "";
|
5523 | case "WIF":
|
5524 | return this._WIF || "";
|
5525 | case "privateKey":
|
5526 | return this._privateKey || "";
|
5527 | case "publicKey":
|
5528 | return this._publicKey || "";
|
5529 | case "scriptHash":
|
5530 | return this._scriptHash || "";
|
5531 | case "address":
|
5532 | return this._address || "";
|
5533 | }
|
5534 | }
|
5535 | /**
|
5536 | * Encrypts the current privateKey and return the Account object.
|
5537 | */
|
5538 | encrypt(keyphrase, scryptParams = DEFAULT_SCRYPT) {
|
5539 | return Promise.resolve()
|
5540 | .then(_ => encrypt(this.privateKey, keyphrase, scryptParams))
|
5541 | .then(encrypted => {
|
5542 | this._encrypted = encrypted;
|
5543 | return this;
|
5544 | });
|
5545 | }
|
5546 | /**
|
5547 | * Decrypts the encrypted key and return the Account object.
|
5548 | */
|
5549 | decrypt(keyphrase, scryptParams = DEFAULT_SCRYPT) {
|
5550 | return Promise.resolve()
|
5551 | .then(_ => decrypt(this.encrypted, keyphrase, scryptParams))
|
5552 | .then(wif => {
|
5553 | this._WIF = wif;
|
5554 | this._updateContractScript();
|
5555 | return this;
|
5556 | });
|
5557 | }
|
5558 | /**
|
5559 | * Export Account as a WalletAccount object.
|
5560 | */
|
5561 | export() {
|
5562 | let key = "";
|
5563 | if (this._privateKey && !this._encrypted) {
|
5564 | throw new Error("Encrypt private key first!");
|
5565 | }
|
5566 | if (this._encrypted) {
|
5567 | key = this._encrypted;
|
5568 | }
|
5569 | return {
|
5570 | address: this.address,
|
5571 | label: this.label,
|
5572 | isDefault: this.isDefault,
|
5573 | lock: this.lock,
|
5574 | key,
|
5575 | contract: this.contract,
|
5576 | extra: this.extra
|
5577 | };
|
5578 | }
|
5579 | equals(other) {
|
5580 | return this.address === other.address;
|
5581 | }
|
5582 | /**
|
5583 | * Attempts to update the contract.script field if public key is available.
|
5584 | */
|
5585 | _updateContractScript() {
|
5586 | try {
|
5587 | if (this.contract.script === "") {
|
5588 | const publicKey = this.publicKey;
|
5589 | this.contract.script = getVerificationScriptFromPublicKey(publicKey);
|
5590 | this._scriptHash = this._getScriptHashFromVerificationScript();
|
5591 | Account_log.debug(`Updated ContractScript for Account: ${this.address}`);
|
5592 | }
|
5593 | }
|
5594 | catch (e) {
|
5595 | return;
|
5596 | }
|
5597 | }
|
5598 | _getScriptHashFromVerificationScript() {
|
5599 | return reverseHex(hash160(this.contract.script));
|
5600 | }
|
5601 | }
|
5602 | /* harmony default export */ var wallet_Account = (Account_Account);
|
5603 | //# sourceMappingURL=Account.js.map
|
5604 | // CONCATENATED MODULE: ../neon-core/lib/tx/strategy.js
|
5605 |
|
5606 | /**
|
5607 | * Selects inputs from left of array till sum of inputs is equal or larger than requiredAmt.
|
5608 | * @param {Fixed8} requiredAmt
|
5609 | * @param {Coin[]} availableInputs
|
5610 | * @return {Coin[]}
|
5611 | */
|
5612 | function fillFromLeft(requiredAmt, availableInputs) {
|
5613 | let selectPointer = 0;
|
5614 | let selectedAmt = new Fixed8_Fixed8(0);
|
5615 | // Selected min inputs to satisfy outputs
|
5616 | while (selectedAmt.lt(requiredAmt)) {
|
5617 | selectPointer += 1;
|
5618 | if (selectPointer > availableInputs.length) {
|
5619 | throw new Error(`Insufficient assets! Reached end of unspent coins! ${availableInputs.length}`);
|
5620 | }
|
5621 | selectedAmt = selectedAmt.add(availableInputs[selectPointer - 1].value);
|
5622 | }
|
5623 | return availableInputs.slice(0, selectPointer);
|
5624 | }
|
5625 | /**
|
5626 | * Select the coins in order of value, smallest first.
|
5627 | * @param {AssetBalance} assetBalance
|
5628 | * @param {Fixed8} requiredAmt
|
5629 | * @return {Coin[]}
|
5630 | */
|
5631 | function smallestFirst(assetBalance, requiredAmt) {
|
5632 | // Ascending order sort
|
5633 | assetBalance.unspent.sort((a, b) => a.value.sub(b.value).toNumber());
|
5634 | return fillFromLeft(requiredAmt, assetBalance.unspent);
|
5635 | }
|
5636 | /**
|
5637 | * Select the coins in order of value, biggest first.
|
5638 | * @param {AssetBalance} assetBalance
|
5639 | * @param {Fixed8} requiredAmt
|
5640 | * @return {Coin[]}
|
5641 | */
|
5642 | function biggestFirst(assetBalance, requiredAmt) {
|
5643 | // Descending order sort
|
5644 | assetBalance.unspent.sort((a, b) => b.value.sub(a.value).toNumber());
|
5645 | return fillFromLeft(requiredAmt, assetBalance.unspent);
|
5646 | }
|
5647 | /**
|
5648 | * Use a balanced approach by selecting a coin that
|
5649 | * @param {AssetBalance} assetBalance
|
5650 | * @param {Fixed8} requiredAmt
|
5651 | * @return {Coin[]}
|
5652 | */
|
5653 | function balancedApproach(assetBalance, requiredAmt) {
|
5654 | // Ascending sort first
|
5655 | assetBalance.unspent.sort((a, b) => a.value.sub(b.value).toNumber());
|
5656 | // Trim off coins larger than requiredAmt
|
5657 | const smallCoins = assetBalance.unspent.filter(c => c.value.lte(requiredAmt));
|
5658 | if (smallCoins.length === 0) {
|
5659 | return [assetBalance.unspent[0]];
|
5660 | }
|
5661 | // Check for naive solution
|
5662 | const i = smallCoins.findIndex(c => requiredAmt.eq(c.value));
|
5663 | if (i >= 0) {
|
5664 | return [smallCoins[i]];
|
5665 | }
|
5666 | // Take the largest coin available and fill it up with little pieces
|
5667 | const bigCoins = assetBalance.unspent.slice(smallCoins.length);
|
5668 | const selectedInputs = [];
|
5669 | if (smallCoins.length > 0) {
|
5670 | selectedInputs.push(smallCoins.pop());
|
5671 | }
|
5672 | const remainderAmt = requiredAmt.minus(selectedInputs.length > 0 ? selectedInputs[0].value : 0);
|
5673 | const remainderInputs = fillFromLeft(remainderAmt, smallCoins.concat(bigCoins));
|
5674 | return selectedInputs.concat(remainderInputs);
|
5675 | }
|
5676 | //# sourceMappingURL=strategy.js.map
|
5677 | // CONCATENATED MODULE: ../neon-core/lib/tx/calculate.js
|
5678 |
|
5679 |
|
5680 |
|
5681 |
|
5682 |
|
5683 | //eslint-disable-next-line
|
5684 | let defaultCalculationStrategy = balancedApproach;
|
5685 | /**
|
5686 | * Helper function that reduces a list of TransactionOutputs to a object of assetSymbol: amount.
|
5687 | * This is useful during the calculations as we just need to know much of an asset we need.
|
5688 | * @param intents List of TransactionOutputs to reduce.
|
5689 | */
|
5690 | function combineIntents(intents) {
|
5691 | return intents.reduce((assets, intent) => {
|
5692 | assets[intent.assetId]
|
5693 | ? (assets[intent.assetId] = assets[intent.assetId].add(intent.value))
|
5694 | : (assets[intent.assetId] = intent.value);
|
5695 | return assets;
|
5696 | }, {});
|
5697 | }
|
5698 | function calculateInputsForAsset(assetBalance, requiredAmt, assetId, address, strategy) {
|
5699 | const selectedInputs = strategy(assetBalance, requiredAmt);
|
5700 | const selectedAmt = selectedInputs.reduce((prev, curr) => prev.add(curr.value), new Fixed8_Fixed8(0));
|
5701 | const change = [];
|
5702 | // Construct change output
|
5703 | if (selectedAmt.gt(requiredAmt)) {
|
5704 | change.push(new TransactionOutput_TransactionOutput({
|
5705 | assetId,
|
5706 | value: selectedAmt.sub(requiredAmt),
|
5707 | scriptHash: getScriptHashFromAddress(address)
|
5708 | }));
|
5709 | }
|
5710 | // Format inputs
|
5711 | const inputs = selectedInputs.map(input => {
|
5712 | return new TransactionInput_TransactionInput({
|
5713 | prevHash: input.txid,
|
5714 | prevIndex: input.index
|
5715 | });
|
5716 | });
|
5717 | return { inputs, change };
|
5718 | }
|
5719 | /**
|
5720 | * Calculate the inputs required given the intents and fees.
|
5721 | * Fees are various GAS outputs that are not reflected as an TransactionOutput (absorbed by network).
|
5722 | * This includes network fees, gas fees and transaction fees.
|
5723 | * The change is automatically attributed to the incoming balance.
|
5724 | * @param balances Balance of all assets available.
|
5725 | * @param intents All sending intents.
|
5726 | * @param fees gasCost required for the transaction.
|
5727 | * @param strategy Calculation strategy to pick inputs.
|
5728 | * @return Object with inputs and change.
|
5729 | */
|
5730 | function calculateInputs(balances, intents = [], fees = 0, strategy) {
|
5731 | const chosenStrategy = strategy || defaultCalculationStrategy;
|
5732 | const fixed8Fees = new Fixed8_Fixed8(fees);
|
5733 | if (fixed8Fees.gt(0)) {
|
5734 | intents = intents.slice();
|
5735 | intents.push(new TransactionOutput_TransactionOutput({
|
5736 | assetId: ASSET_ID.GAS,
|
5737 | value: fees,
|
5738 | scriptHash: getScriptHashFromAddress(balances.address)
|
5739 | }));
|
5740 | }
|
5741 | const requiredAssets = combineIntents(intents);
|
5742 | const inputsAndChange = Object.keys(requiredAssets).map(assetId => {
|
5743 | const requiredAmt = requiredAssets[assetId];
|
5744 | const assetSymbol = ASSETS[assetId];
|
5745 | if (balances.assetSymbols.indexOf(assetSymbol) === -1) {
|
5746 | throw new Error(`This balance does not contain any ${assetSymbol}!`);
|
5747 | }
|
5748 | const assetBalance = balances.assets[assetSymbol];
|
5749 | if (assetBalance.balance.lt(requiredAmt)) {
|
5750 | throw new Error(`Insufficient ${ASSETS[assetId]}! Need ${requiredAmt.toString()} but only found ${assetBalance.balance.toString()}`);
|
5751 | }
|
5752 | return calculateInputsForAsset(new AssetBalance_AssetBalance(assetBalance), requiredAmt, assetId, balances.address, chosenStrategy);
|
5753 | });
|
5754 | const output = inputsAndChange.reduce((prev, curr) => {
|
5755 | return {
|
5756 | inputs: prev.inputs.concat(curr.inputs),
|
5757 | change: prev.change.concat(curr.change)
|
5758 | };
|
5759 | }, { inputs: [], change: [] });
|
5760 | return output;
|
5761 | }
|
5762 | //# sourceMappingURL=calculate.js.map
|
5763 | // CONCATENATED MODULE: ../neon-core/lib/tx/transaction/main.js
|
5764 |
|
5765 |
|
5766 | function deserializeArrayOf(type, ss) {
|
5767 | const output = [];
|
5768 | const len = ss.readVarInt();
|
5769 | for (let i = 0; i < len; i++) {
|
5770 | output.push(type(ss));
|
5771 | }
|
5772 | return output;
|
5773 | }
|
5774 | function serializeArrayOf(prop) {
|
5775 | return num2VarInt(prop.length) + prop.map(p => p.serialize()).join("");
|
5776 | }
|
5777 | function deserializeType(ss, tx = {}) {
|
5778 | const byte = ss.read();
|
5779 | return Object.assign(tx, { type: parseInt(byte, 16) });
|
5780 | }
|
5781 | function deserializeVersion(ss, tx = {}) {
|
5782 | const byte = ss.read();
|
5783 | return Object.assign({ version: parseInt(byte, 16) });
|
5784 | }
|
5785 | function deserializeAttributes(ss, tx) {
|
5786 | const attributes = deserializeArrayOf(TransactionAttribute_TransactionAttribute.fromStream, ss).map(i => i.export());
|
5787 | return Object.assign(tx, { attributes });
|
5788 | }
|
5789 | function deserializeInputs(ss, tx) {
|
5790 | const inputs = deserializeArrayOf(TransactionInput_TransactionInput.fromStream, ss).map(i => i.export());
|
5791 | return Object.assign(tx, { inputs });
|
5792 | }
|
5793 | function deserializeOutputs(ss, tx) {
|
5794 | const outputs = deserializeArrayOf(TransactionOutput_TransactionOutput.fromStream, ss).map(i => i.export());
|
5795 | return Object.assign(tx, { outputs });
|
5796 | }
|
5797 | function deserializeWitnesses(ss, tx) {
|
5798 | const scripts = deserializeArrayOf(Witness_Witness.fromStream, ss).map(i => i.export());
|
5799 | return Object.assign(tx, { scripts });
|
5800 | }
|
5801 | //# sourceMappingURL=main.js.map
|
5802 | // CONCATENATED MODULE: ../neon-core/lib/tx/transaction/BaseTransaction.js
|
5803 |
|
5804 |
|
5805 |
|
5806 |
|
5807 |
|
5808 |
|
5809 |
|
5810 |
|
5811 | const BaseTransaction_log = logging("tx");
|
5812 | class BaseTransaction_BaseTransaction {
|
5813 | constructor(tx = {}) {
|
5814 | this.type = 0x00;
|
5815 | this.version = tx.version || TX_VERSION.CONTRACT;
|
5816 | this.attributes = Array.isArray(tx.attributes)
|
5817 | ? tx.attributes.map(a => new TransactionAttribute_TransactionAttribute(a))
|
5818 | : [];
|
5819 | this.inputs = Array.isArray(tx.inputs)
|
5820 | ? tx.inputs.map(a => new TransactionInput_TransactionInput(a))
|
5821 | : [];
|
5822 | this.outputs = Array.isArray(tx.outputs)
|
5823 | ? tx.outputs.map(a => new TransactionOutput_TransactionOutput(a))
|
5824 | : [];
|
5825 | this.scripts = Array.isArray(tx.scripts)
|
5826 | ? tx.scripts.map(a => new Witness_Witness(a))
|
5827 | : [];
|
5828 | }
|
5829 | get [Symbol.toStringTag]() {
|
5830 | return "Transaction";
|
5831 | }
|
5832 | /**
|
5833 | * Transaction hash.
|
5834 | */
|
5835 | get hash() {
|
5836 | return reverseHex(hash256(this.serialize(false)));
|
5837 | }
|
5838 | addOutput(txOut) {
|
5839 | this.outputs.push(new TransactionOutput_TransactionOutput(txOut));
|
5840 | return this;
|
5841 | }
|
5842 | /**
|
5843 | * Adds a TransactionOutput. TransactionOutput can be given as a TransactionOutput object or as human-friendly values. This is detected by the number of arguments provided.
|
5844 | * @param symbol The symbol of the asset (eg NEO or GAS).
|
5845 | * @param value The value to send.
|
5846 | * @param address The address to send to.
|
5847 | */
|
5848 | addIntent(symbol, value, address) {
|
5849 | this.outputs.push(TransactionOutput_TransactionOutput.fromIntent(symbol, value, address));
|
5850 | return this;
|
5851 | }
|
5852 | /**
|
5853 | * Add an attribute.
|
5854 | * @param usage The usage type. Do refer to txAttrUsage enum values for all available options.
|
5855 | * @param data The data as hexstring.
|
5856 | */
|
5857 | addAttribute(usage, data) {
|
5858 | if (typeof data !== "string") {
|
5859 | throw new TypeError("data should be formatted as string!");
|
5860 | }
|
5861 | this.attributes.push(new TransactionAttribute_TransactionAttribute({ usage, data }));
|
5862 | return this;
|
5863 | }
|
5864 | /**
|
5865 | * Add a remark.
|
5866 | * @param remark A remark in ASCII.
|
5867 | */
|
5868 | addRemark(remark) {
|
5869 | const hexRemark = str2hexstring(remark);
|
5870 | return this.addAttribute(txAttrUsage.Remark, hexRemark);
|
5871 | }
|
5872 | /**
|
5873 | * Adds an Witness to the Transaction and automatically sorts the witnesses according to scripthash.
|
5874 | * @param witness The Witness object to add.
|
5875 | */
|
5876 | addWitness(witness) {
|
5877 | if (witness.scriptHash === "") {
|
5878 | throw new Error("Please define the scriptHash for this Witness!");
|
5879 | }
|
5880 | this.scripts.push(witness);
|
5881 | this.scripts = this.scripts.sort((w1, w2) => parseInt(w1.scriptHash, 16) - parseInt(w2.scriptHash, 16));
|
5882 | return this;
|
5883 | }
|
5884 | /**
|
5885 | * Calculate the inputs required based on existing outputs provided. Also takes into account the fees required through the gas property.
|
5886 | * @param balance Balance to retrieve inputs from.
|
5887 | * @param strategy
|
5888 | * @param fees Additional network fees. Invocation gas and tx fees are already included automatically so this is additional fees for priority on the network.
|
5889 | */
|
5890 | calculate(balance, strategy, fees = 0) {
|
5891 | const { inputs, change } = calculateInputs(balance, this.outputs, new Fixed8_Fixed8(this.fees).add(fees), strategy);
|
5892 | this.inputs = inputs;
|
5893 | this.outputs = this.outputs.concat(change);
|
5894 | BaseTransaction_log.info(`Calculated the inputs required for Transaction with Balance: ${balance.address}`);
|
5895 | return this;
|
5896 | }
|
5897 | /**
|
5898 | * Serialize the transaction and return it as a hexstring.
|
5899 | * @param {boolean} signed - Whether to serialize the signatures. Signing requires it to be serialized without the signatures.
|
5900 | * @return {string} Hexstring.
|
5901 | */
|
5902 | serialize(signed = true) {
|
5903 | let out = "";
|
5904 | out += num2hexstring(this.type);
|
5905 | out += num2hexstring(this.version);
|
5906 | out += this.serializeExclusive();
|
5907 | out += serializeArrayOf(this.attributes);
|
5908 | out += serializeArrayOf(this.inputs);
|
5909 | out += serializeArrayOf(this.outputs);
|
5910 | if (signed) {
|
5911 | out += serializeArrayOf(this.scripts);
|
5912 | }
|
5913 | return out;
|
5914 | }
|
5915 | /**
|
5916 | * Signs a transaction.
|
5917 | * @param {Account|string} signer - Account, privateKey or WIF
|
5918 | * @return {Transaction} this
|
5919 | */
|
5920 | sign(signer) {
|
5921 | if (typeof signer === "string") {
|
5922 | signer = new Account_Account(signer);
|
5923 | }
|
5924 | const signature = sign(this.serialize(false), signer.privateKey);
|
5925 | BaseTransaction_log.info(`Signed Transaction with Account: ${signer.label}`);
|
5926 | this.addWitness(Witness_Witness.fromSignature(signature, signer.publicKey));
|
5927 | return this;
|
5928 | }
|
5929 | export() {
|
5930 | return {
|
5931 | type: this.type,
|
5932 | version: this.version,
|
5933 | attributes: this.attributes.map(a => a.export()),
|
5934 | inputs: this.inputs.map(a => a.export()),
|
5935 | outputs: this.outputs.map(a => a.export()),
|
5936 | scripts: this.scripts.map(a => a.export())
|
5937 | };
|
5938 | }
|
5939 | }
|
5940 | /* harmony default export */ var transaction_BaseTransaction = (BaseTransaction_BaseTransaction);
|
5941 | //# sourceMappingURL=BaseTransaction.js.map
|
5942 | // CONCATENATED MODULE: ../neon-core/lib/wallet/components/Coin.js
|
5943 |
|
5944 | /**
|
5945 | * An alternative form of a TransactionOutput.
|
5946 | */
|
5947 | class Coin_Coin {
|
5948 | constructor(coinLike = {}) {
|
5949 | this.index = coinLike.index || 0;
|
5950 | this.txid = coinLike.txid || "";
|
5951 | this.value = new u_Fixed8(coinLike.value);
|
5952 | }
|
5953 | export() {
|
5954 | return {
|
5955 | index: this.index,
|
5956 | txid: this.txid,
|
5957 | value: this.value.toNumber()
|
5958 | };
|
5959 | }
|
5960 | equals(other) {
|
5961 | return (this.index === other.index &&
|
5962 | this.txid === other.txid &&
|
5963 | this.value.equals(other.value || 0));
|
5964 | }
|
5965 | }
|
5966 | /* harmony default export */ var components_Coin = (Coin_Coin);
|
5967 | //# sourceMappingURL=Coin.js.map
|
5968 | // CONCATENATED MODULE: ../neon-core/lib/wallet/components/AssetBalance.js
|
5969 |
|
5970 |
|
5971 |
|
5972 | /**
|
5973 | * Balance of an UTXO asset.
|
5974 | * We keep track of 3 states: unspent, spent and unconfirmed.
|
5975 | * Unspent coins are ready to be constructed into transactions.
|
5976 | * Spent coins have been used once in confirmed transactions and cannot be used anymore. They are kept here for tracking purposes.
|
5977 | * Unconfirmed coins have been used in transactions but are not confirmed yet. This is a holding state until we confirm that the transactions are mined into blocks.
|
5978 | */
|
5979 | class AssetBalance_AssetBalance {
|
5980 | constructor(abLike = {}) {
|
5981 | this.unspent = abLike.unspent
|
5982 | ? abLike.unspent.map(coin => new components_Coin(coin))
|
5983 | : [];
|
5984 | this.spent = abLike.spent ? abLike.spent.map(coin => new components_Coin(coin)) : [];
|
5985 | this.unconfirmed = abLike.unconfirmed
|
5986 | ? abLike.unconfirmed.map(coin => new components_Coin(coin))
|
5987 | : [];
|
5988 | }
|
5989 | get balance() {
|
5990 | return this.unspent.reduce((p, c) => p.add(c.value), new u_Fixed8(0));
|
5991 | }
|
5992 | export() {
|
5993 | return {
|
5994 | balance: this.balance.toNumber(),
|
5995 | unspent: this.unspent.map(c => c.export()),
|
5996 | spent: this.spent.map(c => c.export()),
|
5997 | unconfirmed: this.unconfirmed.map(c => c.export())
|
5998 | };
|
5999 | }
|
6000 | equals(other) {
|
6001 | return (compareNeonObjectArray(this.unspent, other.unspent) &&
|
6002 | compareNeonObjectArray(this.spent, other.spent) &&
|
6003 | compareNeonObjectArray(this.unconfirmed, other.unconfirmed));
|
6004 | }
|
6005 | }
|
6006 | /* harmony default export */ var components_AssetBalance = (AssetBalance_AssetBalance);
|
6007 | //# sourceMappingURL=AssetBalance.js.map
|
6008 | // CONCATENATED MODULE: ../neon-core/lib/wallet/Balance.js
|
6009 | var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
6010 | return new (P || (P = Promise))(function (resolve, reject) {
|
6011 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6012 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6013 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
6014 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
6015 | });
|
6016 | };
|
6017 |
|
6018 |
|
6019 |
|
6020 |
|
6021 |
|
6022 |
|
6023 |
|
6024 | function verifyCoin(url, c) {
|
6025 | return __awaiter(this, void 0, void 0, function* () {
|
6026 | const response = yield Query_Query.getTxOut(c.txid, c.index).execute(url);
|
6027 | if (!response.result) {
|
6028 | return false;
|
6029 | }
|
6030 | return c.index === response.result.n && c.value.equals(response.result.value);
|
6031 | });
|
6032 | }
|
6033 | /**
|
6034 | * Verifies a list of Coins
|
6035 | * @param url RPC Node to verify against.
|
6036 | * @param coinArr Coins to verify.
|
6037 | */
|
6038 | function verifyCoins(url, coinArr) {
|
6039 | return __awaiter(this, void 0, void 0, function* () {
|
6040 | const promises = coinArr.map(c => verifyCoin(url, c));
|
6041 | return yield Promise.all(promises);
|
6042 | });
|
6043 | }
|
6044 | /**
|
6045 | * Verifies an AssetBalance
|
6046 | * @param url RPC Node to verify against.
|
6047 | * @param assetBalance AssetBalance to verify.
|
6048 | */
|
6049 | function verifyAssetBalance(url, assetBalance) {
|
6050 | return __awaiter(this, void 0, void 0, function* () {
|
6051 | const newAssetBalance = {
|
6052 | balance: new u_Fixed8(0),
|
6053 | spent: [],
|
6054 | unspent: [],
|
6055 | unconfirmed: []
|
6056 | };
|
6057 | const validCoins = yield verifyCoins(url, assetBalance.unspent);
|
6058 | validCoins.forEach((valid, i) => {
|
6059 | const coin = assetBalance.unspent[i];
|
6060 | if (valid) {
|
6061 | newAssetBalance.unspent.push(coin);
|
6062 | newAssetBalance.balance = newAssetBalance.balance.add(coin.value);
|
6063 | }
|
6064 | else {
|
6065 | newAssetBalance.spent.push(coin);
|
6066 | }
|
6067 | });
|
6068 | return new components_AssetBalance(newAssetBalance);
|
6069 | });
|
6070 | }
|
6071 | function exportAssets(assets) {
|
6072 | const output = {};
|
6073 | const keys = Object.keys(assets);
|
6074 | for (const key of keys) {
|
6075 | output[key] = assets[key].export();
|
6076 | }
|
6077 | return output;
|
6078 | }
|
6079 | function exportTokens(tokens) {
|
6080 | const out = {};
|
6081 | Object.keys(tokens).forEach(symbol => {
|
6082 | out[symbol] = tokens[symbol].toNumber();
|
6083 | });
|
6084 | return out;
|
6085 | }
|
6086 | /**
|
6087 | * Represents a balance available for an Account.
|
6088 | * Contains balances for both UTXO assets and NEP5 tokens.
|
6089 | */
|
6090 | class Balance_Balance {
|
6091 | constructor(bal = {}) {
|
6092 | this.address = bal.address || "";
|
6093 | this.net = bal.net || "NoNet";
|
6094 | this.assetSymbols = [];
|
6095 | this.assets = {};
|
6096 | if (typeof bal.assets === "object") {
|
6097 | const keys = Object.keys(bal.assets);
|
6098 | for (const key of keys) {
|
6099 | if (typeof bal.assets[key] === "object") {
|
6100 | this.addAsset(key, bal.assets[key]);
|
6101 | }
|
6102 | }
|
6103 | }
|
6104 | this.tokenSymbols = [];
|
6105 | this.tokens = {};
|
6106 | if (typeof bal.tokens === "object") {
|
6107 | const keys = Object.keys(bal.tokens);
|
6108 | for (const key of keys) {
|
6109 | this.addToken(key, bal.tokens[key]);
|
6110 | }
|
6111 | }
|
6112 | }
|
6113 | get [Symbol.toStringTag]() {
|
6114 | return "Balance";
|
6115 | }
|
6116 | /**
|
6117 | * Adds a new asset to this Balance.
|
6118 | * @param sym The symbol to refer by. This function will force it to upper-case.
|
6119 | * @param assetBalance The assetBalance if initialized. Default is a zero balance object.
|
6120 | */
|
6121 | addAsset(sym, assetBalance) {
|
6122 | sym = sym.toUpperCase();
|
6123 | this.assetSymbols.push(sym);
|
6124 | this.assetSymbols.sort();
|
6125 | const cleanedAssetBalance = new components_AssetBalance(assetBalance);
|
6126 | this.assets[sym] = cleanedAssetBalance;
|
6127 | return this;
|
6128 | }
|
6129 | /**
|
6130 | * Adds a new NEP-5 Token to this Balance.
|
6131 | * @param sym - The NEP-5 Token Symbol to refer by.
|
6132 | * @param tokenBalance - The amount of tokens this account holds.
|
6133 | */
|
6134 | addToken(sym, tokenBalance = 0) {
|
6135 | sym = sym.toUpperCase();
|
6136 | this.tokenSymbols.push(sym);
|
6137 | this.tokens[sym] = new u_Fixed8(tokenBalance);
|
6138 | return this;
|
6139 | }
|
6140 | /**
|
6141 | * Applies a Transaction to a Balance, removing spent coins and adding new coins. This currently applies only to Assets.
|
6142 | * @param tx Transaction that has been sent and accepted by Node.
|
6143 | * @param confirmed If confirmed, new coins will be added to unspent. Else, new coins will be added to unconfirmed property first.
|
6144 | */
|
6145 | applyTx(tx, confirmed = false) {
|
6146 | tx = tx instanceof BaseTransaction_BaseTransaction ? tx : Transaction_Transaction.deserialize(tx);
|
6147 | const symbols = this.assetSymbols;
|
6148 | // Spend coins
|
6149 | for (const input of tx.inputs) {
|
6150 | const findFunc = (el) => el.txid === input.prevHash && el.index === input.prevIndex;
|
6151 | for (const sym of symbols) {
|
6152 | const assetBalance = this.assets[sym];
|
6153 | const ind = assetBalance.unspent.findIndex(findFunc);
|
6154 | if (ind >= 0) {
|
6155 | const spentCoin = assetBalance.unspent.splice(ind, 1);
|
6156 | assetBalance.spent = assetBalance.spent.concat(spentCoin);
|
6157 | break;
|
6158 | }
|
6159 | }
|
6160 | }
|
6161 | // Add new coins
|
6162 | const hash = tx.hash;
|
6163 | for (let i = 0; i < tx.outputs.length; i++) {
|
6164 | const output = tx.outputs[i];
|
6165 | const sym = ASSETS[output.assetId];
|
6166 | const assetBalance = this.assets[sym];
|
6167 | if (!assetBalance) {
|
6168 | this.addAsset(sym);
|
6169 | }
|
6170 | const coin = new components_Coin({ index: i, txid: hash, value: output.value });
|
6171 | if (confirmed) {
|
6172 | const findFunc = (el) => el.txid === coin.txid && el.index === coin.index;
|
6173 | const unconfirmedIndex = assetBalance.unconfirmed.findIndex(findFunc);
|
6174 | if (unconfirmedIndex >= 0) {
|
6175 | assetBalance.unconfirmed.splice(unconfirmedIndex, 1);
|
6176 | }
|
6177 | if (!assetBalance.unspent) {
|
6178 | assetBalance.unspent = [];
|
6179 | }
|
6180 | assetBalance.unspent.push(coin);
|
6181 | }
|
6182 | else {
|
6183 | if (!assetBalance.unconfirmed) {
|
6184 | assetBalance.unconfirmed = [];
|
6185 | }
|
6186 | assetBalance.unconfirmed.push(coin);
|
6187 | }
|
6188 | this.assets[sym] = assetBalance;
|
6189 | }
|
6190 | return this;
|
6191 | }
|
6192 | /**
|
6193 | * Informs the Balance that the next block is confirmed, thus moving all unconfirmed transaction to unspent.
|
6194 | */
|
6195 | confirm() {
|
6196 | for (const sym of this.assetSymbols) {
|
6197 | const assetBalance = this.assets[sym];
|
6198 | assetBalance.unspent = assetBalance.unspent.concat(assetBalance.unconfirmed);
|
6199 | assetBalance.unconfirmed = [];
|
6200 | }
|
6201 | return this;
|
6202 | }
|
6203 | /**
|
6204 | * Export this class as a plain JS object
|
6205 | */
|
6206 | export() {
|
6207 | return {
|
6208 | net: this.net,
|
6209 | address: this.address,
|
6210 | assetSymbols: this.assetSymbols,
|
6211 | assets: exportAssets(this.assets),
|
6212 | tokenSymbols: this.tokenSymbols,
|
6213 | tokens: exportTokens(this.tokens)
|
6214 | };
|
6215 | }
|
6216 | /**
|
6217 | * Verifies the coins in balance are unspent. This is an expensive call.
|
6218 | *
|
6219 | * Any coins categorised incorrectly are moved to their correct arrays.
|
6220 | * @param url NEO Node to check against.
|
6221 | */
|
6222 | verifyAssets(url) {
|
6223 | const promises = [];
|
6224 | const symbols = this.assetSymbols;
|
6225 | symbols.map(key => {
|
6226 | const assetBalance = this.assets[key];
|
6227 | promises.push(verifyAssetBalance(url, assetBalance));
|
6228 | });
|
6229 | return Promise.all(promises).then(newBalances => {
|
6230 | symbols.map((sym, i) => {
|
6231 | this.assets[sym] = newBalances[i];
|
6232 | });
|
6233 | return this;
|
6234 | });
|
6235 | }
|
6236 | }
|
6237 | /* harmony default export */ var wallet_Balance = (Balance_Balance);
|
6238 | //# sourceMappingURL=Balance.js.map
|
6239 | // CONCATENATED MODULE: ../neon-core/lib/wallet/components/ClaimItem.js
|
6240 |
|
6241 | /**
|
6242 | * Contains the information necessary to validate a GAS Claim.
|
6243 | * It is a reference to a spent coin.
|
6244 | */
|
6245 | class ClaimItem_ClaimItem {
|
6246 | constructor(claimItemLike = {}) {
|
6247 | this.claim = new u_Fixed8(claimItemLike.claim);
|
6248 | this.txid = claimItemLike.txid || "";
|
6249 | this.index = claimItemLike.index || 0;
|
6250 | this.value = claimItemLike.value || 0;
|
6251 | this.start = claimItemLike.start;
|
6252 | this.end = claimItemLike.end;
|
6253 | }
|
6254 | export() {
|
6255 | return {
|
6256 | claim: this.claim.toNumber(),
|
6257 | txid: this.txid,
|
6258 | index: this.index,
|
6259 | value: this.value,
|
6260 | start: this.start,
|
6261 | end: this.end
|
6262 | };
|
6263 | }
|
6264 | equals(other) {
|
6265 | return (this.claim.equals(other.claim || 0) &&
|
6266 | this.txid === other.txid &&
|
6267 | this.index === other.index &&
|
6268 | this.value === other.value &&
|
6269 | this.start === other.start &&
|
6270 | this.end === other.end);
|
6271 | }
|
6272 | }
|
6273 | /* harmony default export */ var components_ClaimItem = (ClaimItem_ClaimItem);
|
6274 | //# sourceMappingURL=ClaimItem.js.map
|
6275 | // CONCATENATED MODULE: ../neon-core/lib/wallet/Claims.js
|
6276 |
|
6277 |
|
6278 | const Claims_inspect = external_util_default.a.inspect.custom;
|
6279 | /**
|
6280 | * Claims object used for claiming GAS.
|
6281 | */
|
6282 | class Claims_Claims {
|
6283 | constructor(config = {}) {
|
6284 | this.address = config.address || "";
|
6285 | this.net = config.net || "NoNet";
|
6286 | this.claims = config.claims ? config.claims.map(c => new components_ClaimItem(c)) : [];
|
6287 | }
|
6288 | get [Symbol.toStringTag]() {
|
6289 | return "Claims";
|
6290 | }
|
6291 | [Claims_inspect]() {
|
6292 | const claimsDump = this.claims.map(c => {
|
6293 | return `${c.txid} <${c.index}>: ${c.claim.toString()}`;
|
6294 | });
|
6295 | return `[Claims(${this.net}): ${this.address}]\n${JSON.stringify(claimsDump, null, 2)}`;
|
6296 | }
|
6297 | export() {
|
6298 | return {
|
6299 | address: this.address,
|
6300 | net: this.net,
|
6301 | claims: this.claims.map(c => c.export())
|
6302 | };
|
6303 | }
|
6304 | /**
|
6305 | * Returns new Claims object that contains part of the total claims starting at start, ending at end.
|
6306 | */
|
6307 | slice(start, end) {
|
6308 | return new Claims_Claims({
|
6309 | address: this.address,
|
6310 | net: this.net,
|
6311 | claims: this.claims.slice(start, end)
|
6312 | });
|
6313 | }
|
6314 | }
|
6315 | /* harmony default export */ var wallet_Claims = (Claims_Claims);
|
6316 | //# sourceMappingURL=Claims.js.map
|
6317 | // CONCATENATED MODULE: ../neon-core/lib/wallet/components/index.js
|
6318 |
|
6319 |
|
6320 |
|
6321 | //# sourceMappingURL=index.js.map
|
6322 | // CONCATENATED MODULE: ../neon-core/lib/wallet/Wallet.js
|
6323 | var Wallet_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
6324 | return new (P || (P = Promise))(function (resolve, reject) {
|
6325 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6326 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6327 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
6328 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
6329 | });
|
6330 | };
|
6331 |
|
6332 |
|
6333 |
|
6334 | const Wallet_log = logging("wallet");
|
6335 | /**
|
6336 | * File to store private keys according to the NEP-2 specification.
|
6337 | */
|
6338 | class Wallet_Wallet {
|
6339 | constructor(obj = DEFAULT_WALLET) {
|
6340 | this.name = obj.name || "myWallet";
|
6341 | this.version = obj.version || DEFAULT_WALLET.version;
|
6342 | this.scrypt = Object.assign({}, DEFAULT_SCRYPT, obj.scrypt);
|
6343 | this.accounts = [];
|
6344 | if (obj.accounts) {
|
6345 | for (const acct of obj.accounts) {
|
6346 | this.addAccount(acct);
|
6347 | }
|
6348 | }
|
6349 | this.extra = obj.extra || {};
|
6350 | Wallet_log.info(`New Wallet created: ${this.name}`);
|
6351 | }
|
6352 | get [Symbol.toStringTag]() {
|
6353 | return "Wallet";
|
6354 | }
|
6355 | /**
|
6356 | * Returns the default Account according to the following rules:
|
6357 | * 1. First Account where isDefault is true.
|
6358 | * 2. First Account with a decrypted private key.
|
6359 | * 3. First Account with an encrypted private key.
|
6360 | * 4. First Account in the array.
|
6361 | * Throws error if no accounts available.
|
6362 | */
|
6363 | get defaultAccount() {
|
6364 | if (this.accounts.length === 0) {
|
6365 | throw new Error("No accounts available in this Wallet!");
|
6366 | }
|
6367 | for (const acct of this.accounts) {
|
6368 | if (acct.isDefault) {
|
6369 | return acct;
|
6370 | }
|
6371 | }
|
6372 | for (const acct of this.accounts) {
|
6373 | if (acct.tryGet("privateKey") || acct.tryGet("WIF")) {
|
6374 | return acct;
|
6375 | }
|
6376 | }
|
6377 | for (const acct of this.accounts) {
|
6378 | if (acct.encrypted) {
|
6379 | return acct;
|
6380 | }
|
6381 | }
|
6382 | return this.accounts[0];
|
6383 | }
|
6384 | /**
|
6385 | * Adds an account.
|
6386 | * @param acct Account or WalletAccount object.
|
6387 | * @return Index position of Account in array.
|
6388 | */
|
6389 | addAccount(acct) {
|
6390 | const index = this.accounts.length;
|
6391 | if (!(acct instanceof Account_Account)) {
|
6392 | acct = new Account_Account(acct);
|
6393 | }
|
6394 | this.accounts.push(acct);
|
6395 | try {
|
6396 | const address = acct.address;
|
6397 | Wallet_log.info(`Added Account: ${address} to Wallet ${this.name}`);
|
6398 | }
|
6399 | catch (err) {
|
6400 | Wallet_log.warn(`Encrypted account added to Wallet ${this.name}. You will not be able to export this wallet without first decrypting this account`);
|
6401 | }
|
6402 | return index;
|
6403 | }
|
6404 | /**
|
6405 | * Attempts to decrypt Account at index in array.
|
6406 | * @param index Index of Account in array.
|
6407 | * @param keyphrase keyphrase
|
6408 | * @return Promise of decryption success/failure.
|
6409 | */
|
6410 | decrypt(index, keyphrase) {
|
6411 | return Wallet_awaiter(this, void 0, void 0, function* () {
|
6412 | if (index < 0) {
|
6413 | return Promise.reject(`Index cannot be negative! index: ${index}`);
|
6414 | }
|
6415 | if (index >= this.accounts.length) {
|
6416 | return Promise.reject(`Index cannot larger than Accounts array! index: ${index}`);
|
6417 | }
|
6418 | yield this.accounts[index].decrypt(keyphrase, this.scrypt);
|
6419 | return true;
|
6420 | });
|
6421 | }
|
6422 | /**
|
6423 | * Attempts to decrypt all accounts with keyphrase.
|
6424 | * @param keyphrase
|
6425 | * @return Promise of accounts decryption success/failure .
|
6426 | */
|
6427 | decryptAll(keyphrase) {
|
6428 | return Promise.all(this.accounts.map((acct, i) => this.decrypt(i, keyphrase)));
|
6429 | }
|
6430 | /**
|
6431 | * Attempts to encrypt Account at index in array.
|
6432 | * @param index Index of Account in array.
|
6433 | * @param keyphrase
|
6434 | * @return Promise of encryption success/failure.
|
6435 | */
|
6436 | encrypt(index, keyphrase) {
|
6437 | return Wallet_awaiter(this, void 0, void 0, function* () {
|
6438 | if (index < 0) {
|
6439 | return Promise.reject("Index cannot be negative!");
|
6440 | }
|
6441 | if (index >= this.accounts.length) {
|
6442 | return Promise.reject("Index cannot larger than Accounts array!");
|
6443 | }
|
6444 | yield this.accounts[index].encrypt(keyphrase, this.scrypt);
|
6445 | return true;
|
6446 | });
|
6447 | }
|
6448 | /**
|
6449 | * Attempts to encrypt all accounts with keyphrase.
|
6450 | * @param keyphrase
|
6451 | * @return Promise of accounts encryption success/failure.
|
6452 | */
|
6453 | encryptAll(keyphrase) {
|
6454 | return Promise.all(this.accounts.map((acct, i) => this.encrypt(i, keyphrase)));
|
6455 | }
|
6456 | /**
|
6457 | * Export this class as a JS object.
|
6458 | */
|
6459 | export() {
|
6460 | return {
|
6461 | name: this.name,
|
6462 | version: this.version,
|
6463 | scrypt: this.scrypt,
|
6464 | accounts: this.accounts.map(acct => acct.export()),
|
6465 | extra: this.extra
|
6466 | };
|
6467 | }
|
6468 | /**
|
6469 | * Set Account at index in array to be default account.
|
6470 | * @param index The index of the Account in accounts array.
|
6471 | * @return this
|
6472 | */
|
6473 | setDefault(index) {
|
6474 | for (let i = 0; i < this.accounts.length; i++) {
|
6475 | this.accounts[i].isDefault = i === index;
|
6476 | }
|
6477 | Wallet_log.info(`Set Account: ${this.accounts[index]} as default for Wallet ${this.name}`);
|
6478 | return this;
|
6479 | }
|
6480 | }
|
6481 | /* harmony default export */ var wallet_Wallet = (Wallet_Wallet);
|
6482 | //# sourceMappingURL=Wallet.js.map
|
6483 | // CONCATENATED MODULE: ../neon-core/lib/wallet/index.js
|
6484 |
|
6485 |
|
6486 |
|
6487 |
|
6488 |
|
6489 |
|
6490 |
|
6491 |
|
6492 |
|
6493 |
|
6494 | //# sourceMappingURL=index.js.map
|
6495 | // CONCATENATED MODULE: ../neon-core/lib/tx/components/TransactionOutput.js
|
6496 |
|
6497 |
|
6498 |
|
6499 | /**
|
6500 | * UTXO that is constructed in this transaction.
|
6501 | * This represents a spendable coin in the system.
|
6502 | */
|
6503 | class TransactionOutput_TransactionOutput {
|
6504 | static deserialize(hex) {
|
6505 | const ss = new StringStream_StringStream(hex);
|
6506 | return this.fromStream(ss);
|
6507 | }
|
6508 | static fromStream(ss) {
|
6509 | const assetId = reverseHex(ss.read(32));
|
6510 | const value = Fixed8_Fixed8.fromReverseHex(ss.read(8));
|
6511 | const scriptHash = reverseHex(ss.read(20));
|
6512 | return new TransactionOutput_TransactionOutput({ assetId, value, scriptHash });
|
6513 | }
|
6514 | static fromIntent(symbol, value, address) {
|
6515 | const assetId = ASSET_ID[symbol];
|
6516 | const scriptHash = getScriptHashFromAddress(address);
|
6517 | return new TransactionOutput_TransactionOutput({ assetId, value, scriptHash });
|
6518 | }
|
6519 | constructor(obj) {
|
6520 | if (!obj || !obj.assetId || !obj.value || !obj.scriptHash) {
|
6521 | throw new Error("TransactionOutput requires assetId, value and scriptHash fields");
|
6522 | }
|
6523 | this.assetId = obj.assetId;
|
6524 | this.value = new Fixed8_Fixed8(obj.value);
|
6525 | this.scriptHash = obj.scriptHash;
|
6526 | }
|
6527 | serialize() {
|
6528 | return (reverseHex(this.assetId) +
|
6529 | this.value.toReverseHex() +
|
6530 | reverseHex(this.scriptHash));
|
6531 | }
|
6532 | equals(other) {
|
6533 | return (this.assetId === other.assetId &&
|
6534 | this.value.equals(other.value) &&
|
6535 | this.scriptHash === other.scriptHash);
|
6536 | }
|
6537 | export() {
|
6538 | return {
|
6539 | assetId: this.assetId,
|
6540 | value: this.value.toNumber(),
|
6541 | scriptHash: this.scriptHash
|
6542 | };
|
6543 | }
|
6544 | }
|
6545 | /* harmony default export */ var components_TransactionOutput = (TransactionOutput_TransactionOutput);
|
6546 | //# sourceMappingURL=TransactionOutput.js.map
|
6547 | // CONCATENATED MODULE: ../neon-core/lib/tx/components/Witness.js
|
6548 |
|
6549 |
|
6550 | /**
|
6551 | * A Witness is a section of VM code that is ran during the verification of the transaction.
|
6552 | *
|
6553 | * For example, the most common witness is the VM Script that pushes the ECDSA signature into the VM and calling CHECKSIG to prove the authority to spend the TransactionInputs in the transaction.
|
6554 | */
|
6555 | class Witness_Witness {
|
6556 | constructor(obj) {
|
6557 | // tslint:disable-next-line:variable-name
|
6558 | this._scriptHash = "";
|
6559 | if (!obj ||
|
6560 | obj.invocationScript === undefined ||
|
6561 | obj.verificationScript === undefined) {
|
6562 | throw new Error("Witness requires invocationScript and verificationScript fields");
|
6563 | }
|
6564 | this.invocationScript = obj.invocationScript;
|
6565 | this.verificationScript = obj.verificationScript;
|
6566 | }
|
6567 | static deserialize(hex) {
|
6568 | const ss = new StringStream_StringStream(hex);
|
6569 | return this.fromStream(ss);
|
6570 | }
|
6571 | static fromStream(ss) {
|
6572 | const invocationScript = ss.readVarBytes();
|
6573 | const verificationScript = ss.readVarBytes();
|
6574 | return new Witness_Witness({ invocationScript, verificationScript });
|
6575 | }
|
6576 | static fromSignature(sig, publicKey) {
|
6577 | const invocationScript = "40" + sig;
|
6578 | const verificationScript = getVerificationScriptFromPublicKey(publicKey);
|
6579 | return new Witness_Witness({ invocationScript, verificationScript });
|
6580 | }
|
6581 | /**
|
6582 | * Builds a multi-sig Witness object.
|
6583 | * @param tx Hexstring to be signed.
|
6584 | * @param sigs Unordered list of signatures.
|
6585 | * @param acctOrVerificationScript Account or verification script. Account needs to be the multi-sig account and not one of the public keys.
|
6586 | */
|
6587 | static buildMultiSig(tx, sigs, acctOrVerificationScript) {
|
6588 | const verificationScript = typeof acctOrVerificationScript === "string"
|
6589 | ? acctOrVerificationScript
|
6590 | : acctOrVerificationScript.contract.script;
|
6591 | const publicKeys = getPublicKeysFromVerificationScript(verificationScript);
|
6592 | const orderedSigs = Array(publicKeys.length).fill("");
|
6593 | sigs.forEach(element => {
|
6594 | if (typeof element === "string") {
|
6595 | const position = publicKeys.findIndex(key => verify(tx, element, key));
|
6596 | if (position === -1) {
|
6597 | throw new Error(`Invalid signature given: ${element}`);
|
6598 | }
|
6599 | orderedSigs[position] = element;
|
6600 | }
|
6601 | else if (element instanceof Witness_Witness) {
|
6602 | const keys = getPublicKeysFromVerificationScript(element.verificationScript);
|
6603 | if (keys.length !== 1) {
|
6604 | throw new Error("Given witness contains more than 1 public key!");
|
6605 | }
|
6606 | const position = publicKeys.indexOf(keys[0]);
|
6607 | orderedSigs[position] = getSignaturesFromInvocationScript(element.invocationScript)[0];
|
6608 | }
|
6609 | else {
|
6610 | throw new Error("Unable to process given signature");
|
6611 | }
|
6612 | });
|
6613 | const signingThreshold = getSigningThresholdFromVerificationScript(verificationScript);
|
6614 | const validSigs = orderedSigs.filter(s => s !== "");
|
6615 | if (validSigs.length < signingThreshold) {
|
6616 | throw new Error(`Insufficient signatures: expected ${signingThreshold} but got ${validSigs.length} instead`);
|
6617 | }
|
6618 | return new Witness_Witness({
|
6619 | invocationScript: validSigs
|
6620 | .slice(0, signingThreshold)
|
6621 | .map(s => "40" + s)
|
6622 | .join(""),
|
6623 | verificationScript
|
6624 | });
|
6625 | }
|
6626 | get scriptHash() {
|
6627 | if (this._scriptHash) {
|
6628 | return this._scriptHash;
|
6629 | }
|
6630 | else if (this.verificationScript) {
|
6631 | this._scriptHash = reverseHex(hash160(this.verificationScript));
|
6632 | return this._scriptHash;
|
6633 | }
|
6634 | else {
|
6635 | throw new Error("Unable to produce scriptHash from empty verificationScript");
|
6636 | }
|
6637 | }
|
6638 | set scriptHash(value) {
|
6639 | if (this.verificationScript) {
|
6640 | throw new Error("Unable to set scriptHash when verificationScript is not empty");
|
6641 | }
|
6642 | this._scriptHash = value;
|
6643 | }
|
6644 | serialize() {
|
6645 | const invoLength = num2VarInt(this.invocationScript.length / 2);
|
6646 | const veriLength = num2VarInt(this.verificationScript.length / 2);
|
6647 | return (invoLength + this.invocationScript + veriLength + this.verificationScript);
|
6648 | }
|
6649 | export() {
|
6650 | return {
|
6651 | invocationScript: this.invocationScript,
|
6652 | verificationScript: this.verificationScript
|
6653 | };
|
6654 | }
|
6655 | equals(other) {
|
6656 | return (this.invocationScript === other.invocationScript &&
|
6657 | this.verificationScript === other.verificationScript);
|
6658 | }
|
6659 | generateScriptHash() {
|
6660 | this._scriptHash = reverseHex(hash160(this.verificationScript));
|
6661 | }
|
6662 | }
|
6663 | /* harmony default export */ var components_Witness = (Witness_Witness);
|
6664 | //# sourceMappingURL=Witness.js.map
|
6665 | // CONCATENATED MODULE: ../neon-core/lib/tx/components/StateDescriptor.js
|
6666 |
|
6667 | var StateType;
|
6668 | (function (StateType) {
|
6669 | StateType[StateType["Account"] = 64] = "Account";
|
6670 | StateType[StateType["Validator"] = 72] = "Validator";
|
6671 | })(StateType || (StateType = {}));
|
6672 | function toStateType(type) {
|
6673 | if (typeof type === "string") {
|
6674 | if (type in StateType) {
|
6675 | return StateType[type];
|
6676 | }
|
6677 | throw new Error(`${type} not found in StateType!`);
|
6678 | }
|
6679 | return type;
|
6680 | }
|
6681 | class StateDescriptor_StateDescriptor {
|
6682 | static deserialize(hex) {
|
6683 | const ss = new StringStream_StringStream(hex);
|
6684 | return this.fromStream(ss);
|
6685 | }
|
6686 | static fromStream(ss) {
|
6687 | const type = parseInt(ss.read(), 16);
|
6688 | const key = ss.readVarBytes();
|
6689 | const field = hexstring2str(ss.readVarBytes());
|
6690 | const value = ss.readVarBytes();
|
6691 | return new StateDescriptor_StateDescriptor({ type, key, field, value });
|
6692 | }
|
6693 | constructor(obj = {}) {
|
6694 | this.type = obj.type ? toStateType(obj.type) : StateType.Account;
|
6695 | this.key = obj.key || "";
|
6696 | this.field = obj.field || "";
|
6697 | this.value = obj.value || "";
|
6698 | }
|
6699 | get [Symbol.toStringTag]() {
|
6700 | return "StateDescriptor";
|
6701 | }
|
6702 | serialize() {
|
6703 | let out = num2hexstring(this.type);
|
6704 | out += num2VarInt(this.key.length / 2);
|
6705 | out += this.key;
|
6706 | const hexField = str2hexstring(this.field);
|
6707 | out += num2VarInt(hexField.length / 2);
|
6708 | out += hexField;
|
6709 | out += num2VarInt(this.value.length / 2);
|
6710 | out += this.value;
|
6711 | return out;
|
6712 | }
|
6713 | export() {
|
6714 | return {
|
6715 | type: this.type,
|
6716 | key: this.key,
|
6717 | field: this.field,
|
6718 | value: this.value
|
6719 | };
|
6720 | }
|
6721 | equals(other) {
|
6722 | return (this.type === toStateType(other.type) &&
|
6723 | this.key === other.key &&
|
6724 | this.field === other.field &&
|
6725 | this.value === other.value);
|
6726 | }
|
6727 | }
|
6728 | /* harmony default export */ var components_StateDescriptor = (StateDescriptor_StateDescriptor);
|
6729 | //# sourceMappingURL=StateDescriptor.js.map
|
6730 | // CONCATENATED MODULE: ../neon-core/lib/tx/components/index.js
|
6731 |
|
6732 |
|
6733 |
|
6734 |
|
6735 |
|
6736 | //# sourceMappingURL=index.js.map
|
6737 | // CONCATENATED MODULE: ../neon-core/lib/tx/transaction/ClaimTransaction.js
|
6738 |
|
6739 |
|
6740 |
|
6741 |
|
6742 |
|
6743 |
|
6744 | const MAX_CLAIMS_LENGTH = 255;
|
6745 | /**
|
6746 | * Transaction used for claiming GAS. Do note that GAS Claims can only occur for spent coins.
|
6747 | * Constructed with a list of claims and a TransactionOutput representing the GAS claimed.
|
6748 | */
|
6749 | class ClaimTransaction_ClaimTransaction extends BaseTransaction_BaseTransaction {
|
6750 | constructor(obj = {}) {
|
6751 | super(Object.assign({ version: TX_VERSION.CLAIM }, obj));
|
6752 | this.type = 0x02;
|
6753 | this.claims = Array.isArray(obj.claims)
|
6754 | ? obj.claims.slice(0, MAX_CLAIMS_LENGTH).map(c => new TransactionInput_TransactionInput(c))
|
6755 | : [];
|
6756 | }
|
6757 | static deserializeExclusive(ss, tx) {
|
6758 | const out = {
|
6759 | claims: []
|
6760 | };
|
6761 | const claimLength = ss.readVarInt();
|
6762 | for (let i = 0; i < claimLength; i++) {
|
6763 | out.claims.push(TransactionInput_TransactionInput.fromStream(ss));
|
6764 | }
|
6765 | return Object.assign(tx, out);
|
6766 | }
|
6767 | static fromClaims(claim) {
|
6768 | const totalClaim = claim.claims.reduce((p, c) => {
|
6769 | return p.add(c.claim);
|
6770 | }, new Fixed8_Fixed8(0));
|
6771 | const outputs = [
|
6772 | new TransactionOutput_TransactionOutput({
|
6773 | assetId: ASSET_ID.GAS,
|
6774 | value: totalClaim,
|
6775 | scriptHash: getScriptHashFromAddress(claim.address)
|
6776 | })
|
6777 | ];
|
6778 | const claims = claim.claims.map(c => ({
|
6779 | prevHash: c.txid,
|
6780 | prevIndex: c.index
|
6781 | }));
|
6782 | return new ClaimTransaction_ClaimTransaction({ outputs, claims });
|
6783 | }
|
6784 | get exclusiveData() {
|
6785 | return { claims: this.claims };
|
6786 | }
|
6787 | get fees() {
|
6788 | return 0;
|
6789 | }
|
6790 | addClaims(claim) {
|
6791 | if (this.claims.length !== 0) {
|
6792 | throw new Error(`This transaction already has claims!`);
|
6793 | }
|
6794 | const totalClaim = claim.claims.reduce((p, c) => {
|
6795 | return p.add(c.claim);
|
6796 | }, new Fixed8_Fixed8(0));
|
6797 | this.outputs.push(new TransactionOutput_TransactionOutput({
|
6798 | assetId: ASSET_ID.GAS,
|
6799 | value: totalClaim,
|
6800 | scriptHash: getScriptHashFromAddress(claim.address)
|
6801 | }));
|
6802 | this.claims = claim.claims.map(c => new TransactionInput_TransactionInput({
|
6803 | prevHash: c.txid,
|
6804 | prevIndex: c.index
|
6805 | }));
|
6806 | return this;
|
6807 | }
|
6808 | serializeExclusive() {
|
6809 | return serializeArrayOf(this.claims);
|
6810 | }
|
6811 | equals(other) {
|
6812 | if (this.type !== other.type) {
|
6813 | return false;
|
6814 | }
|
6815 | if (other instanceof ClaimTransaction_ClaimTransaction) {
|
6816 | return this.hash === other.hash;
|
6817 | }
|
6818 | return this.hash === new ClaimTransaction_ClaimTransaction(other).hash;
|
6819 | }
|
6820 | export() {
|
6821 | return Object.assign(super.export(), {
|
6822 | claims: this.claims.map(c => c.export())
|
6823 | });
|
6824 | }
|
6825 | }
|
6826 | /* harmony default export */ var transaction_ClaimTransaction = (ClaimTransaction_ClaimTransaction);
|
6827 | //# sourceMappingURL=ClaimTransaction.js.map
|
6828 | // CONCATENATED MODULE: ../neon-core/lib/tx/transaction/ContractTransaction.js
|
6829 |
|
6830 | /**
|
6831 | * Transaction used for transferring UTXO assets.
|
6832 | */
|
6833 | class ContractTransaction_ContractTransaction extends transaction_BaseTransaction {
|
6834 | constructor(obj = {}) {
|
6835 | super(obj);
|
6836 | this.type = 0x80;
|
6837 | }
|
6838 | static deserializeExclusive(ss, tx) {
|
6839 | return {};
|
6840 | }
|
6841 | get exclusiveData() {
|
6842 | return {};
|
6843 | }
|
6844 | get fees() {
|
6845 | return 0;
|
6846 | }
|
6847 | serializeExclusive() {
|
6848 | return "";
|
6849 | }
|
6850 | equals(other) {
|
6851 | if (this.type !== other.type) {
|
6852 | return false;
|
6853 | }
|
6854 | if (other instanceof ContractTransaction_ContractTransaction) {
|
6855 | return this.hash === other.hash;
|
6856 | }
|
6857 | return this.hash === new ContractTransaction_ContractTransaction(other).hash;
|
6858 | }
|
6859 | }
|
6860 | /* harmony default export */ var transaction_ContractTransaction = (ContractTransaction_ContractTransaction);
|
6861 | //# sourceMappingURL=ContractTransaction.js.map
|
6862 | // CONCATENATED MODULE: ../neon-core/lib/tx/transaction/InvocationTransaction.js
|
6863 |
|
6864 |
|
6865 |
|
6866 | /**
|
6867 | * Transaction used for invoking smart contracts through a VM script.
|
6868 | * Can also be used to transfer UTXO assets.
|
6869 | */
|
6870 | class InvocationTransaction_InvocationTransaction extends BaseTransaction_BaseTransaction {
|
6871 | constructor(obj = {}) {
|
6872 | super(Object.assign({ version: TX_VERSION.INVOCATION }, obj));
|
6873 | this.type = 0xd1;
|
6874 | this.script = obj.script || "";
|
6875 | this.gas = new Fixed8_Fixed8(obj.gas);
|
6876 | }
|
6877 | static deserializeExclusive(ss, tx) {
|
6878 | const script = ss.readVarBytes();
|
6879 | const version = parseInt(ss.str.substr(2, 2), 16);
|
6880 | const gas = version >= 1 ? fixed82num(ss.read(8)) : 0;
|
6881 | return Object.assign(tx, { script, gas });
|
6882 | }
|
6883 | get exclusiveData() {
|
6884 | return { gas: this.gas, script: this.script };
|
6885 | }
|
6886 | get fees() {
|
6887 | return this.gas.toNumber();
|
6888 | }
|
6889 | serializeExclusive() {
|
6890 | let out = num2VarInt(this.script.length / 2);
|
6891 | out += this.script;
|
6892 | if (this.version >= 1) {
|
6893 | out += this.gas.toReverseHex();
|
6894 | }
|
6895 | return out;
|
6896 | }
|
6897 | equals(other) {
|
6898 | if (this.type !== other.type) {
|
6899 | return false;
|
6900 | }
|
6901 | if (other instanceof InvocationTransaction_InvocationTransaction) {
|
6902 | return this.hash === other.hash;
|
6903 | }
|
6904 | return this.hash === new InvocationTransaction_InvocationTransaction(other).hash;
|
6905 | }
|
6906 | export() {
|
6907 | return Object.assign(super.export(), {
|
6908 | script: this.script,
|
6909 | gas: this.gas.toNumber()
|
6910 | });
|
6911 | }
|
6912 | }
|
6913 | /* harmony default export */ var transaction_InvocationTransaction = (InvocationTransaction_InvocationTransaction);
|
6914 | //# sourceMappingURL=InvocationTransaction.js.map
|
6915 | // CONCATENATED MODULE: ../neon-core/lib/tx/transaction/TransactionType.js
|
6916 | var TransactionType;
|
6917 | (function (TransactionType) {
|
6918 | TransactionType[TransactionType["MinerTransaction"] = 0] = "MinerTransaction";
|
6919 | TransactionType[TransactionType["IssueTransaction"] = 1] = "IssueTransaction";
|
6920 | TransactionType[TransactionType["ClaimTransaction"] = 2] = "ClaimTransaction";
|
6921 | TransactionType[TransactionType["EnrollmentTransaction"] = 32] = "EnrollmentTransaction";
|
6922 | TransactionType[TransactionType["RegisterTransaction"] = 64] = "RegisterTransaction";
|
6923 | TransactionType[TransactionType["ContractTransaction"] = 128] = "ContractTransaction";
|
6924 | TransactionType[TransactionType["StateTransaction"] = 144] = "StateTransaction";
|
6925 | TransactionType[TransactionType["PublishTransaction"] = 208] = "PublishTransaction";
|
6926 | TransactionType[TransactionType["InvocationTransaction"] = 209] = "InvocationTransaction";
|
6927 | })(TransactionType || (TransactionType = {}));
|
6928 | /* harmony default export */ var transaction_TransactionType = (TransactionType);
|
6929 | //# sourceMappingURL=TransactionType.js.map
|
6930 | // CONCATENATED MODULE: ../neon-core/lib/tx/transaction/StateTransaction.js
|
6931 |
|
6932 |
|
6933 |
|
6934 |
|
6935 |
|
6936 | /**
|
6937 | * Transaction used for invoking smart contracts through a VM script.
|
6938 | * Can also be used to transfer UTXO assets.
|
6939 | */
|
6940 | class StateTransaction_StateTransaction extends BaseTransaction_BaseTransaction {
|
6941 | constructor(obj = {}) {
|
6942 | super(Object.assign({ version: TX_VERSION.STATE }, obj));
|
6943 | this.type = transaction_TransactionType.StateTransaction;
|
6944 | this.descriptors = obj.descriptors
|
6945 | ? obj.descriptors.map(d => new StateDescriptor_StateDescriptor(d))
|
6946 | : [];
|
6947 | }
|
6948 | static deserializeExclusive(ss, tx) {
|
6949 | const out = {
|
6950 | descriptors: []
|
6951 | };
|
6952 | const descLength = ss.readVarInt();
|
6953 | for (let i = 0; i < descLength; i++) {
|
6954 | out.descriptors.push(StateDescriptor_StateDescriptor.fromStream(ss));
|
6955 | }
|
6956 | return Object.assign(tx, out);
|
6957 | }
|
6958 | get exclusiveData() {
|
6959 | return { descriptors: this.descriptors };
|
6960 | }
|
6961 | get fees() {
|
6962 | return 0;
|
6963 | }
|
6964 | serializeExclusive() {
|
6965 | let out = num2VarInt(this.descriptors.length);
|
6966 | out += this.descriptors.map(d => d.serialize()).join("");
|
6967 | return out;
|
6968 | }
|
6969 | equals(other) {
|
6970 | if (this.type !== other.type) {
|
6971 | return false;
|
6972 | }
|
6973 | if (other instanceof StateTransaction_StateTransaction) {
|
6974 | return this.hash === other.hash;
|
6975 | }
|
6976 | return this.hash === new StateTransaction_StateTransaction(other).hash;
|
6977 | }
|
6978 | export() {
|
6979 | return Object.assign(super.export(), {
|
6980 | descriptors: this.descriptors.map(d => d.export())
|
6981 | });
|
6982 | }
|
6983 | }
|
6984 | /* harmony default export */ var transaction_StateTransaction = (StateTransaction_StateTransaction);
|
6985 | //# sourceMappingURL=StateTransaction.js.map
|
6986 | // CONCATENATED MODULE: ../neon-core/lib/tx/transaction/MinerTransaction.js
|
6987 |
|
6988 |
|
6989 |
|
6990 | class MinerTransaction_MinerTransaction extends BaseTransaction_BaseTransaction {
|
6991 | constructor(obj = {}) {
|
6992 | super(Object.assign({ version: TX_VERSION.MINER }, obj));
|
6993 | this.type = 0x00;
|
6994 | this.nonce = obj.nonce || 0;
|
6995 | }
|
6996 | static deserializeExclusive(ss, tx) {
|
6997 | // read Uint32 from StringStream
|
6998 | const nonce = parseInt(reverseHex(ss.read(4)), 16);
|
6999 | return Object.assign(tx, { nonce });
|
7000 | }
|
7001 | get exclusiveData() {
|
7002 | return { nonce: this.nonce };
|
7003 | }
|
7004 | get fees() {
|
7005 | return 0;
|
7006 | }
|
7007 | serializeExclusive() {
|
7008 | return num2hexstring(this.nonce, 4, true);
|
7009 | }
|
7010 | export() {
|
7011 | return Object.assign(super.export(), {
|
7012 | nonce: this.nonce
|
7013 | });
|
7014 | }
|
7015 | equals(other) {
|
7016 | if (this.type !== other.type) {
|
7017 | return false;
|
7018 | }
|
7019 | if (other instanceof MinerTransaction_MinerTransaction) {
|
7020 | return this.hash === other.hash;
|
7021 | }
|
7022 | return this.hash === new MinerTransaction_MinerTransaction(other).hash;
|
7023 | }
|
7024 | }
|
7025 | /* harmony default export */ var transaction_MinerTransaction = (MinerTransaction_MinerTransaction);
|
7026 | //# sourceMappingURL=MinerTransaction.js.map
|
7027 | // CONCATENATED MODULE: ../neon-core/lib/tx/transaction/EnrollmentTransaction.js
|
7028 |
|
7029 |
|
7030 |
|
7031 |
|
7032 |
|
7033 | class EnrollmentTransaction_EnrollmentTransaction extends BaseTransaction_BaseTransaction {
|
7034 | constructor(obj = {}) {
|
7035 | super(Object.assign({ version: TX_VERSION.ENROLLMENT }, obj));
|
7036 | this.type = transaction_TransactionType.EnrollmentTransaction;
|
7037 | this.publicKey = obj.publicKey || "";
|
7038 | }
|
7039 | static deserializeExclusive(ss, tx) {
|
7040 | const hexStrPrefix = ss.read(1);
|
7041 | const prefix = parseInt(hexStrPrefix, 16);
|
7042 | let pKey = "";
|
7043 | // Compressed public keys.
|
7044 | if (prefix === 0x02 || prefix === 0x03) {
|
7045 | pKey = ss.read(32);
|
7046 | }
|
7047 | else if (prefix === 0x04) {
|
7048 | pKey = ss.read(64);
|
7049 | }
|
7050 | else if (prefix === 0x00) {
|
7051 | // infinity case.
|
7052 | return Object.assign(tx, { publicKey: "" });
|
7053 | }
|
7054 | else {
|
7055 | throw new Error("Prefix not recognised for public key");
|
7056 | }
|
7057 | pKey = hexStrPrefix + pKey;
|
7058 | const publicKey = getPublicKeyUnencoded(pKey);
|
7059 | return Object.assign(tx, { publicKey });
|
7060 | }
|
7061 | get exclusiveData() {
|
7062 | return { publicKey: this.publicKey };
|
7063 | }
|
7064 | get fees() {
|
7065 | return DEFAULT_SYSFEE.enrollmentTransaction;
|
7066 | }
|
7067 | serializeExclusive() {
|
7068 | if (this.publicKey === "") {
|
7069 | return "00";
|
7070 | }
|
7071 | return getPublicKeyEncoded(this.publicKey);
|
7072 | }
|
7073 | export() {
|
7074 | return Object.assign(super.export(), {
|
7075 | publicKey: this.publicKey
|
7076 | });
|
7077 | }
|
7078 | equals(other) {
|
7079 | if (this.type !== other.type) {
|
7080 | return false;
|
7081 | }
|
7082 | if (other instanceof EnrollmentTransaction_EnrollmentTransaction) {
|
7083 | return this.hash === other.hash;
|
7084 | }
|
7085 | return this.hash === new EnrollmentTransaction_EnrollmentTransaction(other).hash;
|
7086 | }
|
7087 | }
|
7088 | /* harmony default export */ var transaction_EnrollmentTransaction = (EnrollmentTransaction_EnrollmentTransaction);
|
7089 | //# sourceMappingURL=EnrollmentTransaction.js.map
|
7090 | // CONCATENATED MODULE: ../neon-core/lib/tx/transaction/IssueTransaction.js
|
7091 |
|
7092 |
|
7093 |
|
7094 |
|
7095 | class IssueTransaction_IssueTransaction extends BaseTransaction_BaseTransaction {
|
7096 | constructor(obj = {}) {
|
7097 | super(Object.assign({ version: TX_VERSION.ISSUE }, obj));
|
7098 | this.type = transaction_TransactionType.IssueTransaction;
|
7099 | }
|
7100 | static deserializeExclusive(ss, tx) {
|
7101 | return {};
|
7102 | }
|
7103 | get exclusiveData() {
|
7104 | return {};
|
7105 | }
|
7106 | get fees() {
|
7107 | if (this.version >= 1) {
|
7108 | return 0;
|
7109 | }
|
7110 | if (this.outputs.every(p => p.assetId === ASSET_ID.NEO || p.assetId === ASSET_ID.GAS)) {
|
7111 | return 0;
|
7112 | }
|
7113 | return DEFAULT_SYSFEE.issueTransaction;
|
7114 | }
|
7115 | serializeExclusive() {
|
7116 | return "";
|
7117 | }
|
7118 | equals(other) {
|
7119 | if (this.type !== other.type) {
|
7120 | return false;
|
7121 | }
|
7122 | if (other instanceof IssueTransaction_IssueTransaction) {
|
7123 | return this.hash === other.hash;
|
7124 | }
|
7125 | return this.hash === new IssueTransaction_IssueTransaction(other).hash;
|
7126 | }
|
7127 | }
|
7128 | /* harmony default export */ var transaction_IssueTransaction = (IssueTransaction_IssueTransaction);
|
7129 | //# sourceMappingURL=IssueTransaction.js.map
|
7130 | // CONCATENATED MODULE: ../neon-core/lib/tx/transaction/RegisterTransaction.js
|
7131 |
|
7132 |
|
7133 |
|
7134 |
|
7135 |
|
7136 | class RegisterTransaction_RegisterTransaction extends BaseTransaction_BaseTransaction {
|
7137 | constructor(obj = {}) {
|
7138 | super(Object.assign({ version: TX_VERSION.REGISTER }, obj));
|
7139 | this.type = transaction_TransactionType.RegisterTransaction;
|
7140 | this.assetType = obj.assetType || 0;
|
7141 | this.name = obj.name || "";
|
7142 | this.amount = new Fixed8_Fixed8(obj.amount);
|
7143 | this.precision = obj.precision || 0;
|
7144 | this.owner = obj.owner || "";
|
7145 | this.admin = obj.admin || "";
|
7146 | }
|
7147 | static deserializeExclusive(ss, tx) {
|
7148 | const assetType = parseInt(reverseHex(ss.read(1)), 16);
|
7149 | const name = hexstring2str(ss.readVarBytes());
|
7150 | const amount = fixed82num(ss.read(8));
|
7151 | const precision = parseInt(reverseHex(ss.read(1)), 16);
|
7152 | // TODO: extract a method to get the publicKey. Refactor both
|
7153 | // enrollment transaction and register transaction
|
7154 | const hexStrPrefix = ss.read(1);
|
7155 | const prefix = parseInt(hexStrPrefix, 16);
|
7156 | let pKey = "";
|
7157 | let owner = "";
|
7158 | // Compressed public keys.
|
7159 | if (prefix === 0x02 || prefix === 0x03) {
|
7160 | pKey = ss.read(32);
|
7161 | }
|
7162 | else if (prefix === 0x04) {
|
7163 | pKey = ss.read(64);
|
7164 | }
|
7165 | else if (prefix === 0x00) {
|
7166 | // do nothing, For infinity, the p.Key == 0x00, included in the prefix
|
7167 | }
|
7168 | else {
|
7169 | throw new Error("Prefix not recognised for public key");
|
7170 | }
|
7171 | if (pKey !== "") {
|
7172 | pKey = hexStrPrefix + pKey;
|
7173 | owner = getPublicKeyUnencoded(pKey);
|
7174 | }
|
7175 | const admin = reverseHex(ss.read(20));
|
7176 | return Object.assign(tx, {
|
7177 | assetType,
|
7178 | name,
|
7179 | amount,
|
7180 | precision,
|
7181 | owner,
|
7182 | admin
|
7183 | });
|
7184 | }
|
7185 | get exclusiveData() {
|
7186 | return {
|
7187 | assetType: this.assetType,
|
7188 | name: this.name,
|
7189 | amount: this.amount,
|
7190 | precision: this.precision,
|
7191 | owner: this.owner,
|
7192 | admin: this.admin
|
7193 | };
|
7194 | }
|
7195 | get fees() {
|
7196 | if (this.assetType === ASSET_TYPE.GoverningToken ||
|
7197 | this.assetType === ASSET_TYPE.UtilityToken) {
|
7198 | return 0;
|
7199 | }
|
7200 | return DEFAULT_SYSFEE.registerTransaction;
|
7201 | }
|
7202 | serializeExclusive() {
|
7203 | let out = num2hexstring(this.assetType, 1, true);
|
7204 | out += num2VarInt(this.name.length);
|
7205 | out += str2hexstring(this.name);
|
7206 | out += this.amount.toReverseHex();
|
7207 | out += num2hexstring(this.precision, 1, true);
|
7208 | out += getPublicKeyEncoded(this.owner);
|
7209 | out += reverseHex(this.admin);
|
7210 | return out;
|
7211 | }
|
7212 | export() {
|
7213 | return Object.assign(super.export(), {
|
7214 | assetType: this.assetType,
|
7215 | name: this.name,
|
7216 | amount: this.amount.toNumber(),
|
7217 | precision: this.precision,
|
7218 | owner: this.owner,
|
7219 | admin: this.admin
|
7220 | });
|
7221 | }
|
7222 | equals(other) {
|
7223 | if (this.type !== other.type) {
|
7224 | return false;
|
7225 | }
|
7226 | if (other instanceof RegisterTransaction_RegisterTransaction) {
|
7227 | return this.hash === other.hash;
|
7228 | }
|
7229 | return this.hash === new RegisterTransaction_RegisterTransaction(other).hash;
|
7230 | }
|
7231 | }
|
7232 | /* harmony default export */ var transaction_RegisterTransaction = (RegisterTransaction_RegisterTransaction);
|
7233 | //# sourceMappingURL=RegisterTransaction.js.map
|
7234 | // CONCATENATED MODULE: ../neon-core/lib/tx/transaction/PublishTransaction.js
|
7235 |
|
7236 |
|
7237 |
|
7238 |
|
7239 | class PublishTransaction_PublishTransaction extends BaseTransaction_BaseTransaction {
|
7240 | constructor(obj = {}) {
|
7241 | super(Object.assign({ version: TX_VERSION.PUBLISH }, obj));
|
7242 | this.type = transaction_TransactionType.PublishTransaction;
|
7243 | this.script = obj.script || "";
|
7244 | this.parameterList = obj.parameterList || [0];
|
7245 | this.returnType = obj.returnType || 0;
|
7246 | this.needStorage = obj.needStorage || false;
|
7247 | this.name = obj.name || "";
|
7248 | this.codeVersion = obj.codeVersion || "";
|
7249 | this.author = obj.author || "";
|
7250 | this.email = obj.email || "";
|
7251 | this.description = obj.description || "";
|
7252 | }
|
7253 | static deserializeExclusive(ss, tx) {
|
7254 | if (tx.version === undefined) {
|
7255 | tx.version = 0;
|
7256 | }
|
7257 | if (tx.version > 1) {
|
7258 | throw new Error(`version need to be less or equal than 1. Got ${tx.version}`);
|
7259 | }
|
7260 | const script = ss.readVarBytes();
|
7261 | const paramList = ss.readVarBytes();
|
7262 | const parameterList = [];
|
7263 | for (let i = 0; i + 2 <= paramList.length; i = i + 2) {
|
7264 | parameterList.push(parseInt(paramList.substring(i, i + 2), 16));
|
7265 | }
|
7266 | const returnType = parseInt(ss.read(1), 16);
|
7267 | if (tx.version >= 1) {
|
7268 | throw new Error(`version need to be less or equal than 1. Got ${tx.version}`);
|
7269 | }
|
7270 | let NeedStorage = false;
|
7271 | if (tx.version >= 1) {
|
7272 | NeedStorage = !!parseInt(ss.read(1), 16);
|
7273 | }
|
7274 | const name = hexstring2str(ss.readVarBytes());
|
7275 | const codeVersion = hexstring2str(ss.readVarBytes());
|
7276 | const author = hexstring2str(ss.readVarBytes());
|
7277 | const email = hexstring2str(ss.readVarBytes());
|
7278 | const description = hexstring2str(ss.readVarBytes());
|
7279 | return Object.assign(tx, {
|
7280 | script,
|
7281 | parameterList,
|
7282 | returnType,
|
7283 | NeedStorage,
|
7284 | name,
|
7285 | codeVersion,
|
7286 | author,
|
7287 | email,
|
7288 | description
|
7289 | });
|
7290 | }
|
7291 | get exclusiveData() {
|
7292 | return {
|
7293 | script: this.script,
|
7294 | parameterList: this.parameterList,
|
7295 | returnType: this.returnType,
|
7296 | needStorage: this.needStorage,
|
7297 | name: this.name,
|
7298 | codeVersion: this.codeVersion,
|
7299 | author: this.author,
|
7300 | email: this.email,
|
7301 | description: this.description
|
7302 | };
|
7303 | }
|
7304 | get fees() {
|
7305 | return 0;
|
7306 | }
|
7307 | serializeExclusive() {
|
7308 | let out = num2VarInt(this.script.length / 2);
|
7309 | out += this.script;
|
7310 | out += num2VarInt(this.parameterList.length);
|
7311 | out += ab2hexstring(this.parameterList);
|
7312 | if (this.version >= 1) {
|
7313 | out += num2hexstring(this.needStorage, 1);
|
7314 | }
|
7315 | out += num2VarInt(this.returnType);
|
7316 | out += num2VarInt(this.name.length);
|
7317 | out += str2hexstring(this.name);
|
7318 | out += num2VarInt(this.codeVersion.length);
|
7319 | out += str2hexstring(this.codeVersion);
|
7320 | out += num2VarInt(this.author.length);
|
7321 | out += str2hexstring(this.author);
|
7322 | out += num2VarInt(this.email.length);
|
7323 | out += str2hexstring(this.email);
|
7324 | out += num2VarInt(this.description.length);
|
7325 | out += str2hexstring(this.description);
|
7326 | return out;
|
7327 | }
|
7328 | equals(other) {
|
7329 | if (this.type !== other.type) {
|
7330 | return false;
|
7331 | }
|
7332 | if (other instanceof PublishTransaction_PublishTransaction) {
|
7333 | return this.hash === other.hash;
|
7334 | }
|
7335 | return this.hash === new PublishTransaction_PublishTransaction(other).hash;
|
7336 | }
|
7337 | export() {
|
7338 | return Object.assign(super.export(), {
|
7339 | script: this.script,
|
7340 | parameterList: this.parameterList,
|
7341 | returnType: this.returnType,
|
7342 | needStorage: this.needStorage,
|
7343 | name: this.name,
|
7344 | codeVersion: this.codeVersion,
|
7345 | author: this.author,
|
7346 | email: this.email,
|
7347 | description: this.description
|
7348 | });
|
7349 | }
|
7350 | }
|
7351 | /* harmony default export */ var transaction_PublishTransaction = (PublishTransaction_PublishTransaction);
|
7352 | //# sourceMappingURL=PublishTransaction.js.map
|
7353 | // CONCATENATED MODULE: ../neon-core/lib/tx/transaction/Transaction.js
|
7354 |
|
7355 |
|
7356 |
|
7357 |
|
7358 |
|
7359 |
|
7360 |
|
7361 |
|
7362 |
|
7363 |
|
7364 |
|
7365 |
|
7366 | function getType(type) {
|
7367 | switch (type) {
|
7368 | case 0x00:
|
7369 | return MinerTransaction_MinerTransaction;
|
7370 | case 0x01:
|
7371 | return IssueTransaction_IssueTransaction;
|
7372 | case 0x02:
|
7373 | return ClaimTransaction_ClaimTransaction;
|
7374 | case 0x20:
|
7375 | return EnrollmentTransaction_EnrollmentTransaction;
|
7376 | case 0x40:
|
7377 | return RegisterTransaction_RegisterTransaction;
|
7378 | case 0x80:
|
7379 | return ContractTransaction_ContractTransaction;
|
7380 | case 0xd0:
|
7381 | return PublishTransaction_PublishTransaction;
|
7382 | case 0xd1:
|
7383 | return InvocationTransaction_InvocationTransaction;
|
7384 | case 0x90:
|
7385 | return StateTransaction_StateTransaction;
|
7386 | default:
|
7387 | throw new Error(`Unknown TransactionType: ${type}`);
|
7388 | }
|
7389 | }
|
7390 | /**
|
7391 | * @class Transaction
|
7392 | * @classdesc
|
7393 | * Transactions are what you use to interact with the blockchain.
|
7394 | * A transaction is made up of components found in the component file.
|
7395 | * Besides those components which are found in every transaction, there are also special data that is unique to each transaction type. These 'exclusive' data can be found in the exclusive file.
|
7396 | * This class is a wrapper around the various transaction building methods found in this folder.
|
7397 | */
|
7398 | class Transaction_Transaction extends BaseTransaction_BaseTransaction {
|
7399 | /**
|
7400 | * Deserializes a hexstring into a Transaction object.
|
7401 | * @param {string} hexstring - Hexstring of the transaction.
|
7402 | */
|
7403 | static deserialize(hex) {
|
7404 | const ss = new StringStream_StringStream(hex);
|
7405 | let txObj = deserializeType(ss);
|
7406 | const txClass = getType(txObj.type);
|
7407 | txObj = deserializeVersion(ss, txObj);
|
7408 | txObj = txClass.deserializeExclusive(ss, txObj);
|
7409 | txObj = deserializeAttributes(ss, txObj);
|
7410 | txObj = deserializeInputs(ss, txObj);
|
7411 | txObj = deserializeOutputs(ss, txObj);
|
7412 | if (!ss.isEmpty()) {
|
7413 | txObj = deserializeWitnesses(ss, txObj);
|
7414 | }
|
7415 | return new txClass(txObj);
|
7416 | }
|
7417 | static deserializeExclusive(ss, tx) {
|
7418 | throw new Error("Method not implemented.");
|
7419 | }
|
7420 | constructor(tx = {}) {
|
7421 | super(tx);
|
7422 | }
|
7423 | get [Symbol.toStringTag]() {
|
7424 | return "Transaction";
|
7425 | }
|
7426 | /**
|
7427 | * Exclusive Data
|
7428 | */
|
7429 | get exclusiveData() {
|
7430 | throw new Error("Not Implemented!");
|
7431 | }
|
7432 | get fees() {
|
7433 | return 0;
|
7434 | }
|
7435 | serializeExclusive() {
|
7436 | throw new Error("Method not implemented.");
|
7437 | }
|
7438 | }
|
7439 | /* harmony default export */ var transaction_Transaction = (Transaction_Transaction);
|
7440 | //# sourceMappingURL=Transaction.js.map
|
7441 | // CONCATENATED MODULE: ../neon-core/lib/tx/transaction/index.js
|
7442 |
|
7443 |
|
7444 |
|
7445 |
|
7446 |
|
7447 |
|
7448 |
|
7449 |
|
7450 |
|
7451 |
|
7452 |
|
7453 |
|
7454 | //# sourceMappingURL=index.js.map
|
7455 | // CONCATENATED MODULE: ../neon-core/lib/tx/index.js
|
7456 |
|
7457 |
|
7458 |
|
7459 |
|
7460 |
|
7461 | //# sourceMappingURL=index.js.map
|
7462 | // CONCATENATED MODULE: ../neon-core/lib/settings.js
|
7463 |
|
7464 | const networks = {};
|
7465 |
|
7466 | const timeout = {
|
7467 | ping: 2000,
|
7468 | rpc: 30000
|
7469 | };
|
7470 | //# sourceMappingURL=settings.js.map
|
7471 | // CONCATENATED MODULE: ../neon-core/lib/rpc/Query.js
|
7472 | var Query_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
7473 | return new (P || (P = Promise))(function (resolve, reject) {
|
7474 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
7475 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7476 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
7477 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
7478 | });
|
7479 | };
|
7480 |
|
7481 |
|
7482 |
|
7483 |
|
7484 |
|
7485 |
|
7486 | const Query_log = logging("rpc");
|
7487 | /**
|
7488 | * Wrapper for querying node RPC
|
7489 | * @param url Node URL.
|
7490 | * @param req RPC Request object.
|
7491 | * @param config Configuration to pass down to axios
|
7492 | * @returns RPC Response
|
7493 | */
|
7494 | function queryRPC(url, req, config = {}) {
|
7495 | return Query_awaiter(this, void 0, void 0, function* () {
|
7496 | const body = Object.assign({}, DEFAULT_REQ, req);
|
7497 | const conf = Object.assign({
|
7498 | headers: { "Content-Type": "application/json" },
|
7499 | timeout: timeout.rpc
|
7500 | }, config);
|
7501 | const response = yield axios_default.a.post(url, body, conf);
|
7502 | return response.data;
|
7503 | });
|
7504 | }
|
7505 | /**
|
7506 | * A Query object helps us to construct and record requests
|
7507 | */
|
7508 | class Query_Query {
|
7509 | /**
|
7510 | * @param addr address in Base58 encoding (starting with A)
|
7511 | */
|
7512 | static getAccountState(addr) {
|
7513 | return new Query_Query({
|
7514 | method: "getaccountstate",
|
7515 | params: [addr]
|
7516 | });
|
7517 | }
|
7518 | /**
|
7519 | * @param assetId
|
7520 | */
|
7521 | static getAssetState(assetId) {
|
7522 | return new Query_Query({
|
7523 | method: "getassetstate",
|
7524 | params: [assetId]
|
7525 | });
|
7526 | }
|
7527 | /**
|
7528 | * This Query returns the specified block either as a hexstring or human readable JSON.
|
7529 | * @param indexOrHash height or hash of block.
|
7530 | * @param verbose 0 for hexstring, 1 for JSON. Defaults to 1.
|
7531 | */
|
7532 | static getBlock(indexOrHash, verbose = 1) {
|
7533 | return new Query_Query({
|
7534 | method: "getblock",
|
7535 | params: [indexOrHash, verbose]
|
7536 | });
|
7537 | }
|
7538 | /**
|
7539 | * This Query returns the hash of a specific block.
|
7540 | * @param {number} index height of block.
|
7541 | */
|
7542 | static getBlockHash(index) {
|
7543 | return new Query_Query({
|
7544 | method: "getblockhash",
|
7545 | params: [index]
|
7546 | });
|
7547 | }
|
7548 | /**
|
7549 | * This Query returns the hash of the highest block.
|
7550 | */
|
7551 | static getBestBlockHash() {
|
7552 | return new Query_Query({
|
7553 | method: "getbestblockhash"
|
7554 | });
|
7555 | }
|
7556 | /**
|
7557 | * This Query returns the current block height.
|
7558 | */
|
7559 | static getBlockCount() {
|
7560 | return new Query_Query({
|
7561 | method: "getblockcount"
|
7562 | });
|
7563 | }
|
7564 | /**
|
7565 | * This Query returns the amount of GAS burnt as fees within a specific block.
|
7566 | * @param index height of block.
|
7567 | */
|
7568 | static getBlockSysFee(index) {
|
7569 | return new Query_Query({
|
7570 | method: "getblocksysfee",
|
7571 | params: [index]
|
7572 | });
|
7573 | }
|
7574 | /**
|
7575 | * This Query returns the number of other nodes that this node is connected to.
|
7576 | */
|
7577 | static getConnectionCount() {
|
7578 | return new Query_Query({
|
7579 | method: "getconnectioncount"
|
7580 | });
|
7581 | }
|
7582 | /**
|
7583 | * This Query returns information about the smart contract registered at the specific hash.
|
7584 | * @param scriptHash hash of contract
|
7585 | */
|
7586 | static getContractState(scriptHash) {
|
7587 | return new Query_Query({
|
7588 | method: "getcontractstate",
|
7589 | params: [scriptHash]
|
7590 | });
|
7591 | }
|
7592 | /**
|
7593 | * This Query returns the list of nodes that this node is connected to.
|
7594 | */
|
7595 | static getPeers() {
|
7596 | return new Query_Query({
|
7597 | method: "getpeers"
|
7598 | });
|
7599 | }
|
7600 | /**
|
7601 | * This Query returns the transaction hashes of the transactions waiting to be processed at the node.
|
7602 | */
|
7603 | static getRawMemPool() {
|
7604 | return new Query_Query({
|
7605 | method: "getrawmempool"
|
7606 | });
|
7607 | }
|
7608 | /**
|
7609 | * This Query returns information about a specific transaction in either hexstring or human readable JSON.
|
7610 | * @param txid hash of the specific transaction.
|
7611 | * @param verbose 0 for hexstring, 1 for JSON. Defaults to 1.
|
7612 | */
|
7613 | static getRawTransaction(txid, verbose = 1) {
|
7614 | return new Query_Query({
|
7615 | method: "getrawtransaction",
|
7616 | params: [txid, verbose]
|
7617 | });
|
7618 | }
|
7619 | /**
|
7620 | * This Query returns the raw value stored at the specific key under a specific contract.
|
7621 | * @param scriptHash hash of contract.
|
7622 | * @param key
|
7623 | */
|
7624 | static getStorage(scriptHash, key) {
|
7625 | return new Query_Query({
|
7626 | method: "getstorage",
|
7627 | params: [scriptHash, key]
|
7628 | });
|
7629 | }
|
7630 | /**
|
7631 | * This Query returns the status of a TransactionOutput. If the output has been spent, this will return null.
|
7632 | * @param txid hash of transaction.
|
7633 | * @param index position of output in the vout array.
|
7634 | */
|
7635 | static getTxOut(txid, index) {
|
7636 | return new Query_Query({
|
7637 | method: "gettxout",
|
7638 | params: [txid, index]
|
7639 | });
|
7640 | }
|
7641 | /**
|
7642 | * Gets the list of candidates available for voting.
|
7643 | * @return List of validators
|
7644 | */
|
7645 | static getValidators() {
|
7646 | return new Query_Query({
|
7647 | method: "getvalidators"
|
7648 | });
|
7649 | }
|
7650 | /**
|
7651 | * This Query returns the node version.
|
7652 | */
|
7653 | static getVersion() {
|
7654 | return new Query_Query({
|
7655 | method: "getversion"
|
7656 | });
|
7657 | }
|
7658 | /**
|
7659 | * This Query invokes the VM to run the given contract with the given parameters.
|
7660 | * @param scriptHash hash of contract to test.
|
7661 | * @param params parameters to pass into the VM.
|
7662 | */
|
7663 | static invoke(scriptHash, ...params) {
|
7664 | return new Query_Query({
|
7665 | method: "invoke",
|
7666 | params: [scriptHash, params]
|
7667 | });
|
7668 | }
|
7669 | /**
|
7670 | * This Query invokes the VM to run the specific contract with the provided operation and params. Do note that this function only suits contracts with a Main(string, args[]) entry method.
|
7671 | * @param scriptHash hash of contract to test.
|
7672 | * @param operation name of operation to call (first argument)
|
7673 | * @param params parameters to pass (second argument)
|
7674 | */
|
7675 | static invokeFunction(scriptHash, operation, ...params) {
|
7676 | return new Query_Query({
|
7677 | method: "invokefunction",
|
7678 | params: [scriptHash, operation, params]
|
7679 | });
|
7680 | }
|
7681 | /**
|
7682 | * This Query runs the specific script through the VM.
|
7683 | * @param script
|
7684 | */
|
7685 | static invokeScript(script) {
|
7686 | return new Query_Query({
|
7687 | method: "invokescript",
|
7688 | params: [script]
|
7689 | });
|
7690 | }
|
7691 | /**
|
7692 | * This Query transmits the specific transaction to the node.
|
7693 | * @param transaction Transaction as a Transaction object or hexstring.
|
7694 | */
|
7695 | static sendRawTransaction(transaction) {
|
7696 | const serialized = transaction instanceof BaseTransaction_BaseTransaction
|
7697 | ? transaction.serialize(true)
|
7698 | : transaction;
|
7699 | return new Query_Query({
|
7700 | method: "sendrawtransaction",
|
7701 | params: [serialized]
|
7702 | });
|
7703 | }
|
7704 | /**
|
7705 | * This Query submits a block for processing.
|
7706 | * @param block
|
7707 | */
|
7708 | static submitBlock(block) {
|
7709 | return new Query_Query({
|
7710 | method: "submitblock",
|
7711 | params: [block]
|
7712 | });
|
7713 | }
|
7714 | /**
|
7715 | * This Query submits an address for validation.
|
7716 | * @param addr Address to validate.
|
7717 | */
|
7718 | static validateAddress(addr) {
|
7719 | return new Query_Query({
|
7720 | method: "validateaddress",
|
7721 | params: [addr]
|
7722 | });
|
7723 | }
|
7724 | /**
|
7725 | * This Query Returns information of the unspent UTXO assets at the specified address.
|
7726 | * @param addr Address to get the UTXO
|
7727 | */
|
7728 | static getUnspents(addr) {
|
7729 | return new Query_Query({
|
7730 | method: "getunspents",
|
7731 | params: [addr]
|
7732 | });
|
7733 | }
|
7734 | /**
|
7735 | * This Query returns unclaimed GAS amount of the specified address.
|
7736 | * @param addr Address to get the unclaimed gas
|
7737 | */
|
7738 | static getUnclaimed(addr) {
|
7739 | return new Query_Query({
|
7740 | method: "getunclaimed",
|
7741 | params: [addr]
|
7742 | });
|
7743 | }
|
7744 | /**
|
7745 | * This Query returns claimable GAS information of the specified address.
|
7746 | * @param addr Address to get the claimable gas
|
7747 | */
|
7748 | static getClaimable(addr) {
|
7749 | return new Query_Query({
|
7750 | method: "getclaimable",
|
7751 | params: [addr]
|
7752 | });
|
7753 | }
|
7754 | get id() {
|
7755 | return this.req.id;
|
7756 | }
|
7757 | get method() {
|
7758 | return this.req.method;
|
7759 | }
|
7760 | get params() {
|
7761 | return this.req.params;
|
7762 | }
|
7763 | constructor(req) {
|
7764 | this.req = Object.assign({}, DEFAULT_REQ, req);
|
7765 | this.completed = false;
|
7766 | }
|
7767 | get [Symbol.toStringTag]() {
|
7768 | return "Query";
|
7769 | }
|
7770 | /**
|
7771 | * Attaches a parser method to the Query. This method will be used to parse the response.
|
7772 | */
|
7773 | parseWith(parser) {
|
7774 | this.parse = parser;
|
7775 | return this;
|
7776 | }
|
7777 | /**
|
7778 | * Executes the Query by sending the RPC request to the provided net.
|
7779 | * @param url The URL of the node.
|
7780 | * @param config Request configuration
|
7781 | */
|
7782 | execute(url, config = {}) {
|
7783 | return Query_awaiter(this, void 0, void 0, function* () {
|
7784 | if (this.completed) {
|
7785 | throw new Error("This request has been sent");
|
7786 | }
|
7787 | const response = yield queryRPC(url, this.req, config);
|
7788 | this.res = response;
|
7789 | this.completed = true;
|
7790 | if (response.error) {
|
7791 | throw new Error(`${url}: ${response.error.message}`);
|
7792 | }
|
7793 | if (this.parse) {
|
7794 | Query_log.info(`Query[${this.req.method}] successful`);
|
7795 | return this.parse(response.result);
|
7796 | }
|
7797 | return response;
|
7798 | });
|
7799 | }
|
7800 | export() {
|
7801 | return Object.assign({}, this.req, {
|
7802 | params: this.req.params.map(p => {
|
7803 | if (typeof p === "object") {
|
7804 | return JSON.parse(JSON.stringify(p));
|
7805 | }
|
7806 | return p;
|
7807 | })
|
7808 | });
|
7809 | }
|
7810 | equals(other) {
|
7811 | return (this.req.id === other.id &&
|
7812 | this.req.method === other.method &&
|
7813 | compareArray(this.req.params, other.params || []));
|
7814 | }
|
7815 | }
|
7816 | /* harmony default export */ var rpc_Query = (Query_Query);
|
7817 | //# sourceMappingURL=Query.js.map
|
7818 | // CONCATENATED MODULE: ../neon-core/lib/rpc/RPCClient.js
|
7819 | var RPCClient_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
7820 | return new (P || (P = Promise))(function (resolve, reject) {
|
7821 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
7822 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7823 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
7824 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
7825 | });
|
7826 | };
|
7827 |
|
7828 |
|
7829 |
|
7830 |
|
7831 |
|
7832 | const RPCClient_log = logging("rpc");
|
7833 | const versionRegex = /NEO:(\d+\.\d+\.\d+)/;
|
7834 | /**
|
7835 | * RPC Client model to query a NEO node. Contains built-in methods to query using RPC calls.
|
7836 | */
|
7837 | class RPCClient_RPCClient {
|
7838 | /**
|
7839 | * @param net 'MainNet' or 'TestNet' will query the default RPC address found in consts. You may provide a custom URL.
|
7840 | * @param version Version of NEO node. Used to check if RPC methods have been implemented. it will default to DEFAULT_RPC found in CONST
|
7841 | */
|
7842 | constructor(net, version = RPC_VERSION) {
|
7843 | if (net === NEO_NETWORK.MAIN) {
|
7844 | this.net = DEFAULT_RPC.MAIN;
|
7845 | }
|
7846 | else if (net === NEO_NETWORK.TEST) {
|
7847 | this.net = DEFAULT_RPC.TEST;
|
7848 | }
|
7849 | else {
|
7850 | this.net = net;
|
7851 | }
|
7852 | this.history = [];
|
7853 | this.lastSeenHeight = 0;
|
7854 | this._latencies = [];
|
7855 | this.version = version;
|
7856 | }
|
7857 | get [Symbol.toStringTag]() {
|
7858 | return "RPC Client";
|
7859 | }
|
7860 | get latency() {
|
7861 | if (this._latencies.length === 0) {
|
7862 | return 99999;
|
7863 | }
|
7864 | return Math.floor(this._latencies.reduce((p, c) => p + c, 0) / this._latencies.length);
|
7865 | }
|
7866 | set latency(lat) {
|
7867 | if (this._latencies.length > 4) {
|
7868 | this._latencies.shift();
|
7869 | }
|
7870 | this._latencies.push(lat);
|
7871 | }
|
7872 | /**
|
7873 | * Measures the latency using getBlockCount call. Returns the current latency. For average, call this.latency
|
7874 | */
|
7875 | ping() {
|
7876 | return RPCClient_awaiter(this, void 0, void 0, function* () {
|
7877 | const timeStart = Date.now();
|
7878 | const query = rpc_Query.getBlockCount();
|
7879 | try {
|
7880 | const response = yield this.execute(query, { timeout: timeout.ping });
|
7881 | this.lastSeenHeight = response.result;
|
7882 | const newPing = Date.now() - timeStart;
|
7883 | this.latency = newPing;
|
7884 | return newPing;
|
7885 | }
|
7886 | catch (err) {
|
7887 | this.latency = timeout.ping;
|
7888 | return timeout.ping;
|
7889 | }
|
7890 | });
|
7891 | }
|
7892 | /**
|
7893 | * Takes an Query object and executes it. Adds the Query object to history.
|
7894 | */
|
7895 | execute(query, config) {
|
7896 | this.history.push(query);
|
7897 | RPCClient_log.info(`RPC: ${this.net} executing Query[${query.req.method}]`);
|
7898 | return query.execute(this.net, config);
|
7899 | }
|
7900 | /**
|
7901 | * Creates a query with the given req and immediately executes it.
|
7902 | */
|
7903 | query(req, config) {
|
7904 | const query = new rpc_Query(req);
|
7905 | return this.execute(query, config);
|
7906 | }
|
7907 | /**
|
7908 | * Gets the state of an account given an address.
|
7909 | */
|
7910 | getAccountState(addr) {
|
7911 | return RPCClient_awaiter(this, void 0, void 0, function* () {
|
7912 | if (!isAddress(addr)) {
|
7913 | throw new Error(`Invalid address given: ${addr}`);
|
7914 | }
|
7915 | const response = yield this.execute(rpc_Query.getAccountState(addr));
|
7916 | return response.result;
|
7917 | });
|
7918 | }
|
7919 | /**
|
7920 | * Gets the state of an asset given an id.
|
7921 | */
|
7922 | getAssetState(assetId) {
|
7923 | return RPCClient_awaiter(this, void 0, void 0, function* () {
|
7924 | const response = yield this.execute(rpc_Query.getAssetState(assetId));
|
7925 | return response.result;
|
7926 | });
|
7927 | }
|
7928 | /**
|
7929 | * Gets the block at a given height or hash.
|
7930 | */
|
7931 | getBlock(indexOrHash, verbose = 1) {
|
7932 | return RPCClient_awaiter(this, void 0, void 0, function* () {
|
7933 | const response = yield this.execute(rpc_Query.getBlock(indexOrHash, verbose));
|
7934 | return response.result;
|
7935 | });
|
7936 | }
|
7937 | /**
|
7938 | * Gets the block hash at a given height.
|
7939 | */
|
7940 | getBlockHash(index) {
|
7941 | return RPCClient_awaiter(this, void 0, void 0, function* () {
|
7942 | const response = yield this.execute(rpc_Query.getBlockHash(index));
|
7943 | return response.result;
|
7944 | });
|
7945 | }
|
7946 | /**
|
7947 | * Get the latest block hash.
|
7948 | */
|
7949 | getBestBlockHash() {
|
7950 | return RPCClient_awaiter(this, void 0, void 0, function* () {
|
7951 | const response = yield this.execute(rpc_Query.getBestBlockHash());
|
7952 | return response.result;
|
7953 | });
|
7954 | }
|
7955 | /**
|
7956 | * Get the current block height.
|
7957 | */
|
7958 | getBlockCount() {
|
7959 | return RPCClient_awaiter(this, void 0, void 0, function* () {
|
7960 | const response = yield this.execute(rpc_Query.getBlockCount());
|
7961 | return response.result;
|
7962 | });
|
7963 | }
|
7964 | /**
|
7965 | * Get the system fees of a block.
|
7966 | * @param {number} index
|
7967 | * @return {Promise<string>} - System fees as a string.
|
7968 | */
|
7969 | getBlockSysFee(index) {
|
7970 | return RPCClient_awaiter(this, void 0, void 0, function* () {
|
7971 | const response = yield this.execute(rpc_Query.getBlockSysFee(index));
|
7972 | return response.result;
|
7973 | });
|
7974 | }
|
7975 | /**
|
7976 | * Gets the number of peers this node is connected to.
|
7977 | * @return {Promise<number>}
|
7978 | */
|
7979 | getConnectionCount() {
|
7980 | return RPCClient_awaiter(this, void 0, void 0, function* () {
|
7981 | const response = yield this.execute(rpc_Query.getConnectionCount());
|
7982 | return response.result;
|
7983 | });
|
7984 | }
|
7985 | /**
|
7986 | * Gets the state of the contract at the given scriptHash.
|
7987 | */
|
7988 | getContractState(scriptHash) {
|
7989 | return RPCClient_awaiter(this, void 0, void 0, function* () {
|
7990 | const response = yield this.execute(rpc_Query.getContractState(scriptHash));
|
7991 | return response.result;
|
7992 | });
|
7993 | }
|
7994 | /**
|
7995 | * Gets a list of all peers that this node has discovered.
|
7996 | */
|
7997 | getPeers() {
|
7998 | return RPCClient_awaiter(this, void 0, void 0, function* () {
|
7999 | const response = yield this.execute(rpc_Query.getPeers());
|
8000 | return response.result;
|
8001 | });
|
8002 | }
|
8003 | /**
|
8004 | * Gets a list of all transaction hashes waiting to be processed.
|
8005 | */
|
8006 | getRawMemPool() {
|
8007 | return RPCClient_awaiter(this, void 0, void 0, function* () {
|
8008 | const response = yield this.execute(rpc_Query.getRawMemPool());
|
8009 | return response.result;
|
8010 | });
|
8011 | }
|
8012 | /**
|
8013 | * Gets a transaction based on its hash.
|
8014 | */
|
8015 | getRawTransaction(txid, verbose = 1) {
|
8016 | return RPCClient_awaiter(this, void 0, void 0, function* () {
|
8017 | const response = yield this.execute(rpc_Query.getRawTransaction(txid, verbose));
|
8018 | return response.result;
|
8019 | });
|
8020 | }
|
8021 | /**
|
8022 | * Gets the corresponding value of a key in the storage of a contract address.
|
8023 | */
|
8024 | getStorage(scriptHash, key) {
|
8025 | return RPCClient_awaiter(this, void 0, void 0, function* () {
|
8026 | const response = yield this.execute(rpc_Query.getStorage(scriptHash, key));
|
8027 | return response.result;
|
8028 | });
|
8029 | }
|
8030 | /**
|
8031 | * Gets the transaction output given a transaction id and index
|
8032 | */
|
8033 | getTxOut(txid, index) {
|
8034 | return RPCClient_awaiter(this, void 0, void 0, function* () {
|
8035 | const response = yield this.execute(rpc_Query.getTxOut(txid, index));
|
8036 | return response.result;
|
8037 | });
|
8038 | }
|
8039 | /**
|
8040 | * Gets the list of validators available for voting.
|
8041 | */
|
8042 | getValidators() {
|
8043 | return RPCClient_awaiter(this, void 0, void 0, function* () {
|
8044 | const response = yield this.execute(rpc_Query.getValidators());
|
8045 | return response.result;
|
8046 | });
|
8047 | }
|
8048 | /**
|
8049 | * Gets the version of the NEO node. This method will never be blocked by version. This method will also update the current Client's version to the one received.
|
8050 | */
|
8051 | getVersion() {
|
8052 | return RPCClient_awaiter(this, void 0, void 0, function* () {
|
8053 | try {
|
8054 | const response = yield this.execute(rpc_Query.getVersion());
|
8055 | if (response && response.result && response.result.useragent) {
|
8056 | const useragent = response.result.useragent;
|
8057 | const responseLength = useragent.length;
|
8058 | const strippedResponse = useragent.substring(1, responseLength - 1);
|
8059 | const [header, newVersion] = strippedResponse.split(":");
|
8060 | this.version = newVersion;
|
8061 | }
|
8062 | else {
|
8063 | throw new Error("Empty or unexpected version pattern");
|
8064 | }
|
8065 | return this.version;
|
8066 | }
|
8067 | catch (err) {
|
8068 | if (err.message.includes("Method not found")) {
|
8069 | this.version = RPC_VERSION;
|
8070 | return this.version;
|
8071 | }
|
8072 | else {
|
8073 | throw err;
|
8074 | }
|
8075 | }
|
8076 | });
|
8077 | }
|
8078 | /**
|
8079 | * Calls a smart contract with the given parameters. This method is a local invoke, results are not reflected on the blockchain.
|
8080 | */
|
8081 | invoke(scriptHash, ...params) {
|
8082 | return RPCClient_awaiter(this, void 0, void 0, function* () {
|
8083 | const response = yield this.execute(rpc_Query.invoke(scriptHash, ...params));
|
8084 | return response.result;
|
8085 | });
|
8086 | }
|
8087 | /**
|
8088 | * Submits a contract method call with parameters for the node to run. This method is a local invoke, results are not reflected on the blockchain.
|
8089 | */
|
8090 | invokeFunction(scriptHash, operation, ...params) {
|
8091 | return RPCClient_awaiter(this, void 0, void 0, function* () {
|
8092 | const response = yield this.execute(rpc_Query.invokeFunction(scriptHash, operation, ...params));
|
8093 | return response.result;
|
8094 | });
|
8095 | }
|
8096 | /**
|
8097 | * Submits a script for the node to run. This method is a local invoke, results are not reflected on the blockchain.
|
8098 | */
|
8099 | invokeScript(script) {
|
8100 | return RPCClient_awaiter(this, void 0, void 0, function* () {
|
8101 | const response = yield this.execute(rpc_Query.invokeScript(script));
|
8102 | return response.result;
|
8103 | });
|
8104 | }
|
8105 | /**
|
8106 | * Sends a serialized transaction to the network.
|
8107 | */
|
8108 | sendRawTransaction(transaction) {
|
8109 | return RPCClient_awaiter(this, void 0, void 0, function* () {
|
8110 | const response = yield this.execute(rpc_Query.sendRawTransaction(transaction));
|
8111 | return response.result;
|
8112 | });
|
8113 | }
|
8114 | /**
|
8115 | * Submits a serialized block to the network.
|
8116 | */
|
8117 | submitBlock(block) {
|
8118 | return RPCClient_awaiter(this, void 0, void 0, function* () {
|
8119 | const response = yield this.execute(rpc_Query.submitBlock(block));
|
8120 | return response.result;
|
8121 | });
|
8122 | }
|
8123 | /**
|
8124 | * Checks if the provided address is a valid NEO address.
|
8125 | */
|
8126 | validateAddress(addr) {
|
8127 | return RPCClient_awaiter(this, void 0, void 0, function* () {
|
8128 | const response = yield this.execute(rpc_Query.validateAddress(addr));
|
8129 | return response.result.isvalid;
|
8130 | });
|
8131 | }
|
8132 | /**
|
8133 | * Get the unspent utxo for an address
|
8134 | */
|
8135 | getUnspents(addr) {
|
8136 | return RPCClient_awaiter(this, void 0, void 0, function* () {
|
8137 | const response = yield this.execute(rpc_Query.getUnspents(addr));
|
8138 | return this.parseUnspentsToBalance(response.result);
|
8139 | });
|
8140 | }
|
8141 | /**
|
8142 | * Get the unclaimed gas amount for an address
|
8143 | */
|
8144 | getUnclaimed(addr) {
|
8145 | return RPCClient_awaiter(this, void 0, void 0, function* () {
|
8146 | const response = yield this.execute(rpc_Query.getUnclaimed(addr));
|
8147 | return response.result;
|
8148 | });
|
8149 | }
|
8150 | /**
|
8151 | * Get the claimable for an address
|
8152 | */
|
8153 | getClaimable(addr) {
|
8154 | return RPCClient_awaiter(this, void 0, void 0, function* () {
|
8155 | const response = yield this.execute(rpc_Query.getClaimable(addr));
|
8156 | return new Claims_Claims({
|
8157 | net: this.net,
|
8158 | address: response.result.address,
|
8159 | claims: response.result.claimable.map((rawClaim) => new Object({
|
8160 | claim: rawClaim.unclaimed,
|
8161 | txid: rawClaim.txid,
|
8162 | index: rawClaim.n,
|
8163 | value: rawClaim.value,
|
8164 | start: rawClaim.start_height,
|
8165 | end: rawClaim.end_height
|
8166 | }))
|
8167 | });
|
8168 | });
|
8169 | }
|
8170 | parseUnspentsToBalance(getUnspentsResult) {
|
8171 | const bal = new Balance_Balance({
|
8172 | address: getUnspentsResult.address
|
8173 | });
|
8174 | for (const assetBalance of getUnspentsResult.balance) {
|
8175 | if (assetBalance.amount === 0) {
|
8176 | continue;
|
8177 | }
|
8178 | if (assetBalance.unspent.length > 0) {
|
8179 | bal.addAsset(assetBalance.asset_symbol, {
|
8180 | unspent: assetBalance.unspent.map((utxo) => new Coin_Coin({
|
8181 | index: utxo.n,
|
8182 | txid: utxo.txid,
|
8183 | value: utxo.value
|
8184 | }))
|
8185 | });
|
8186 | }
|
8187 | else {
|
8188 | bal.addToken(assetBalance.asset_symbol, assetBalance.amount);
|
8189 | }
|
8190 | }
|
8191 | return bal;
|
8192 | }
|
8193 | }
|
8194 | /* harmony default export */ var rpc_RPCClient = (RPCClient_RPCClient);
|
8195 | //# sourceMappingURL=RPCClient.js.map
|
8196 | // CONCATENATED MODULE: ../neon-core/lib/rpc/parse.js
|
8197 |
|
8198 | /**
|
8199 | * Builds a parser to parse the results of the stack.
|
8200 | * @param args A list of functions to parse arguments. Each function is mapped to its corresponding StackItem in the result.
|
8201 | * @returns parser function
|
8202 | */
|
8203 | function buildParser(...args) {
|
8204 | return (result) => {
|
8205 | if (result.stack.length !== args.length) {
|
8206 | throw new Error(`Wrong number of items to parse! Expected ${args.length} but got ${result.stack.length}!`);
|
8207 | }
|
8208 | return result.stack.map((item, i) => args[i](item));
|
8209 | };
|
8210 | }
|
8211 | /**
|
8212 | * This just returns the value of the StackItem.
|
8213 | */
|
8214 | function NoOpParser(item) {
|
8215 | return item.value;
|
8216 | }
|
8217 | /**
|
8218 | * Parses the result to an integer.
|
8219 | */
|
8220 | function IntegerParser(item) {
|
8221 | return parseInt(item.value || "0", 10);
|
8222 | }
|
8223 | /**
|
8224 | * Parses the result to a ASCII string.
|
8225 | */
|
8226 | function StringParser(item) {
|
8227 | return hexstring2str(item.value);
|
8228 | }
|
8229 | /**
|
8230 | * Parses the result to a Fixed8.
|
8231 | */
|
8232 | function Fixed8Parser(item) {
|
8233 | return Fixed8_Fixed8.fromReverseHex(item.value);
|
8234 | }
|
8235 | /**
|
8236 | * Parses the VM Stack and returns human readable strings. The types are inferred based on the StackItem type.
|
8237 | * @param res RPC Response
|
8238 | * @return Array of results
|
8239 | */
|
8240 | function SimpleParser(res) {
|
8241 | return res.stack.map(item => {
|
8242 | switch (item.type) {
|
8243 | case "ByteArray":
|
8244 | return StringParser(item);
|
8245 | case "Integer":
|
8246 | return IntegerParser(item);
|
8247 | default:
|
8248 | throw Error(`Unknown type: ${item.type}`);
|
8249 | }
|
8250 | });
|
8251 | }
|
8252 | //# sourceMappingURL=parse.js.map
|
8253 | // CONCATENATED MODULE: ../neon-core/lib/rpc/index.js
|
8254 |
|
8255 |
|
8256 |
|
8257 |
|
8258 |
|
8259 | //# sourceMappingURL=index.js.map
|
8260 | // CONCATENATED MODULE: ../neon-core/lib/index.js
|
8261 | /* concated harmony reexport rpc */__webpack_require__.d(__webpack_exports__, "rpc", function() { return rpc_namespaceObject; });
|
8262 | /* concated harmony reexport sc */__webpack_require__.d(__webpack_exports__, "sc", function() { return sc_namespaceObject; });
|
8263 | /* concated harmony reexport tx */__webpack_require__.d(__webpack_exports__, "tx", function() { return tx_namespaceObject; });
|
8264 | /* concated harmony reexport wallet */__webpack_require__.d(__webpack_exports__, "wallet", function() { return wallet_namespaceObject; });
|
8265 | /* concated harmony reexport u */__webpack_require__.d(__webpack_exports__, "u", function() { return u_namespaceObject; });
|
8266 | /* concated harmony reexport CONST */__webpack_require__.d(__webpack_exports__, "CONST", function() { return consts_namespaceObject; });
|
8267 | /* concated harmony reexport settings */__webpack_require__.d(__webpack_exports__, "settings", function() { return settings_namespaceObject; });
|
8268 | /* concated harmony reexport logging */__webpack_require__.d(__webpack_exports__, "logging", function() { return logging_namespaceObject; });
|
8269 |
|
8270 |
|
8271 |
|
8272 |
|
8273 |
|
8274 |
|
8275 |
|
8276 |
|
8277 |
|
8278 | //# sourceMappingURL=index.js.map
|
8279 |
|
8280 | /***/ }),
|
8281 | /* 1 */
|
8282 | /***/ (function(module, exports, __webpack_require__) {
|
8283 |
|
8284 | module.exports = __webpack_require__(51);
|
8285 |
|
8286 | /***/ }),
|
8287 | /* 2 */
|
8288 | /***/ (function(module, exports, __webpack_require__) {
|
8289 |
|
8290 | "use strict";
|
8291 |
|
8292 |
|
8293 | var bind = __webpack_require__(27);
|
8294 | var isBuffer = __webpack_require__(52);
|
8295 |
|
8296 | /*global toString:true*/
|
8297 |
|
8298 | // utils is a library of generic helper functions non-specific to axios
|
8299 |
|
8300 | var toString = Object.prototype.toString;
|
8301 |
|
8302 | /**
|
8303 | * Determine if a value is an Array
|
8304 | *
|
8305 | * @param {Object} val The value to test
|
8306 | * @returns {boolean} True if value is an Array, otherwise false
|
8307 | */
|
8308 | function isArray(val) {
|
8309 | return toString.call(val) === '[object Array]';
|
8310 | }
|
8311 |
|
8312 | /**
|
8313 | * Determine if a value is an ArrayBuffer
|
8314 | *
|
8315 | * @param {Object} val The value to test
|
8316 | * @returns {boolean} True if value is an ArrayBuffer, otherwise false
|
8317 | */
|
8318 | function isArrayBuffer(val) {
|
8319 | return toString.call(val) === '[object ArrayBuffer]';
|
8320 | }
|
8321 |
|
8322 | /**
|
8323 | * Determine if a value is a FormData
|
8324 | *
|
8325 | * @param {Object} val The value to test
|
8326 | * @returns {boolean} True if value is an FormData, otherwise false
|
8327 | */
|
8328 | function isFormData(val) {
|
8329 | return (typeof FormData !== 'undefined') && (val instanceof FormData);
|
8330 | }
|
8331 |
|
8332 | /**
|
8333 | * Determine if a value is a view on an ArrayBuffer
|
8334 | *
|
8335 | * @param {Object} val The value to test
|
8336 | * @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
|
8337 | */
|
8338 | function isArrayBufferView(val) {
|
8339 | var result;
|
8340 | if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
|
8341 | result = ArrayBuffer.isView(val);
|
8342 | } else {
|
8343 | result = (val) && (val.buffer) && (val.buffer instanceof ArrayBuffer);
|
8344 | }
|
8345 | return result;
|
8346 | }
|
8347 |
|
8348 | /**
|
8349 | * Determine if a value is a String
|
8350 | *
|
8351 | * @param {Object} val The value to test
|
8352 | * @returns {boolean} True if value is a String, otherwise false
|
8353 | */
|
8354 | function isString(val) {
|
8355 | return typeof val === 'string';
|
8356 | }
|
8357 |
|
8358 | /**
|
8359 | * Determine if a value is a Number
|
8360 | *
|
8361 | * @param {Object} val The value to test
|
8362 | * @returns {boolean} True if value is a Number, otherwise false
|
8363 | */
|
8364 | function isNumber(val) {
|
8365 | return typeof val === 'number';
|
8366 | }
|
8367 |
|
8368 | /**
|
8369 | * Determine if a value is undefined
|
8370 | *
|
8371 | * @param {Object} val The value to test
|
8372 | * @returns {boolean} True if the value is undefined, otherwise false
|
8373 | */
|
8374 | function isUndefined(val) {
|
8375 | return typeof val === 'undefined';
|
8376 | }
|
8377 |
|
8378 | /**
|
8379 | * Determine if a value is an Object
|
8380 | *
|
8381 | * @param {Object} val The value to test
|
8382 | * @returns {boolean} True if value is an Object, otherwise false
|
8383 | */
|
8384 | function isObject(val) {
|
8385 | return val !== null && typeof val === 'object';
|
8386 | }
|
8387 |
|
8388 | /**
|
8389 | * Determine if a value is a Date
|
8390 | *
|
8391 | * @param {Object} val The value to test
|
8392 | * @returns {boolean} True if value is a Date, otherwise false
|
8393 | */
|
8394 | function isDate(val) {
|
8395 | return toString.call(val) === '[object Date]';
|
8396 | }
|
8397 |
|
8398 | /**
|
8399 | * Determine if a value is a File
|
8400 | *
|
8401 | * @param {Object} val The value to test
|
8402 | * @returns {boolean} True if value is a File, otherwise false
|
8403 | */
|
8404 | function isFile(val) {
|
8405 | return toString.call(val) === '[object File]';
|
8406 | }
|
8407 |
|
8408 | /**
|
8409 | * Determine if a value is a Blob
|
8410 | *
|
8411 | * @param {Object} val The value to test
|
8412 | * @returns {boolean} True if value is a Blob, otherwise false
|
8413 | */
|
8414 | function isBlob(val) {
|
8415 | return toString.call(val) === '[object Blob]';
|
8416 | }
|
8417 |
|
8418 | /**
|
8419 | * Determine if a value is a Function
|
8420 | *
|
8421 | * @param {Object} val The value to test
|
8422 | * @returns {boolean} True if value is a Function, otherwise false
|
8423 | */
|
8424 | function isFunction(val) {
|
8425 | return toString.call(val) === '[object Function]';
|
8426 | }
|
8427 |
|
8428 | /**
|
8429 | * Determine if a value is a Stream
|
8430 | *
|
8431 | * @param {Object} val The value to test
|
8432 | * @returns {boolean} True if value is a Stream, otherwise false
|
8433 | */
|
8434 | function isStream(val) {
|
8435 | return isObject(val) && isFunction(val.pipe);
|
8436 | }
|
8437 |
|
8438 | /**
|
8439 | * Determine if a value is a URLSearchParams object
|
8440 | *
|
8441 | * @param {Object} val The value to test
|
8442 | * @returns {boolean} True if value is a URLSearchParams object, otherwise false
|
8443 | */
|
8444 | function isURLSearchParams(val) {
|
8445 | return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams;
|
8446 | }
|
8447 |
|
8448 | /**
|
8449 | * Trim excess whitespace off the beginning and end of a string
|
8450 | *
|
8451 | * @param {String} str The String to trim
|
8452 | * @returns {String} The String freed of excess whitespace
|
8453 | */
|
8454 | function trim(str) {
|
8455 | return str.replace(/^\s*/, '').replace(/\s*$/, '');
|
8456 | }
|
8457 |
|
8458 | /**
|
8459 | * Determine if we're running in a standard browser environment
|
8460 | *
|
8461 | * This allows axios to run in a web worker, and react-native.
|
8462 | * Both environments support XMLHttpRequest, but not fully standard globals.
|
8463 | *
|
8464 | * web workers:
|
8465 | * typeof window -> undefined
|
8466 | * typeof document -> undefined
|
8467 | *
|
8468 | * react-native:
|
8469 | * navigator.product -> 'ReactNative'
|
8470 | * nativescript
|
8471 | * navigator.product -> 'NativeScript' or 'NS'
|
8472 | */
|
8473 | function isStandardBrowserEnv() {
|
8474 | if (typeof navigator !== 'undefined' && (navigator.product === 'ReactNative' ||
|
8475 | navigator.product === 'NativeScript' ||
|
8476 | navigator.product === 'NS')) {
|
8477 | return false;
|
8478 | }
|
8479 | return (
|
8480 | typeof window !== 'undefined' &&
|
8481 | typeof document !== 'undefined'
|
8482 | );
|
8483 | }
|
8484 |
|
8485 | /**
|
8486 | * Iterate over an Array or an Object invoking a function for each item.
|
8487 | *
|
8488 | * If `obj` is an Array callback will be called passing
|
8489 | * the value, index, and complete array for each item.
|
8490 | *
|
8491 | * If 'obj' is an Object callback will be called passing
|
8492 | * the value, key, and complete object for each property.
|
8493 | *
|
8494 | * @param {Object|Array} obj The object to iterate
|
8495 | * @param {Function} fn The callback to invoke for each item
|
8496 | */
|
8497 | function forEach(obj, fn) {
|
8498 | // Don't bother if no value provided
|
8499 | if (obj === null || typeof obj === 'undefined') {
|
8500 | return;
|
8501 | }
|
8502 |
|
8503 | // Force an array if not already something iterable
|
8504 | if (typeof obj !== 'object') {
|
8505 | /*eslint no-param-reassign:0*/
|
8506 | obj = [obj];
|
8507 | }
|
8508 |
|
8509 | if (isArray(obj)) {
|
8510 | // Iterate over array values
|
8511 | for (var i = 0, l = obj.length; i < l; i++) {
|
8512 | fn.call(null, obj[i], i, obj);
|
8513 | }
|
8514 | } else {
|
8515 | // Iterate over object keys
|
8516 | for (var key in obj) {
|
8517 | if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
8518 | fn.call(null, obj[key], key, obj);
|
8519 | }
|
8520 | }
|
8521 | }
|
8522 | }
|
8523 |
|
8524 | /**
|
8525 | * Accepts varargs expecting each argument to be an object, then
|
8526 | * immutably merges the properties of each object and returns result.
|
8527 | *
|
8528 | * When multiple objects contain the same key the later object in
|
8529 | * the arguments list will take precedence.
|
8530 | *
|
8531 | * Example:
|
8532 | *
|
8533 | * ```js
|
8534 | * var result = merge({foo: 123}, {foo: 456});
|
8535 | * console.log(result.foo); // outputs 456
|
8536 | * ```
|
8537 | *
|
8538 | * @param {Object} obj1 Object to merge
|
8539 | * @returns {Object} Result of all merge properties
|
8540 | */
|
8541 | function merge(/* obj1, obj2, obj3, ... */) {
|
8542 | var result = {};
|
8543 | function assignValue(val, key) {
|
8544 | if (typeof result[key] === 'object' && typeof val === 'object') {
|
8545 | result[key] = merge(result[key], val);
|
8546 | } else {
|
8547 | result[key] = val;
|
8548 | }
|
8549 | }
|
8550 |
|
8551 | for (var i = 0, l = arguments.length; i < l; i++) {
|
8552 | forEach(arguments[i], assignValue);
|
8553 | }
|
8554 | return result;
|
8555 | }
|
8556 |
|
8557 | /**
|
8558 | * Function equal to merge with the difference being that no reference
|
8559 | * to original objects is kept.
|
8560 | *
|
8561 | * @see merge
|
8562 | * @param {Object} obj1 Object to merge
|
8563 | * @returns {Object} Result of all merge properties
|
8564 | */
|
8565 | function deepMerge(/* obj1, obj2, obj3, ... */) {
|
8566 | var result = {};
|
8567 | function assignValue(val, key) {
|
8568 | if (typeof result[key] === 'object' && typeof val === 'object') {
|
8569 | result[key] = deepMerge(result[key], val);
|
8570 | } else if (typeof val === 'object') {
|
8571 | result[key] = deepMerge({}, val);
|
8572 | } else {
|
8573 | result[key] = val;
|
8574 | }
|
8575 | }
|
8576 |
|
8577 | for (var i = 0, l = arguments.length; i < l; i++) {
|
8578 | forEach(arguments[i], assignValue);
|
8579 | }
|
8580 | return result;
|
8581 | }
|
8582 |
|
8583 | /**
|
8584 | * Extends object a by mutably adding to it the properties of object b.
|
8585 | *
|
8586 | * @param {Object} a The object to be extended
|
8587 | * @param {Object} b The object to copy properties from
|
8588 | * @param {Object} thisArg The object to bind function to
|
8589 | * @return {Object} The resulting value of object a
|
8590 | */
|
8591 | function extend(a, b, thisArg) {
|
8592 | forEach(b, function assignValue(val, key) {
|
8593 | if (thisArg && typeof val === 'function') {
|
8594 | a[key] = bind(val, thisArg);
|
8595 | } else {
|
8596 | a[key] = val;
|
8597 | }
|
8598 | });
|
8599 | return a;
|
8600 | }
|
8601 |
|
8602 | module.exports = {
|
8603 | isArray: isArray,
|
8604 | isArrayBuffer: isArrayBuffer,
|
8605 | isBuffer: isBuffer,
|
8606 | isFormData: isFormData,
|
8607 | isArrayBufferView: isArrayBufferView,
|
8608 | isString: isString,
|
8609 | isNumber: isNumber,
|
8610 | isObject: isObject,
|
8611 | isUndefined: isUndefined,
|
8612 | isDate: isDate,
|
8613 | isFile: isFile,
|
8614 | isBlob: isBlob,
|
8615 | isFunction: isFunction,
|
8616 | isStream: isStream,
|
8617 | isURLSearchParams: isURLSearchParams,
|
8618 | isStandardBrowserEnv: isStandardBrowserEnv,
|
8619 | forEach: forEach,
|
8620 | merge: merge,
|
8621 | deepMerge: deepMerge,
|
8622 | extend: extend,
|
8623 | trim: trim
|
8624 | };
|
8625 |
|
8626 |
|
8627 | /***/ }),
|
8628 | /* 3 */
|
8629 | /***/ (function(module, exports, __webpack_require__) {
|
8630 |
|
8631 | /* WEBPACK VAR INJECTION */(function(module) {(function (module, exports) {
|
8632 | 'use strict';
|
8633 |
|
8634 | // Utils
|
8635 | function assert (val, msg) {
|
8636 | if (!val) throw new Error(msg || 'Assertion failed');
|
8637 | }
|
8638 |
|
8639 | // Could use `inherits` module, but don't want to move from single file
|
8640 | // architecture yet.
|
8641 | function inherits (ctor, superCtor) {
|
8642 | ctor.super_ = superCtor;
|
8643 | var TempCtor = function () {};
|
8644 | TempCtor.prototype = superCtor.prototype;
|
8645 | ctor.prototype = new TempCtor();
|
8646 | ctor.prototype.constructor = ctor;
|
8647 | }
|
8648 |
|
8649 | // BN
|
8650 |
|
8651 | function BN (number, base, endian) {
|
8652 | if (BN.isBN(number)) {
|
8653 | return number;
|
8654 | }
|
8655 |
|
8656 | this.negative = 0;
|
8657 | this.words = null;
|
8658 | this.length = 0;
|
8659 |
|
8660 | // Reduction context
|
8661 | this.red = null;
|
8662 |
|
8663 | if (number !== null) {
|
8664 | if (base === 'le' || base === 'be') {
|
8665 | endian = base;
|
8666 | base = 10;
|
8667 | }
|
8668 |
|
8669 | this._init(number || 0, base || 10, endian || 'be');
|
8670 | }
|
8671 | }
|
8672 | if (typeof module === 'object') {
|
8673 | module.exports = BN;
|
8674 | } else {
|
8675 | exports.BN = BN;
|
8676 | }
|
8677 |
|
8678 | BN.BN = BN;
|
8679 | BN.wordSize = 26;
|
8680 |
|
8681 | var Buffer;
|
8682 | try {
|
8683 | Buffer = __webpack_require__(9).Buffer;
|
8684 | } catch (e) {
|
8685 | }
|
8686 |
|
8687 | BN.isBN = function isBN (num) {
|
8688 | if (num instanceof BN) {
|
8689 | return true;
|
8690 | }
|
8691 |
|
8692 | return num !== null && typeof num === 'object' &&
|
8693 | num.constructor.wordSize === BN.wordSize && Array.isArray(num.words);
|
8694 | };
|
8695 |
|
8696 | BN.max = function max (left, right) {
|
8697 | if (left.cmp(right) > 0) return left;
|
8698 | return right;
|
8699 | };
|
8700 |
|
8701 | BN.min = function min (left, right) {
|
8702 | if (left.cmp(right) < 0) return left;
|
8703 | return right;
|
8704 | };
|
8705 |
|
8706 | BN.prototype._init = function init (number, base, endian) {
|
8707 | if (typeof number === 'number') {
|
8708 | return this._initNumber(number, base, endian);
|
8709 | }
|
8710 |
|
8711 | if (typeof number === 'object') {
|
8712 | return this._initArray(number, base, endian);
|
8713 | }
|
8714 |
|
8715 | if (base === 'hex') {
|
8716 | base = 16;
|
8717 | }
|
8718 | assert(base === (base | 0) && base >= 2 && base <= 36);
|
8719 |
|
8720 | number = number.toString().replace(/\s+/g, '');
|
8721 | var start = 0;
|
8722 | if (number[0] === '-') {
|
8723 | start++;
|
8724 | }
|
8725 |
|
8726 | if (base === 16) {
|
8727 | this._parseHex(number, start);
|
8728 | } else {
|
8729 | this._parseBase(number, base, start);
|
8730 | }
|
8731 |
|
8732 | if (number[0] === '-') {
|
8733 | this.negative = 1;
|
8734 | }
|
8735 |
|
8736 | this.strip();
|
8737 |
|
8738 | if (endian !== 'le') return;
|
8739 |
|
8740 | this._initArray(this.toArray(), base, endian);
|
8741 | };
|
8742 |
|
8743 | BN.prototype._initNumber = function _initNumber (number, base, endian) {
|
8744 | if (number < 0) {
|
8745 | this.negative = 1;
|
8746 | number = -number;
|
8747 | }
|
8748 | if (number < 0x4000000) {
|
8749 | this.words = [ number & 0x3ffffff ];
|
8750 | this.length = 1;
|
8751 | } else if (number < 0x10000000000000) {
|
8752 | this.words = [
|
8753 | number & 0x3ffffff,
|
8754 | (number / 0x4000000) & 0x3ffffff
|
8755 | ];
|
8756 | this.length = 2;
|
8757 | } else {
|
8758 | assert(number < 0x20000000000000); // 2 ^ 53 (unsafe)
|
8759 | this.words = [
|
8760 | number & 0x3ffffff,
|
8761 | (number / 0x4000000) & 0x3ffffff,
|
8762 | 1
|
8763 | ];
|
8764 | this.length = 3;
|
8765 | }
|
8766 |
|
8767 | if (endian !== 'le') return;
|
8768 |
|
8769 | // Reverse the bytes
|
8770 | this._initArray(this.toArray(), base, endian);
|
8771 | };
|
8772 |
|
8773 | BN.prototype._initArray = function _initArray (number, base, endian) {
|
8774 | // Perhaps a Uint8Array
|
8775 | assert(typeof number.length === 'number');
|
8776 | if (number.length <= 0) {
|
8777 | this.words = [ 0 ];
|
8778 | this.length = 1;
|
8779 | return this;
|
8780 | }
|
8781 |
|
8782 | this.length = Math.ceil(number.length / 3);
|
8783 | this.words = new Array(this.length);
|
8784 | for (var i = 0; i < this.length; i++) {
|
8785 | this.words[i] = 0;
|
8786 | }
|
8787 |
|
8788 | var j, w;
|
8789 | var off = 0;
|
8790 | if (endian === 'be') {
|
8791 | for (i = number.length - 1, j = 0; i >= 0; i -= 3) {
|
8792 | w = number[i] | (number[i - 1] << 8) | (number[i - 2] << 16);
|
8793 | this.words[j] |= (w << off) & 0x3ffffff;
|
8794 | this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff;
|
8795 | off += 24;
|
8796 | if (off >= 26) {
|
8797 | off -= 26;
|
8798 | j++;
|
8799 | }
|
8800 | }
|
8801 | } else if (endian === 'le') {
|
8802 | for (i = 0, j = 0; i < number.length; i += 3) {
|
8803 | w = number[i] | (number[i + 1] << 8) | (number[i + 2] << 16);
|
8804 | this.words[j] |= (w << off) & 0x3ffffff;
|
8805 | this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff;
|
8806 | off += 24;
|
8807 | if (off >= 26) {
|
8808 | off -= 26;
|
8809 | j++;
|
8810 | }
|
8811 | }
|
8812 | }
|
8813 | return this.strip();
|
8814 | };
|
8815 |
|
8816 | function parseHex (str, start, end) {
|
8817 | var r = 0;
|
8818 | var len = Math.min(str.length, end);
|
8819 | for (var i = start; i < len; i++) {
|
8820 | var c = str.charCodeAt(i) - 48;
|
8821 |
|
8822 | r <<= 4;
|
8823 |
|
8824 | // 'a' - 'f'
|
8825 | if (c >= 49 && c <= 54) {
|
8826 | r |= c - 49 + 0xa;
|
8827 |
|
8828 | // 'A' - 'F'
|
8829 | } else if (c >= 17 && c <= 22) {
|
8830 | r |= c - 17 + 0xa;
|
8831 |
|
8832 | // '0' - '9'
|
8833 | } else {
|
8834 | r |= c & 0xf;
|
8835 | }
|
8836 | }
|
8837 | return r;
|
8838 | }
|
8839 |
|
8840 | BN.prototype._parseHex = function _parseHex (number, start) {
|
8841 | // Create possibly bigger array to ensure that it fits the number
|
8842 | this.length = Math.ceil((number.length - start) / 6);
|
8843 | this.words = new Array(this.length);
|
8844 | for (var i = 0; i < this.length; i++) {
|
8845 | this.words[i] = 0;
|
8846 | }
|
8847 |
|
8848 | var j, w;
|
8849 | // Scan 24-bit chunks and add them to the number
|
8850 | var off = 0;
|
8851 | for (i = number.length - 6, j = 0; i >= start; i -= 6) {
|
8852 | w = parseHex(number, i, i + 6);
|
8853 | this.words[j] |= (w << off) & 0x3ffffff;
|
8854 | // NOTE: `0x3fffff` is intentional here, 26bits max shift + 24bit hex limb
|
8855 | this.words[j + 1] |= w >>> (26 - off) & 0x3fffff;
|
8856 | off += 24;
|
8857 | if (off >= 26) {
|
8858 | off -= 26;
|
8859 | j++;
|
8860 | }
|
8861 | }
|
8862 | if (i + 6 !== start) {
|
8863 | w = parseHex(number, start, i + 6);
|
8864 | this.words[j] |= (w << off) & 0x3ffffff;
|
8865 | this.words[j + 1] |= w >>> (26 - off) & 0x3fffff;
|
8866 | }
|
8867 | this.strip();
|
8868 | };
|
8869 |
|
8870 | function parseBase (str, start, end, mul) {
|
8871 | var r = 0;
|
8872 | var len = Math.min(str.length, end);
|
8873 | for (var i = start; i < len; i++) {
|
8874 | var c = str.charCodeAt(i) - 48;
|
8875 |
|
8876 | r *= mul;
|
8877 |
|
8878 | // 'a'
|
8879 | if (c >= 49) {
|
8880 | r += c - 49 + 0xa;
|
8881 |
|
8882 | // 'A'
|
8883 | } else if (c >= 17) {
|
8884 | r += c - 17 + 0xa;
|
8885 |
|
8886 | // '0' - '9'
|
8887 | } else {
|
8888 | r += c;
|
8889 | }
|
8890 | }
|
8891 | return r;
|
8892 | }
|
8893 |
|
8894 | BN.prototype._parseBase = function _parseBase (number, base, start) {
|
8895 | // Initialize as zero
|
8896 | this.words = [ 0 ];
|
8897 | this.length = 1;
|
8898 |
|
8899 | // Find length of limb in base
|
8900 | for (var limbLen = 0, limbPow = 1; limbPow <= 0x3ffffff; limbPow *= base) {
|
8901 | limbLen++;
|
8902 | }
|
8903 | limbLen--;
|
8904 | limbPow = (limbPow / base) | 0;
|
8905 |
|
8906 | var total = number.length - start;
|
8907 | var mod = total % limbLen;
|
8908 | var end = Math.min(total, total - mod) + start;
|
8909 |
|
8910 | var word = 0;
|
8911 | for (var i = start; i < end; i += limbLen) {
|
8912 | word = parseBase(number, i, i + limbLen, base);
|
8913 |
|
8914 | this.imuln(limbPow);
|
8915 | if (this.words[0] + word < 0x4000000) {
|
8916 | this.words[0] += word;
|
8917 | } else {
|
8918 | this._iaddn(word);
|
8919 | }
|
8920 | }
|
8921 |
|
8922 | if (mod !== 0) {
|
8923 | var pow = 1;
|
8924 | word = parseBase(number, i, number.length, base);
|
8925 |
|
8926 | for (i = 0; i < mod; i++) {
|
8927 | pow *= base;
|
8928 | }
|
8929 |
|
8930 | this.imuln(pow);
|
8931 | if (this.words[0] + word < 0x4000000) {
|
8932 | this.words[0] += word;
|
8933 | } else {
|
8934 | this._iaddn(word);
|
8935 | }
|
8936 | }
|
8937 | };
|
8938 |
|
8939 | BN.prototype.copy = function copy (dest) {
|
8940 | dest.words = new Array(this.length);
|
8941 | for (var i = 0; i < this.length; i++) {
|
8942 | dest.words[i] = this.words[i];
|
8943 | }
|
8944 | dest.length = this.length;
|
8945 | dest.negative = this.negative;
|
8946 | dest.red = this.red;
|
8947 | };
|
8948 |
|
8949 | BN.prototype.clone = function clone () {
|
8950 | var r = new BN(null);
|
8951 | this.copy(r);
|
8952 | return r;
|
8953 | };
|
8954 |
|
8955 | BN.prototype._expand = function _expand (size) {
|
8956 | while (this.length < size) {
|
8957 | this.words[this.length++] = 0;
|
8958 | }
|
8959 | return this;
|
8960 | };
|
8961 |
|
8962 | // Remove leading `0` from `this`
|
8963 | BN.prototype.strip = function strip () {
|
8964 | while (this.length > 1 && this.words[this.length - 1] === 0) {
|
8965 | this.length--;
|
8966 | }
|
8967 | return this._normSign();
|
8968 | };
|
8969 |
|
8970 | BN.prototype._normSign = function _normSign () {
|
8971 | // -0 = 0
|
8972 | if (this.length === 1 && this.words[0] === 0) {
|
8973 | this.negative = 0;
|
8974 | }
|
8975 | return this;
|
8976 | };
|
8977 |
|
8978 | BN.prototype.inspect = function inspect () {
|
8979 | return (this.red ? '<BN-R: ' : '<BN: ') + this.toString(16) + '>';
|
8980 | };
|
8981 |
|
8982 | /*
|
8983 |
|
8984 | var zeros = [];
|
8985 | var groupSizes = [];
|
8986 | var groupBases = [];
|
8987 |
|
8988 | var s = '';
|
8989 | var i = -1;
|
8990 | while (++i < BN.wordSize) {
|
8991 | zeros[i] = s;
|
8992 | s += '0';
|
8993 | }
|
8994 | groupSizes[0] = 0;
|
8995 | groupSizes[1] = 0;
|
8996 | groupBases[0] = 0;
|
8997 | groupBases[1] = 0;
|
8998 | var base = 2 - 1;
|
8999 | while (++base < 36 + 1) {
|
9000 | var groupSize = 0;
|
9001 | var groupBase = 1;
|
9002 | while (groupBase < (1 << BN.wordSize) / base) {
|
9003 | groupBase *= base;
|
9004 | groupSize += 1;
|
9005 | }
|
9006 | groupSizes[base] = groupSize;
|
9007 | groupBases[base] = groupBase;
|
9008 | }
|
9009 |
|
9010 | */
|
9011 |
|
9012 | var zeros = [
|
9013 | '',
|
9014 | '0',
|
9015 | '00',
|
9016 | '000',
|
9017 | '0000',
|
9018 | '00000',
|
9019 | '000000',
|
9020 | '0000000',
|
9021 | '00000000',
|
9022 | '000000000',
|
9023 | '0000000000',
|
9024 | '00000000000',
|
9025 | '000000000000',
|
9026 | '0000000000000',
|
9027 | '00000000000000',
|
9028 | '000000000000000',
|
9029 | '0000000000000000',
|
9030 | '00000000000000000',
|
9031 | '000000000000000000',
|
9032 | '0000000000000000000',
|
9033 | '00000000000000000000',
|
9034 | '000000000000000000000',
|
9035 | '0000000000000000000000',
|
9036 | '00000000000000000000000',
|
9037 | '000000000000000000000000',
|
9038 | '0000000000000000000000000'
|
9039 | ];
|
9040 |
|
9041 | var groupSizes = [
|
9042 | 0, 0,
|
9043 | 25, 16, 12, 11, 10, 9, 8,
|
9044 | 8, 7, 7, 7, 7, 6, 6,
|
9045 | 6, 6, 6, 6, 6, 5, 5,
|
9046 | 5, 5, 5, 5, 5, 5, 5,
|
9047 | 5, 5, 5, 5, 5, 5, 5
|
9048 | ];
|
9049 |
|
9050 | var groupBases = [
|
9051 | 0, 0,
|
9052 | 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216,
|
9053 | 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625,
|
9054 | 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632,
|
9055 | 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149,
|
9056 | 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176
|
9057 | ];
|
9058 |
|
9059 | BN.prototype.toString = function toString (base, padding) {
|
9060 | base = base || 10;
|
9061 | padding = padding | 0 || 1;
|
9062 |
|
9063 | var out;
|
9064 | if (base === 16 || base === 'hex') {
|
9065 | out = '';
|
9066 | var off = 0;
|
9067 | var carry = 0;
|
9068 | for (var i = 0; i < this.length; i++) {
|
9069 | var w = this.words[i];
|
9070 | var word = (((w << off) | carry) & 0xffffff).toString(16);
|
9071 | carry = (w >>> (24 - off)) & 0xffffff;
|
9072 | if (carry !== 0 || i !== this.length - 1) {
|
9073 | out = zeros[6 - word.length] + word + out;
|
9074 | } else {
|
9075 | out = word + out;
|
9076 | }
|
9077 | off += 2;
|
9078 | if (off >= 26) {
|
9079 | off -= 26;
|
9080 | i--;
|
9081 | }
|
9082 | }
|
9083 | if (carry !== 0) {
|
9084 | out = carry.toString(16) + out;
|
9085 | }
|
9086 | while (out.length % padding !== 0) {
|
9087 | out = '0' + out;
|
9088 | }
|
9089 | if (this.negative !== 0) {
|
9090 | out = '-' + out;
|
9091 | }
|
9092 | return out;
|
9093 | }
|
9094 |
|
9095 | if (base === (base | 0) && base >= 2 && base <= 36) {
|
9096 | // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base));
|
9097 | var groupSize = groupSizes[base];
|
9098 | // var groupBase = Math.pow(base, groupSize);
|
9099 | var groupBase = groupBases[base];
|
9100 | out = '';
|
9101 | var c = this.clone();
|
9102 | c.negative = 0;
|
9103 | while (!c.isZero()) {
|
9104 | var r = c.modn(groupBase).toString(base);
|
9105 | c = c.idivn(groupBase);
|
9106 |
|
9107 | if (!c.isZero()) {
|
9108 | out = zeros[groupSize - r.length] + r + out;
|
9109 | } else {
|
9110 | out = r + out;
|
9111 | }
|
9112 | }
|
9113 | if (this.isZero()) {
|
9114 | out = '0' + out;
|
9115 | }
|
9116 | while (out.length % padding !== 0) {
|
9117 | out = '0' + out;
|
9118 | }
|
9119 | if (this.negative !== 0) {
|
9120 | out = '-' + out;
|
9121 | }
|
9122 | return out;
|
9123 | }
|
9124 |
|
9125 | assert(false, 'Base should be between 2 and 36');
|
9126 | };
|
9127 |
|
9128 | BN.prototype.toNumber = function toNumber () {
|
9129 | var ret = this.words[0];
|
9130 | if (this.length === 2) {
|
9131 | ret += this.words[1] * 0x4000000;
|
9132 | } else if (this.length === 3 && this.words[2] === 0x01) {
|
9133 | // NOTE: at this stage it is known that the top bit is set
|
9134 | ret += 0x10000000000000 + (this.words[1] * 0x4000000);
|
9135 | } else if (this.length > 2) {
|
9136 | assert(false, 'Number can only safely store up to 53 bits');
|
9137 | }
|
9138 | return (this.negative !== 0) ? -ret : ret;
|
9139 | };
|
9140 |
|
9141 | BN.prototype.toJSON = function toJSON () {
|
9142 | return this.toString(16);
|
9143 | };
|
9144 |
|
9145 | BN.prototype.toBuffer = function toBuffer (endian, length) {
|
9146 | assert(typeof Buffer !== 'undefined');
|
9147 | return this.toArrayLike(Buffer, endian, length);
|
9148 | };
|
9149 |
|
9150 | BN.prototype.toArray = function toArray (endian, length) {
|
9151 | return this.toArrayLike(Array, endian, length);
|
9152 | };
|
9153 |
|
9154 | BN.prototype.toArrayLike = function toArrayLike (ArrayType, endian, length) {
|
9155 | var byteLength = this.byteLength();
|
9156 | var reqLength = length || Math.max(1, byteLength);
|
9157 | assert(byteLength <= reqLength, 'byte array longer than desired length');
|
9158 | assert(reqLength > 0, 'Requested array length <= 0');
|
9159 |
|
9160 | this.strip();
|
9161 | var littleEndian = endian === 'le';
|
9162 | var res = new ArrayType(reqLength);
|
9163 |
|
9164 | var b, i;
|
9165 | var q = this.clone();
|
9166 | if (!littleEndian) {
|
9167 | // Assume big-endian
|
9168 | for (i = 0; i < reqLength - byteLength; i++) {
|
9169 | res[i] = 0;
|
9170 | }
|
9171 |
|
9172 | for (i = 0; !q.isZero(); i++) {
|
9173 | b = q.andln(0xff);
|
9174 | q.iushrn(8);
|
9175 |
|
9176 | res[reqLength - i - 1] = b;
|
9177 | }
|
9178 | } else {
|
9179 | for (i = 0; !q.isZero(); i++) {
|
9180 | b = q.andln(0xff);
|
9181 | q.iushrn(8);
|
9182 |
|
9183 | res[i] = b;
|
9184 | }
|
9185 |
|
9186 | for (; i < reqLength; i++) {
|
9187 | res[i] = 0;
|
9188 | }
|
9189 | }
|
9190 |
|
9191 | return res;
|
9192 | };
|
9193 |
|
9194 | if (Math.clz32) {
|
9195 | BN.prototype._countBits = function _countBits (w) {
|
9196 | return 32 - Math.clz32(w);
|
9197 | };
|
9198 | } else {
|
9199 | BN.prototype._countBits = function _countBits (w) {
|
9200 | var t = w;
|
9201 | var r = 0;
|
9202 | if (t >= 0x1000) {
|
9203 | r += 13;
|
9204 | t >>>= 13;
|
9205 | }
|
9206 | if (t >= 0x40) {
|
9207 | r += 7;
|
9208 | t >>>= 7;
|
9209 | }
|
9210 | if (t >= 0x8) {
|
9211 | r += 4;
|
9212 | t >>>= 4;
|
9213 | }
|
9214 | if (t >= 0x02) {
|
9215 | r += 2;
|
9216 | t >>>= 2;
|
9217 | }
|
9218 | return r + t;
|
9219 | };
|
9220 | }
|
9221 |
|
9222 | BN.prototype._zeroBits = function _zeroBits (w) {
|
9223 | // Short-cut
|
9224 | if (w === 0) return 26;
|
9225 |
|
9226 | var t = w;
|
9227 | var r = 0;
|
9228 | if ((t & 0x1fff) === 0) {
|
9229 | r += 13;
|
9230 | t >>>= 13;
|
9231 | }
|
9232 | if ((t & 0x7f) === 0) {
|
9233 | r += 7;
|
9234 | t >>>= 7;
|
9235 | }
|
9236 | if ((t & 0xf) === 0) {
|
9237 | r += 4;
|
9238 | t >>>= 4;
|
9239 | }
|
9240 | if ((t & 0x3) === 0) {
|
9241 | r += 2;
|
9242 | t >>>= 2;
|
9243 | }
|
9244 | if ((t & 0x1) === 0) {
|
9245 | r++;
|
9246 | }
|
9247 | return r;
|
9248 | };
|
9249 |
|
9250 | // Return number of used bits in a BN
|
9251 | BN.prototype.bitLength = function bitLength () {
|
9252 | var w = this.words[this.length - 1];
|
9253 | var hi = this._countBits(w);
|
9254 | return (this.length - 1) * 26 + hi;
|
9255 | };
|
9256 |
|
9257 | function toBitArray (num) {
|
9258 | var w = new Array(num.bitLength());
|
9259 |
|
9260 | for (var bit = 0; bit < w.length; bit++) {
|
9261 | var off = (bit / 26) | 0;
|
9262 | var wbit = bit % 26;
|
9263 |
|
9264 | w[bit] = (num.words[off] & (1 << wbit)) >>> wbit;
|
9265 | }
|
9266 |
|
9267 | return w;
|
9268 | }
|
9269 |
|
9270 | // Number of trailing zero bits
|
9271 | BN.prototype.zeroBits = function zeroBits () {
|
9272 | if (this.isZero()) return 0;
|
9273 |
|
9274 | var r = 0;
|
9275 | for (var i = 0; i < this.length; i++) {
|
9276 | var b = this._zeroBits(this.words[i]);
|
9277 | r += b;
|
9278 | if (b !== 26) break;
|
9279 | }
|
9280 | return r;
|
9281 | };
|
9282 |
|
9283 | BN.prototype.byteLength = function byteLength () {
|
9284 | return Math.ceil(this.bitLength() / 8);
|
9285 | };
|
9286 |
|
9287 | BN.prototype.toTwos = function toTwos (width) {
|
9288 | if (this.negative !== 0) {
|
9289 | return this.abs().inotn(width).iaddn(1);
|
9290 | }
|
9291 | return this.clone();
|
9292 | };
|
9293 |
|
9294 | BN.prototype.fromTwos = function fromTwos (width) {
|
9295 | if (this.testn(width - 1)) {
|
9296 | return this.notn(width).iaddn(1).ineg();
|
9297 | }
|
9298 | return this.clone();
|
9299 | };
|
9300 |
|
9301 | BN.prototype.isNeg = function isNeg () {
|
9302 | return this.negative !== 0;
|
9303 | };
|
9304 |
|
9305 | // Return negative clone of `this`
|
9306 | BN.prototype.neg = function neg () {
|
9307 | return this.clone().ineg();
|
9308 | };
|
9309 |
|
9310 | BN.prototype.ineg = function ineg () {
|
9311 | if (!this.isZero()) {
|
9312 | this.negative ^= 1;
|
9313 | }
|
9314 |
|
9315 | return this;
|
9316 | };
|
9317 |
|
9318 | // Or `num` with `this` in-place
|
9319 | BN.prototype.iuor = function iuor (num) {
|
9320 | while (this.length < num.length) {
|
9321 | this.words[this.length++] = 0;
|
9322 | }
|
9323 |
|
9324 | for (var i = 0; i < num.length; i++) {
|
9325 | this.words[i] = this.words[i] | num.words[i];
|
9326 | }
|
9327 |
|
9328 | return this.strip();
|
9329 | };
|
9330 |
|
9331 | BN.prototype.ior = function ior (num) {
|
9332 | assert((this.negative | num.negative) === 0);
|
9333 | return this.iuor(num);
|
9334 | };
|
9335 |
|
9336 | // Or `num` with `this`
|
9337 | BN.prototype.or = function or (num) {
|
9338 | if (this.length > num.length) return this.clone().ior(num);
|
9339 | return num.clone().ior(this);
|
9340 | };
|
9341 |
|
9342 | BN.prototype.uor = function uor (num) {
|
9343 | if (this.length > num.length) return this.clone().iuor(num);
|
9344 | return num.clone().iuor(this);
|
9345 | };
|
9346 |
|
9347 | // And `num` with `this` in-place
|
9348 | BN.prototype.iuand = function iuand (num) {
|
9349 | // b = min-length(num, this)
|
9350 | var b;
|
9351 | if (this.length > num.length) {
|
9352 | b = num;
|
9353 | } else {
|
9354 | b = this;
|
9355 | }
|
9356 |
|
9357 | for (var i = 0; i < b.length; i++) {
|
9358 | this.words[i] = this.words[i] & num.words[i];
|
9359 | }
|
9360 |
|
9361 | this.length = b.length;
|
9362 |
|
9363 | return this.strip();
|
9364 | };
|
9365 |
|
9366 | BN.prototype.iand = function iand (num) {
|
9367 | assert((this.negative | num.negative) === 0);
|
9368 | return this.iuand(num);
|
9369 | };
|
9370 |
|
9371 | // And `num` with `this`
|
9372 | BN.prototype.and = function and (num) {
|
9373 | if (this.length > num.length) return this.clone().iand(num);
|
9374 | return num.clone().iand(this);
|
9375 | };
|
9376 |
|
9377 | BN.prototype.uand = function uand (num) {
|
9378 | if (this.length > num.length) return this.clone().iuand(num);
|
9379 | return num.clone().iuand(this);
|
9380 | };
|
9381 |
|
9382 | // Xor `num` with `this` in-place
|
9383 | BN.prototype.iuxor = function iuxor (num) {
|
9384 | // a.length > b.length
|
9385 | var a;
|
9386 | var b;
|
9387 | if (this.length > num.length) {
|
9388 | a = this;
|
9389 | b = num;
|
9390 | } else {
|
9391 | a = num;
|
9392 | b = this;
|
9393 | }
|
9394 |
|
9395 | for (var i = 0; i < b.length; i++) {
|
9396 | this.words[i] = a.words[i] ^ b.words[i];
|
9397 | }
|
9398 |
|
9399 | if (this !== a) {
|
9400 | for (; i < a.length; i++) {
|
9401 | this.words[i] = a.words[i];
|
9402 | }
|
9403 | }
|
9404 |
|
9405 | this.length = a.length;
|
9406 |
|
9407 | return this.strip();
|
9408 | };
|
9409 |
|
9410 | BN.prototype.ixor = function ixor (num) {
|
9411 | assert((this.negative | num.negative) === 0);
|
9412 | return this.iuxor(num);
|
9413 | };
|
9414 |
|
9415 | // Xor `num` with `this`
|
9416 | BN.prototype.xor = function xor (num) {
|
9417 | if (this.length > num.length) return this.clone().ixor(num);
|
9418 | return num.clone().ixor(this);
|
9419 | };
|
9420 |
|
9421 | BN.prototype.uxor = function uxor (num) {
|
9422 | if (this.length > num.length) return this.clone().iuxor(num);
|
9423 | return num.clone().iuxor(this);
|
9424 | };
|
9425 |
|
9426 | // Not ``this`` with ``width`` bitwidth
|
9427 | BN.prototype.inotn = function inotn (width) {
|
9428 | assert(typeof width === 'number' && width >= 0);
|
9429 |
|
9430 | var bytesNeeded = Math.ceil(width / 26) | 0;
|
9431 | var bitsLeft = width % 26;
|
9432 |
|
9433 | // Extend the buffer with leading zeroes
|
9434 | this._expand(bytesNeeded);
|
9435 |
|
9436 | if (bitsLeft > 0) {
|
9437 | bytesNeeded--;
|
9438 | }
|
9439 |
|
9440 | // Handle complete words
|
9441 | for (var i = 0; i < bytesNeeded; i++) {
|
9442 | this.words[i] = ~this.words[i] & 0x3ffffff;
|
9443 | }
|
9444 |
|
9445 | // Handle the residue
|
9446 | if (bitsLeft > 0) {
|
9447 | this.words[i] = ~this.words[i] & (0x3ffffff >> (26 - bitsLeft));
|
9448 | }
|
9449 |
|
9450 | // And remove leading zeroes
|
9451 | return this.strip();
|
9452 | };
|
9453 |
|
9454 | BN.prototype.notn = function notn (width) {
|
9455 | return this.clone().inotn(width);
|
9456 | };
|
9457 |
|
9458 | // Set `bit` of `this`
|
9459 | BN.prototype.setn = function setn (bit, val) {
|
9460 | assert(typeof bit === 'number' && bit >= 0);
|
9461 |
|
9462 | var off = (bit / 26) | 0;
|
9463 | var wbit = bit % 26;
|
9464 |
|
9465 | this._expand(off + 1);
|
9466 |
|
9467 | if (val) {
|
9468 | this.words[off] = this.words[off] | (1 << wbit);
|
9469 | } else {
|
9470 | this.words[off] = this.words[off] & ~(1 << wbit);
|
9471 | }
|
9472 |
|
9473 | return this.strip();
|
9474 | };
|
9475 |
|
9476 | // Add `num` to `this` in-place
|
9477 | BN.prototype.iadd = function iadd (num) {
|
9478 | var r;
|
9479 |
|
9480 | // negative + positive
|
9481 | if (this.negative !== 0 && num.negative === 0) {
|
9482 | this.negative = 0;
|
9483 | r = this.isub(num);
|
9484 | this.negative ^= 1;
|
9485 | return this._normSign();
|
9486 |
|
9487 | // positive + negative
|
9488 | } else if (this.negative === 0 && num.negative !== 0) {
|
9489 | num.negative = 0;
|
9490 | r = this.isub(num);
|
9491 | num.negative = 1;
|
9492 | return r._normSign();
|
9493 | }
|
9494 |
|
9495 | // a.length > b.length
|
9496 | var a, b;
|
9497 | if (this.length > num.length) {
|
9498 | a = this;
|
9499 | b = num;
|
9500 | } else {
|
9501 | a = num;
|
9502 | b = this;
|
9503 | }
|
9504 |
|
9505 | var carry = 0;
|
9506 | for (var i = 0; i < b.length; i++) {
|
9507 | r = (a.words[i] | 0) + (b.words[i] | 0) + carry;
|
9508 | this.words[i] = r & 0x3ffffff;
|
9509 | carry = r >>> 26;
|
9510 | }
|
9511 | for (; carry !== 0 && i < a.length; i++) {
|
9512 | r = (a.words[i] | 0) + carry;
|
9513 | this.words[i] = r & 0x3ffffff;
|
9514 | carry = r >>> 26;
|
9515 | }
|
9516 |
|
9517 | this.length = a.length;
|
9518 | if (carry !== 0) {
|
9519 | this.words[this.length] = carry;
|
9520 | this.length++;
|
9521 | // Copy the rest of the words
|
9522 | } else if (a !== this) {
|
9523 | for (; i < a.length; i++) {
|
9524 | this.words[i] = a.words[i];
|
9525 | }
|
9526 | }
|
9527 |
|
9528 | return this;
|
9529 | };
|
9530 |
|
9531 | // Add `num` to `this`
|
9532 | BN.prototype.add = function add (num) {
|
9533 | var res;
|
9534 | if (num.negative !== 0 && this.negative === 0) {
|
9535 | num.negative = 0;
|
9536 | res = this.sub(num);
|
9537 | num.negative ^= 1;
|
9538 | return res;
|
9539 | } else if (num.negative === 0 && this.negative !== 0) {
|
9540 | this.negative = 0;
|
9541 | res = num.sub(this);
|
9542 | this.negative = 1;
|
9543 | return res;
|
9544 | }
|
9545 |
|
9546 | if (this.length > num.length) return this.clone().iadd(num);
|
9547 |
|
9548 | return num.clone().iadd(this);
|
9549 | };
|
9550 |
|
9551 | // Subtract `num` from `this` in-place
|
9552 | BN.prototype.isub = function isub (num) {
|
9553 | // this - (-num) = this + num
|
9554 | if (num.negative !== 0) {
|
9555 | num.negative = 0;
|
9556 | var r = this.iadd(num);
|
9557 | num.negative = 1;
|
9558 | return r._normSign();
|
9559 |
|
9560 | // -this - num = -(this + num)
|
9561 | } else if (this.negative !== 0) {
|
9562 | this.negative = 0;
|
9563 | this.iadd(num);
|
9564 | this.negative = 1;
|
9565 | return this._normSign();
|
9566 | }
|
9567 |
|
9568 | // At this point both numbers are positive
|
9569 | var cmp = this.cmp(num);
|
9570 |
|
9571 | // Optimization - zeroify
|
9572 | if (cmp === 0) {
|
9573 | this.negative = 0;
|
9574 | this.length = 1;
|
9575 | this.words[0] = 0;
|
9576 | return this;
|
9577 | }
|
9578 |
|
9579 | // a > b
|
9580 | var a, b;
|
9581 | if (cmp > 0) {
|
9582 | a = this;
|
9583 | b = num;
|
9584 | } else {
|
9585 | a = num;
|
9586 | b = this;
|
9587 | }
|
9588 |
|
9589 | var carry = 0;
|
9590 | for (var i = 0; i < b.length; i++) {
|
9591 | r = (a.words[i] | 0) - (b.words[i] | 0) + carry;
|
9592 | carry = r >> 26;
|
9593 | this.words[i] = r & 0x3ffffff;
|
9594 | }
|
9595 | for (; carry !== 0 && i < a.length; i++) {
|
9596 | r = (a.words[i] | 0) + carry;
|
9597 | carry = r >> 26;
|
9598 | this.words[i] = r & 0x3ffffff;
|
9599 | }
|
9600 |
|
9601 | // Copy rest of the words
|
9602 | if (carry === 0 && i < a.length && a !== this) {
|
9603 | for (; i < a.length; i++) {
|
9604 | this.words[i] = a.words[i];
|
9605 | }
|
9606 | }
|
9607 |
|
9608 | this.length = Math.max(this.length, i);
|
9609 |
|
9610 | if (a !== this) {
|
9611 | this.negative = 1;
|
9612 | }
|
9613 |
|
9614 | return this.strip();
|
9615 | };
|
9616 |
|
9617 | // Subtract `num` from `this`
|
9618 | BN.prototype.sub = function sub (num) {
|
9619 | return this.clone().isub(num);
|
9620 | };
|
9621 |
|
9622 | function smallMulTo (self, num, out) {
|
9623 | out.negative = num.negative ^ self.negative;
|
9624 | var len = (self.length + num.length) | 0;
|
9625 | out.length = len;
|
9626 | len = (len - 1) | 0;
|
9627 |
|
9628 | // Peel one iteration (compiler can't do it, because of code complexity)
|
9629 | var a = self.words[0] | 0;
|
9630 | var b = num.words[0] | 0;
|
9631 | var r = a * b;
|
9632 |
|
9633 | var lo = r & 0x3ffffff;
|
9634 | var carry = (r / 0x4000000) | 0;
|
9635 | out.words[0] = lo;
|
9636 |
|
9637 | for (var k = 1; k < len; k++) {
|
9638 | // Sum all words with the same `i + j = k` and accumulate `ncarry`,
|
9639 | // note that ncarry could be >= 0x3ffffff
|
9640 | var ncarry = carry >>> 26;
|
9641 | var rword = carry & 0x3ffffff;
|
9642 | var maxJ = Math.min(k, num.length - 1);
|
9643 | for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
|
9644 | var i = (k - j) | 0;
|
9645 | a = self.words[i] | 0;
|
9646 | b = num.words[j] | 0;
|
9647 | r = a * b + rword;
|
9648 | ncarry += (r / 0x4000000) | 0;
|
9649 | rword = r & 0x3ffffff;
|
9650 | }
|
9651 | out.words[k] = rword | 0;
|
9652 | carry = ncarry | 0;
|
9653 | }
|
9654 | if (carry !== 0) {
|
9655 | out.words[k] = carry | 0;
|
9656 | } else {
|
9657 | out.length--;
|
9658 | }
|
9659 |
|
9660 | return out.strip();
|
9661 | }
|
9662 |
|
9663 | // TODO(indutny): it may be reasonable to omit it for users who don't need
|
9664 | // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit
|
9665 | // multiplication (like elliptic secp256k1).
|
9666 | var comb10MulTo = function comb10MulTo (self, num, out) {
|
9667 | var a = self.words;
|
9668 | var b = num.words;
|
9669 | var o = out.words;
|
9670 | var c = 0;
|
9671 | var lo;
|
9672 | var mid;
|
9673 | var hi;
|
9674 | var a0 = a[0] | 0;
|
9675 | var al0 = a0 & 0x1fff;
|
9676 | var ah0 = a0 >>> 13;
|
9677 | var a1 = a[1] | 0;
|
9678 | var al1 = a1 & 0x1fff;
|
9679 | var ah1 = a1 >>> 13;
|
9680 | var a2 = a[2] | 0;
|
9681 | var al2 = a2 & 0x1fff;
|
9682 | var ah2 = a2 >>> 13;
|
9683 | var a3 = a[3] | 0;
|
9684 | var al3 = a3 & 0x1fff;
|
9685 | var ah3 = a3 >>> 13;
|
9686 | var a4 = a[4] | 0;
|
9687 | var al4 = a4 & 0x1fff;
|
9688 | var ah4 = a4 >>> 13;
|
9689 | var a5 = a[5] | 0;
|
9690 | var al5 = a5 & 0x1fff;
|
9691 | var ah5 = a5 >>> 13;
|
9692 | var a6 = a[6] | 0;
|
9693 | var al6 = a6 & 0x1fff;
|
9694 | var ah6 = a6 >>> 13;
|
9695 | var a7 = a[7] | 0;
|
9696 | var al7 = a7 & 0x1fff;
|
9697 | var ah7 = a7 >>> 13;
|
9698 | var a8 = a[8] | 0;
|
9699 | var al8 = a8 & 0x1fff;
|
9700 | var ah8 = a8 >>> 13;
|
9701 | var a9 = a[9] | 0;
|
9702 | var al9 = a9 & 0x1fff;
|
9703 | var ah9 = a9 >>> 13;
|
9704 | var b0 = b[0] | 0;
|
9705 | var bl0 = b0 & 0x1fff;
|
9706 | var bh0 = b0 >>> 13;
|
9707 | var b1 = b[1] | 0;
|
9708 | var bl1 = b1 & 0x1fff;
|
9709 | var bh1 = b1 >>> 13;
|
9710 | var b2 = b[2] | 0;
|
9711 | var bl2 = b2 & 0x1fff;
|
9712 | var bh2 = b2 >>> 13;
|
9713 | var b3 = b[3] | 0;
|
9714 | var bl3 = b3 & 0x1fff;
|
9715 | var bh3 = b3 >>> 13;
|
9716 | var b4 = b[4] | 0;
|
9717 | var bl4 = b4 & 0x1fff;
|
9718 | var bh4 = b4 >>> 13;
|
9719 | var b5 = b[5] | 0;
|
9720 | var bl5 = b5 & 0x1fff;
|
9721 | var bh5 = b5 >>> 13;
|
9722 | var b6 = b[6] | 0;
|
9723 | var bl6 = b6 & 0x1fff;
|
9724 | var bh6 = b6 >>> 13;
|
9725 | var b7 = b[7] | 0;
|
9726 | var bl7 = b7 & 0x1fff;
|
9727 | var bh7 = b7 >>> 13;
|
9728 | var b8 = b[8] | 0;
|
9729 | var bl8 = b8 & 0x1fff;
|
9730 | var bh8 = b8 >>> 13;
|
9731 | var b9 = b[9] | 0;
|
9732 | var bl9 = b9 & 0x1fff;
|
9733 | var bh9 = b9 >>> 13;
|
9734 |
|
9735 | out.negative = self.negative ^ num.negative;
|
9736 | out.length = 19;
|
9737 | /* k = 0 */
|
9738 | lo = Math.imul(al0, bl0);
|
9739 | mid = Math.imul(al0, bh0);
|
9740 | mid = (mid + Math.imul(ah0, bl0)) | 0;
|
9741 | hi = Math.imul(ah0, bh0);
|
9742 | var w0 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
|
9743 | c = (((hi + (mid >>> 13)) | 0) + (w0 >>> 26)) | 0;
|
9744 | w0 &= 0x3ffffff;
|
9745 | /* k = 1 */
|
9746 | lo = Math.imul(al1, bl0);
|
9747 | mid = Math.imul(al1, bh0);
|
9748 | mid = (mid + Math.imul(ah1, bl0)) | 0;
|
9749 | hi = Math.imul(ah1, bh0);
|
9750 | lo = (lo + Math.imul(al0, bl1)) | 0;
|
9751 | mid = (mid + Math.imul(al0, bh1)) | 0;
|
9752 | mid = (mid + Math.imul(ah0, bl1)) | 0;
|
9753 | hi = (hi + Math.imul(ah0, bh1)) | 0;
|
9754 | var w1 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
|
9755 | c = (((hi + (mid >>> 13)) | 0) + (w1 >>> 26)) | 0;
|
9756 | w1 &= 0x3ffffff;
|
9757 | /* k = 2 */
|
9758 | lo = Math.imul(al2, bl0);
|
9759 | mid = Math.imul(al2, bh0);
|
9760 | mid = (mid + Math.imul(ah2, bl0)) | 0;
|
9761 | hi = Math.imul(ah2, bh0);
|
9762 | lo = (lo + Math.imul(al1, bl1)) | 0;
|
9763 | mid = (mid + Math.imul(al1, bh1)) | 0;
|
9764 | mid = (mid + Math.imul(ah1, bl1)) | 0;
|
9765 | hi = (hi + Math.imul(ah1, bh1)) | 0;
|
9766 | lo = (lo + Math.imul(al0, bl2)) | 0;
|
9767 | mid = (mid + Math.imul(al0, bh2)) | 0;
|
9768 | mid = (mid + Math.imul(ah0, bl2)) | 0;
|
9769 | hi = (hi + Math.imul(ah0, bh2)) | 0;
|
9770 | var w2 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
|
9771 | c = (((hi + (mid >>> 13)) | 0) + (w2 >>> 26)) | 0;
|
9772 | w2 &= 0x3ffffff;
|
9773 | /* k = 3 */
|
9774 | lo = Math.imul(al3, bl0);
|
9775 | mid = Math.imul(al3, bh0);
|
9776 | mid = (mid + Math.imul(ah3, bl0)) | 0;
|
9777 | hi = Math.imul(ah3, bh0);
|
9778 | lo = (lo + Math.imul(al2, bl1)) | 0;
|
9779 | mid = (mid + Math.imul(al2, bh1)) | 0;
|
9780 | mid = (mid + Math.imul(ah2, bl1)) | 0;
|
9781 | hi = (hi + Math.imul(ah2, bh1)) | 0;
|
9782 | lo = (lo + Math.imul(al1, bl2)) | 0;
|
9783 | mid = (mid + Math.imul(al1, bh2)) | 0;
|
9784 | mid = (mid + Math.imul(ah1, bl2)) | 0;
|
9785 | hi = (hi + Math.imul(ah1, bh2)) | 0;
|
9786 | lo = (lo + Math.imul(al0, bl3)) | 0;
|
9787 | mid = (mid + Math.imul(al0, bh3)) | 0;
|
9788 | mid = (mid + Math.imul(ah0, bl3)) | 0;
|
9789 | hi = (hi + Math.imul(ah0, bh3)) | 0;
|
9790 | var w3 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
|
9791 | c = (((hi + (mid >>> 13)) | 0) + (w3 >>> 26)) | 0;
|
9792 | w3 &= 0x3ffffff;
|
9793 | /* k = 4 */
|
9794 | lo = Math.imul(al4, bl0);
|
9795 | mid = Math.imul(al4, bh0);
|
9796 | mid = (mid + Math.imul(ah4, bl0)) | 0;
|
9797 | hi = Math.imul(ah4, bh0);
|
9798 | lo = (lo + Math.imul(al3, bl1)) | 0;
|
9799 | mid = (mid + Math.imul(al3, bh1)) | 0;
|
9800 | mid = (mid + Math.imul(ah3, bl1)) | 0;
|
9801 | hi = (hi + Math.imul(ah3, bh1)) | 0;
|
9802 | lo = (lo + Math.imul(al2, bl2)) | 0;
|
9803 | mid = (mid + Math.imul(al2, bh2)) | 0;
|
9804 | mid = (mid + Math.imul(ah2, bl2)) | 0;
|
9805 | hi = (hi + Math.imul(ah2, bh2)) | 0;
|
9806 | lo = (lo + Math.imul(al1, bl3)) | 0;
|
9807 | mid = (mid + Math.imul(al1, bh3)) | 0;
|
9808 | mid = (mid + Math.imul(ah1, bl3)) | 0;
|
9809 | hi = (hi + Math.imul(ah1, bh3)) | 0;
|
9810 | lo = (lo + Math.imul(al0, bl4)) | 0;
|
9811 | mid = (mid + Math.imul(al0, bh4)) | 0;
|
9812 | mid = (mid + Math.imul(ah0, bl4)) | 0;
|
9813 | hi = (hi + Math.imul(ah0, bh4)) | 0;
|
9814 | var w4 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
|
9815 | c = (((hi + (mid >>> 13)) | 0) + (w4 >>> 26)) | 0;
|
9816 | w4 &= 0x3ffffff;
|
9817 | /* k = 5 */
|
9818 | lo = Math.imul(al5, bl0);
|
9819 | mid = Math.imul(al5, bh0);
|
9820 | mid = (mid + Math.imul(ah5, bl0)) | 0;
|
9821 | hi = Math.imul(ah5, bh0);
|
9822 | lo = (lo + Math.imul(al4, bl1)) | 0;
|
9823 | mid = (mid + Math.imul(al4, bh1)) | 0;
|
9824 | mid = (mid + Math.imul(ah4, bl1)) | 0;
|
9825 | hi = (hi + Math.imul(ah4, bh1)) | 0;
|
9826 | lo = (lo + Math.imul(al3, bl2)) | 0;
|
9827 | mid = (mid + Math.imul(al3, bh2)) | 0;
|
9828 | mid = (mid + Math.imul(ah3, bl2)) | 0;
|
9829 | hi = (hi + Math.imul(ah3, bh2)) | 0;
|
9830 | lo = (lo + Math.imul(al2, bl3)) | 0;
|
9831 | mid = (mid + Math.imul(al2, bh3)) | 0;
|
9832 | mid = (mid + Math.imul(ah2, bl3)) | 0;
|
9833 | hi = (hi + Math.imul(ah2, bh3)) | 0;
|
9834 | lo = (lo + Math.imul(al1, bl4)) | 0;
|
9835 | mid = (mid + Math.imul(al1, bh4)) | 0;
|
9836 | mid = (mid + Math.imul(ah1, bl4)) | 0;
|
9837 | hi = (hi + Math.imul(ah1, bh4)) | 0;
|
9838 | lo = (lo + Math.imul(al0, bl5)) | 0;
|
9839 | mid = (mid + Math.imul(al0, bh5)) | 0;
|
9840 | mid = (mid + Math.imul(ah0, bl5)) | 0;
|
9841 | hi = (hi + Math.imul(ah0, bh5)) | 0;
|
9842 | var w5 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
|
9843 | c = (((hi + (mid >>> 13)) | 0) + (w5 >>> 26)) | 0;
|
9844 | w5 &= 0x3ffffff;
|
9845 | /* k = 6 */
|
9846 | lo = Math.imul(al6, bl0);
|
9847 | mid = Math.imul(al6, bh0);
|
9848 | mid = (mid + Math.imul(ah6, bl0)) | 0;
|
9849 | hi = Math.imul(ah6, bh0);
|
9850 | lo = (lo + Math.imul(al5, bl1)) | 0;
|
9851 | mid = (mid + Math.imul(al5, bh1)) | 0;
|
9852 | mid = (mid + Math.imul(ah5, bl1)) | 0;
|
9853 | hi = (hi + Math.imul(ah5, bh1)) | 0;
|
9854 | lo = (lo + Math.imul(al4, bl2)) | 0;
|
9855 | mid = (mid + Math.imul(al4, bh2)) | 0;
|
9856 | mid = (mid + Math.imul(ah4, bl2)) | 0;
|
9857 | hi = (hi + Math.imul(ah4, bh2)) | 0;
|
9858 | lo = (lo + Math.imul(al3, bl3)) | 0;
|
9859 | mid = (mid + Math.imul(al3, bh3)) | 0;
|
9860 | mid = (mid + Math.imul(ah3, bl3)) | 0;
|
9861 | hi = (hi + Math.imul(ah3, bh3)) | 0;
|
9862 | lo = (lo + Math.imul(al2, bl4)) | 0;
|
9863 | mid = (mid + Math.imul(al2, bh4)) | 0;
|
9864 | mid = (mid + Math.imul(ah2, bl4)) | 0;
|
9865 | hi = (hi + Math.imul(ah2, bh4)) | 0;
|
9866 | lo = (lo + Math.imul(al1, bl5)) | 0;
|
9867 | mid = (mid + Math.imul(al1, bh5)) | 0;
|
9868 | mid = (mid + Math.imul(ah1, bl5)) | 0;
|
9869 | hi = (hi + Math.imul(ah1, bh5)) | 0;
|
9870 | lo = (lo + Math.imul(al0, bl6)) | 0;
|
9871 | mid = (mid + Math.imul(al0, bh6)) | 0;
|
9872 | mid = (mid + Math.imul(ah0, bl6)) | 0;
|
9873 | hi = (hi + Math.imul(ah0, bh6)) | 0;
|
9874 | var w6 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
|
9875 | c = (((hi + (mid >>> 13)) | 0) + (w6 >>> 26)) | 0;
|
9876 | w6 &= 0x3ffffff;
|
9877 | /* k = 7 */
|
9878 | lo = Math.imul(al7, bl0);
|
9879 | mid = Math.imul(al7, bh0);
|
9880 | mid = (mid + Math.imul(ah7, bl0)) | 0;
|
9881 | hi = Math.imul(ah7, bh0);
|
9882 | lo = (lo + Math.imul(al6, bl1)) | 0;
|
9883 | mid = (mid + Math.imul(al6, bh1)) | 0;
|
9884 | mid = (mid + Math.imul(ah6, bl1)) | 0;
|
9885 | hi = (hi + Math.imul(ah6, bh1)) | 0;
|
9886 | lo = (lo + Math.imul(al5, bl2)) | 0;
|
9887 | mid = (mid + Math.imul(al5, bh2)) | 0;
|
9888 | mid = (mid + Math.imul(ah5, bl2)) | 0;
|
9889 | hi = (hi + Math.imul(ah5, bh2)) | 0;
|
9890 | lo = (lo + Math.imul(al4, bl3)) | 0;
|
9891 | mid = (mid + Math.imul(al4, bh3)) | 0;
|
9892 | mid = (mid + Math.imul(ah4, bl3)) | 0;
|
9893 | hi = (hi + Math.imul(ah4, bh3)) | 0;
|
9894 | lo = (lo + Math.imul(al3, bl4)) | 0;
|
9895 | mid = (mid + Math.imul(al3, bh4)) | 0;
|
9896 | mid = (mid + Math.imul(ah3, bl4)) | 0;
|
9897 | hi = (hi + Math.imul(ah3, bh4)) | 0;
|
9898 | lo = (lo + Math.imul(al2, bl5)) | 0;
|
9899 | mid = (mid + Math.imul(al2, bh5)) | 0;
|
9900 | mid = (mid + Math.imul(ah2, bl5)) | 0;
|
9901 | hi = (hi + Math.imul(ah2, bh5)) | 0;
|
9902 | lo = (lo + Math.imul(al1, bl6)) | 0;
|
9903 | mid = (mid + Math.imul(al1, bh6)) | 0;
|
9904 | mid = (mid + Math.imul(ah1, bl6)) | 0;
|
9905 | hi = (hi + Math.imul(ah1, bh6)) | 0;
|
9906 | lo = (lo + Math.imul(al0, bl7)) | 0;
|
9907 | mid = (mid + Math.imul(al0, bh7)) | 0;
|
9908 | mid = (mid + Math.imul(ah0, bl7)) | 0;
|
9909 | hi = (hi + Math.imul(ah0, bh7)) | 0;
|
9910 | var w7 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
|
9911 | c = (((hi + (mid >>> 13)) | 0) + (w7 >>> 26)) | 0;
|
9912 | w7 &= 0x3ffffff;
|
9913 | /* k = 8 */
|
9914 | lo = Math.imul(al8, bl0);
|
9915 | mid = Math.imul(al8, bh0);
|
9916 | mid = (mid + Math.imul(ah8, bl0)) | 0;
|
9917 | hi = Math.imul(ah8, bh0);
|
9918 | lo = (lo + Math.imul(al7, bl1)) | 0;
|
9919 | mid = (mid + Math.imul(al7, bh1)) | 0;
|
9920 | mid = (mid + Math.imul(ah7, bl1)) | 0;
|
9921 | hi = (hi + Math.imul(ah7, bh1)) | 0;
|
9922 | lo = (lo + Math.imul(al6, bl2)) | 0;
|
9923 | mid = (mid + Math.imul(al6, bh2)) | 0;
|
9924 | mid = (mid + Math.imul(ah6, bl2)) | 0;
|
9925 | hi = (hi + Math.imul(ah6, bh2)) | 0;
|
9926 | lo = (lo + Math.imul(al5, bl3)) | 0;
|
9927 | mid = (mid + Math.imul(al5, bh3)) | 0;
|
9928 | mid = (mid + Math.imul(ah5, bl3)) | 0;
|
9929 | hi = (hi + Math.imul(ah5, bh3)) | 0;
|
9930 | lo = (lo + Math.imul(al4, bl4)) | 0;
|
9931 | mid = (mid + Math.imul(al4, bh4)) | 0;
|
9932 | mid = (mid + Math.imul(ah4, bl4)) | 0;
|
9933 | hi = (hi + Math.imul(ah4, bh4)) | 0;
|
9934 | lo = (lo + Math.imul(al3, bl5)) | 0;
|
9935 | mid = (mid + Math.imul(al3, bh5)) | 0;
|
9936 | mid = (mid + Math.imul(ah3, bl5)) | 0;
|
9937 | hi = (hi + Math.imul(ah3, bh5)) | 0;
|
9938 | lo = (lo + Math.imul(al2, bl6)) | 0;
|
9939 | mid = (mid + Math.imul(al2, bh6)) | 0;
|
9940 | mid = (mid + Math.imul(ah2, bl6)) | 0;
|
9941 | hi = (hi + Math.imul(ah2, bh6)) | 0;
|
9942 | lo = (lo + Math.imul(al1, bl7)) | 0;
|
9943 | mid = (mid + Math.imul(al1, bh7)) | 0;
|
9944 | mid = (mid + Math.imul(ah1, bl7)) | 0;
|
9945 | hi = (hi + Math.imul(ah1, bh7)) | 0;
|
9946 | lo = (lo + Math.imul(al0, bl8)) | 0;
|
9947 | mid = (mid + Math.imul(al0, bh8)) | 0;
|
9948 | mid = (mid + Math.imul(ah0, bl8)) | 0;
|
9949 | hi = (hi + Math.imul(ah0, bh8)) | 0;
|
9950 | var w8 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
|
9951 | c = (((hi + (mid >>> 13)) | 0) + (w8 >>> 26)) | 0;
|
9952 | w8 &= 0x3ffffff;
|
9953 | /* k = 9 */
|
9954 | lo = Math.imul(al9, bl0);
|
9955 | mid = Math.imul(al9, bh0);
|
9956 | mid = (mid + Math.imul(ah9, bl0)) | 0;
|
9957 | hi = Math.imul(ah9, bh0);
|
9958 | lo = (lo + Math.imul(al8, bl1)) | 0;
|
9959 | mid = (mid + Math.imul(al8, bh1)) | 0;
|
9960 | mid = (mid + Math.imul(ah8, bl1)) | 0;
|
9961 | hi = (hi + Math.imul(ah8, bh1)) | 0;
|
9962 | lo = (lo + Math.imul(al7, bl2)) | 0;
|
9963 | mid = (mid + Math.imul(al7, bh2)) | 0;
|
9964 | mid = (mid + Math.imul(ah7, bl2)) | 0;
|
9965 | hi = (hi + Math.imul(ah7, bh2)) | 0;
|
9966 | lo = (lo + Math.imul(al6, bl3)) | 0;
|
9967 | mid = (mid + Math.imul(al6, bh3)) | 0;
|
9968 | mid = (mid + Math.imul(ah6, bl3)) | 0;
|
9969 | hi = (hi + Math.imul(ah6, bh3)) | 0;
|
9970 | lo = (lo + Math.imul(al5, bl4)) | 0;
|
9971 | mid = (mid + Math.imul(al5, bh4)) | 0;
|
9972 | mid = (mid + Math.imul(ah5, bl4)) | 0;
|
9973 | hi = (hi + Math.imul(ah5, bh4)) | 0;
|
9974 | lo = (lo + Math.imul(al4, bl5)) | 0;
|
9975 | mid = (mid + Math.imul(al4, bh5)) | 0;
|
9976 | mid = (mid + Math.imul(ah4, bl5)) | 0;
|
9977 | hi = (hi + Math.imul(ah4, bh5)) | 0;
|
9978 | lo = (lo + Math.imul(al3, bl6)) | 0;
|
9979 | mid = (mid + Math.imul(al3, bh6)) | 0;
|
9980 | mid = (mid + Math.imul(ah3, bl6)) | 0;
|
9981 | hi = (hi + Math.imul(ah3, bh6)) | 0;
|
9982 | lo = (lo + Math.imul(al2, bl7)) | 0;
|
9983 | mid = (mid + Math.imul(al2, bh7)) | 0;
|
9984 | mid = (mid + Math.imul(ah2, bl7)) | 0;
|
9985 | hi = (hi + Math.imul(ah2, bh7)) | 0;
|
9986 | lo = (lo + Math.imul(al1, bl8)) | 0;
|
9987 | mid = (mid + Math.imul(al1, bh8)) | 0;
|
9988 | mid = (mid + Math.imul(ah1, bl8)) | 0;
|
9989 | hi = (hi + Math.imul(ah1, bh8)) | 0;
|
9990 | lo = (lo + Math.imul(al0, bl9)) | 0;
|
9991 | mid = (mid + Math.imul(al0, bh9)) | 0;
|
9992 | mid = (mid + Math.imul(ah0, bl9)) | 0;
|
9993 | hi = (hi + Math.imul(ah0, bh9)) | 0;
|
9994 | var w9 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
|
9995 | c = (((hi + (mid >>> 13)) | 0) + (w9 >>> 26)) | 0;
|
9996 | w9 &= 0x3ffffff;
|
9997 | /* k = 10 */
|
9998 | lo = Math.imul(al9, bl1);
|
9999 | mid = Math.imul(al9, bh1);
|
10000 | mid = (mid + Math.imul(ah9, bl1)) | 0;
|
10001 | hi = Math.imul(ah9, bh1);
|
10002 | lo = (lo + Math.imul(al8, bl2)) | 0;
|
10003 | mid = (mid + Math.imul(al8, bh2)) | 0;
|
10004 | mid = (mid + Math.imul(ah8, bl2)) | 0;
|
10005 | hi = (hi + Math.imul(ah8, bh2)) | 0;
|
10006 | lo = (lo + Math.imul(al7, bl3)) | 0;
|
10007 | mid = (mid + Math.imul(al7, bh3)) | 0;
|
10008 | mid = (mid + Math.imul(ah7, bl3)) | 0;
|
10009 | hi = (hi + Math.imul(ah7, bh3)) | 0;
|
10010 | lo = (lo + Math.imul(al6, bl4)) | 0;
|
10011 | mid = (mid + Math.imul(al6, bh4)) | 0;
|
10012 | mid = (mid + Math.imul(ah6, bl4)) | 0;
|
10013 | hi = (hi + Math.imul(ah6, bh4)) | 0;
|
10014 | lo = (lo + Math.imul(al5, bl5)) | 0;
|
10015 | mid = (mid + Math.imul(al5, bh5)) | 0;
|
10016 | mid = (mid + Math.imul(ah5, bl5)) | 0;
|
10017 | hi = (hi + Math.imul(ah5, bh5)) | 0;
|
10018 | lo = (lo + Math.imul(al4, bl6)) | 0;
|
10019 | mid = (mid + Math.imul(al4, bh6)) | 0;
|
10020 | mid = (mid + Math.imul(ah4, bl6)) | 0;
|
10021 | hi = (hi + Math.imul(ah4, bh6)) | 0;
|
10022 | lo = (lo + Math.imul(al3, bl7)) | 0;
|
10023 | mid = (mid + Math.imul(al3, bh7)) | 0;
|
10024 | mid = (mid + Math.imul(ah3, bl7)) | 0;
|
10025 | hi = (hi + Math.imul(ah3, bh7)) | 0;
|
10026 | lo = (lo + Math.imul(al2, bl8)) | 0;
|
10027 | mid = (mid + Math.imul(al2, bh8)) | 0;
|
10028 | mid = (mid + Math.imul(ah2, bl8)) | 0;
|
10029 | hi = (hi + Math.imul(ah2, bh8)) | 0;
|
10030 | lo = (lo + Math.imul(al1, bl9)) | 0;
|
10031 | mid = (mid + Math.imul(al1, bh9)) | 0;
|
10032 | mid = (mid + Math.imul(ah1, bl9)) | 0;
|
10033 | hi = (hi + Math.imul(ah1, bh9)) | 0;
|
10034 | var w10 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
|
10035 | c = (((hi + (mid >>> 13)) | 0) + (w10 >>> 26)) | 0;
|
10036 | w10 &= 0x3ffffff;
|
10037 | /* k = 11 */
|
10038 | lo = Math.imul(al9, bl2);
|
10039 | mid = Math.imul(al9, bh2);
|
10040 | mid = (mid + Math.imul(ah9, bl2)) | 0;
|
10041 | hi = Math.imul(ah9, bh2);
|
10042 | lo = (lo + Math.imul(al8, bl3)) | 0;
|
10043 | mid = (mid + Math.imul(al8, bh3)) | 0;
|
10044 | mid = (mid + Math.imul(ah8, bl3)) | 0;
|
10045 | hi = (hi + Math.imul(ah8, bh3)) | 0;
|
10046 | lo = (lo + Math.imul(al7, bl4)) | 0;
|
10047 | mid = (mid + Math.imul(al7, bh4)) | 0;
|
10048 | mid = (mid + Math.imul(ah7, bl4)) | 0;
|
10049 | hi = (hi + Math.imul(ah7, bh4)) | 0;
|
10050 | lo = (lo + Math.imul(al6, bl5)) | 0;
|
10051 | mid = (mid + Math.imul(al6, bh5)) | 0;
|
10052 | mid = (mid + Math.imul(ah6, bl5)) | 0;
|
10053 | hi = (hi + Math.imul(ah6, bh5)) | 0;
|
10054 | lo = (lo + Math.imul(al5, bl6)) | 0;
|
10055 | mid = (mid + Math.imul(al5, bh6)) | 0;
|
10056 | mid = (mid + Math.imul(ah5, bl6)) | 0;
|
10057 | hi = (hi + Math.imul(ah5, bh6)) | 0;
|
10058 | lo = (lo + Math.imul(al4, bl7)) | 0;
|
10059 | mid = (mid + Math.imul(al4, bh7)) | 0;
|
10060 | mid = (mid + Math.imul(ah4, bl7)) | 0;
|
10061 | hi = (hi + Math.imul(ah4, bh7)) | 0;
|
10062 | lo = (lo + Math.imul(al3, bl8)) | 0;
|
10063 | mid = (mid + Math.imul(al3, bh8)) | 0;
|
10064 | mid = (mid + Math.imul(ah3, bl8)) | 0;
|
10065 | hi = (hi + Math.imul(ah3, bh8)) | 0;
|
10066 | lo = (lo + Math.imul(al2, bl9)) | 0;
|
10067 | mid = (mid + Math.imul(al2, bh9)) | 0;
|
10068 | mid = (mid + Math.imul(ah2, bl9)) | 0;
|
10069 | hi = (hi + Math.imul(ah2, bh9)) | 0;
|
10070 | var w11 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
|
10071 | c = (((hi + (mid >>> 13)) | 0) + (w11 >>> 26)) | 0;
|
10072 | w11 &= 0x3ffffff;
|
10073 | /* k = 12 */
|
10074 | lo = Math.imul(al9, bl3);
|
10075 | mid = Math.imul(al9, bh3);
|
10076 | mid = (mid + Math.imul(ah9, bl3)) | 0;
|
10077 | hi = Math.imul(ah9, bh3);
|
10078 | lo = (lo + Math.imul(al8, bl4)) | 0;
|
10079 | mid = (mid + Math.imul(al8, bh4)) | 0;
|
10080 | mid = (mid + Math.imul(ah8, bl4)) | 0;
|
10081 | hi = (hi + Math.imul(ah8, bh4)) | 0;
|
10082 | lo = (lo + Math.imul(al7, bl5)) | 0;
|
10083 | mid = (mid + Math.imul(al7, bh5)) | 0;
|
10084 | mid = (mid + Math.imul(ah7, bl5)) | 0;
|
10085 | hi = (hi + Math.imul(ah7, bh5)) | 0;
|
10086 | lo = (lo + Math.imul(al6, bl6)) | 0;
|
10087 | mid = (mid + Math.imul(al6, bh6)) | 0;
|
10088 | mid = (mid + Math.imul(ah6, bl6)) | 0;
|
10089 | hi = (hi + Math.imul(ah6, bh6)) | 0;
|
10090 | lo = (lo + Math.imul(al5, bl7)) | 0;
|
10091 | mid = (mid + Math.imul(al5, bh7)) | 0;
|
10092 | mid = (mid + Math.imul(ah5, bl7)) | 0;
|
10093 | hi = (hi + Math.imul(ah5, bh7)) | 0;
|
10094 | lo = (lo + Math.imul(al4, bl8)) | 0;
|
10095 | mid = (mid + Math.imul(al4, bh8)) | 0;
|
10096 | mid = (mid + Math.imul(ah4, bl8)) | 0;
|
10097 | hi = (hi + Math.imul(ah4, bh8)) | 0;
|
10098 | lo = (lo + Math.imul(al3, bl9)) | 0;
|
10099 | mid = (mid + Math.imul(al3, bh9)) | 0;
|
10100 | mid = (mid + Math.imul(ah3, bl9)) | 0;
|
10101 | hi = (hi + Math.imul(ah3, bh9)) | 0;
|
10102 | var w12 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
|
10103 | c = (((hi + (mid >>> 13)) | 0) + (w12 >>> 26)) | 0;
|
10104 | w12 &= 0x3ffffff;
|
10105 | /* k = 13 */
|
10106 | lo = Math.imul(al9, bl4);
|
10107 | mid = Math.imul(al9, bh4);
|
10108 | mid = (mid + Math.imul(ah9, bl4)) | 0;
|
10109 | hi = Math.imul(ah9, bh4);
|
10110 | lo = (lo + Math.imul(al8, bl5)) | 0;
|
10111 | mid = (mid + Math.imul(al8, bh5)) | 0;
|
10112 | mid = (mid + Math.imul(ah8, bl5)) | 0;
|
10113 | hi = (hi + Math.imul(ah8, bh5)) | 0;
|
10114 | lo = (lo + Math.imul(al7, bl6)) | 0;
|
10115 | mid = (mid + Math.imul(al7, bh6)) | 0;
|
10116 | mid = (mid + Math.imul(ah7, bl6)) | 0;
|
10117 | hi = (hi + Math.imul(ah7, bh6)) | 0;
|
10118 | lo = (lo + Math.imul(al6, bl7)) | 0;
|
10119 | mid = (mid + Math.imul(al6, bh7)) | 0;
|
10120 | mid = (mid + Math.imul(ah6, bl7)) | 0;
|
10121 | hi = (hi + Math.imul(ah6, bh7)) | 0;
|
10122 | lo = (lo + Math.imul(al5, bl8)) | 0;
|
10123 | mid = (mid + Math.imul(al5, bh8)) | 0;
|
10124 | mid = (mid + Math.imul(ah5, bl8)) | 0;
|
10125 | hi = (hi + Math.imul(ah5, bh8)) | 0;
|
10126 | lo = (lo + Math.imul(al4, bl9)) | 0;
|
10127 | mid = (mid + Math.imul(al4, bh9)) | 0;
|
10128 | mid = (mid + Math.imul(ah4, bl9)) | 0;
|
10129 | hi = (hi + Math.imul(ah4, bh9)) | 0;
|
10130 | var w13 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
|
10131 | c = (((hi + (mid >>> 13)) | 0) + (w13 >>> 26)) | 0;
|
10132 | w13 &= 0x3ffffff;
|
10133 | /* k = 14 */
|
10134 | lo = Math.imul(al9, bl5);
|
10135 | mid = Math.imul(al9, bh5);
|
10136 | mid = (mid + Math.imul(ah9, bl5)) | 0;
|
10137 | hi = Math.imul(ah9, bh5);
|
10138 | lo = (lo + Math.imul(al8, bl6)) | 0;
|
10139 | mid = (mid + Math.imul(al8, bh6)) | 0;
|
10140 | mid = (mid + Math.imul(ah8, bl6)) | 0;
|
10141 | hi = (hi + Math.imul(ah8, bh6)) | 0;
|
10142 | lo = (lo + Math.imul(al7, bl7)) | 0;
|
10143 | mid = (mid + Math.imul(al7, bh7)) | 0;
|
10144 | mid = (mid + Math.imul(ah7, bl7)) | 0;
|
10145 | hi = (hi + Math.imul(ah7, bh7)) | 0;
|
10146 | lo = (lo + Math.imul(al6, bl8)) | 0;
|
10147 | mid = (mid + Math.imul(al6, bh8)) | 0;
|
10148 | mid = (mid + Math.imul(ah6, bl8)) | 0;
|
10149 | hi = (hi + Math.imul(ah6, bh8)) | 0;
|
10150 | lo = (lo + Math.imul(al5, bl9)) | 0;
|
10151 | mid = (mid + Math.imul(al5, bh9)) | 0;
|
10152 | mid = (mid + Math.imul(ah5, bl9)) | 0;
|
10153 | hi = (hi + Math.imul(ah5, bh9)) | 0;
|
10154 | var w14 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
|
10155 | c = (((hi + (mid >>> 13)) | 0) + (w14 >>> 26)) | 0;
|
10156 | w14 &= 0x3ffffff;
|
10157 | /* k = 15 */
|
10158 | lo = Math.imul(al9, bl6);
|
10159 | mid = Math.imul(al9, bh6);
|
10160 | mid = (mid + Math.imul(ah9, bl6)) | 0;
|
10161 | hi = Math.imul(ah9, bh6);
|
10162 | lo = (lo + Math.imul(al8, bl7)) | 0;
|
10163 | mid = (mid + Math.imul(al8, bh7)) | 0;
|
10164 | mid = (mid + Math.imul(ah8, bl7)) | 0;
|
10165 | hi = (hi + Math.imul(ah8, bh7)) | 0;
|
10166 | lo = (lo + Math.imul(al7, bl8)) | 0;
|
10167 | mid = (mid + Math.imul(al7, bh8)) | 0;
|
10168 | mid = (mid + Math.imul(ah7, bl8)) | 0;
|
10169 | hi = (hi + Math.imul(ah7, bh8)) | 0;
|
10170 | lo = (lo + Math.imul(al6, bl9)) | 0;
|
10171 | mid = (mid + Math.imul(al6, bh9)) | 0;
|
10172 | mid = (mid + Math.imul(ah6, bl9)) | 0;
|
10173 | hi = (hi + Math.imul(ah6, bh9)) | 0;
|
10174 | var w15 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
|
10175 | c = (((hi + (mid >>> 13)) | 0) + (w15 >>> 26)) | 0;
|
10176 | w15 &= 0x3ffffff;
|
10177 | /* k = 16 */
|
10178 | lo = Math.imul(al9, bl7);
|
10179 | mid = Math.imul(al9, bh7);
|
10180 | mid = (mid + Math.imul(ah9, bl7)) | 0;
|
10181 | hi = Math.imul(ah9, bh7);
|
10182 | lo = (lo + Math.imul(al8, bl8)) | 0;
|
10183 | mid = (mid + Math.imul(al8, bh8)) | 0;
|
10184 | mid = (mid + Math.imul(ah8, bl8)) | 0;
|
10185 | hi = (hi + Math.imul(ah8, bh8)) | 0;
|
10186 | lo = (lo + Math.imul(al7, bl9)) | 0;
|
10187 | mid = (mid + Math.imul(al7, bh9)) | 0;
|
10188 | mid = (mid + Math.imul(ah7, bl9)) | 0;
|
10189 | hi = (hi + Math.imul(ah7, bh9)) | 0;
|
10190 | var w16 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
|
10191 | c = (((hi + (mid >>> 13)) | 0) + (w16 >>> 26)) | 0;
|
10192 | w16 &= 0x3ffffff;
|
10193 | /* k = 17 */
|
10194 | lo = Math.imul(al9, bl8);
|
10195 | mid = Math.imul(al9, bh8);
|
10196 | mid = (mid + Math.imul(ah9, bl8)) | 0;
|
10197 | hi = Math.imul(ah9, bh8);
|
10198 | lo = (lo + Math.imul(al8, bl9)) | 0;
|
10199 | mid = (mid + Math.imul(al8, bh9)) | 0;
|
10200 | mid = (mid + Math.imul(ah8, bl9)) | 0;
|
10201 | hi = (hi + Math.imul(ah8, bh9)) | 0;
|
10202 | var w17 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
|
10203 | c = (((hi + (mid >>> 13)) | 0) + (w17 >>> 26)) | 0;
|
10204 | w17 &= 0x3ffffff;
|
10205 | /* k = 18 */
|
10206 | lo = Math.imul(al9, bl9);
|
10207 | mid = Math.imul(al9, bh9);
|
10208 | mid = (mid + Math.imul(ah9, bl9)) | 0;
|
10209 | hi = Math.imul(ah9, bh9);
|
10210 | var w18 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
|
10211 | c = (((hi + (mid >>> 13)) | 0) + (w18 >>> 26)) | 0;
|
10212 | w18 &= 0x3ffffff;
|
10213 | o[0] = w0;
|
10214 | o[1] = w1;
|
10215 | o[2] = w2;
|
10216 | o[3] = w3;
|
10217 | o[4] = w4;
|
10218 | o[5] = w5;
|
10219 | o[6] = w6;
|
10220 | o[7] = w7;
|
10221 | o[8] = w8;
|
10222 | o[9] = w9;
|
10223 | o[10] = w10;
|
10224 | o[11] = w11;
|
10225 | o[12] = w12;
|
10226 | o[13] = w13;
|
10227 | o[14] = w14;
|
10228 | o[15] = w15;
|
10229 | o[16] = w16;
|
10230 | o[17] = w17;
|
10231 | o[18] = w18;
|
10232 | if (c !== 0) {
|
10233 | o[19] = c;
|
10234 | out.length++;
|
10235 | }
|
10236 | return out;
|
10237 | };
|
10238 |
|
10239 | // Polyfill comb
|
10240 | if (!Math.imul) {
|
10241 | comb10MulTo = smallMulTo;
|
10242 | }
|
10243 |
|
10244 | function bigMulTo (self, num, out) {
|
10245 | out.negative = num.negative ^ self.negative;
|
10246 | out.length = self.length + num.length;
|
10247 |
|
10248 | var carry = 0;
|
10249 | var hncarry = 0;
|
10250 | for (var k = 0; k < out.length - 1; k++) {
|
10251 | // Sum all words with the same `i + j = k` and accumulate `ncarry`,
|
10252 | // note that ncarry could be >= 0x3ffffff
|
10253 | var ncarry = hncarry;
|
10254 | hncarry = 0;
|
10255 | var rword = carry & 0x3ffffff;
|
10256 | var maxJ = Math.min(k, num.length - 1);
|
10257 | for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
|
10258 | var i = k - j;
|
10259 | var a = self.words[i] | 0;
|
10260 | var b = num.words[j] | 0;
|
10261 | var r = a * b;
|
10262 |
|
10263 | var lo = r & 0x3ffffff;
|
10264 | ncarry = (ncarry + ((r / 0x4000000) | 0)) | 0;
|
10265 | lo = (lo + rword) | 0;
|
10266 | rword = lo & 0x3ffffff;
|
10267 | ncarry = (ncarry + (lo >>> 26)) | 0;
|
10268 |
|
10269 | hncarry += ncarry >>> 26;
|
10270 | ncarry &= 0x3ffffff;
|
10271 | }
|
10272 | out.words[k] = rword;
|
10273 | carry = ncarry;
|
10274 | ncarry = hncarry;
|
10275 | }
|
10276 | if (carry !== 0) {
|
10277 | out.words[k] = carry;
|
10278 | } else {
|
10279 | out.length--;
|
10280 | }
|
10281 |
|
10282 | return out.strip();
|
10283 | }
|
10284 |
|
10285 | function jumboMulTo (self, num, out) {
|
10286 | var fftm = new FFTM();
|
10287 | return fftm.mulp(self, num, out);
|
10288 | }
|
10289 |
|
10290 | BN.prototype.mulTo = function mulTo (num, out) {
|
10291 | var res;
|
10292 | var len = this.length + num.length;
|
10293 | if (this.length === 10 && num.length === 10) {
|
10294 | res = comb10MulTo(this, num, out);
|
10295 | } else if (len < 63) {
|
10296 | res = smallMulTo(this, num, out);
|
10297 | } else if (len < 1024) {
|
10298 | res = bigMulTo(this, num, out);
|
10299 | } else {
|
10300 | res = jumboMulTo(this, num, out);
|
10301 | }
|
10302 |
|
10303 | return res;
|
10304 | };
|
10305 |
|
10306 | // Cooley-Tukey algorithm for FFT
|
10307 | // slightly revisited to rely on looping instead of recursion
|
10308 |
|
10309 | function FFTM (x, y) {
|
10310 | this.x = x;
|
10311 | this.y = y;
|
10312 | }
|
10313 |
|
10314 | FFTM.prototype.makeRBT = function makeRBT (N) {
|
10315 | var t = new Array(N);
|
10316 | var l = BN.prototype._countBits(N) - 1;
|
10317 | for (var i = 0; i < N; i++) {
|
10318 | t[i] = this.revBin(i, l, N);
|
10319 | }
|
10320 |
|
10321 | return t;
|
10322 | };
|
10323 |
|
10324 | // Returns binary-reversed representation of `x`
|
10325 | FFTM.prototype.revBin = function revBin (x, l, N) {
|
10326 | if (x === 0 || x === N - 1) return x;
|
10327 |
|
10328 | var rb = 0;
|
10329 | for (var i = 0; i < l; i++) {
|
10330 | rb |= (x & 1) << (l - i - 1);
|
10331 | x >>= 1;
|
10332 | }
|
10333 |
|
10334 | return rb;
|
10335 | };
|
10336 |
|
10337 | // Performs "tweedling" phase, therefore 'emulating'
|
10338 | // behaviour of the recursive algorithm
|
10339 | FFTM.prototype.permute = function permute (rbt, rws, iws, rtws, itws, N) {
|
10340 | for (var i = 0; i < N; i++) {
|
10341 | rtws[i] = rws[rbt[i]];
|
10342 | itws[i] = iws[rbt[i]];
|
10343 | }
|
10344 | };
|
10345 |
|
10346 | FFTM.prototype.transform = function transform (rws, iws, rtws, itws, N, rbt) {
|
10347 | this.permute(rbt, rws, iws, rtws, itws, N);
|
10348 |
|
10349 | for (var s = 1; s < N; s <<= 1) {
|
10350 | var l = s << 1;
|
10351 |
|
10352 | var rtwdf = Math.cos(2 * Math.PI / l);
|
10353 | var itwdf = Math.sin(2 * Math.PI / l);
|
10354 |
|
10355 | for (var p = 0; p < N; p += l) {
|
10356 | var rtwdf_ = rtwdf;
|
10357 | var itwdf_ = itwdf;
|
10358 |
|
10359 | for (var j = 0; j < s; j++) {
|
10360 | var re = rtws[p + j];
|
10361 | var ie = itws[p + j];
|
10362 |
|
10363 | var ro = rtws[p + j + s];
|
10364 | var io = itws[p + j + s];
|
10365 |
|
10366 | var rx = rtwdf_ * ro - itwdf_ * io;
|
10367 |
|
10368 | io = rtwdf_ * io + itwdf_ * ro;
|
10369 | ro = rx;
|
10370 |
|
10371 | rtws[p + j] = re + ro;
|
10372 | itws[p + j] = ie + io;
|
10373 |
|
10374 | rtws[p + j + s] = re - ro;
|
10375 | itws[p + j + s] = ie - io;
|
10376 |
|
10377 | /* jshint maxdepth : false */
|
10378 | if (j !== l) {
|
10379 | rx = rtwdf * rtwdf_ - itwdf * itwdf_;
|
10380 |
|
10381 | itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_;
|
10382 | rtwdf_ = rx;
|
10383 | }
|
10384 | }
|
10385 | }
|
10386 | }
|
10387 | };
|
10388 |
|
10389 | FFTM.prototype.guessLen13b = function guessLen13b (n, m) {
|
10390 | var N = Math.max(m, n) | 1;
|
10391 | var odd = N & 1;
|
10392 | var i = 0;
|
10393 | for (N = N / 2 | 0; N; N = N >>> 1) {
|
10394 | i++;
|
10395 | }
|
10396 |
|
10397 | return 1 << i + 1 + odd;
|
10398 | };
|
10399 |
|
10400 | FFTM.prototype.conjugate = function conjugate (rws, iws, N) {
|
10401 | if (N <= 1) return;
|
10402 |
|
10403 | for (var i = 0; i < N / 2; i++) {
|
10404 | var t = rws[i];
|
10405 |
|
10406 | rws[i] = rws[N - i - 1];
|
10407 | rws[N - i - 1] = t;
|
10408 |
|
10409 | t = iws[i];
|
10410 |
|
10411 | iws[i] = -iws[N - i - 1];
|
10412 | iws[N - i - 1] = -t;
|
10413 | }
|
10414 | };
|
10415 |
|
10416 | FFTM.prototype.normalize13b = function normalize13b (ws, N) {
|
10417 | var carry = 0;
|
10418 | for (var i = 0; i < N / 2; i++) {
|
10419 | var w = Math.round(ws[2 * i + 1] / N) * 0x2000 +
|
10420 | Math.round(ws[2 * i] / N) +
|
10421 | carry;
|
10422 |
|
10423 | ws[i] = w & 0x3ffffff;
|
10424 |
|
10425 | if (w < 0x4000000) {
|
10426 | carry = 0;
|
10427 | } else {
|
10428 | carry = w / 0x4000000 | 0;
|
10429 | }
|
10430 | }
|
10431 |
|
10432 | return ws;
|
10433 | };
|
10434 |
|
10435 | FFTM.prototype.convert13b = function convert13b (ws, len, rws, N) {
|
10436 | var carry = 0;
|
10437 | for (var i = 0; i < len; i++) {
|
10438 | carry = carry + (ws[i] | 0);
|
10439 |
|
10440 | rws[2 * i] = carry & 0x1fff; carry = carry >>> 13;
|
10441 | rws[2 * i + 1] = carry & 0x1fff; carry = carry >>> 13;
|
10442 | }
|
10443 |
|
10444 | // Pad with zeroes
|
10445 | for (i = 2 * len; i < N; ++i) {
|
10446 | rws[i] = 0;
|
10447 | }
|
10448 |
|
10449 | assert(carry === 0);
|
10450 | assert((carry & ~0x1fff) === 0);
|
10451 | };
|
10452 |
|
10453 | FFTM.prototype.stub = function stub (N) {
|
10454 | var ph = new Array(N);
|
10455 | for (var i = 0; i < N; i++) {
|
10456 | ph[i] = 0;
|
10457 | }
|
10458 |
|
10459 | return ph;
|
10460 | };
|
10461 |
|
10462 | FFTM.prototype.mulp = function mulp (x, y, out) {
|
10463 | var N = 2 * this.guessLen13b(x.length, y.length);
|
10464 |
|
10465 | var rbt = this.makeRBT(N);
|
10466 |
|
10467 | var _ = this.stub(N);
|
10468 |
|
10469 | var rws = new Array(N);
|
10470 | var rwst = new Array(N);
|
10471 | var iwst = new Array(N);
|
10472 |
|
10473 | var nrws = new Array(N);
|
10474 | var nrwst = new Array(N);
|
10475 | var niwst = new Array(N);
|
10476 |
|
10477 | var rmws = out.words;
|
10478 | rmws.length = N;
|
10479 |
|
10480 | this.convert13b(x.words, x.length, rws, N);
|
10481 | this.convert13b(y.words, y.length, nrws, N);
|
10482 |
|
10483 | this.transform(rws, _, rwst, iwst, N, rbt);
|
10484 | this.transform(nrws, _, nrwst, niwst, N, rbt);
|
10485 |
|
10486 | for (var i = 0; i < N; i++) {
|
10487 | var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i];
|
10488 | iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i];
|
10489 | rwst[i] = rx;
|
10490 | }
|
10491 |
|
10492 | this.conjugate(rwst, iwst, N);
|
10493 | this.transform(rwst, iwst, rmws, _, N, rbt);
|
10494 | this.conjugate(rmws, _, N);
|
10495 | this.normalize13b(rmws, N);
|
10496 |
|
10497 | out.negative = x.negative ^ y.negative;
|
10498 | out.length = x.length + y.length;
|
10499 | return out.strip();
|
10500 | };
|
10501 |
|
10502 | // Multiply `this` by `num`
|
10503 | BN.prototype.mul = function mul (num) {
|
10504 | var out = new BN(null);
|
10505 | out.words = new Array(this.length + num.length);
|
10506 | return this.mulTo(num, out);
|
10507 | };
|
10508 |
|
10509 | // Multiply employing FFT
|
10510 | BN.prototype.mulf = function mulf (num) {
|
10511 | var out = new BN(null);
|
10512 | out.words = new Array(this.length + num.length);
|
10513 | return jumboMulTo(this, num, out);
|
10514 | };
|
10515 |
|
10516 | // In-place Multiplication
|
10517 | BN.prototype.imul = function imul (num) {
|
10518 | return this.clone().mulTo(num, this);
|
10519 | };
|
10520 |
|
10521 | BN.prototype.imuln = function imuln (num) {
|
10522 | assert(typeof num === 'number');
|
10523 | assert(num < 0x4000000);
|
10524 |
|
10525 | // Carry
|
10526 | var carry = 0;
|
10527 | for (var i = 0; i < this.length; i++) {
|
10528 | var w = (this.words[i] | 0) * num;
|
10529 | var lo = (w & 0x3ffffff) + (carry & 0x3ffffff);
|
10530 | carry >>= 26;
|
10531 | carry += (w / 0x4000000) | 0;
|
10532 | // NOTE: lo is 27bit maximum
|
10533 | carry += lo >>> 26;
|
10534 | this.words[i] = lo & 0x3ffffff;
|
10535 | }
|
10536 |
|
10537 | if (carry !== 0) {
|
10538 | this.words[i] = carry;
|
10539 | this.length++;
|
10540 | }
|
10541 |
|
10542 | return this;
|
10543 | };
|
10544 |
|
10545 | BN.prototype.muln = function muln (num) {
|
10546 | return this.clone().imuln(num);
|
10547 | };
|
10548 |
|
10549 | // `this` * `this`
|
10550 | BN.prototype.sqr = function sqr () {
|
10551 | return this.mul(this);
|
10552 | };
|
10553 |
|
10554 | // `this` * `this` in-place
|
10555 | BN.prototype.isqr = function isqr () {
|
10556 | return this.imul(this.clone());
|
10557 | };
|
10558 |
|
10559 | // Math.pow(`this`, `num`)
|
10560 | BN.prototype.pow = function pow (num) {
|
10561 | var w = toBitArray(num);
|
10562 | if (w.length === 0) return new BN(1);
|
10563 |
|
10564 | // Skip leading zeroes
|
10565 | var res = this;
|
10566 | for (var i = 0; i < w.length; i++, res = res.sqr()) {
|
10567 | if (w[i] !== 0) break;
|
10568 | }
|
10569 |
|
10570 | if (++i < w.length) {
|
10571 | for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) {
|
10572 | if (w[i] === 0) continue;
|
10573 |
|
10574 | res = res.mul(q);
|
10575 | }
|
10576 | }
|
10577 |
|
10578 | return res;
|
10579 | };
|
10580 |
|
10581 | // Shift-left in-place
|
10582 | BN.prototype.iushln = function iushln (bits) {
|
10583 | assert(typeof bits === 'number' && bits >= 0);
|
10584 | var r = bits % 26;
|
10585 | var s = (bits - r) / 26;
|
10586 | var carryMask = (0x3ffffff >>> (26 - r)) << (26 - r);
|
10587 | var i;
|
10588 |
|
10589 | if (r !== 0) {
|
10590 | var carry = 0;
|
10591 |
|
10592 | for (i = 0; i < this.length; i++) {
|
10593 | var newCarry = this.words[i] & carryMask;
|
10594 | var c = ((this.words[i] | 0) - newCarry) << r;
|
10595 | this.words[i] = c | carry;
|
10596 | carry = newCarry >>> (26 - r);
|
10597 | }
|
10598 |
|
10599 | if (carry) {
|
10600 | this.words[i] = carry;
|
10601 | this.length++;
|
10602 | }
|
10603 | }
|
10604 |
|
10605 | if (s !== 0) {
|
10606 | for (i = this.length - 1; i >= 0; i--) {
|
10607 | this.words[i + s] = this.words[i];
|
10608 | }
|
10609 |
|
10610 | for (i = 0; i < s; i++) {
|
10611 | this.words[i] = 0;
|
10612 | }
|
10613 |
|
10614 | this.length += s;
|
10615 | }
|
10616 |
|
10617 | return this.strip();
|
10618 | };
|
10619 |
|
10620 | BN.prototype.ishln = function ishln (bits) {
|
10621 | // TODO(indutny): implement me
|
10622 | assert(this.negative === 0);
|
10623 | return this.iushln(bits);
|
10624 | };
|
10625 |
|
10626 | // Shift-right in-place
|
10627 | // NOTE: `hint` is a lowest bit before trailing zeroes
|
10628 | // NOTE: if `extended` is present - it will be filled with destroyed bits
|
10629 | BN.prototype.iushrn = function iushrn (bits, hint, extended) {
|
10630 | assert(typeof bits === 'number' && bits >= 0);
|
10631 | var h;
|
10632 | if (hint) {
|
10633 | h = (hint - (hint % 26)) / 26;
|
10634 | } else {
|
10635 | h = 0;
|
10636 | }
|
10637 |
|
10638 | var r = bits % 26;
|
10639 | var s = Math.min((bits - r) / 26, this.length);
|
10640 | var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r);
|
10641 | var maskedWords = extended;
|
10642 |
|
10643 | h -= s;
|
10644 | h = Math.max(0, h);
|
10645 |
|
10646 | // Extended mode, copy masked part
|
10647 | if (maskedWords) {
|
10648 | for (var i = 0; i < s; i++) {
|
10649 | maskedWords.words[i] = this.words[i];
|
10650 | }
|
10651 | maskedWords.length = s;
|
10652 | }
|
10653 |
|
10654 | if (s === 0) {
|
10655 | // No-op, we should not move anything at all
|
10656 | } else if (this.length > s) {
|
10657 | this.length -= s;
|
10658 | for (i = 0; i < this.length; i++) {
|
10659 | this.words[i] = this.words[i + s];
|
10660 | }
|
10661 | } else {
|
10662 | this.words[0] = 0;
|
10663 | this.length = 1;
|
10664 | }
|
10665 |
|
10666 | var carry = 0;
|
10667 | for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {
|
10668 | var word = this.words[i] | 0;
|
10669 | this.words[i] = (carry << (26 - r)) | (word >>> r);
|
10670 | carry = word & mask;
|
10671 | }
|
10672 |
|
10673 | // Push carried bits as a mask
|
10674 | if (maskedWords && carry !== 0) {
|
10675 | maskedWords.words[maskedWords.length++] = carry;
|
10676 | }
|
10677 |
|
10678 | if (this.length === 0) {
|
10679 | this.words[0] = 0;
|
10680 | this.length = 1;
|
10681 | }
|
10682 |
|
10683 | return this.strip();
|
10684 | };
|
10685 |
|
10686 | BN.prototype.ishrn = function ishrn (bits, hint, extended) {
|
10687 | // TODO(indutny): implement me
|
10688 | assert(this.negative === 0);
|
10689 | return this.iushrn(bits, hint, extended);
|
10690 | };
|
10691 |
|
10692 | // Shift-left
|
10693 | BN.prototype.shln = function shln (bits) {
|
10694 | return this.clone().ishln(bits);
|
10695 | };
|
10696 |
|
10697 | BN.prototype.ushln = function ushln (bits) {
|
10698 | return this.clone().iushln(bits);
|
10699 | };
|
10700 |
|
10701 | // Shift-right
|
10702 | BN.prototype.shrn = function shrn (bits) {
|
10703 | return this.clone().ishrn(bits);
|
10704 | };
|
10705 |
|
10706 | BN.prototype.ushrn = function ushrn (bits) {
|
10707 | return this.clone().iushrn(bits);
|
10708 | };
|
10709 |
|
10710 | // Test if n bit is set
|
10711 | BN.prototype.testn = function testn (bit) {
|
10712 | assert(typeof bit === 'number' && bit >= 0);
|
10713 | var r = bit % 26;
|
10714 | var s = (bit - r) / 26;
|
10715 | var q = 1 << r;
|
10716 |
|
10717 | // Fast case: bit is much higher than all existing words
|
10718 | if (this.length <= s) return false;
|
10719 |
|
10720 | // Check bit and return
|
10721 | var w = this.words[s];
|
10722 |
|
10723 | return !!(w & q);
|
10724 | };
|
10725 |
|
10726 | // Return only lowers bits of number (in-place)
|
10727 | BN.prototype.imaskn = function imaskn (bits) {
|
10728 | assert(typeof bits === 'number' && bits >= 0);
|
10729 | var r = bits % 26;
|
10730 | var s = (bits - r) / 26;
|
10731 |
|
10732 | assert(this.negative === 0, 'imaskn works only with positive numbers');
|
10733 |
|
10734 | if (this.length <= s) {
|
10735 | return this;
|
10736 | }
|
10737 |
|
10738 | if (r !== 0) {
|
10739 | s++;
|
10740 | }
|
10741 | this.length = Math.min(s, this.length);
|
10742 |
|
10743 | if (r !== 0) {
|
10744 | var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r);
|
10745 | this.words[this.length - 1] &= mask;
|
10746 | }
|
10747 |
|
10748 | return this.strip();
|
10749 | };
|
10750 |
|
10751 | // Return only lowers bits of number
|
10752 | BN.prototype.maskn = function maskn (bits) {
|
10753 | return this.clone().imaskn(bits);
|
10754 | };
|
10755 |
|
10756 | // Add plain number `num` to `this`
|
10757 | BN.prototype.iaddn = function iaddn (num) {
|
10758 | assert(typeof num === 'number');
|
10759 | assert(num < 0x4000000);
|
10760 | if (num < 0) return this.isubn(-num);
|
10761 |
|
10762 | // Possible sign change
|
10763 | if (this.negative !== 0) {
|
10764 | if (this.length === 1 && (this.words[0] | 0) < num) {
|
10765 | this.words[0] = num - (this.words[0] | 0);
|
10766 | this.negative = 0;
|
10767 | return this;
|
10768 | }
|
10769 |
|
10770 | this.negative = 0;
|
10771 | this.isubn(num);
|
10772 | this.negative = 1;
|
10773 | return this;
|
10774 | }
|
10775 |
|
10776 | // Add without checks
|
10777 | return this._iaddn(num);
|
10778 | };
|
10779 |
|
10780 | BN.prototype._iaddn = function _iaddn (num) {
|
10781 | this.words[0] += num;
|
10782 |
|
10783 | // Carry
|
10784 | for (var i = 0; i < this.length && this.words[i] >= 0x4000000; i++) {
|
10785 | this.words[i] -= 0x4000000;
|
10786 | if (i === this.length - 1) {
|
10787 | this.words[i + 1] = 1;
|
10788 | } else {
|
10789 | this.words[i + 1]++;
|
10790 | }
|
10791 | }
|
10792 | this.length = Math.max(this.length, i + 1);
|
10793 |
|
10794 | return this;
|
10795 | };
|
10796 |
|
10797 | // Subtract plain number `num` from `this`
|
10798 | BN.prototype.isubn = function isubn (num) {
|
10799 | assert(typeof num === 'number');
|
10800 | assert(num < 0x4000000);
|
10801 | if (num < 0) return this.iaddn(-num);
|
10802 |
|
10803 | if (this.negative !== 0) {
|
10804 | this.negative = 0;
|
10805 | this.iaddn(num);
|
10806 | this.negative = 1;
|
10807 | return this;
|
10808 | }
|
10809 |
|
10810 | this.words[0] -= num;
|
10811 |
|
10812 | if (this.length === 1 && this.words[0] < 0) {
|
10813 | this.words[0] = -this.words[0];
|
10814 | this.negative = 1;
|
10815 | } else {
|
10816 | // Carry
|
10817 | for (var i = 0; i < this.length && this.words[i] < 0; i++) {
|
10818 | this.words[i] += 0x4000000;
|
10819 | this.words[i + 1] -= 1;
|
10820 | }
|
10821 | }
|
10822 |
|
10823 | return this.strip();
|
10824 | };
|
10825 |
|
10826 | BN.prototype.addn = function addn (num) {
|
10827 | return this.clone().iaddn(num);
|
10828 | };
|
10829 |
|
10830 | BN.prototype.subn = function subn (num) {
|
10831 | return this.clone().isubn(num);
|
10832 | };
|
10833 |
|
10834 | BN.prototype.iabs = function iabs () {
|
10835 | this.negative = 0;
|
10836 |
|
10837 | return this;
|
10838 | };
|
10839 |
|
10840 | BN.prototype.abs = function abs () {
|
10841 | return this.clone().iabs();
|
10842 | };
|
10843 |
|
10844 | BN.prototype._ishlnsubmul = function _ishlnsubmul (num, mul, shift) {
|
10845 | var len = num.length + shift;
|
10846 | var i;
|
10847 |
|
10848 | this._expand(len);
|
10849 |
|
10850 | var w;
|
10851 | var carry = 0;
|
10852 | for (i = 0; i < num.length; i++) {
|
10853 | w = (this.words[i + shift] | 0) + carry;
|
10854 | var right = (num.words[i] | 0) * mul;
|
10855 | w -= right & 0x3ffffff;
|
10856 | carry = (w >> 26) - ((right / 0x4000000) | 0);
|
10857 | this.words[i + shift] = w & 0x3ffffff;
|
10858 | }
|
10859 | for (; i < this.length - shift; i++) {
|
10860 | w = (this.words[i + shift] | 0) + carry;
|
10861 | carry = w >> 26;
|
10862 | this.words[i + shift] = w & 0x3ffffff;
|
10863 | }
|
10864 |
|
10865 | if (carry === 0) return this.strip();
|
10866 |
|
10867 | // Subtraction overflow
|
10868 | assert(carry === -1);
|
10869 | carry = 0;
|
10870 | for (i = 0; i < this.length; i++) {
|
10871 | w = -(this.words[i] | 0) + carry;
|
10872 | carry = w >> 26;
|
10873 | this.words[i] = w & 0x3ffffff;
|
10874 | }
|
10875 | this.negative = 1;
|
10876 |
|
10877 | return this.strip();
|
10878 | };
|
10879 |
|
10880 | BN.prototype._wordDiv = function _wordDiv (num, mode) {
|
10881 | var shift = this.length - num.length;
|
10882 |
|
10883 | var a = this.clone();
|
10884 | var b = num;
|
10885 |
|
10886 | // Normalize
|
10887 | var bhi = b.words[b.length - 1] | 0;
|
10888 | var bhiBits = this._countBits(bhi);
|
10889 | shift = 26 - bhiBits;
|
10890 | if (shift !== 0) {
|
10891 | b = b.ushln(shift);
|
10892 | a.iushln(shift);
|
10893 | bhi = b.words[b.length - 1] | 0;
|
10894 | }
|
10895 |
|
10896 | // Initialize quotient
|
10897 | var m = a.length - b.length;
|
10898 | var q;
|
10899 |
|
10900 | if (mode !== 'mod') {
|
10901 | q = new BN(null);
|
10902 | q.length = m + 1;
|
10903 | q.words = new Array(q.length);
|
10904 | for (var i = 0; i < q.length; i++) {
|
10905 | q.words[i] = 0;
|
10906 | }
|
10907 | }
|
10908 |
|
10909 | var diff = a.clone()._ishlnsubmul(b, 1, m);
|
10910 | if (diff.negative === 0) {
|
10911 | a = diff;
|
10912 | if (q) {
|
10913 | q.words[m] = 1;
|
10914 | }
|
10915 | }
|
10916 |
|
10917 | for (var j = m - 1; j >= 0; j--) {
|
10918 | var qj = (a.words[b.length + j] | 0) * 0x4000000 +
|
10919 | (a.words[b.length + j - 1] | 0);
|
10920 |
|
10921 | // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max
|
10922 | // (0x7ffffff)
|
10923 | qj = Math.min((qj / bhi) | 0, 0x3ffffff);
|
10924 |
|
10925 | a._ishlnsubmul(b, qj, j);
|
10926 | while (a.negative !== 0) {
|
10927 | qj--;
|
10928 | a.negative = 0;
|
10929 | a._ishlnsubmul(b, 1, j);
|
10930 | if (!a.isZero()) {
|
10931 | a.negative ^= 1;
|
10932 | }
|
10933 | }
|
10934 | if (q) {
|
10935 | q.words[j] = qj;
|
10936 | }
|
10937 | }
|
10938 | if (q) {
|
10939 | q.strip();
|
10940 | }
|
10941 | a.strip();
|
10942 |
|
10943 | // Denormalize
|
10944 | if (mode !== 'div' && shift !== 0) {
|
10945 | a.iushrn(shift);
|
10946 | }
|
10947 |
|
10948 | return {
|
10949 | div: q || null,
|
10950 | mod: a
|
10951 | };
|
10952 | };
|
10953 |
|
10954 | // NOTE: 1) `mode` can be set to `mod` to request mod only,
|
10955 | // to `div` to request div only, or be absent to
|
10956 | // request both div & mod
|
10957 | // 2) `positive` is true if unsigned mod is requested
|
10958 | BN.prototype.divmod = function divmod (num, mode, positive) {
|
10959 | assert(!num.isZero());
|
10960 |
|
10961 | if (this.isZero()) {
|
10962 | return {
|
10963 | div: new BN(0),
|
10964 | mod: new BN(0)
|
10965 | };
|
10966 | }
|
10967 |
|
10968 | var div, mod, res;
|
10969 | if (this.negative !== 0 && num.negative === 0) {
|
10970 | res = this.neg().divmod(num, mode);
|
10971 |
|
10972 | if (mode !== 'mod') {
|
10973 | div = res.div.neg();
|
10974 | }
|
10975 |
|
10976 | if (mode !== 'div') {
|
10977 | mod = res.mod.neg();
|
10978 | if (positive && mod.negative !== 0) {
|
10979 | mod.iadd(num);
|
10980 | }
|
10981 | }
|
10982 |
|
10983 | return {
|
10984 | div: div,
|
10985 | mod: mod
|
10986 | };
|
10987 | }
|
10988 |
|
10989 | if (this.negative === 0 && num.negative !== 0) {
|
10990 | res = this.divmod(num.neg(), mode);
|
10991 |
|
10992 | if (mode !== 'mod') {
|
10993 | div = res.div.neg();
|
10994 | }
|
10995 |
|
10996 | return {
|
10997 | div: div,
|
10998 | mod: res.mod
|
10999 | };
|
11000 | }
|
11001 |
|
11002 | if ((this.negative & num.negative) !== 0) {
|
11003 | res = this.neg().divmod(num.neg(), mode);
|
11004 |
|
11005 | if (mode !== 'div') {
|
11006 | mod = res.mod.neg();
|
11007 | if (positive && mod.negative !== 0) {
|
11008 | mod.isub(num);
|
11009 | }
|
11010 | }
|
11011 |
|
11012 | return {
|
11013 | div: res.div,
|
11014 | mod: mod
|
11015 | };
|
11016 | }
|
11017 |
|
11018 | // Both numbers are positive at this point
|
11019 |
|
11020 | // Strip both numbers to approximate shift value
|
11021 | if (num.length > this.length || this.cmp(num) < 0) {
|
11022 | return {
|
11023 | div: new BN(0),
|
11024 | mod: this
|
11025 | };
|
11026 | }
|
11027 |
|
11028 | // Very short reduction
|
11029 | if (num.length === 1) {
|
11030 | if (mode === 'div') {
|
11031 | return {
|
11032 | div: this.divn(num.words[0]),
|
11033 | mod: null
|
11034 | };
|
11035 | }
|
11036 |
|
11037 | if (mode === 'mod') {
|
11038 | return {
|
11039 | div: null,
|
11040 | mod: new BN(this.modn(num.words[0]))
|
11041 | };
|
11042 | }
|
11043 |
|
11044 | return {
|
11045 | div: this.divn(num.words[0]),
|
11046 | mod: new BN(this.modn(num.words[0]))
|
11047 | };
|
11048 | }
|
11049 |
|
11050 | return this._wordDiv(num, mode);
|
11051 | };
|
11052 |
|
11053 | // Find `this` / `num`
|
11054 | BN.prototype.div = function div (num) {
|
11055 | return this.divmod(num, 'div', false).div;
|
11056 | };
|
11057 |
|
11058 | // Find `this` % `num`
|
11059 | BN.prototype.mod = function mod (num) {
|
11060 | return this.divmod(num, 'mod', false).mod;
|
11061 | };
|
11062 |
|
11063 | BN.prototype.umod = function umod (num) {
|
11064 | return this.divmod(num, 'mod', true).mod;
|
11065 | };
|
11066 |
|
11067 | // Find Round(`this` / `num`)
|
11068 | BN.prototype.divRound = function divRound (num) {
|
11069 | var dm = this.divmod(num);
|
11070 |
|
11071 | // Fast case - exact division
|
11072 | if (dm.mod.isZero()) return dm.div;
|
11073 |
|
11074 | var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
|
11075 |
|
11076 | var half = num.ushrn(1);
|
11077 | var r2 = num.andln(1);
|
11078 | var cmp = mod.cmp(half);
|
11079 |
|
11080 | // Round down
|
11081 | if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div;
|
11082 |
|
11083 | // Round up
|
11084 | return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
|
11085 | };
|
11086 |
|
11087 | BN.prototype.modn = function modn (num) {
|
11088 | assert(num <= 0x3ffffff);
|
11089 | var p = (1 << 26) % num;
|
11090 |
|
11091 | var acc = 0;
|
11092 | for (var i = this.length - 1; i >= 0; i--) {
|
11093 | acc = (p * acc + (this.words[i] | 0)) % num;
|
11094 | }
|
11095 |
|
11096 | return acc;
|
11097 | };
|
11098 |
|
11099 | // In-place division by number
|
11100 | BN.prototype.idivn = function idivn (num) {
|
11101 | assert(num <= 0x3ffffff);
|
11102 |
|
11103 | var carry = 0;
|
11104 | for (var i = this.length - 1; i >= 0; i--) {
|
11105 | var w = (this.words[i] | 0) + carry * 0x4000000;
|
11106 | this.words[i] = (w / num) | 0;
|
11107 | carry = w % num;
|
11108 | }
|
11109 |
|
11110 | return this.strip();
|
11111 | };
|
11112 |
|
11113 | BN.prototype.divn = function divn (num) {
|
11114 | return this.clone().idivn(num);
|
11115 | };
|
11116 |
|
11117 | BN.prototype.egcd = function egcd (p) {
|
11118 | assert(p.negative === 0);
|
11119 | assert(!p.isZero());
|
11120 |
|
11121 | var x = this;
|
11122 | var y = p.clone();
|
11123 |
|
11124 | if (x.negative !== 0) {
|
11125 | x = x.umod(p);
|
11126 | } else {
|
11127 | x = x.clone();
|
11128 | }
|
11129 |
|
11130 | // A * x + B * y = x
|
11131 | var A = new BN(1);
|
11132 | var B = new BN(0);
|
11133 |
|
11134 | // C * x + D * y = y
|
11135 | var C = new BN(0);
|
11136 | var D = new BN(1);
|
11137 |
|
11138 | var g = 0;
|
11139 |
|
11140 | while (x.isEven() && y.isEven()) {
|
11141 | x.iushrn(1);
|
11142 | y.iushrn(1);
|
11143 | ++g;
|
11144 | }
|
11145 |
|
11146 | var yp = y.clone();
|
11147 | var xp = x.clone();
|
11148 |
|
11149 | while (!x.isZero()) {
|
11150 | for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
|
11151 | if (i > 0) {
|
11152 | x.iushrn(i);
|
11153 | while (i-- > 0) {
|
11154 | if (A.isOdd() || B.isOdd()) {
|
11155 | A.iadd(yp);
|
11156 | B.isub(xp);
|
11157 | }
|
11158 |
|
11159 | A.iushrn(1);
|
11160 | B.iushrn(1);
|
11161 | }
|
11162 | }
|
11163 |
|
11164 | for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
|
11165 | if (j > 0) {
|
11166 | y.iushrn(j);
|
11167 | while (j-- > 0) {
|
11168 | if (C.isOdd() || D.isOdd()) {
|
11169 | C.iadd(yp);
|
11170 | D.isub(xp);
|
11171 | }
|
11172 |
|
11173 | C.iushrn(1);
|
11174 | D.iushrn(1);
|
11175 | }
|
11176 | }
|
11177 |
|
11178 | if (x.cmp(y) >= 0) {
|
11179 | x.isub(y);
|
11180 | A.isub(C);
|
11181 | B.isub(D);
|
11182 | } else {
|
11183 | y.isub(x);
|
11184 | C.isub(A);
|
11185 | D.isub(B);
|
11186 | }
|
11187 | }
|
11188 |
|
11189 | return {
|
11190 | a: C,
|
11191 | b: D,
|
11192 | gcd: y.iushln(g)
|
11193 | };
|
11194 | };
|
11195 |
|
11196 | // This is reduced incarnation of the binary EEA
|
11197 | // above, designated to invert members of the
|
11198 | // _prime_ fields F(p) at a maximal speed
|
11199 | BN.prototype._invmp = function _invmp (p) {
|
11200 | assert(p.negative === 0);
|
11201 | assert(!p.isZero());
|
11202 |
|
11203 | var a = this;
|
11204 | var b = p.clone();
|
11205 |
|
11206 | if (a.negative !== 0) {
|
11207 | a = a.umod(p);
|
11208 | } else {
|
11209 | a = a.clone();
|
11210 | }
|
11211 |
|
11212 | var x1 = new BN(1);
|
11213 | var x2 = new BN(0);
|
11214 |
|
11215 | var delta = b.clone();
|
11216 |
|
11217 | while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
|
11218 | for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
|
11219 | if (i > 0) {
|
11220 | a.iushrn(i);
|
11221 | while (i-- > 0) {
|
11222 | if (x1.isOdd()) {
|
11223 | x1.iadd(delta);
|
11224 | }
|
11225 |
|
11226 | x1.iushrn(1);
|
11227 | }
|
11228 | }
|
11229 |
|
11230 | for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
|
11231 | if (j > 0) {
|
11232 | b.iushrn(j);
|
11233 | while (j-- > 0) {
|
11234 | if (x2.isOdd()) {
|
11235 | x2.iadd(delta);
|
11236 | }
|
11237 |
|
11238 | x2.iushrn(1);
|
11239 | }
|
11240 | }
|
11241 |
|
11242 | if (a.cmp(b) >= 0) {
|
11243 | a.isub(b);
|
11244 | x1.isub(x2);
|
11245 | } else {
|
11246 | b.isub(a);
|
11247 | x2.isub(x1);
|
11248 | }
|
11249 | }
|
11250 |
|
11251 | var res;
|
11252 | if (a.cmpn(1) === 0) {
|
11253 | res = x1;
|
11254 | } else {
|
11255 | res = x2;
|
11256 | }
|
11257 |
|
11258 | if (res.cmpn(0) < 0) {
|
11259 | res.iadd(p);
|
11260 | }
|
11261 |
|
11262 | return res;
|
11263 | };
|
11264 |
|
11265 | BN.prototype.gcd = function gcd (num) {
|
11266 | if (this.isZero()) return num.abs();
|
11267 | if (num.isZero()) return this.abs();
|
11268 |
|
11269 | var a = this.clone();
|
11270 | var b = num.clone();
|
11271 | a.negative = 0;
|
11272 | b.negative = 0;
|
11273 |
|
11274 | // Remove common factor of two
|
11275 | for (var shift = 0; a.isEven() && b.isEven(); shift++) {
|
11276 | a.iushrn(1);
|
11277 | b.iushrn(1);
|
11278 | }
|
11279 |
|
11280 | do {
|
11281 | while (a.isEven()) {
|
11282 | a.iushrn(1);
|
11283 | }
|
11284 | while (b.isEven()) {
|
11285 | b.iushrn(1);
|
11286 | }
|
11287 |
|
11288 | var r = a.cmp(b);
|
11289 | if (r < 0) {
|
11290 | // Swap `a` and `b` to make `a` always bigger than `b`
|
11291 | var t = a;
|
11292 | a = b;
|
11293 | b = t;
|
11294 | } else if (r === 0 || b.cmpn(1) === 0) {
|
11295 | break;
|
11296 | }
|
11297 |
|
11298 | a.isub(b);
|
11299 | } while (true);
|
11300 |
|
11301 | return b.iushln(shift);
|
11302 | };
|
11303 |
|
11304 | // Invert number in the field F(num)
|
11305 | BN.prototype.invm = function invm (num) {
|
11306 | return this.egcd(num).a.umod(num);
|
11307 | };
|
11308 |
|
11309 | BN.prototype.isEven = function isEven () {
|
11310 | return (this.words[0] & 1) === 0;
|
11311 | };
|
11312 |
|
11313 | BN.prototype.isOdd = function isOdd () {
|
11314 | return (this.words[0] & 1) === 1;
|
11315 | };
|
11316 |
|
11317 | // And first word and num
|
11318 | BN.prototype.andln = function andln (num) {
|
11319 | return this.words[0] & num;
|
11320 | };
|
11321 |
|
11322 | // Increment at the bit position in-line
|
11323 | BN.prototype.bincn = function bincn (bit) {
|
11324 | assert(typeof bit === 'number');
|
11325 | var r = bit % 26;
|
11326 | var s = (bit - r) / 26;
|
11327 | var q = 1 << r;
|
11328 |
|
11329 | // Fast case: bit is much higher than all existing words
|
11330 | if (this.length <= s) {
|
11331 | this._expand(s + 1);
|
11332 | this.words[s] |= q;
|
11333 | return this;
|
11334 | }
|
11335 |
|
11336 | // Add bit and propagate, if needed
|
11337 | var carry = q;
|
11338 | for (var i = s; carry !== 0 && i < this.length; i++) {
|
11339 | var w = this.words[i] | 0;
|
11340 | w += carry;
|
11341 | carry = w >>> 26;
|
11342 | w &= 0x3ffffff;
|
11343 | this.words[i] = w;
|
11344 | }
|
11345 | if (carry !== 0) {
|
11346 | this.words[i] = carry;
|
11347 | this.length++;
|
11348 | }
|
11349 | return this;
|
11350 | };
|
11351 |
|
11352 | BN.prototype.isZero = function isZero () {
|
11353 | return this.length === 1 && this.words[0] === 0;
|
11354 | };
|
11355 |
|
11356 | BN.prototype.cmpn = function cmpn (num) {
|
11357 | var negative = num < 0;
|
11358 |
|
11359 | if (this.negative !== 0 && !negative) return -1;
|
11360 | if (this.negative === 0 && negative) return 1;
|
11361 |
|
11362 | this.strip();
|
11363 |
|
11364 | var res;
|
11365 | if (this.length > 1) {
|
11366 | res = 1;
|
11367 | } else {
|
11368 | if (negative) {
|
11369 | num = -num;
|
11370 | }
|
11371 |
|
11372 | assert(num <= 0x3ffffff, 'Number is too big');
|
11373 |
|
11374 | var w = this.words[0] | 0;
|
11375 | res = w === num ? 0 : w < num ? -1 : 1;
|
11376 | }
|
11377 | if (this.negative !== 0) return -res | 0;
|
11378 | return res;
|
11379 | };
|
11380 |
|
11381 | // Compare two numbers and return:
|
11382 | // 1 - if `this` > `num`
|
11383 | // 0 - if `this` == `num`
|
11384 | // -1 - if `this` < `num`
|
11385 | BN.prototype.cmp = function cmp (num) {
|
11386 | if (this.negative !== 0 && num.negative === 0) return -1;
|
11387 | if (this.negative === 0 && num.negative !== 0) return 1;
|
11388 |
|
11389 | var res = this.ucmp(num);
|
11390 | if (this.negative !== 0) return -res | 0;
|
11391 | return res;
|
11392 | };
|
11393 |
|
11394 | // Unsigned comparison
|
11395 | BN.prototype.ucmp = function ucmp (num) {
|
11396 | // At this point both numbers have the same sign
|
11397 | if (this.length > num.length) return 1;
|
11398 | if (this.length < num.length) return -1;
|
11399 |
|
11400 | var res = 0;
|
11401 | for (var i = this.length - 1; i >= 0; i--) {
|
11402 | var a = this.words[i] | 0;
|
11403 | var b = num.words[i] | 0;
|
11404 |
|
11405 | if (a === b) continue;
|
11406 | if (a < b) {
|
11407 | res = -1;
|
11408 | } else if (a > b) {
|
11409 | res = 1;
|
11410 | }
|
11411 | break;
|
11412 | }
|
11413 | return res;
|
11414 | };
|
11415 |
|
11416 | BN.prototype.gtn = function gtn (num) {
|
11417 | return this.cmpn(num) === 1;
|
11418 | };
|
11419 |
|
11420 | BN.prototype.gt = function gt (num) {
|
11421 | return this.cmp(num) === 1;
|
11422 | };
|
11423 |
|
11424 | BN.prototype.gten = function gten (num) {
|
11425 | return this.cmpn(num) >= 0;
|
11426 | };
|
11427 |
|
11428 | BN.prototype.gte = function gte (num) {
|
11429 | return this.cmp(num) >= 0;
|
11430 | };
|
11431 |
|
11432 | BN.prototype.ltn = function ltn (num) {
|
11433 | return this.cmpn(num) === -1;
|
11434 | };
|
11435 |
|
11436 | BN.prototype.lt = function lt (num) {
|
11437 | return this.cmp(num) === -1;
|
11438 | };
|
11439 |
|
11440 | BN.prototype.lten = function lten (num) {
|
11441 | return this.cmpn(num) <= 0;
|
11442 | };
|
11443 |
|
11444 | BN.prototype.lte = function lte (num) {
|
11445 | return this.cmp(num) <= 0;
|
11446 | };
|
11447 |
|
11448 | BN.prototype.eqn = function eqn (num) {
|
11449 | return this.cmpn(num) === 0;
|
11450 | };
|
11451 |
|
11452 | BN.prototype.eq = function eq (num) {
|
11453 | return this.cmp(num) === 0;
|
11454 | };
|
11455 |
|
11456 | //
|
11457 | // A reduce context, could be using montgomery or something better, depending
|
11458 | // on the `m` itself.
|
11459 | //
|
11460 | BN.red = function red (num) {
|
11461 | return new Red(num);
|
11462 | };
|
11463 |
|
11464 | BN.prototype.toRed = function toRed (ctx) {
|
11465 | assert(!this.red, 'Already a number in reduction context');
|
11466 | assert(this.negative === 0, 'red works only with positives');
|
11467 | return ctx.convertTo(this)._forceRed(ctx);
|
11468 | };
|
11469 |
|
11470 | BN.prototype.fromRed = function fromRed () {
|
11471 | assert(this.red, 'fromRed works only with numbers in reduction context');
|
11472 | return this.red.convertFrom(this);
|
11473 | };
|
11474 |
|
11475 | BN.prototype._forceRed = function _forceRed (ctx) {
|
11476 | this.red = ctx;
|
11477 | return this;
|
11478 | };
|
11479 |
|
11480 | BN.prototype.forceRed = function forceRed (ctx) {
|
11481 | assert(!this.red, 'Already a number in reduction context');
|
11482 | return this._forceRed(ctx);
|
11483 | };
|
11484 |
|
11485 | BN.prototype.redAdd = function redAdd (num) {
|
11486 | assert(this.red, 'redAdd works only with red numbers');
|
11487 | return this.red.add(this, num);
|
11488 | };
|
11489 |
|
11490 | BN.prototype.redIAdd = function redIAdd (num) {
|
11491 | assert(this.red, 'redIAdd works only with red numbers');
|
11492 | return this.red.iadd(this, num);
|
11493 | };
|
11494 |
|
11495 | BN.prototype.redSub = function redSub (num) {
|
11496 | assert(this.red, 'redSub works only with red numbers');
|
11497 | return this.red.sub(this, num);
|
11498 | };
|
11499 |
|
11500 | BN.prototype.redISub = function redISub (num) {
|
11501 | assert(this.red, 'redISub works only with red numbers');
|
11502 | return this.red.isub(this, num);
|
11503 | };
|
11504 |
|
11505 | BN.prototype.redShl = function redShl (num) {
|
11506 | assert(this.red, 'redShl works only with red numbers');
|
11507 | return this.red.shl(this, num);
|
11508 | };
|
11509 |
|
11510 | BN.prototype.redMul = function redMul (num) {
|
11511 | assert(this.red, 'redMul works only with red numbers');
|
11512 | this.red._verify2(this, num);
|
11513 | return this.red.mul(this, num);
|
11514 | };
|
11515 |
|
11516 | BN.prototype.redIMul = function redIMul (num) {
|
11517 | assert(this.red, 'redMul works only with red numbers');
|
11518 | this.red._verify2(this, num);
|
11519 | return this.red.imul(this, num);
|
11520 | };
|
11521 |
|
11522 | BN.prototype.redSqr = function redSqr () {
|
11523 | assert(this.red, 'redSqr works only with red numbers');
|
11524 | this.red._verify1(this);
|
11525 | return this.red.sqr(this);
|
11526 | };
|
11527 |
|
11528 | BN.prototype.redISqr = function redISqr () {
|
11529 | assert(this.red, 'redISqr works only with red numbers');
|
11530 | this.red._verify1(this);
|
11531 | return this.red.isqr(this);
|
11532 | };
|
11533 |
|
11534 | // Square root over p
|
11535 | BN.prototype.redSqrt = function redSqrt () {
|
11536 | assert(this.red, 'redSqrt works only with red numbers');
|
11537 | this.red._verify1(this);
|
11538 | return this.red.sqrt(this);
|
11539 | };
|
11540 |
|
11541 | BN.prototype.redInvm = function redInvm () {
|
11542 | assert(this.red, 'redInvm works only with red numbers');
|
11543 | this.red._verify1(this);
|
11544 | return this.red.invm(this);
|
11545 | };
|
11546 |
|
11547 | // Return negative clone of `this` % `red modulo`
|
11548 | BN.prototype.redNeg = function redNeg () {
|
11549 | assert(this.red, 'redNeg works only with red numbers');
|
11550 | this.red._verify1(this);
|
11551 | return this.red.neg(this);
|
11552 | };
|
11553 |
|
11554 | BN.prototype.redPow = function redPow (num) {
|
11555 | assert(this.red && !num.red, 'redPow(normalNum)');
|
11556 | this.red._verify1(this);
|
11557 | return this.red.pow(this, num);
|
11558 | };
|
11559 |
|
11560 | // Prime numbers with efficient reduction
|
11561 | var primes = {
|
11562 | k256: null,
|
11563 | p224: null,
|
11564 | p192: null,
|
11565 | p25519: null
|
11566 | };
|
11567 |
|
11568 | // Pseudo-Mersenne prime
|
11569 | function MPrime (name, p) {
|
11570 | // P = 2 ^ N - K
|
11571 | this.name = name;
|
11572 | this.p = new BN(p, 16);
|
11573 | this.n = this.p.bitLength();
|
11574 | this.k = new BN(1).iushln(this.n).isub(this.p);
|
11575 |
|
11576 | this.tmp = this._tmp();
|
11577 | }
|
11578 |
|
11579 | MPrime.prototype._tmp = function _tmp () {
|
11580 | var tmp = new BN(null);
|
11581 | tmp.words = new Array(Math.ceil(this.n / 13));
|
11582 | return tmp;
|
11583 | };
|
11584 |
|
11585 | MPrime.prototype.ireduce = function ireduce (num) {
|
11586 | // Assumes that `num` is less than `P^2`
|
11587 | // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P)
|
11588 | var r = num;
|
11589 | var rlen;
|
11590 |
|
11591 | do {
|
11592 | this.split(r, this.tmp);
|
11593 | r = this.imulK(r);
|
11594 | r = r.iadd(this.tmp);
|
11595 | rlen = r.bitLength();
|
11596 | } while (rlen > this.n);
|
11597 |
|
11598 | var cmp = rlen < this.n ? -1 : r.ucmp(this.p);
|
11599 | if (cmp === 0) {
|
11600 | r.words[0] = 0;
|
11601 | r.length = 1;
|
11602 | } else if (cmp > 0) {
|
11603 | r.isub(this.p);
|
11604 | } else {
|
11605 | r.strip();
|
11606 | }
|
11607 |
|
11608 | return r;
|
11609 | };
|
11610 |
|
11611 | MPrime.prototype.split = function split (input, out) {
|
11612 | input.iushrn(this.n, 0, out);
|
11613 | };
|
11614 |
|
11615 | MPrime.prototype.imulK = function imulK (num) {
|
11616 | return num.imul(this.k);
|
11617 | };
|
11618 |
|
11619 | function K256 () {
|
11620 | MPrime.call(
|
11621 | this,
|
11622 | 'k256',
|
11623 | 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f');
|
11624 | }
|
11625 | inherits(K256, MPrime);
|
11626 |
|
11627 | K256.prototype.split = function split (input, output) {
|
11628 | // 256 = 9 * 26 + 22
|
11629 | var mask = 0x3fffff;
|
11630 |
|
11631 | var outLen = Math.min(input.length, 9);
|
11632 | for (var i = 0; i < outLen; i++) {
|
11633 | output.words[i] = input.words[i];
|
11634 | }
|
11635 | output.length = outLen;
|
11636 |
|
11637 | if (input.length <= 9) {
|
11638 | input.words[0] = 0;
|
11639 | input.length = 1;
|
11640 | return;
|
11641 | }
|
11642 |
|
11643 | // Shift by 9 limbs
|
11644 | var prev = input.words[9];
|
11645 | output.words[output.length++] = prev & mask;
|
11646 |
|
11647 | for (i = 10; i < input.length; i++) {
|
11648 | var next = input.words[i] | 0;
|
11649 | input.words[i - 10] = ((next & mask) << 4) | (prev >>> 22);
|
11650 | prev = next;
|
11651 | }
|
11652 | prev >>>= 22;
|
11653 | input.words[i - 10] = prev;
|
11654 | if (prev === 0 && input.length > 10) {
|
11655 | input.length -= 10;
|
11656 | } else {
|
11657 | input.length -= 9;
|
11658 | }
|
11659 | };
|
11660 |
|
11661 | K256.prototype.imulK = function imulK (num) {
|
11662 | // K = 0x1000003d1 = [ 0x40, 0x3d1 ]
|
11663 | num.words[num.length] = 0;
|
11664 | num.words[num.length + 1] = 0;
|
11665 | num.length += 2;
|
11666 |
|
11667 | // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390
|
11668 | var lo = 0;
|
11669 | for (var i = 0; i < num.length; i++) {
|
11670 | var w = num.words[i] | 0;
|
11671 | lo += w * 0x3d1;
|
11672 | num.words[i] = lo & 0x3ffffff;
|
11673 | lo = w * 0x40 + ((lo / 0x4000000) | 0);
|
11674 | }
|
11675 |
|
11676 | // Fast length reduction
|
11677 | if (num.words[num.length - 1] === 0) {
|
11678 | num.length--;
|
11679 | if (num.words[num.length - 1] === 0) {
|
11680 | num.length--;
|
11681 | }
|
11682 | }
|
11683 | return num;
|
11684 | };
|
11685 |
|
11686 | function P224 () {
|
11687 | MPrime.call(
|
11688 | this,
|
11689 | 'p224',
|
11690 | 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001');
|
11691 | }
|
11692 | inherits(P224, MPrime);
|
11693 |
|
11694 | function P192 () {
|
11695 | MPrime.call(
|
11696 | this,
|
11697 | 'p192',
|
11698 | 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff');
|
11699 | }
|
11700 | inherits(P192, MPrime);
|
11701 |
|
11702 | function P25519 () {
|
11703 | // 2 ^ 255 - 19
|
11704 | MPrime.call(
|
11705 | this,
|
11706 | '25519',
|
11707 | '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed');
|
11708 | }
|
11709 | inherits(P25519, MPrime);
|
11710 |
|
11711 | P25519.prototype.imulK = function imulK (num) {
|
11712 | // K = 0x13
|
11713 | var carry = 0;
|
11714 | for (var i = 0; i < num.length; i++) {
|
11715 | var hi = (num.words[i] | 0) * 0x13 + carry;
|
11716 | var lo = hi & 0x3ffffff;
|
11717 | hi >>>= 26;
|
11718 |
|
11719 | num.words[i] = lo;
|
11720 | carry = hi;
|
11721 | }
|
11722 | if (carry !== 0) {
|
11723 | num.words[num.length++] = carry;
|
11724 | }
|
11725 | return num;
|
11726 | };
|
11727 |
|
11728 | // Exported mostly for testing purposes, use plain name instead
|
11729 | BN._prime = function prime (name) {
|
11730 | // Cached version of prime
|
11731 | if (primes[name]) return primes[name];
|
11732 |
|
11733 | var prime;
|
11734 | if (name === 'k256') {
|
11735 | prime = new K256();
|
11736 | } else if (name === 'p224') {
|
11737 | prime = new P224();
|
11738 | } else if (name === 'p192') {
|
11739 | prime = new P192();
|
11740 | } else if (name === 'p25519') {
|
11741 | prime = new P25519();
|
11742 | } else {
|
11743 | throw new Error('Unknown prime ' + name);
|
11744 | }
|
11745 | primes[name] = prime;
|
11746 |
|
11747 | return prime;
|
11748 | };
|
11749 |
|
11750 | //
|
11751 | // Base reduction engine
|
11752 | //
|
11753 | function Red (m) {
|
11754 | if (typeof m === 'string') {
|
11755 | var prime = BN._prime(m);
|
11756 | this.m = prime.p;
|
11757 | this.prime = prime;
|
11758 | } else {
|
11759 | assert(m.gtn(1), 'modulus must be greater than 1');
|
11760 | this.m = m;
|
11761 | this.prime = null;
|
11762 | }
|
11763 | }
|
11764 |
|
11765 | Red.prototype._verify1 = function _verify1 (a) {
|
11766 | assert(a.negative === 0, 'red works only with positives');
|
11767 | assert(a.red, 'red works only with red numbers');
|
11768 | };
|
11769 |
|
11770 | Red.prototype._verify2 = function _verify2 (a, b) {
|
11771 | assert((a.negative | b.negative) === 0, 'red works only with positives');
|
11772 | assert(a.red && a.red === b.red,
|
11773 | 'red works only with red numbers');
|
11774 | };
|
11775 |
|
11776 | Red.prototype.imod = function imod (a) {
|
11777 | if (this.prime) return this.prime.ireduce(a)._forceRed(this);
|
11778 | return a.umod(this.m)._forceRed(this);
|
11779 | };
|
11780 |
|
11781 | Red.prototype.neg = function neg (a) {
|
11782 | if (a.isZero()) {
|
11783 | return a.clone();
|
11784 | }
|
11785 |
|
11786 | return this.m.sub(a)._forceRed(this);
|
11787 | };
|
11788 |
|
11789 | Red.prototype.add = function add (a, b) {
|
11790 | this._verify2(a, b);
|
11791 |
|
11792 | var res = a.add(b);
|
11793 | if (res.cmp(this.m) >= 0) {
|
11794 | res.isub(this.m);
|
11795 | }
|
11796 | return res._forceRed(this);
|
11797 | };
|
11798 |
|
11799 | Red.prototype.iadd = function iadd (a, b) {
|
11800 | this._verify2(a, b);
|
11801 |
|
11802 | var res = a.iadd(b);
|
11803 | if (res.cmp(this.m) >= 0) {
|
11804 | res.isub(this.m);
|
11805 | }
|
11806 | return res;
|
11807 | };
|
11808 |
|
11809 | Red.prototype.sub = function sub (a, b) {
|
11810 | this._verify2(a, b);
|
11811 |
|
11812 | var res = a.sub(b);
|
11813 | if (res.cmpn(0) < 0) {
|
11814 | res.iadd(this.m);
|
11815 | }
|
11816 | return res._forceRed(this);
|
11817 | };
|
11818 |
|
11819 | Red.prototype.isub = function isub (a, b) {
|
11820 | this._verify2(a, b);
|
11821 |
|
11822 | var res = a.isub(b);
|
11823 | if (res.cmpn(0) < 0) {
|
11824 | res.iadd(this.m);
|
11825 | }
|
11826 | return res;
|
11827 | };
|
11828 |
|
11829 | Red.prototype.shl = function shl (a, num) {
|
11830 | this._verify1(a);
|
11831 | return this.imod(a.ushln(num));
|
11832 | };
|
11833 |
|
11834 | Red.prototype.imul = function imul (a, b) {
|
11835 | this._verify2(a, b);
|
11836 | return this.imod(a.imul(b));
|
11837 | };
|
11838 |
|
11839 | Red.prototype.mul = function mul (a, b) {
|
11840 | this._verify2(a, b);
|
11841 | return this.imod(a.mul(b));
|
11842 | };
|
11843 |
|
11844 | Red.prototype.isqr = function isqr (a) {
|
11845 | return this.imul(a, a.clone());
|
11846 | };
|
11847 |
|
11848 | Red.prototype.sqr = function sqr (a) {
|
11849 | return this.mul(a, a);
|
11850 | };
|
11851 |
|
11852 | Red.prototype.sqrt = function sqrt (a) {
|
11853 | if (a.isZero()) return a.clone();
|
11854 |
|
11855 | var mod3 = this.m.andln(3);
|
11856 | assert(mod3 % 2 === 1);
|
11857 |
|
11858 | // Fast case
|
11859 | if (mod3 === 3) {
|
11860 | var pow = this.m.add(new BN(1)).iushrn(2);
|
11861 | return this.pow(a, pow);
|
11862 | }
|
11863 |
|
11864 | // Tonelli-Shanks algorithm (Totally unoptimized and slow)
|
11865 | //
|
11866 | // Find Q and S, that Q * 2 ^ S = (P - 1)
|
11867 | var q = this.m.subn(1);
|
11868 | var s = 0;
|
11869 | while (!q.isZero() && q.andln(1) === 0) {
|
11870 | s++;
|
11871 | q.iushrn(1);
|
11872 | }
|
11873 | assert(!q.isZero());
|
11874 |
|
11875 | var one = new BN(1).toRed(this);
|
11876 | var nOne = one.redNeg();
|
11877 |
|
11878 | // Find quadratic non-residue
|
11879 | // NOTE: Max is such because of generalized Riemann hypothesis.
|
11880 | var lpow = this.m.subn(1).iushrn(1);
|
11881 | var z = this.m.bitLength();
|
11882 | z = new BN(2 * z * z).toRed(this);
|
11883 |
|
11884 | while (this.pow(z, lpow).cmp(nOne) !== 0) {
|
11885 | z.redIAdd(nOne);
|
11886 | }
|
11887 |
|
11888 | var c = this.pow(z, q);
|
11889 | var r = this.pow(a, q.addn(1).iushrn(1));
|
11890 | var t = this.pow(a, q);
|
11891 | var m = s;
|
11892 | while (t.cmp(one) !== 0) {
|
11893 | var tmp = t;
|
11894 | for (var i = 0; tmp.cmp(one) !== 0; i++) {
|
11895 | tmp = tmp.redSqr();
|
11896 | }
|
11897 | assert(i < m);
|
11898 | var b = this.pow(c, new BN(1).iushln(m - i - 1));
|
11899 |
|
11900 | r = r.redMul(b);
|
11901 | c = b.redSqr();
|
11902 | t = t.redMul(c);
|
11903 | m = i;
|
11904 | }
|
11905 |
|
11906 | return r;
|
11907 | };
|
11908 |
|
11909 | Red.prototype.invm = function invm (a) {
|
11910 | var inv = a._invmp(this.m);
|
11911 | if (inv.negative !== 0) {
|
11912 | inv.negative = 0;
|
11913 | return this.imod(inv).redNeg();
|
11914 | } else {
|
11915 | return this.imod(inv);
|
11916 | }
|
11917 | };
|
11918 |
|
11919 | Red.prototype.pow = function pow (a, num) {
|
11920 | if (num.isZero()) return new BN(1).toRed(this);
|
11921 | if (num.cmpn(1) === 0) return a.clone();
|
11922 |
|
11923 | var windowSize = 4;
|
11924 | var wnd = new Array(1 << windowSize);
|
11925 | wnd[0] = new BN(1).toRed(this);
|
11926 | wnd[1] = a;
|
11927 | for (var i = 2; i < wnd.length; i++) {
|
11928 | wnd[i] = this.mul(wnd[i - 1], a);
|
11929 | }
|
11930 |
|
11931 | var res = wnd[0];
|
11932 | var current = 0;
|
11933 | var currentLen = 0;
|
11934 | var start = num.bitLength() % 26;
|
11935 | if (start === 0) {
|
11936 | start = 26;
|
11937 | }
|
11938 |
|
11939 | for (i = num.length - 1; i >= 0; i--) {
|
11940 | var word = num.words[i];
|
11941 | for (var j = start - 1; j >= 0; j--) {
|
11942 | var bit = (word >> j) & 1;
|
11943 | if (res !== wnd[0]) {
|
11944 | res = this.sqr(res);
|
11945 | }
|
11946 |
|
11947 | if (bit === 0 && current === 0) {
|
11948 | currentLen = 0;
|
11949 | continue;
|
11950 | }
|
11951 |
|
11952 | current <<= 1;
|
11953 | current |= bit;
|
11954 | currentLen++;
|
11955 | if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue;
|
11956 |
|
11957 | res = this.mul(res, wnd[current]);
|
11958 | currentLen = 0;
|
11959 | current = 0;
|
11960 | }
|
11961 | start = 26;
|
11962 | }
|
11963 |
|
11964 | return res;
|
11965 | };
|
11966 |
|
11967 | Red.prototype.convertTo = function convertTo (num) {
|
11968 | var r = num.umod(this.m);
|
11969 |
|
11970 | return r === num ? r.clone() : r;
|
11971 | };
|
11972 |
|
11973 | Red.prototype.convertFrom = function convertFrom (num) {
|
11974 | var res = num.clone();
|
11975 | res.red = null;
|
11976 | return res;
|
11977 | };
|
11978 |
|
11979 | //
|
11980 | // Montgomery method engine
|
11981 | //
|
11982 |
|
11983 | BN.mont = function mont (num) {
|
11984 | return new Mont(num);
|
11985 | };
|
11986 |
|
11987 | function Mont (m) {
|
11988 | Red.call(this, m);
|
11989 |
|
11990 | this.shift = this.m.bitLength();
|
11991 | if (this.shift % 26 !== 0) {
|
11992 | this.shift += 26 - (this.shift % 26);
|
11993 | }
|
11994 |
|
11995 | this.r = new BN(1).iushln(this.shift);
|
11996 | this.r2 = this.imod(this.r.sqr());
|
11997 | this.rinv = this.r._invmp(this.m);
|
11998 |
|
11999 | this.minv = this.rinv.mul(this.r).isubn(1).div(this.m);
|
12000 | this.minv = this.minv.umod(this.r);
|
12001 | this.minv = this.r.sub(this.minv);
|
12002 | }
|
12003 | inherits(Mont, Red);
|
12004 |
|
12005 | Mont.prototype.convertTo = function convertTo (num) {
|
12006 | return this.imod(num.ushln(this.shift));
|
12007 | };
|
12008 |
|
12009 | Mont.prototype.convertFrom = function convertFrom (num) {
|
12010 | var r = this.imod(num.mul(this.rinv));
|
12011 | r.red = null;
|
12012 | return r;
|
12013 | };
|
12014 |
|
12015 | Mont.prototype.imul = function imul (a, b) {
|
12016 | if (a.isZero() || b.isZero()) {
|
12017 | a.words[0] = 0;
|
12018 | a.length = 1;
|
12019 | return a;
|
12020 | }
|
12021 |
|
12022 | var t = a.imul(b);
|
12023 | var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
|
12024 | var u = t.isub(c).iushrn(this.shift);
|
12025 | var res = u;
|
12026 |
|
12027 | if (u.cmp(this.m) >= 0) {
|
12028 | res = u.isub(this.m);
|
12029 | } else if (u.cmpn(0) < 0) {
|
12030 | res = u.iadd(this.m);
|
12031 | }
|
12032 |
|
12033 | return res._forceRed(this);
|
12034 | };
|
12035 |
|
12036 | Mont.prototype.mul = function mul (a, b) {
|
12037 | if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this);
|
12038 |
|
12039 | var t = a.mul(b);
|
12040 | var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
|
12041 | var u = t.isub(c).iushrn(this.shift);
|
12042 | var res = u;
|
12043 | if (u.cmp(this.m) >= 0) {
|
12044 | res = u.isub(this.m);
|
12045 | } else if (u.cmpn(0) < 0) {
|
12046 | res = u.iadd(this.m);
|
12047 | }
|
12048 |
|
12049 | return res._forceRed(this);
|
12050 | };
|
12051 |
|
12052 | Mont.prototype.invm = function invm (a) {
|
12053 | // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R
|
12054 | var res = this.imod(a._invmp(this.m).mul(this.r2));
|
12055 | return res._forceRed(this);
|
12056 | };
|
12057 | })( false || module, this);
|
12058 |
|
12059 | /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(82)(module)))
|
12060 |
|
12061 | /***/ }),
|
12062 | /* 4 */
|
12063 | /***/ (function(module, exports, __webpack_require__) {
|
12064 |
|
12065 | ;(function (root, factory) {
|
12066 | if (true) {
|
12067 | // CommonJS
|
12068 | module.exports = exports = factory();
|
12069 | }
|
12070 | else {}
|
12071 | }(this, function () {
|
12072 |
|
12073 | /**
|
12074 | * CryptoJS core components.
|
12075 | */
|
12076 | var CryptoJS = CryptoJS || (function (Math, undefined) {
|
12077 | /*
|
12078 | * Local polyfil of Object.create
|
12079 | */
|
12080 | var create = Object.create || (function () {
|
12081 | function F() {};
|
12082 |
|
12083 | return function (obj) {
|
12084 | var subtype;
|
12085 |
|
12086 | F.prototype = obj;
|
12087 |
|
12088 | subtype = new F();
|
12089 |
|
12090 | F.prototype = null;
|
12091 |
|
12092 | return subtype;
|
12093 | };
|
12094 | }())
|
12095 |
|
12096 | /**
|
12097 | * CryptoJS namespace.
|
12098 | */
|
12099 | var C = {};
|
12100 |
|
12101 | /**
|
12102 | * Library namespace.
|
12103 | */
|
12104 | var C_lib = C.lib = {};
|
12105 |
|
12106 | /**
|
12107 | * Base object for prototypal inheritance.
|
12108 | */
|
12109 | var Base = C_lib.Base = (function () {
|
12110 |
|
12111 |
|
12112 | return {
|
12113 | /**
|
12114 | * Creates a new object that inherits from this object.
|
12115 | *
|
12116 | * @param {Object} overrides Properties to copy into the new object.
|
12117 | *
|
12118 | * @return {Object} The new object.
|
12119 | *
|
12120 | * @static
|
12121 | *
|
12122 | * @example
|
12123 | *
|
12124 | * var MyType = CryptoJS.lib.Base.extend({
|
12125 | * field: 'value',
|
12126 | *
|
12127 | * method: function () {
|
12128 | * }
|
12129 | * });
|
12130 | */
|
12131 | extend: function (overrides) {
|
12132 | // Spawn
|
12133 | var subtype = create(this);
|
12134 |
|
12135 | // Augment
|
12136 | if (overrides) {
|
12137 | subtype.mixIn(overrides);
|
12138 | }
|
12139 |
|
12140 | // Create default initializer
|
12141 | if (!subtype.hasOwnProperty('init') || this.init === subtype.init) {
|
12142 | subtype.init = function () {
|
12143 | subtype.$super.init.apply(this, arguments);
|
12144 | };
|
12145 | }
|
12146 |
|
12147 | // Initializer's prototype is the subtype object
|
12148 | subtype.init.prototype = subtype;
|
12149 |
|
12150 | // Reference supertype
|
12151 | subtype.$super = this;
|
12152 |
|
12153 | return subtype;
|
12154 | },
|
12155 |
|
12156 | /**
|
12157 | * Extends this object and runs the init method.
|
12158 | * Arguments to create() will be passed to init().
|
12159 | *
|
12160 | * @return {Object} The new object.
|
12161 | *
|
12162 | * @static
|
12163 | *
|
12164 | * @example
|
12165 | *
|
12166 | * var instance = MyType.create();
|
12167 | */
|
12168 | create: function () {
|
12169 | var instance = this.extend();
|
12170 | instance.init.apply(instance, arguments);
|
12171 |
|
12172 | return instance;
|
12173 | },
|
12174 |
|
12175 | /**
|
12176 | * Initializes a newly created object.
|
12177 | * Override this method to add some logic when your objects are created.
|
12178 | *
|
12179 | * @example
|
12180 | *
|
12181 | * var MyType = CryptoJS.lib.Base.extend({
|
12182 | * init: function () {
|
12183 | * // ...
|
12184 | * }
|
12185 | * });
|
12186 | */
|
12187 | init: function () {
|
12188 | },
|
12189 |
|
12190 | /**
|
12191 | * Copies properties into this object.
|
12192 | *
|
12193 | * @param {Object} properties The properties to mix in.
|
12194 | *
|
12195 | * @example
|
12196 | *
|
12197 | * MyType.mixIn({
|
12198 | * field: 'value'
|
12199 | * });
|
12200 | */
|
12201 | mixIn: function (properties) {
|
12202 | for (var propertyName in properties) {
|
12203 | if (properties.hasOwnProperty(propertyName)) {
|
12204 | this[propertyName] = properties[propertyName];
|
12205 | }
|
12206 | }
|
12207 |
|
12208 | // IE won't copy toString using the loop above
|
12209 | if (properties.hasOwnProperty('toString')) {
|
12210 | this.toString = properties.toString;
|
12211 | }
|
12212 | },
|
12213 |
|
12214 | /**
|
12215 | * Creates a copy of this object.
|
12216 | *
|
12217 | * @return {Object} The clone.
|
12218 | *
|
12219 | * @example
|
12220 | *
|
12221 | * var clone = instance.clone();
|
12222 | */
|
12223 | clone: function () {
|
12224 | return this.init.prototype.extend(this);
|
12225 | }
|
12226 | };
|
12227 | }());
|
12228 |
|
12229 | /**
|
12230 | * An array of 32-bit words.
|
12231 | *
|
12232 | * @property {Array} words The array of 32-bit words.
|
12233 | * @property {number} sigBytes The number of significant bytes in this word array.
|
12234 | */
|
12235 | var WordArray = C_lib.WordArray = Base.extend({
|
12236 | /**
|
12237 | * Initializes a newly created word array.
|
12238 | *
|
12239 | * @param {Array} words (Optional) An array of 32-bit words.
|
12240 | * @param {number} sigBytes (Optional) The number of significant bytes in the words.
|
12241 | *
|
12242 | * @example
|
12243 | *
|
12244 | * var wordArray = CryptoJS.lib.WordArray.create();
|
12245 | * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]);
|
12246 | * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6);
|
12247 | */
|
12248 | init: function (words, sigBytes) {
|
12249 | words = this.words = words || [];
|
12250 |
|
12251 | if (sigBytes != undefined) {
|
12252 | this.sigBytes = sigBytes;
|
12253 | } else {
|
12254 | this.sigBytes = words.length * 4;
|
12255 | }
|
12256 | },
|
12257 |
|
12258 | /**
|
12259 | * Converts this word array to a string.
|
12260 | *
|
12261 | * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex
|
12262 | *
|
12263 | * @return {string} The stringified word array.
|
12264 | *
|
12265 | * @example
|
12266 | *
|
12267 | * var string = wordArray + '';
|
12268 | * var string = wordArray.toString();
|
12269 | * var string = wordArray.toString(CryptoJS.enc.Utf8);
|
12270 | */
|
12271 | toString: function (encoder) {
|
12272 | return (encoder || Hex).stringify(this);
|
12273 | },
|
12274 |
|
12275 | /**
|
12276 | * Concatenates a word array to this word array.
|
12277 | *
|
12278 | * @param {WordArray} wordArray The word array to append.
|
12279 | *
|
12280 | * @return {WordArray} This word array.
|
12281 | *
|
12282 | * @example
|
12283 | *
|
12284 | * wordArray1.concat(wordArray2);
|
12285 | */
|
12286 | concat: function (wordArray) {
|
12287 | // Shortcuts
|
12288 | var thisWords = this.words;
|
12289 | var thatWords = wordArray.words;
|
12290 | var thisSigBytes = this.sigBytes;
|
12291 | var thatSigBytes = wordArray.sigBytes;
|
12292 |
|
12293 | // Clamp excess bits
|
12294 | this.clamp();
|
12295 |
|
12296 | // Concat
|
12297 | if (thisSigBytes % 4) {
|
12298 | // Copy one byte at a time
|
12299 | for (var i = 0; i < thatSigBytes; i++) {
|
12300 | var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
|
12301 | thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8);
|
12302 | }
|
12303 | } else {
|
12304 | // Copy one word at a time
|
12305 | for (var i = 0; i < thatSigBytes; i += 4) {
|
12306 | thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2];
|
12307 | }
|
12308 | }
|
12309 | this.sigBytes += thatSigBytes;
|
12310 |
|
12311 | // Chainable
|
12312 | return this;
|
12313 | },
|
12314 |
|
12315 | /**
|
12316 | * Removes insignificant bits.
|
12317 | *
|
12318 | * @example
|
12319 | *
|
12320 | * wordArray.clamp();
|
12321 | */
|
12322 | clamp: function () {
|
12323 | // Shortcuts
|
12324 | var words = this.words;
|
12325 | var sigBytes = this.sigBytes;
|
12326 |
|
12327 | // Clamp
|
12328 | words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8);
|
12329 | words.length = Math.ceil(sigBytes / 4);
|
12330 | },
|
12331 |
|
12332 | /**
|
12333 | * Creates a copy of this word array.
|
12334 | *
|
12335 | * @return {WordArray} The clone.
|
12336 | *
|
12337 | * @example
|
12338 | *
|
12339 | * var clone = wordArray.clone();
|
12340 | */
|
12341 | clone: function () {
|
12342 | var clone = Base.clone.call(this);
|
12343 | clone.words = this.words.slice(0);
|
12344 |
|
12345 | return clone;
|
12346 | },
|
12347 |
|
12348 | /**
|
12349 | * Creates a word array filled with random bytes.
|
12350 | *
|
12351 | * @param {number} nBytes The number of random bytes to generate.
|
12352 | *
|
12353 | * @return {WordArray} The random word array.
|
12354 | *
|
12355 | * @static
|
12356 | *
|
12357 | * @example
|
12358 | *
|
12359 | * var wordArray = CryptoJS.lib.WordArray.random(16);
|
12360 | */
|
12361 | random: function (nBytes) {
|
12362 | var words = [];
|
12363 |
|
12364 | var r = (function (m_w) {
|
12365 | var m_w = m_w;
|
12366 | var m_z = 0x3ade68b1;
|
12367 | var mask = 0xffffffff;
|
12368 |
|
12369 | return function () {
|
12370 | m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask;
|
12371 | m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask;
|
12372 | var result = ((m_z << 0x10) + m_w) & mask;
|
12373 | result /= 0x100000000;
|
12374 | result += 0.5;
|
12375 | return result * (Math.random() > .5 ? 1 : -1);
|
12376 | }
|
12377 | });
|
12378 |
|
12379 | for (var i = 0, rcache; i < nBytes; i += 4) {
|
12380 | var _r = r((rcache || Math.random()) * 0x100000000);
|
12381 |
|
12382 | rcache = _r() * 0x3ade67b7;
|
12383 | words.push((_r() * 0x100000000) | 0);
|
12384 | }
|
12385 |
|
12386 | return new WordArray.init(words, nBytes);
|
12387 | }
|
12388 | });
|
12389 |
|
12390 | /**
|
12391 | * Encoder namespace.
|
12392 | */
|
12393 | var C_enc = C.enc = {};
|
12394 |
|
12395 | /**
|
12396 | * Hex encoding strategy.
|
12397 | */
|
12398 | var Hex = C_enc.Hex = {
|
12399 | /**
|
12400 | * Converts a word array to a hex string.
|
12401 | *
|
12402 | * @param {WordArray} wordArray The word array.
|
12403 | *
|
12404 | * @return {string} The hex string.
|
12405 | *
|
12406 | * @static
|
12407 | *
|
12408 | * @example
|
12409 | *
|
12410 | * var hexString = CryptoJS.enc.Hex.stringify(wordArray);
|
12411 | */
|
12412 | stringify: function (wordArray) {
|
12413 | // Shortcuts
|
12414 | var words = wordArray.words;
|
12415 | var sigBytes = wordArray.sigBytes;
|
12416 |
|
12417 | // Convert
|
12418 | var hexChars = [];
|
12419 | for (var i = 0; i < sigBytes; i++) {
|
12420 | var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
|
12421 | hexChars.push((bite >>> 4).toString(16));
|
12422 | hexChars.push((bite & 0x0f).toString(16));
|
12423 | }
|
12424 |
|
12425 | return hexChars.join('');
|
12426 | },
|
12427 |
|
12428 | /**
|
12429 | * Converts a hex string to a word array.
|
12430 | *
|
12431 | * @param {string} hexStr The hex string.
|
12432 | *
|
12433 | * @return {WordArray} The word array.
|
12434 | *
|
12435 | * @static
|
12436 | *
|
12437 | * @example
|
12438 | *
|
12439 | * var wordArray = CryptoJS.enc.Hex.parse(hexString);
|
12440 | */
|
12441 | parse: function (hexStr) {
|
12442 | // Shortcut
|
12443 | var hexStrLength = hexStr.length;
|
12444 |
|
12445 | // Convert
|
12446 | var words = [];
|
12447 | for (var i = 0; i < hexStrLength; i += 2) {
|
12448 | words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4);
|
12449 | }
|
12450 |
|
12451 | return new WordArray.init(words, hexStrLength / 2);
|
12452 | }
|
12453 | };
|
12454 |
|
12455 | /**
|
12456 | * Latin1 encoding strategy.
|
12457 | */
|
12458 | var Latin1 = C_enc.Latin1 = {
|
12459 | /**
|
12460 | * Converts a word array to a Latin1 string.
|
12461 | *
|
12462 | * @param {WordArray} wordArray The word array.
|
12463 | *
|
12464 | * @return {string} The Latin1 string.
|
12465 | *
|
12466 | * @static
|
12467 | *
|
12468 | * @example
|
12469 | *
|
12470 | * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray);
|
12471 | */
|
12472 | stringify: function (wordArray) {
|
12473 | // Shortcuts
|
12474 | var words = wordArray.words;
|
12475 | var sigBytes = wordArray.sigBytes;
|
12476 |
|
12477 | // Convert
|
12478 | var latin1Chars = [];
|
12479 | for (var i = 0; i < sigBytes; i++) {
|
12480 | var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
|
12481 | latin1Chars.push(String.fromCharCode(bite));
|
12482 | }
|
12483 |
|
12484 | return latin1Chars.join('');
|
12485 | },
|
12486 |
|
12487 | /**
|
12488 | * Converts a Latin1 string to a word array.
|
12489 | *
|
12490 | * @param {string} latin1Str The Latin1 string.
|
12491 | *
|
12492 | * @return {WordArray} The word array.
|
12493 | *
|
12494 | * @static
|
12495 | *
|
12496 | * @example
|
12497 | *
|
12498 | * var wordArray = CryptoJS.enc.Latin1.parse(latin1String);
|
12499 | */
|
12500 | parse: function (latin1Str) {
|
12501 | // Shortcut
|
12502 | var latin1StrLength = latin1Str.length;
|
12503 |
|
12504 | // Convert
|
12505 | var words = [];
|
12506 | for (var i = 0; i < latin1StrLength; i++) {
|
12507 | words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8);
|
12508 | }
|
12509 |
|
12510 | return new WordArray.init(words, latin1StrLength);
|
12511 | }
|
12512 | };
|
12513 |
|
12514 | /**
|
12515 | * UTF-8 encoding strategy.
|
12516 | */
|
12517 | var Utf8 = C_enc.Utf8 = {
|
12518 | /**
|
12519 | * Converts a word array to a UTF-8 string.
|
12520 | *
|
12521 | * @param {WordArray} wordArray The word array.
|
12522 | *
|
12523 | * @return {string} The UTF-8 string.
|
12524 | *
|
12525 | * @static
|
12526 | *
|
12527 | * @example
|
12528 | *
|
12529 | * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray);
|
12530 | */
|
12531 | stringify: function (wordArray) {
|
12532 | try {
|
12533 | return decodeURIComponent(escape(Latin1.stringify(wordArray)));
|
12534 | } catch (e) {
|
12535 | throw new Error('Malformed UTF-8 data');
|
12536 | }
|
12537 | },
|
12538 |
|
12539 | /**
|
12540 | * Converts a UTF-8 string to a word array.
|
12541 | *
|
12542 | * @param {string} utf8Str The UTF-8 string.
|
12543 | *
|
12544 | * @return {WordArray} The word array.
|
12545 | *
|
12546 | * @static
|
12547 | *
|
12548 | * @example
|
12549 | *
|
12550 | * var wordArray = CryptoJS.enc.Utf8.parse(utf8String);
|
12551 | */
|
12552 | parse: function (utf8Str) {
|
12553 | return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
|
12554 | }
|
12555 | };
|
12556 |
|
12557 | /**
|
12558 | * Abstract buffered block algorithm template.
|
12559 | *
|
12560 | * The property blockSize must be implemented in a concrete subtype.
|
12561 | *
|
12562 | * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0
|
12563 | */
|
12564 | var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({
|
12565 | /**
|
12566 | * Resets this block algorithm's data buffer to its initial state.
|
12567 | *
|
12568 | * @example
|
12569 | *
|
12570 | * bufferedBlockAlgorithm.reset();
|
12571 | */
|
12572 | reset: function () {
|
12573 | // Initial values
|
12574 | this._data = new WordArray.init();
|
12575 | this._nDataBytes = 0;
|
12576 | },
|
12577 |
|
12578 | /**
|
12579 | * Adds new data to this block algorithm's buffer.
|
12580 | *
|
12581 | * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8.
|
12582 | *
|
12583 | * @example
|
12584 | *
|
12585 | * bufferedBlockAlgorithm._append('data');
|
12586 | * bufferedBlockAlgorithm._append(wordArray);
|
12587 | */
|
12588 | _append: function (data) {
|
12589 | // Convert string to WordArray, else assume WordArray already
|
12590 | if (typeof data == 'string') {
|
12591 | data = Utf8.parse(data);
|
12592 | }
|
12593 |
|
12594 | // Append
|
12595 | this._data.concat(data);
|
12596 | this._nDataBytes += data.sigBytes;
|
12597 | },
|
12598 |
|
12599 | /**
|
12600 | * Processes available data blocks.
|
12601 | *
|
12602 | * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype.
|
12603 | *
|
12604 | * @param {boolean} doFlush Whether all blocks and partial blocks should be processed.
|
12605 | *
|
12606 | * @return {WordArray} The processed data.
|
12607 | *
|
12608 | * @example
|
12609 | *
|
12610 | * var processedData = bufferedBlockAlgorithm._process();
|
12611 | * var processedData = bufferedBlockAlgorithm._process(!!'flush');
|
12612 | */
|
12613 | _process: function (doFlush) {
|
12614 | // Shortcuts
|
12615 | var data = this._data;
|
12616 | var dataWords = data.words;
|
12617 | var dataSigBytes = data.sigBytes;
|
12618 | var blockSize = this.blockSize;
|
12619 | var blockSizeBytes = blockSize * 4;
|
12620 |
|
12621 | // Count blocks ready
|
12622 | var nBlocksReady = dataSigBytes / blockSizeBytes;
|
12623 | if (doFlush) {
|
12624 | // Round up to include partial blocks
|
12625 | nBlocksReady = Math.ceil(nBlocksReady);
|
12626 | } else {
|
12627 | // Round down to include only full blocks,
|
12628 | // less the number of blocks that must remain in the buffer
|
12629 | nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0);
|
12630 | }
|
12631 |
|
12632 | // Count words ready
|
12633 | var nWordsReady = nBlocksReady * blockSize;
|
12634 |
|
12635 | // Count bytes ready
|
12636 | var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes);
|
12637 |
|
12638 | // Process blocks
|
12639 | if (nWordsReady) {
|
12640 | for (var offset = 0; offset < nWordsReady; offset += blockSize) {
|
12641 | // Perform concrete-algorithm logic
|
12642 | this._doProcessBlock(dataWords, offset);
|
12643 | }
|
12644 |
|
12645 | // Remove processed words
|
12646 | var processedWords = dataWords.splice(0, nWordsReady);
|
12647 | data.sigBytes -= nBytesReady;
|
12648 | }
|
12649 |
|
12650 | // Return processed words
|
12651 | return new WordArray.init(processedWords, nBytesReady);
|
12652 | },
|
12653 |
|
12654 | /**
|
12655 | * Creates a copy of this object.
|
12656 | *
|
12657 | * @return {Object} The clone.
|
12658 | *
|
12659 | * @example
|
12660 | *
|
12661 | * var clone = bufferedBlockAlgorithm.clone();
|
12662 | */
|
12663 | clone: function () {
|
12664 | var clone = Base.clone.call(this);
|
12665 | clone._data = this._data.clone();
|
12666 |
|
12667 | return clone;
|
12668 | },
|
12669 |
|
12670 | _minBufferSize: 0
|
12671 | });
|
12672 |
|
12673 | /**
|
12674 | * Abstract hasher template.
|
12675 | *
|
12676 | * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits)
|
12677 | */
|
12678 | var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({
|
12679 | /**
|
12680 | * Configuration options.
|
12681 | */
|
12682 | cfg: Base.extend(),
|
12683 |
|
12684 | /**
|
12685 | * Initializes a newly created hasher.
|
12686 | *
|
12687 | * @param {Object} cfg (Optional) The configuration options to use for this hash computation.
|
12688 | *
|
12689 | * @example
|
12690 | *
|
12691 | * var hasher = CryptoJS.algo.SHA256.create();
|
12692 | */
|
12693 | init: function (cfg) {
|
12694 | // Apply config defaults
|
12695 | this.cfg = this.cfg.extend(cfg);
|
12696 |
|
12697 | // Set initial values
|
12698 | this.reset();
|
12699 | },
|
12700 |
|
12701 | /**
|
12702 | * Resets this hasher to its initial state.
|
12703 | *
|
12704 | * @example
|
12705 | *
|
12706 | * hasher.reset();
|
12707 | */
|
12708 | reset: function () {
|
12709 | // Reset data buffer
|
12710 | BufferedBlockAlgorithm.reset.call(this);
|
12711 |
|
12712 | // Perform concrete-hasher logic
|
12713 | this._doReset();
|
12714 | },
|
12715 |
|
12716 | /**
|
12717 | * Updates this hasher with a message.
|
12718 | *
|
12719 | * @param {WordArray|string} messageUpdate The message to append.
|
12720 | *
|
12721 | * @return {Hasher} This hasher.
|
12722 | *
|
12723 | * @example
|
12724 | *
|
12725 | * hasher.update('message');
|
12726 | * hasher.update(wordArray);
|
12727 | */
|
12728 | update: function (messageUpdate) {
|
12729 | // Append
|
12730 | this._append(messageUpdate);
|
12731 |
|
12732 | // Update the hash
|
12733 | this._process();
|
12734 |
|
12735 | // Chainable
|
12736 | return this;
|
12737 | },
|
12738 |
|
12739 | /**
|
12740 | * Finalizes the hash computation.
|
12741 | * Note that the finalize operation is effectively a destructive, read-once operation.
|
12742 | *
|
12743 | * @param {WordArray|string} messageUpdate (Optional) A final message update.
|
12744 | *
|
12745 | * @return {WordArray} The hash.
|
12746 | *
|
12747 | * @example
|
12748 | *
|
12749 | * var hash = hasher.finalize();
|
12750 | * var hash = hasher.finalize('message');
|
12751 | * var hash = hasher.finalize(wordArray);
|
12752 | */
|
12753 | finalize: function (messageUpdate) {
|
12754 | // Final message update
|
12755 | if (messageUpdate) {
|
12756 | this._append(messageUpdate);
|
12757 | }
|
12758 |
|
12759 | // Perform concrete-hasher logic
|
12760 | var hash = this._doFinalize();
|
12761 |
|
12762 | return hash;
|
12763 | },
|
12764 |
|
12765 | blockSize: 512/32,
|
12766 |
|
12767 | /**
|
12768 | * Creates a shortcut function to a hasher's object interface.
|
12769 | *
|
12770 | * @param {Hasher} hasher The hasher to create a helper for.
|
12771 | *
|
12772 | * @return {Function} The shortcut function.
|
12773 | *
|
12774 | * @static
|
12775 | *
|
12776 | * @example
|
12777 | *
|
12778 | * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256);
|
12779 | */
|
12780 | _createHelper: function (hasher) {
|
12781 | return function (message, cfg) {
|
12782 | return new hasher.init(cfg).finalize(message);
|
12783 | };
|
12784 | },
|
12785 |
|
12786 | /**
|
12787 | * Creates a shortcut function to the HMAC's object interface.
|
12788 | *
|
12789 | * @param {Hasher} hasher The hasher to use in this HMAC helper.
|
12790 | *
|
12791 | * @return {Function} The shortcut function.
|
12792 | *
|
12793 | * @static
|
12794 | *
|
12795 | * @example
|
12796 | *
|
12797 | * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256);
|
12798 | */
|
12799 | _createHmacHelper: function (hasher) {
|
12800 | return function (message, key) {
|
12801 | return new C_algo.HMAC.init(hasher, key).finalize(message);
|
12802 | };
|
12803 | }
|
12804 | });
|
12805 |
|
12806 | /**
|
12807 | * Algorithm namespace.
|
12808 | */
|
12809 | var C_algo = C.algo = {};
|
12810 |
|
12811 | return C;
|
12812 | }(Math));
|
12813 |
|
12814 |
|
12815 | return CryptoJS;
|
12816 |
|
12817 | }));
|
12818 |
|
12819 | /***/ }),
|
12820 | /* 5 */
|
12821 | /***/ (function(module, exports, __webpack_require__) {
|
12822 |
|
12823 | "use strict";
|
12824 |
|
12825 |
|
12826 | var elliptic = exports;
|
12827 |
|
12828 | elliptic.version = __webpack_require__(83).version;
|
12829 | elliptic.utils = __webpack_require__(84);
|
12830 | elliptic.rand = __webpack_require__(85);
|
12831 | elliptic.curve = __webpack_require__(15);
|
12832 | elliptic.curves = __webpack_require__(91);
|
12833 |
|
12834 | // Protocols
|
12835 | elliptic.ec = __webpack_require__(99);
|
12836 | elliptic.eddsa = __webpack_require__(103);
|
12837 |
|
12838 |
|
12839 | /***/ }),
|
12840 | /* 6 */
|
12841 | /***/ (function(module, exports, __webpack_require__) {
|
12842 |
|
12843 | "use strict";
|
12844 |
|
12845 |
|
12846 | var assert = __webpack_require__(8);
|
12847 | var inherits = __webpack_require__(16);
|
12848 |
|
12849 | exports.inherits = inherits;
|
12850 |
|
12851 | function isSurrogatePair(msg, i) {
|
12852 | if ((msg.charCodeAt(i) & 0xFC00) !== 0xD800) {
|
12853 | return false;
|
12854 | }
|
12855 | if (i < 0 || i + 1 >= msg.length) {
|
12856 | return false;
|
12857 | }
|
12858 | return (msg.charCodeAt(i + 1) & 0xFC00) === 0xDC00;
|
12859 | }
|
12860 |
|
12861 | function toArray(msg, enc) {
|
12862 | if (Array.isArray(msg))
|
12863 | return msg.slice();
|
12864 | if (!msg)
|
12865 | return [];
|
12866 | var res = [];
|
12867 | if (typeof msg === 'string') {
|
12868 | if (!enc) {
|
12869 | // Inspired by stringToUtf8ByteArray() in closure-library by Google
|
12870 | // https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt.js#L117-L143
|
12871 | // Apache License 2.0
|
12872 | // https://github.com/google/closure-library/blob/master/LICENSE
|
12873 | var p = 0;
|
12874 | for (var i = 0; i < msg.length; i++) {
|
12875 | var c = msg.charCodeAt(i);
|
12876 | if (c < 128) {
|
12877 | res[p++] = c;
|
12878 | } else if (c < 2048) {
|
12879 | res[p++] = (c >> 6) | 192;
|
12880 | res[p++] = (c & 63) | 128;
|
12881 | } else if (isSurrogatePair(msg, i)) {
|
12882 | c = 0x10000 + ((c & 0x03FF) << 10) + (msg.charCodeAt(++i) & 0x03FF);
|
12883 | res[p++] = (c >> 18) | 240;
|
12884 | res[p++] = ((c >> 12) & 63) | 128;
|
12885 | res[p++] = ((c >> 6) & 63) | 128;
|
12886 | res[p++] = (c & 63) | 128;
|
12887 | } else {
|
12888 | res[p++] = (c >> 12) | 224;
|
12889 | res[p++] = ((c >> 6) & 63) | 128;
|
12890 | res[p++] = (c & 63) | 128;
|
12891 | }
|
12892 | }
|
12893 | } else if (enc === 'hex') {
|
12894 | msg = msg.replace(/[^a-z0-9]+/ig, '');
|
12895 | if (msg.length % 2 !== 0)
|
12896 | msg = '0' + msg;
|
12897 | for (i = 0; i < msg.length; i += 2)
|
12898 | res.push(parseInt(msg[i] + msg[i + 1], 16));
|
12899 | }
|
12900 | } else {
|
12901 | for (i = 0; i < msg.length; i++)
|
12902 | res[i] = msg[i] | 0;
|
12903 | }
|
12904 | return res;
|
12905 | }
|
12906 | exports.toArray = toArray;
|
12907 |
|
12908 | function toHex(msg) {
|
12909 | var res = '';
|
12910 | for (var i = 0; i < msg.length; i++)
|
12911 | res += zero2(msg[i].toString(16));
|
12912 | return res;
|
12913 | }
|
12914 | exports.toHex = toHex;
|
12915 |
|
12916 | function htonl(w) {
|
12917 | var res = (w >>> 24) |
|
12918 | ((w >>> 8) & 0xff00) |
|
12919 | ((w << 8) & 0xff0000) |
|
12920 | ((w & 0xff) << 24);
|
12921 | return res >>> 0;
|
12922 | }
|
12923 | exports.htonl = htonl;
|
12924 |
|
12925 | function toHex32(msg, endian) {
|
12926 | var res = '';
|
12927 | for (var i = 0; i < msg.length; i++) {
|
12928 | var w = msg[i];
|
12929 | if (endian === 'little')
|
12930 | w = htonl(w);
|
12931 | res += zero8(w.toString(16));
|
12932 | }
|
12933 | return res;
|
12934 | }
|
12935 | exports.toHex32 = toHex32;
|
12936 |
|
12937 | function zero2(word) {
|
12938 | if (word.length === 1)
|
12939 | return '0' + word;
|
12940 | else
|
12941 | return word;
|
12942 | }
|
12943 | exports.zero2 = zero2;
|
12944 |
|
12945 | function zero8(word) {
|
12946 | if (word.length === 7)
|
12947 | return '0' + word;
|
12948 | else if (word.length === 6)
|
12949 | return '00' + word;
|
12950 | else if (word.length === 5)
|
12951 | return '000' + word;
|
12952 | else if (word.length === 4)
|
12953 | return '0000' + word;
|
12954 | else if (word.length === 3)
|
12955 | return '00000' + word;
|
12956 | else if (word.length === 2)
|
12957 | return '000000' + word;
|
12958 | else if (word.length === 1)
|
12959 | return '0000000' + word;
|
12960 | else
|
12961 | return word;
|
12962 | }
|
12963 | exports.zero8 = zero8;
|
12964 |
|
12965 | function join32(msg, start, end, endian) {
|
12966 | var len = end - start;
|
12967 | assert(len % 4 === 0);
|
12968 | var res = new Array(len / 4);
|
12969 | for (var i = 0, k = start; i < res.length; i++, k += 4) {
|
12970 | var w;
|
12971 | if (endian === 'big')
|
12972 | w = (msg[k] << 24) | (msg[k + 1] << 16) | (msg[k + 2] << 8) | msg[k + 3];
|
12973 | else
|
12974 | w = (msg[k + 3] << 24) | (msg[k + 2] << 16) | (msg[k + 1] << 8) | msg[k];
|
12975 | res[i] = w >>> 0;
|
12976 | }
|
12977 | return res;
|
12978 | }
|
12979 | exports.join32 = join32;
|
12980 |
|
12981 | function split32(msg, endian) {
|
12982 | var res = new Array(msg.length * 4);
|
12983 | for (var i = 0, k = 0; i < msg.length; i++, k += 4) {
|
12984 | var m = msg[i];
|
12985 | if (endian === 'big') {
|
12986 | res[k] = m >>> 24;
|
12987 | res[k + 1] = (m >>> 16) & 0xff;
|
12988 | res[k + 2] = (m >>> 8) & 0xff;
|
12989 | res[k + 3] = m & 0xff;
|
12990 | } else {
|
12991 | res[k + 3] = m >>> 24;
|
12992 | res[k + 2] = (m >>> 16) & 0xff;
|
12993 | res[k + 1] = (m >>> 8) & 0xff;
|
12994 | res[k] = m & 0xff;
|
12995 | }
|
12996 | }
|
12997 | return res;
|
12998 | }
|
12999 | exports.split32 = split32;
|
13000 |
|
13001 | function rotr32(w, b) {
|
13002 | return (w >>> b) | (w << (32 - b));
|
13003 | }
|
13004 | exports.rotr32 = rotr32;
|
13005 |
|
13006 | function rotl32(w, b) {
|
13007 | return (w << b) | (w >>> (32 - b));
|
13008 | }
|
13009 | exports.rotl32 = rotl32;
|
13010 |
|
13011 | function sum32(a, b) {
|
13012 | return (a + b) >>> 0;
|
13013 | }
|
13014 | exports.sum32 = sum32;
|
13015 |
|
13016 | function sum32_3(a, b, c) {
|
13017 | return (a + b + c) >>> 0;
|
13018 | }
|
13019 | exports.sum32_3 = sum32_3;
|
13020 |
|
13021 | function sum32_4(a, b, c, d) {
|
13022 | return (a + b + c + d) >>> 0;
|
13023 | }
|
13024 | exports.sum32_4 = sum32_4;
|
13025 |
|
13026 | function sum32_5(a, b, c, d, e) {
|
13027 | return (a + b + c + d + e) >>> 0;
|
13028 | }
|
13029 | exports.sum32_5 = sum32_5;
|
13030 |
|
13031 | function sum64(buf, pos, ah, al) {
|
13032 | var bh = buf[pos];
|
13033 | var bl = buf[pos + 1];
|
13034 |
|
13035 | var lo = (al + bl) >>> 0;
|
13036 | var hi = (lo < al ? 1 : 0) + ah + bh;
|
13037 | buf[pos] = hi >>> 0;
|
13038 | buf[pos + 1] = lo;
|
13039 | }
|
13040 | exports.sum64 = sum64;
|
13041 |
|
13042 | function sum64_hi(ah, al, bh, bl) {
|
13043 | var lo = (al + bl) >>> 0;
|
13044 | var hi = (lo < al ? 1 : 0) + ah + bh;
|
13045 | return hi >>> 0;
|
13046 | }
|
13047 | exports.sum64_hi = sum64_hi;
|
13048 |
|
13049 | function sum64_lo(ah, al, bh, bl) {
|
13050 | var lo = al + bl;
|
13051 | return lo >>> 0;
|
13052 | }
|
13053 | exports.sum64_lo = sum64_lo;
|
13054 |
|
13055 | function sum64_4_hi(ah, al, bh, bl, ch, cl, dh, dl) {
|
13056 | var carry = 0;
|
13057 | var lo = al;
|
13058 | lo = (lo + bl) >>> 0;
|
13059 | carry += lo < al ? 1 : 0;
|
13060 | lo = (lo + cl) >>> 0;
|
13061 | carry += lo < cl ? 1 : 0;
|
13062 | lo = (lo + dl) >>> 0;
|
13063 | carry += lo < dl ? 1 : 0;
|
13064 |
|
13065 | var hi = ah + bh + ch + dh + carry;
|
13066 | return hi >>> 0;
|
13067 | }
|
13068 | exports.sum64_4_hi = sum64_4_hi;
|
13069 |
|
13070 | function sum64_4_lo(ah, al, bh, bl, ch, cl, dh, dl) {
|
13071 | var lo = al + bl + cl + dl;
|
13072 | return lo >>> 0;
|
13073 | }
|
13074 | exports.sum64_4_lo = sum64_4_lo;
|
13075 |
|
13076 | function sum64_5_hi(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
|
13077 | var carry = 0;
|
13078 | var lo = al;
|
13079 | lo = (lo + bl) >>> 0;
|
13080 | carry += lo < al ? 1 : 0;
|
13081 | lo = (lo + cl) >>> 0;
|
13082 | carry += lo < cl ? 1 : 0;
|
13083 | lo = (lo + dl) >>> 0;
|
13084 | carry += lo < dl ? 1 : 0;
|
13085 | lo = (lo + el) >>> 0;
|
13086 | carry += lo < el ? 1 : 0;
|
13087 |
|
13088 | var hi = ah + bh + ch + dh + eh + carry;
|
13089 | return hi >>> 0;
|
13090 | }
|
13091 | exports.sum64_5_hi = sum64_5_hi;
|
13092 |
|
13093 | function sum64_5_lo(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
|
13094 | var lo = al + bl + cl + dl + el;
|
13095 |
|
13096 | return lo >>> 0;
|
13097 | }
|
13098 | exports.sum64_5_lo = sum64_5_lo;
|
13099 |
|
13100 | function rotr64_hi(ah, al, num) {
|
13101 | var r = (al << (32 - num)) | (ah >>> num);
|
13102 | return r >>> 0;
|
13103 | }
|
13104 | exports.rotr64_hi = rotr64_hi;
|
13105 |
|
13106 | function rotr64_lo(ah, al, num) {
|
13107 | var r = (ah << (32 - num)) | (al >>> num);
|
13108 | return r >>> 0;
|
13109 | }
|
13110 | exports.rotr64_lo = rotr64_lo;
|
13111 |
|
13112 | function shr64_hi(ah, al, num) {
|
13113 | return ah >>> num;
|
13114 | }
|
13115 | exports.shr64_hi = shr64_hi;
|
13116 |
|
13117 | function shr64_lo(ah, al, num) {
|
13118 | var r = (ah << (32 - num)) | (al >>> num);
|
13119 | return r >>> 0;
|
13120 | }
|
13121 | exports.shr64_lo = shr64_lo;
|
13122 |
|
13123 |
|
13124 | /***/ }),
|
13125 | /* 7 */
|
13126 | /***/ (function(module, exports, __webpack_require__) {
|
13127 |
|
13128 | var basex = __webpack_require__(79)
|
13129 | var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
|
13130 |
|
13131 | module.exports = basex(ALPHABET)
|
13132 |
|
13133 |
|
13134 | /***/ }),
|
13135 | /* 8 */
|
13136 | /***/ (function(module, exports) {
|
13137 |
|
13138 | module.exports = assert;
|
13139 |
|
13140 | function assert(val, msg) {
|
13141 | if (!val)
|
13142 | throw new Error(msg || 'Assertion failed');
|
13143 | }
|
13144 |
|
13145 | assert.equal = function assertEqual(l, r, msg) {
|
13146 | if (l != r)
|
13147 | throw new Error(msg || ('Assertion failed: ' + l + ' != ' + r));
|
13148 | };
|
13149 |
|
13150 |
|
13151 | /***/ }),
|
13152 | /* 9 */
|
13153 | /***/ (function(module, exports) {
|
13154 |
|
13155 | module.exports = require("buffer");
|
13156 |
|
13157 | /***/ }),
|
13158 | /* 10 */
|
13159 | /***/ (function(module, exports, __webpack_require__) {
|
13160 |
|
13161 | ;(function (root, factory) {
|
13162 | if (true) {
|
13163 | // CommonJS
|
13164 | module.exports = exports = factory(__webpack_require__(4));
|
13165 | }
|
13166 | else {}
|
13167 | }(this, function (CryptoJS) {
|
13168 |
|
13169 | (function (Math) {
|
13170 | // Shortcuts
|
13171 | var C = CryptoJS;
|
13172 | var C_lib = C.lib;
|
13173 | var WordArray = C_lib.WordArray;
|
13174 | var Hasher = C_lib.Hasher;
|
13175 | var C_algo = C.algo;
|
13176 |
|
13177 | // Initialization and round constants tables
|
13178 | var H = [];
|
13179 | var K = [];
|
13180 |
|
13181 | // Compute constants
|
13182 | (function () {
|
13183 | function isPrime(n) {
|
13184 | var sqrtN = Math.sqrt(n);
|
13185 | for (var factor = 2; factor <= sqrtN; factor++) {
|
13186 | if (!(n % factor)) {
|
13187 | return false;
|
13188 | }
|
13189 | }
|
13190 |
|
13191 | return true;
|
13192 | }
|
13193 |
|
13194 | function getFractionalBits(n) {
|
13195 | return ((n - (n | 0)) * 0x100000000) | 0;
|
13196 | }
|
13197 |
|
13198 | var n = 2;
|
13199 | var nPrime = 0;
|
13200 | while (nPrime < 64) {
|
13201 | if (isPrime(n)) {
|
13202 | if (nPrime < 8) {
|
13203 | H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2));
|
13204 | }
|
13205 | K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3));
|
13206 |
|
13207 | nPrime++;
|
13208 | }
|
13209 |
|
13210 | n++;
|
13211 | }
|
13212 | }());
|
13213 |
|
13214 | // Reusable object
|
13215 | var W = [];
|
13216 |
|
13217 | /**
|
13218 | * SHA-256 hash algorithm.
|
13219 | */
|
13220 | var SHA256 = C_algo.SHA256 = Hasher.extend({
|
13221 | _doReset: function () {
|
13222 | this._hash = new WordArray.init(H.slice(0));
|
13223 | },
|
13224 |
|
13225 | _doProcessBlock: function (M, offset) {
|
13226 | // Shortcut
|
13227 | var H = this._hash.words;
|
13228 |
|
13229 | // Working variables
|
13230 | var a = H[0];
|
13231 | var b = H[1];
|
13232 | var c = H[2];
|
13233 | var d = H[3];
|
13234 | var e = H[4];
|
13235 | var f = H[5];
|
13236 | var g = H[6];
|
13237 | var h = H[7];
|
13238 |
|
13239 | // Computation
|
13240 | for (var i = 0; i < 64; i++) {
|
13241 | if (i < 16) {
|
13242 | W[i] = M[offset + i] | 0;
|
13243 | } else {
|
13244 | var gamma0x = W[i - 15];
|
13245 | var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^
|
13246 | ((gamma0x << 14) | (gamma0x >>> 18)) ^
|
13247 | (gamma0x >>> 3);
|
13248 |
|
13249 | var gamma1x = W[i - 2];
|
13250 | var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^
|
13251 | ((gamma1x << 13) | (gamma1x >>> 19)) ^
|
13252 | (gamma1x >>> 10);
|
13253 |
|
13254 | W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16];
|
13255 | }
|
13256 |
|
13257 | var ch = (e & f) ^ (~e & g);
|
13258 | var maj = (a & b) ^ (a & c) ^ (b & c);
|
13259 |
|
13260 | var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22));
|
13261 | var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25));
|
13262 |
|
13263 | var t1 = h + sigma1 + ch + K[i] + W[i];
|
13264 | var t2 = sigma0 + maj;
|
13265 |
|
13266 | h = g;
|
13267 | g = f;
|
13268 | f = e;
|
13269 | e = (d + t1) | 0;
|
13270 | d = c;
|
13271 | c = b;
|
13272 | b = a;
|
13273 | a = (t1 + t2) | 0;
|
13274 | }
|
13275 |
|
13276 | // Intermediate hash value
|
13277 | H[0] = (H[0] + a) | 0;
|
13278 | H[1] = (H[1] + b) | 0;
|
13279 | H[2] = (H[2] + c) | 0;
|
13280 | H[3] = (H[3] + d) | 0;
|
13281 | H[4] = (H[4] + e) | 0;
|
13282 | H[5] = (H[5] + f) | 0;
|
13283 | H[6] = (H[6] + g) | 0;
|
13284 | H[7] = (H[7] + h) | 0;
|
13285 | },
|
13286 |
|
13287 | _doFinalize: function () {
|
13288 | // Shortcuts
|
13289 | var data = this._data;
|
13290 | var dataWords = data.words;
|
13291 |
|
13292 | var nBitsTotal = this._nDataBytes * 8;
|
13293 | var nBitsLeft = data.sigBytes * 8;
|
13294 |
|
13295 | // Add padding
|
13296 | dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
|
13297 | dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
|
13298 | dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
|
13299 | data.sigBytes = dataWords.length * 4;
|
13300 |
|
13301 | // Hash final blocks
|
13302 | this._process();
|
13303 |
|
13304 | // Return final computed hash
|
13305 | return this._hash;
|
13306 | },
|
13307 |
|
13308 | clone: function () {
|
13309 | var clone = Hasher.clone.call(this);
|
13310 | clone._hash = this._hash.clone();
|
13311 |
|
13312 | return clone;
|
13313 | }
|
13314 | });
|
13315 |
|
13316 | /**
|
13317 | * Shortcut function to the hasher's object interface.
|
13318 | *
|
13319 | * @param {WordArray|string} message The message to hash.
|
13320 | *
|
13321 | * @return {WordArray} The hash.
|
13322 | *
|
13323 | * @static
|
13324 | *
|
13325 | * @example
|
13326 | *
|
13327 | * var hash = CryptoJS.SHA256('message');
|
13328 | * var hash = CryptoJS.SHA256(wordArray);
|
13329 | */
|
13330 | C.SHA256 = Hasher._createHelper(SHA256);
|
13331 |
|
13332 | /**
|
13333 | * Shortcut function to the HMAC's object interface.
|
13334 | *
|
13335 | * @param {WordArray|string} message The message to hash.
|
13336 | * @param {WordArray|string} key The secret key.
|
13337 | *
|
13338 | * @return {WordArray} The HMAC.
|
13339 | *
|
13340 | * @static
|
13341 | *
|
13342 | * @example
|
13343 | *
|
13344 | * var hmac = CryptoJS.HmacSHA256(message, key);
|
13345 | */
|
13346 | C.HmacSHA256 = Hasher._createHmacHelper(SHA256);
|
13347 | }(Math));
|
13348 |
|
13349 |
|
13350 | return CryptoJS.SHA256;
|
13351 |
|
13352 | }));
|
13353 |
|
13354 | /***/ }),
|
13355 | /* 11 */
|
13356 | /***/ (function(module, exports, __webpack_require__) {
|
13357 |
|
13358 | var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;/*
|
13359 | * loglevel - https://github.com/pimterry/loglevel
|
13360 | *
|
13361 | * Copyright (c) 2013 Tim Perry
|
13362 | * Licensed under the MIT license.
|
13363 | */
|
13364 | (function (root, definition) {
|
13365 | "use strict";
|
13366 | if (true) {
|
13367 | !(__WEBPACK_AMD_DEFINE_FACTORY__ = (definition),
|
13368 | __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
|
13369 | (__WEBPACK_AMD_DEFINE_FACTORY__.call(exports, __webpack_require__, exports, module)) :
|
13370 | __WEBPACK_AMD_DEFINE_FACTORY__),
|
13371 | __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
13372 | } else {}
|
13373 | }(this, function () {
|
13374 | "use strict";
|
13375 |
|
13376 | // Slightly dubious tricks to cut down minimized file size
|
13377 | var noop = function() {};
|
13378 | var undefinedType = "undefined";
|
13379 |
|
13380 | var logMethods = [
|
13381 | "trace",
|
13382 | "debug",
|
13383 | "info",
|
13384 | "warn",
|
13385 | "error"
|
13386 | ];
|
13387 |
|
13388 | // Cross-browser bind equivalent that works at least back to IE6
|
13389 | function bindMethod(obj, methodName) {
|
13390 | var method = obj[methodName];
|
13391 | if (typeof method.bind === 'function') {
|
13392 | return method.bind(obj);
|
13393 | } else {
|
13394 | try {
|
13395 | return Function.prototype.bind.call(method, obj);
|
13396 | } catch (e) {
|
13397 | // Missing bind shim or IE8 + Modernizr, fallback to wrapping
|
13398 | return function() {
|
13399 | return Function.prototype.apply.apply(method, [obj, arguments]);
|
13400 | };
|
13401 | }
|
13402 | }
|
13403 | }
|
13404 |
|
13405 | // Build the best logging method possible for this env
|
13406 | // Wherever possible we want to bind, not wrap, to preserve stack traces
|
13407 | function realMethod(methodName) {
|
13408 | if (methodName === 'debug') {
|
13409 | methodName = 'log';
|
13410 | }
|
13411 |
|
13412 | if (typeof console === undefinedType) {
|
13413 | return false; // No method possible, for now - fixed later by enableLoggingWhenConsoleArrives
|
13414 | } else if (console[methodName] !== undefined) {
|
13415 | return bindMethod(console, methodName);
|
13416 | } else if (console.log !== undefined) {
|
13417 | return bindMethod(console, 'log');
|
13418 | } else {
|
13419 | return noop;
|
13420 | }
|
13421 | }
|
13422 |
|
13423 | // These private functions always need `this` to be set properly
|
13424 |
|
13425 | function replaceLoggingMethods(level, loggerName) {
|
13426 | /*jshint validthis:true */
|
13427 | for (var i = 0; i < logMethods.length; i++) {
|
13428 | var methodName = logMethods[i];
|
13429 | this[methodName] = (i < level) ?
|
13430 | noop :
|
13431 | this.methodFactory(methodName, level, loggerName);
|
13432 | }
|
13433 |
|
13434 | // Define log.log as an alias for log.debug
|
13435 | this.log = this.debug;
|
13436 | }
|
13437 |
|
13438 | // In old IE versions, the console isn't present until you first open it.
|
13439 | // We build realMethod() replacements here that regenerate logging methods
|
13440 | function enableLoggingWhenConsoleArrives(methodName, level, loggerName) {
|
13441 | return function () {
|
13442 | if (typeof console !== undefinedType) {
|
13443 | replaceLoggingMethods.call(this, level, loggerName);
|
13444 | this[methodName].apply(this, arguments);
|
13445 | }
|
13446 | };
|
13447 | }
|
13448 |
|
13449 | // By default, we use closely bound real methods wherever possible, and
|
13450 | // otherwise we wait for a console to appear, and then try again.
|
13451 | function defaultMethodFactory(methodName, level, loggerName) {
|
13452 | /*jshint validthis:true */
|
13453 | return realMethod(methodName) ||
|
13454 | enableLoggingWhenConsoleArrives.apply(this, arguments);
|
13455 | }
|
13456 |
|
13457 | function Logger(name, defaultLevel, factory) {
|
13458 | var self = this;
|
13459 | var currentLevel;
|
13460 | var storageKey = "loglevel";
|
13461 | if (name) {
|
13462 | storageKey += ":" + name;
|
13463 | }
|
13464 |
|
13465 | function persistLevelIfPossible(levelNum) {
|
13466 | var levelName = (logMethods[levelNum] || 'silent').toUpperCase();
|
13467 |
|
13468 | if (typeof window === undefinedType) return;
|
13469 |
|
13470 | // Use localStorage if available
|
13471 | try {
|
13472 | window.localStorage[storageKey] = levelName;
|
13473 | return;
|
13474 | } catch (ignore) {}
|
13475 |
|
13476 | // Use session cookie as fallback
|
13477 | try {
|
13478 | window.document.cookie =
|
13479 | encodeURIComponent(storageKey) + "=" + levelName + ";";
|
13480 | } catch (ignore) {}
|
13481 | }
|
13482 |
|
13483 | function getPersistedLevel() {
|
13484 | var storedLevel;
|
13485 |
|
13486 | if (typeof window === undefinedType) return;
|
13487 |
|
13488 | try {
|
13489 | storedLevel = window.localStorage[storageKey];
|
13490 | } catch (ignore) {}
|
13491 |
|
13492 | // Fallback to cookies if local storage gives us nothing
|
13493 | if (typeof storedLevel === undefinedType) {
|
13494 | try {
|
13495 | var cookie = window.document.cookie;
|
13496 | var location = cookie.indexOf(
|
13497 | encodeURIComponent(storageKey) + "=");
|
13498 | if (location !== -1) {
|
13499 | storedLevel = /^([^;]+)/.exec(cookie.slice(location))[1];
|
13500 | }
|
13501 | } catch (ignore) {}
|
13502 | }
|
13503 |
|
13504 | // If the stored level is not valid, treat it as if nothing was stored.
|
13505 | if (self.levels[storedLevel] === undefined) {
|
13506 | storedLevel = undefined;
|
13507 | }
|
13508 |
|
13509 | return storedLevel;
|
13510 | }
|
13511 |
|
13512 | /*
|
13513 | *
|
13514 | * Public logger API - see https://github.com/pimterry/loglevel for details
|
13515 | *
|
13516 | */
|
13517 |
|
13518 | self.name = name;
|
13519 |
|
13520 | self.levels = { "TRACE": 0, "DEBUG": 1, "INFO": 2, "WARN": 3,
|
13521 | "ERROR": 4, "SILENT": 5};
|
13522 |
|
13523 | self.methodFactory = factory || defaultMethodFactory;
|
13524 |
|
13525 | self.getLevel = function () {
|
13526 | return currentLevel;
|
13527 | };
|
13528 |
|
13529 | self.setLevel = function (level, persist) {
|
13530 | if (typeof level === "string" && self.levels[level.toUpperCase()] !== undefined) {
|
13531 | level = self.levels[level.toUpperCase()];
|
13532 | }
|
13533 | if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) {
|
13534 | currentLevel = level;
|
13535 | if (persist !== false) { // defaults to true
|
13536 | persistLevelIfPossible(level);
|
13537 | }
|
13538 | replaceLoggingMethods.call(self, level, name);
|
13539 | if (typeof console === undefinedType && level < self.levels.SILENT) {
|
13540 | return "No console available for logging";
|
13541 | }
|
13542 | } else {
|
13543 | throw "log.setLevel() called with invalid level: " + level;
|
13544 | }
|
13545 | };
|
13546 |
|
13547 | self.setDefaultLevel = function (level) {
|
13548 | if (!getPersistedLevel()) {
|
13549 | self.setLevel(level, false);
|
13550 | }
|
13551 | };
|
13552 |
|
13553 | self.enableAll = function(persist) {
|
13554 | self.setLevel(self.levels.TRACE, persist);
|
13555 | };
|
13556 |
|
13557 | self.disableAll = function(persist) {
|
13558 | self.setLevel(self.levels.SILENT, persist);
|
13559 | };
|
13560 |
|
13561 | // Initialize with the right level
|
13562 | var initialLevel = getPersistedLevel();
|
13563 | if (initialLevel == null) {
|
13564 | initialLevel = defaultLevel == null ? "WARN" : defaultLevel;
|
13565 | }
|
13566 | self.setLevel(initialLevel, false);
|
13567 | }
|
13568 |
|
13569 | /*
|
13570 | *
|
13571 | * Top-level API
|
13572 | *
|
13573 | */
|
13574 |
|
13575 | var defaultLogger = new Logger();
|
13576 |
|
13577 | var _loggersByName = {};
|
13578 | defaultLogger.getLogger = function getLogger(name) {
|
13579 | if (typeof name !== "string" || name === "") {
|
13580 | throw new TypeError("You must supply a name when creating a logger.");
|
13581 | }
|
13582 |
|
13583 | var logger = _loggersByName[name];
|
13584 | if (!logger) {
|
13585 | logger = _loggersByName[name] = new Logger(
|
13586 | name, defaultLogger.getLevel(), defaultLogger.methodFactory);
|
13587 | }
|
13588 | return logger;
|
13589 | };
|
13590 |
|
13591 | // Grab the current global log variable in case of overwrite
|
13592 | var _log = (typeof window !== undefinedType) ? window.log : undefined;
|
13593 | defaultLogger.noConflict = function() {
|
13594 | if (typeof window !== undefinedType &&
|
13595 | window.log === defaultLogger) {
|
13596 | window.log = _log;
|
13597 | }
|
13598 |
|
13599 | return defaultLogger;
|
13600 | };
|
13601 |
|
13602 | defaultLogger.getLoggers = function getLoggers() {
|
13603 | return _loggersByName;
|
13604 | };
|
13605 |
|
13606 | return defaultLogger;
|
13607 | }));
|
13608 |
|
13609 |
|
13610 | /***/ }),
|
13611 | /* 12 */
|
13612 | /***/ (function(module, exports) {
|
13613 |
|
13614 | module.exports = require("util");
|
13615 |
|
13616 | /***/ }),
|
13617 | /* 13 */
|
13618 | /***/ (function(module, exports, __webpack_require__) {
|
13619 |
|
13620 | "use strict";
|
13621 |
|
13622 |
|
13623 | var utils = __webpack_require__(6);
|
13624 | var assert = __webpack_require__(8);
|
13625 |
|
13626 | function BlockHash() {
|
13627 | this.pending = null;
|
13628 | this.pendingTotal = 0;
|
13629 | this.blockSize = this.constructor.blockSize;
|
13630 | this.outSize = this.constructor.outSize;
|
13631 | this.hmacStrength = this.constructor.hmacStrength;
|
13632 | this.padLength = this.constructor.padLength / 8;
|
13633 | this.endian = 'big';
|
13634 |
|
13635 | this._delta8 = this.blockSize / 8;
|
13636 | this._delta32 = this.blockSize / 32;
|
13637 | }
|
13638 | exports.BlockHash = BlockHash;
|
13639 |
|
13640 | BlockHash.prototype.update = function update(msg, enc) {
|
13641 | // Convert message to array, pad it, and join into 32bit blocks
|
13642 | msg = utils.toArray(msg, enc);
|
13643 | if (!this.pending)
|
13644 | this.pending = msg;
|
13645 | else
|
13646 | this.pending = this.pending.concat(msg);
|
13647 | this.pendingTotal += msg.length;
|
13648 |
|
13649 | // Enough data, try updating
|
13650 | if (this.pending.length >= this._delta8) {
|
13651 | msg = this.pending;
|
13652 |
|
13653 | // Process pending data in blocks
|
13654 | var r = msg.length % this._delta8;
|
13655 | this.pending = msg.slice(msg.length - r, msg.length);
|
13656 | if (this.pending.length === 0)
|
13657 | this.pending = null;
|
13658 |
|
13659 | msg = utils.join32(msg, 0, msg.length - r, this.endian);
|
13660 | for (var i = 0; i < msg.length; i += this._delta32)
|
13661 | this._update(msg, i, i + this._delta32);
|
13662 | }
|
13663 |
|
13664 | return this;
|
13665 | };
|
13666 |
|
13667 | BlockHash.prototype.digest = function digest(enc) {
|
13668 | this.update(this._pad());
|
13669 | assert(this.pending === null);
|
13670 |
|
13671 | return this._digest(enc);
|
13672 | };
|
13673 |
|
13674 | BlockHash.prototype._pad = function pad() {
|
13675 | var len = this.pendingTotal;
|
13676 | var bytes = this._delta8;
|
13677 | var k = bytes - ((len + this.padLength) % bytes);
|
13678 | var res = new Array(k + this.padLength);
|
13679 | res[0] = 0x80;
|
13680 | for (var i = 1; i < k; i++)
|
13681 | res[i] = 0;
|
13682 |
|
13683 | // Append length
|
13684 | len <<= 3;
|
13685 | if (this.endian === 'big') {
|
13686 | for (var t = 8; t < this.padLength; t++)
|
13687 | res[i++] = 0;
|
13688 |
|
13689 | res[i++] = 0;
|
13690 | res[i++] = 0;
|
13691 | res[i++] = 0;
|
13692 | res[i++] = 0;
|
13693 | res[i++] = (len >>> 24) & 0xff;
|
13694 | res[i++] = (len >>> 16) & 0xff;
|
13695 | res[i++] = (len >>> 8) & 0xff;
|
13696 | res[i++] = len & 0xff;
|
13697 | } else {
|
13698 | res[i++] = len & 0xff;
|
13699 | res[i++] = (len >>> 8) & 0xff;
|
13700 | res[i++] = (len >>> 16) & 0xff;
|
13701 | res[i++] = (len >>> 24) & 0xff;
|
13702 | res[i++] = 0;
|
13703 | res[i++] = 0;
|
13704 | res[i++] = 0;
|
13705 | res[i++] = 0;
|
13706 |
|
13707 | for (t = 8; t < this.padLength; t++)
|
13708 | res[i++] = 0;
|
13709 | }
|
13710 |
|
13711 | return res;
|
13712 | };
|
13713 |
|
13714 |
|
13715 | /***/ }),
|
13716 | /* 14 */
|
13717 | /***/ (function(module, exports, __webpack_require__) {
|
13718 |
|
13719 | ;(function (root, factory) {
|
13720 | if (true) {
|
13721 | // CommonJS
|
13722 | module.exports = exports = factory(__webpack_require__(4));
|
13723 | }
|
13724 | else {}
|
13725 | }(this, function (CryptoJS) {
|
13726 |
|
13727 | return CryptoJS.enc.Hex;
|
13728 |
|
13729 | }));
|
13730 |
|
13731 | /***/ }),
|
13732 | /* 15 */
|
13733 | /***/ (function(module, exports, __webpack_require__) {
|
13734 |
|
13735 | "use strict";
|
13736 |
|
13737 |
|
13738 | var curve = exports;
|
13739 |
|
13740 | curve.base = __webpack_require__(86);
|
13741 | curve.short = __webpack_require__(87);
|
13742 | curve.mont = __webpack_require__(89);
|
13743 | curve.edwards = __webpack_require__(90);
|
13744 |
|
13745 |
|
13746 | /***/ }),
|
13747 | /* 16 */
|
13748 | /***/ (function(module, exports, __webpack_require__) {
|
13749 |
|
13750 | try {
|
13751 | var util = __webpack_require__(12);
|
13752 | if (typeof util.inherits !== 'function') throw '';
|
13753 | module.exports = util.inherits;
|
13754 | } catch (e) {
|
13755 | module.exports = __webpack_require__(88);
|
13756 | }
|
13757 |
|
13758 |
|
13759 | /***/ }),
|
13760 | /* 17 */
|
13761 | /***/ (function(module, exports, __webpack_require__) {
|
13762 |
|
13763 | "use strict";
|
13764 |
|
13765 |
|
13766 | var createHash = __webpack_require__(80)
|
13767 | var bs58checkBase = __webpack_require__(81)
|
13768 |
|
13769 | // SHA256(SHA256(buffer))
|
13770 | function sha256x2 (buffer) {
|
13771 | var tmp = createHash('sha256').update(buffer).digest()
|
13772 | return createHash('sha256').update(tmp).digest()
|
13773 | }
|
13774 |
|
13775 | module.exports = bs58checkBase(sha256x2)
|
13776 |
|
13777 |
|
13778 | /***/ }),
|
13779 | /* 18 */
|
13780 | /***/ (function(module, exports, __webpack_require__) {
|
13781 |
|
13782 | "use strict";
|
13783 |
|
13784 |
|
13785 | var utils = __webpack_require__(2);
|
13786 |
|
13787 | function encode(val) {
|
13788 | return encodeURIComponent(val).
|
13789 | replace(/%40/gi, '@').
|
13790 | replace(/%3A/gi, ':').
|
13791 | replace(/%24/g, '$').
|
13792 | replace(/%2C/gi, ',').
|
13793 | replace(/%20/g, '+').
|
13794 | replace(/%5B/gi, '[').
|
13795 | replace(/%5D/gi, ']');
|
13796 | }
|
13797 |
|
13798 | /**
|
13799 | * Build a URL by appending params to the end
|
13800 | *
|
13801 | * @param {string} url The base of the url (e.g., http://www.google.com)
|
13802 | * @param {object} [params] The params to be appended
|
13803 | * @returns {string} The formatted url
|
13804 | */
|
13805 | module.exports = function buildURL(url, params, paramsSerializer) {
|
13806 | /*eslint no-param-reassign:0*/
|
13807 | if (!params) {
|
13808 | return url;
|
13809 | }
|
13810 |
|
13811 | var serializedParams;
|
13812 | if (paramsSerializer) {
|
13813 | serializedParams = paramsSerializer(params);
|
13814 | } else if (utils.isURLSearchParams(params)) {
|
13815 | serializedParams = params.toString();
|
13816 | } else {
|
13817 | var parts = [];
|
13818 |
|
13819 | utils.forEach(params, function serialize(val, key) {
|
13820 | if (val === null || typeof val === 'undefined') {
|
13821 | return;
|
13822 | }
|
13823 |
|
13824 | if (utils.isArray(val)) {
|
13825 | key = key + '[]';
|
13826 | } else {
|
13827 | val = [val];
|
13828 | }
|
13829 |
|
13830 | utils.forEach(val, function parseValue(v) {
|
13831 | if (utils.isDate(v)) {
|
13832 | v = v.toISOString();
|
13833 | } else if (utils.isObject(v)) {
|
13834 | v = JSON.stringify(v);
|
13835 | }
|
13836 | parts.push(encode(key) + '=' + encode(v));
|
13837 | });
|
13838 | });
|
13839 |
|
13840 | serializedParams = parts.join('&');
|
13841 | }
|
13842 |
|
13843 | if (serializedParams) {
|
13844 | var hashmarkIndex = url.indexOf('#');
|
13845 | if (hashmarkIndex !== -1) {
|
13846 | url = url.slice(0, hashmarkIndex);
|
13847 | }
|
13848 |
|
13849 | url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
|
13850 | }
|
13851 |
|
13852 | return url;
|
13853 | };
|
13854 |
|
13855 |
|
13856 | /***/ }),
|
13857 | /* 19 */
|
13858 | /***/ (function(module, exports, __webpack_require__) {
|
13859 |
|
13860 | "use strict";
|
13861 |
|
13862 |
|
13863 | var enhanceError = __webpack_require__(31);
|
13864 |
|
13865 | /**
|
13866 | * Create an Error with the specified message, config, error code, request and response.
|
13867 | *
|
13868 | * @param {string} message The error message.
|
13869 | * @param {Object} config The config.
|
13870 | * @param {string} [code] The error code (for example, 'ECONNABORTED').
|
13871 | * @param {Object} [request] The request.
|
13872 | * @param {Object} [response] The response.
|
13873 | * @returns {Error} The created error.
|
13874 | */
|
13875 | module.exports = function createError(message, config, code, request, response) {
|
13876 | var error = new Error(message);
|
13877 | return enhanceError(error, config, code, request, response);
|
13878 | };
|
13879 |
|
13880 |
|
13881 | /***/ }),
|
13882 | /* 20 */
|
13883 | /***/ (function(module, exports) {
|
13884 |
|
13885 | module.exports = require("crypto");
|
13886 |
|
13887 | /***/ }),
|
13888 | /* 21 */
|
13889 | /***/ (function(module, exports, __webpack_require__) {
|
13890 |
|
13891 | var hash = exports;
|
13892 |
|
13893 | hash.utils = __webpack_require__(6);
|
13894 | hash.common = __webpack_require__(13);
|
13895 | hash.sha = __webpack_require__(92);
|
13896 | hash.ripemd = __webpack_require__(96);
|
13897 | hash.hmac = __webpack_require__(97);
|
13898 |
|
13899 | // Proxy hash functions to the main object
|
13900 | hash.sha1 = hash.sha.sha1;
|
13901 | hash.sha256 = hash.sha.sha256;
|
13902 | hash.sha224 = hash.sha.sha224;
|
13903 | hash.sha384 = hash.sha.sha384;
|
13904 | hash.sha512 = hash.sha.sha512;
|
13905 | hash.ripemd160 = hash.ripemd.ripemd160;
|
13906 |
|
13907 |
|
13908 | /***/ }),
|
13909 | /* 22 */
|
13910 | /***/ (function(module, exports, __webpack_require__) {
|
13911 |
|
13912 | ;(function (root, factory, undef) {
|
13913 | if (true) {
|
13914 | // CommonJS
|
13915 | module.exports = exports = factory(__webpack_require__(4), __webpack_require__(44));
|
13916 | }
|
13917 | else {}
|
13918 | }(this, function (CryptoJS) {
|
13919 |
|
13920 | /**
|
13921 | * Cipher core components.
|
13922 | */
|
13923 | CryptoJS.lib.Cipher || (function (undefined) {
|
13924 | // Shortcuts
|
13925 | var C = CryptoJS;
|
13926 | var C_lib = C.lib;
|
13927 | var Base = C_lib.Base;
|
13928 | var WordArray = C_lib.WordArray;
|
13929 | var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm;
|
13930 | var C_enc = C.enc;
|
13931 | var Utf8 = C_enc.Utf8;
|
13932 | var Base64 = C_enc.Base64;
|
13933 | var C_algo = C.algo;
|
13934 | var EvpKDF = C_algo.EvpKDF;
|
13935 |
|
13936 | /**
|
13937 | * Abstract base cipher template.
|
13938 | *
|
13939 | * @property {number} keySize This cipher's key size. Default: 4 (128 bits)
|
13940 | * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits)
|
13941 | * @property {number} _ENC_XFORM_MODE A constant representing encryption mode.
|
13942 | * @property {number} _DEC_XFORM_MODE A constant representing decryption mode.
|
13943 | */
|
13944 | var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({
|
13945 | /**
|
13946 | * Configuration options.
|
13947 | *
|
13948 | * @property {WordArray} iv The IV to use for this operation.
|
13949 | */
|
13950 | cfg: Base.extend(),
|
13951 |
|
13952 | /**
|
13953 | * Creates this cipher in encryption mode.
|
13954 | *
|
13955 | * @param {WordArray} key The key.
|
13956 | * @param {Object} cfg (Optional) The configuration options to use for this operation.
|
13957 | *
|
13958 | * @return {Cipher} A cipher instance.
|
13959 | *
|
13960 | * @static
|
13961 | *
|
13962 | * @example
|
13963 | *
|
13964 | * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray });
|
13965 | */
|
13966 | createEncryptor: function (key, cfg) {
|
13967 | return this.create(this._ENC_XFORM_MODE, key, cfg);
|
13968 | },
|
13969 |
|
13970 | /**
|
13971 | * Creates this cipher in decryption mode.
|
13972 | *
|
13973 | * @param {WordArray} key The key.
|
13974 | * @param {Object} cfg (Optional) The configuration options to use for this operation.
|
13975 | *
|
13976 | * @return {Cipher} A cipher instance.
|
13977 | *
|
13978 | * @static
|
13979 | *
|
13980 | * @example
|
13981 | *
|
13982 | * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray });
|
13983 | */
|
13984 | createDecryptor: function (key, cfg) {
|
13985 | return this.create(this._DEC_XFORM_MODE, key, cfg);
|
13986 | },
|
13987 |
|
13988 | /**
|
13989 | * Initializes a newly created cipher.
|
13990 | *
|
13991 | * @param {number} xformMode Either the encryption or decryption transormation mode constant.
|
13992 | * @param {WordArray} key The key.
|
13993 | * @param {Object} cfg (Optional) The configuration options to use for this operation.
|
13994 | *
|
13995 | * @example
|
13996 | *
|
13997 | * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray });
|
13998 | */
|
13999 | init: function (xformMode, key, cfg) {
|
14000 | // Apply config defaults
|
14001 | this.cfg = this.cfg.extend(cfg);
|
14002 |
|
14003 | // Store transform mode and key
|
14004 | this._xformMode = xformMode;
|
14005 | this._key = key;
|
14006 |
|
14007 | // Set initial values
|
14008 | this.reset();
|
14009 | },
|
14010 |
|
14011 | /**
|
14012 | * Resets this cipher to its initial state.
|
14013 | *
|
14014 | * @example
|
14015 | *
|
14016 | * cipher.reset();
|
14017 | */
|
14018 | reset: function () {
|
14019 | // Reset data buffer
|
14020 | BufferedBlockAlgorithm.reset.call(this);
|
14021 |
|
14022 | // Perform concrete-cipher logic
|
14023 | this._doReset();
|
14024 | },
|
14025 |
|
14026 | /**
|
14027 | * Adds data to be encrypted or decrypted.
|
14028 | *
|
14029 | * @param {WordArray|string} dataUpdate The data to encrypt or decrypt.
|
14030 | *
|
14031 | * @return {WordArray} The data after processing.
|
14032 | *
|
14033 | * @example
|
14034 | *
|
14035 | * var encrypted = cipher.process('data');
|
14036 | * var encrypted = cipher.process(wordArray);
|
14037 | */
|
14038 | process: function (dataUpdate) {
|
14039 | // Append
|
14040 | this._append(dataUpdate);
|
14041 |
|
14042 | // Process available blocks
|
14043 | return this._process();
|
14044 | },
|
14045 |
|
14046 | /**
|
14047 | * Finalizes the encryption or decryption process.
|
14048 | * Note that the finalize operation is effectively a destructive, read-once operation.
|
14049 | *
|
14050 | * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt.
|
14051 | *
|
14052 | * @return {WordArray} The data after final processing.
|
14053 | *
|
14054 | * @example
|
14055 | *
|
14056 | * var encrypted = cipher.finalize();
|
14057 | * var encrypted = cipher.finalize('data');
|
14058 | * var encrypted = cipher.finalize(wordArray);
|
14059 | */
|
14060 | finalize: function (dataUpdate) {
|
14061 | // Final data update
|
14062 | if (dataUpdate) {
|
14063 | this._append(dataUpdate);
|
14064 | }
|
14065 |
|
14066 | // Perform concrete-cipher logic
|
14067 | var finalProcessedData = this._doFinalize();
|
14068 |
|
14069 | return finalProcessedData;
|
14070 | },
|
14071 |
|
14072 | keySize: 128/32,
|
14073 |
|
14074 | ivSize: 128/32,
|
14075 |
|
14076 | _ENC_XFORM_MODE: 1,
|
14077 |
|
14078 | _DEC_XFORM_MODE: 2,
|
14079 |
|
14080 | /**
|
14081 | * Creates shortcut functions to a cipher's object interface.
|
14082 | *
|
14083 | * @param {Cipher} cipher The cipher to create a helper for.
|
14084 | *
|
14085 | * @return {Object} An object with encrypt and decrypt shortcut functions.
|
14086 | *
|
14087 | * @static
|
14088 | *
|
14089 | * @example
|
14090 | *
|
14091 | * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES);
|
14092 | */
|
14093 | _createHelper: (function () {
|
14094 | function selectCipherStrategy(key) {
|
14095 | if (typeof key == 'string') {
|
14096 | return PasswordBasedCipher;
|
14097 | } else {
|
14098 | return SerializableCipher;
|
14099 | }
|
14100 | }
|
14101 |
|
14102 | return function (cipher) {
|
14103 | return {
|
14104 | encrypt: function (message, key, cfg) {
|
14105 | return selectCipherStrategy(key).encrypt(cipher, message, key, cfg);
|
14106 | },
|
14107 |
|
14108 | decrypt: function (ciphertext, key, cfg) {
|
14109 | return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg);
|
14110 | }
|
14111 | };
|
14112 | };
|
14113 | }())
|
14114 | });
|
14115 |
|
14116 | /**
|
14117 | * Abstract base stream cipher template.
|
14118 | *
|
14119 | * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits)
|
14120 | */
|
14121 | var StreamCipher = C_lib.StreamCipher = Cipher.extend({
|
14122 | _doFinalize: function () {
|
14123 | // Process partial blocks
|
14124 | var finalProcessedBlocks = this._process(!!'flush');
|
14125 |
|
14126 | return finalProcessedBlocks;
|
14127 | },
|
14128 |
|
14129 | blockSize: 1
|
14130 | });
|
14131 |
|
14132 | /**
|
14133 | * Mode namespace.
|
14134 | */
|
14135 | var C_mode = C.mode = {};
|
14136 |
|
14137 | /**
|
14138 | * Abstract base block cipher mode template.
|
14139 | */
|
14140 | var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({
|
14141 | /**
|
14142 | * Creates this mode for encryption.
|
14143 | *
|
14144 | * @param {Cipher} cipher A block cipher instance.
|
14145 | * @param {Array} iv The IV words.
|
14146 | *
|
14147 | * @static
|
14148 | *
|
14149 | * @example
|
14150 | *
|
14151 | * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words);
|
14152 | */
|
14153 | createEncryptor: function (cipher, iv) {
|
14154 | return this.Encryptor.create(cipher, iv);
|
14155 | },
|
14156 |
|
14157 | /**
|
14158 | * Creates this mode for decryption.
|
14159 | *
|
14160 | * @param {Cipher} cipher A block cipher instance.
|
14161 | * @param {Array} iv The IV words.
|
14162 | *
|
14163 | * @static
|
14164 | *
|
14165 | * @example
|
14166 | *
|
14167 | * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words);
|
14168 | */
|
14169 | createDecryptor: function (cipher, iv) {
|
14170 | return this.Decryptor.create(cipher, iv);
|
14171 | },
|
14172 |
|
14173 | /**
|
14174 | * Initializes a newly created mode.
|
14175 | *
|
14176 | * @param {Cipher} cipher A block cipher instance.
|
14177 | * @param {Array} iv The IV words.
|
14178 | *
|
14179 | * @example
|
14180 | *
|
14181 | * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words);
|
14182 | */
|
14183 | init: function (cipher, iv) {
|
14184 | this._cipher = cipher;
|
14185 | this._iv = iv;
|
14186 | }
|
14187 | });
|
14188 |
|
14189 | /**
|
14190 | * Cipher Block Chaining mode.
|
14191 | */
|
14192 | var CBC = C_mode.CBC = (function () {
|
14193 | /**
|
14194 | * Abstract base CBC mode.
|
14195 | */
|
14196 | var CBC = BlockCipherMode.extend();
|
14197 |
|
14198 | /**
|
14199 | * CBC encryptor.
|
14200 | */
|
14201 | CBC.Encryptor = CBC.extend({
|
14202 | /**
|
14203 | * Processes the data block at offset.
|
14204 | *
|
14205 | * @param {Array} words The data words to operate on.
|
14206 | * @param {number} offset The offset where the block starts.
|
14207 | *
|
14208 | * @example
|
14209 | *
|
14210 | * mode.processBlock(data.words, offset);
|
14211 | */
|
14212 | processBlock: function (words, offset) {
|
14213 | // Shortcuts
|
14214 | var cipher = this._cipher;
|
14215 | var blockSize = cipher.blockSize;
|
14216 |
|
14217 | // XOR and encrypt
|
14218 | xorBlock.call(this, words, offset, blockSize);
|
14219 | cipher.encryptBlock(words, offset);
|
14220 |
|
14221 | // Remember this block to use with next block
|
14222 | this._prevBlock = words.slice(offset, offset + blockSize);
|
14223 | }
|
14224 | });
|
14225 |
|
14226 | /**
|
14227 | * CBC decryptor.
|
14228 | */
|
14229 | CBC.Decryptor = CBC.extend({
|
14230 | /**
|
14231 | * Processes the data block at offset.
|
14232 | *
|
14233 | * @param {Array} words The data words to operate on.
|
14234 | * @param {number} offset The offset where the block starts.
|
14235 | *
|
14236 | * @example
|
14237 | *
|
14238 | * mode.processBlock(data.words, offset);
|
14239 | */
|
14240 | processBlock: function (words, offset) {
|
14241 | // Shortcuts
|
14242 | var cipher = this._cipher;
|
14243 | var blockSize = cipher.blockSize;
|
14244 |
|
14245 | // Remember this block to use with next block
|
14246 | var thisBlock = words.slice(offset, offset + blockSize);
|
14247 |
|
14248 | // Decrypt and XOR
|
14249 | cipher.decryptBlock(words, offset);
|
14250 | xorBlock.call(this, words, offset, blockSize);
|
14251 |
|
14252 | // This block becomes the previous block
|
14253 | this._prevBlock = thisBlock;
|
14254 | }
|
14255 | });
|
14256 |
|
14257 | function xorBlock(words, offset, blockSize) {
|
14258 | // Shortcut
|
14259 | var iv = this._iv;
|
14260 |
|
14261 | // Choose mixing block
|
14262 | if (iv) {
|
14263 | var block = iv;
|
14264 |
|
14265 | // Remove IV for subsequent blocks
|
14266 | this._iv = undefined;
|
14267 | } else {
|
14268 | var block = this._prevBlock;
|
14269 | }
|
14270 |
|
14271 | // XOR blocks
|
14272 | for (var i = 0; i < blockSize; i++) {
|
14273 | words[offset + i] ^= block[i];
|
14274 | }
|
14275 | }
|
14276 |
|
14277 | return CBC;
|
14278 | }());
|
14279 |
|
14280 | /**
|
14281 | * Padding namespace.
|
14282 | */
|
14283 | var C_pad = C.pad = {};
|
14284 |
|
14285 | /**
|
14286 | * PKCS #5/7 padding strategy.
|
14287 | */
|
14288 | var Pkcs7 = C_pad.Pkcs7 = {
|
14289 | /**
|
14290 | * Pads data using the algorithm defined in PKCS #5/7.
|
14291 | *
|
14292 | * @param {WordArray} data The data to pad.
|
14293 | * @param {number} blockSize The multiple that the data should be padded to.
|
14294 | *
|
14295 | * @static
|
14296 | *
|
14297 | * @example
|
14298 | *
|
14299 | * CryptoJS.pad.Pkcs7.pad(wordArray, 4);
|
14300 | */
|
14301 | pad: function (data, blockSize) {
|
14302 | // Shortcut
|
14303 | var blockSizeBytes = blockSize * 4;
|
14304 |
|
14305 | // Count padding bytes
|
14306 | var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes;
|
14307 |
|
14308 | // Create padding word
|
14309 | var paddingWord = (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes;
|
14310 |
|
14311 | // Create padding
|
14312 | var paddingWords = [];
|
14313 | for (var i = 0; i < nPaddingBytes; i += 4) {
|
14314 | paddingWords.push(paddingWord);
|
14315 | }
|
14316 | var padding = WordArray.create(paddingWords, nPaddingBytes);
|
14317 |
|
14318 | // Add padding
|
14319 | data.concat(padding);
|
14320 | },
|
14321 |
|
14322 | /**
|
14323 | * Unpads data that had been padded using the algorithm defined in PKCS #5/7.
|
14324 | *
|
14325 | * @param {WordArray} data The data to unpad.
|
14326 | *
|
14327 | * @static
|
14328 | *
|
14329 | * @example
|
14330 | *
|
14331 | * CryptoJS.pad.Pkcs7.unpad(wordArray);
|
14332 | */
|
14333 | unpad: function (data) {
|
14334 | // Get number of padding bytes from last byte
|
14335 | var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
|
14336 |
|
14337 | // Remove padding
|
14338 | data.sigBytes -= nPaddingBytes;
|
14339 | }
|
14340 | };
|
14341 |
|
14342 | /**
|
14343 | * Abstract base block cipher template.
|
14344 | *
|
14345 | * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits)
|
14346 | */
|
14347 | var BlockCipher = C_lib.BlockCipher = Cipher.extend({
|
14348 | /**
|
14349 | * Configuration options.
|
14350 | *
|
14351 | * @property {Mode} mode The block mode to use. Default: CBC
|
14352 | * @property {Padding} padding The padding strategy to use. Default: Pkcs7
|
14353 | */
|
14354 | cfg: Cipher.cfg.extend({
|
14355 | mode: CBC,
|
14356 | padding: Pkcs7
|
14357 | }),
|
14358 |
|
14359 | reset: function () {
|
14360 | // Reset cipher
|
14361 | Cipher.reset.call(this);
|
14362 |
|
14363 | // Shortcuts
|
14364 | var cfg = this.cfg;
|
14365 | var iv = cfg.iv;
|
14366 | var mode = cfg.mode;
|
14367 |
|
14368 | // Reset block mode
|
14369 | if (this._xformMode == this._ENC_XFORM_MODE) {
|
14370 | var modeCreator = mode.createEncryptor;
|
14371 | } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
|
14372 | var modeCreator = mode.createDecryptor;
|
14373 | // Keep at least one block in the buffer for unpadding
|
14374 | this._minBufferSize = 1;
|
14375 | }
|
14376 |
|
14377 | if (this._mode && this._mode.__creator == modeCreator) {
|
14378 | this._mode.init(this, iv && iv.words);
|
14379 | } else {
|
14380 | this._mode = modeCreator.call(mode, this, iv && iv.words);
|
14381 | this._mode.__creator = modeCreator;
|
14382 | }
|
14383 | },
|
14384 |
|
14385 | _doProcessBlock: function (words, offset) {
|
14386 | this._mode.processBlock(words, offset);
|
14387 | },
|
14388 |
|
14389 | _doFinalize: function () {
|
14390 | // Shortcut
|
14391 | var padding = this.cfg.padding;
|
14392 |
|
14393 | // Finalize
|
14394 | if (this._xformMode == this._ENC_XFORM_MODE) {
|
14395 | // Pad data
|
14396 | padding.pad(this._data, this.blockSize);
|
14397 |
|
14398 | // Process final blocks
|
14399 | var finalProcessedBlocks = this._process(!!'flush');
|
14400 | } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
|
14401 | // Process final blocks
|
14402 | var finalProcessedBlocks = this._process(!!'flush');
|
14403 |
|
14404 | // Unpad data
|
14405 | padding.unpad(finalProcessedBlocks);
|
14406 | }
|
14407 |
|
14408 | return finalProcessedBlocks;
|
14409 | },
|
14410 |
|
14411 | blockSize: 128/32
|
14412 | });
|
14413 |
|
14414 | /**
|
14415 | * A collection of cipher parameters.
|
14416 | *
|
14417 | * @property {WordArray} ciphertext The raw ciphertext.
|
14418 | * @property {WordArray} key The key to this ciphertext.
|
14419 | * @property {WordArray} iv The IV used in the ciphering operation.
|
14420 | * @property {WordArray} salt The salt used with a key derivation function.
|
14421 | * @property {Cipher} algorithm The cipher algorithm.
|
14422 | * @property {Mode} mode The block mode used in the ciphering operation.
|
14423 | * @property {Padding} padding The padding scheme used in the ciphering operation.
|
14424 | * @property {number} blockSize The block size of the cipher.
|
14425 | * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string.
|
14426 | */
|
14427 | var CipherParams = C_lib.CipherParams = Base.extend({
|
14428 | /**
|
14429 | * Initializes a newly created cipher params object.
|
14430 | *
|
14431 | * @param {Object} cipherParams An object with any of the possible cipher parameters.
|
14432 | *
|
14433 | * @example
|
14434 | *
|
14435 | * var cipherParams = CryptoJS.lib.CipherParams.create({
|
14436 | * ciphertext: ciphertextWordArray,
|
14437 | * key: keyWordArray,
|
14438 | * iv: ivWordArray,
|
14439 | * salt: saltWordArray,
|
14440 | * algorithm: CryptoJS.algo.AES,
|
14441 | * mode: CryptoJS.mode.CBC,
|
14442 | * padding: CryptoJS.pad.PKCS7,
|
14443 | * blockSize: 4,
|
14444 | * formatter: CryptoJS.format.OpenSSL
|
14445 | * });
|
14446 | */
|
14447 | init: function (cipherParams) {
|
14448 | this.mixIn(cipherParams);
|
14449 | },
|
14450 |
|
14451 | /**
|
14452 | * Converts this cipher params object to a string.
|
14453 | *
|
14454 | * @param {Format} formatter (Optional) The formatting strategy to use.
|
14455 | *
|
14456 | * @return {string} The stringified cipher params.
|
14457 | *
|
14458 | * @throws Error If neither the formatter nor the default formatter is set.
|
14459 | *
|
14460 | * @example
|
14461 | *
|
14462 | * var string = cipherParams + '';
|
14463 | * var string = cipherParams.toString();
|
14464 | * var string = cipherParams.toString(CryptoJS.format.OpenSSL);
|
14465 | */
|
14466 | toString: function (formatter) {
|
14467 | return (formatter || this.formatter).stringify(this);
|
14468 | }
|
14469 | });
|
14470 |
|
14471 | /**
|
14472 | * Format namespace.
|
14473 | */
|
14474 | var C_format = C.format = {};
|
14475 |
|
14476 | /**
|
14477 | * OpenSSL formatting strategy.
|
14478 | */
|
14479 | var OpenSSLFormatter = C_format.OpenSSL = {
|
14480 | /**
|
14481 | * Converts a cipher params object to an OpenSSL-compatible string.
|
14482 | *
|
14483 | * @param {CipherParams} cipherParams The cipher params object.
|
14484 | *
|
14485 | * @return {string} The OpenSSL-compatible string.
|
14486 | *
|
14487 | * @static
|
14488 | *
|
14489 | * @example
|
14490 | *
|
14491 | * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams);
|
14492 | */
|
14493 | stringify: function (cipherParams) {
|
14494 | // Shortcuts
|
14495 | var ciphertext = cipherParams.ciphertext;
|
14496 | var salt = cipherParams.salt;
|
14497 |
|
14498 | // Format
|
14499 | if (salt) {
|
14500 | var wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext);
|
14501 | } else {
|
14502 | var wordArray = ciphertext;
|
14503 | }
|
14504 |
|
14505 | return wordArray.toString(Base64);
|
14506 | },
|
14507 |
|
14508 | /**
|
14509 | * Converts an OpenSSL-compatible string to a cipher params object.
|
14510 | *
|
14511 | * @param {string} openSSLStr The OpenSSL-compatible string.
|
14512 | *
|
14513 | * @return {CipherParams} The cipher params object.
|
14514 | *
|
14515 | * @static
|
14516 | *
|
14517 | * @example
|
14518 | *
|
14519 | * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString);
|
14520 | */
|
14521 | parse: function (openSSLStr) {
|
14522 | // Parse base64
|
14523 | var ciphertext = Base64.parse(openSSLStr);
|
14524 |
|
14525 | // Shortcut
|
14526 | var ciphertextWords = ciphertext.words;
|
14527 |
|
14528 | // Test for salt
|
14529 | if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) {
|
14530 | // Extract salt
|
14531 | var salt = WordArray.create(ciphertextWords.slice(2, 4));
|
14532 |
|
14533 | // Remove salt from ciphertext
|
14534 | ciphertextWords.splice(0, 4);
|
14535 | ciphertext.sigBytes -= 16;
|
14536 | }
|
14537 |
|
14538 | return CipherParams.create({ ciphertext: ciphertext, salt: salt });
|
14539 | }
|
14540 | };
|
14541 |
|
14542 | /**
|
14543 | * A cipher wrapper that returns ciphertext as a serializable cipher params object.
|
14544 | */
|
14545 | var SerializableCipher = C_lib.SerializableCipher = Base.extend({
|
14546 | /**
|
14547 | * Configuration options.
|
14548 | *
|
14549 | * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL
|
14550 | */
|
14551 | cfg: Base.extend({
|
14552 | format: OpenSSLFormatter
|
14553 | }),
|
14554 |
|
14555 | /**
|
14556 | * Encrypts a message.
|
14557 | *
|
14558 | * @param {Cipher} cipher The cipher algorithm to use.
|
14559 | * @param {WordArray|string} message The message to encrypt.
|
14560 | * @param {WordArray} key The key.
|
14561 | * @param {Object} cfg (Optional) The configuration options to use for this operation.
|
14562 | *
|
14563 | * @return {CipherParams} A cipher params object.
|
14564 | *
|
14565 | * @static
|
14566 | *
|
14567 | * @example
|
14568 | *
|
14569 | * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key);
|
14570 | * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv });
|
14571 | * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL });
|
14572 | */
|
14573 | encrypt: function (cipher, message, key, cfg) {
|
14574 | // Apply config defaults
|
14575 | cfg = this.cfg.extend(cfg);
|
14576 |
|
14577 | // Encrypt
|
14578 | var encryptor = cipher.createEncryptor(key, cfg);
|
14579 | var ciphertext = encryptor.finalize(message);
|
14580 |
|
14581 | // Shortcut
|
14582 | var cipherCfg = encryptor.cfg;
|
14583 |
|
14584 | // Create and return serializable cipher params
|
14585 | return CipherParams.create({
|
14586 | ciphertext: ciphertext,
|
14587 | key: key,
|
14588 | iv: cipherCfg.iv,
|
14589 | algorithm: cipher,
|
14590 | mode: cipherCfg.mode,
|
14591 | padding: cipherCfg.padding,
|
14592 | blockSize: cipher.blockSize,
|
14593 | formatter: cfg.format
|
14594 | });
|
14595 | },
|
14596 |
|
14597 | /**
|
14598 | * Decrypts serialized ciphertext.
|
14599 | *
|
14600 | * @param {Cipher} cipher The cipher algorithm to use.
|
14601 | * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
|
14602 | * @param {WordArray} key The key.
|
14603 | * @param {Object} cfg (Optional) The configuration options to use for this operation.
|
14604 | *
|
14605 | * @return {WordArray} The plaintext.
|
14606 | *
|
14607 | * @static
|
14608 | *
|
14609 | * @example
|
14610 | *
|
14611 | * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL });
|
14612 | * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL });
|
14613 | */
|
14614 | decrypt: function (cipher, ciphertext, key, cfg) {
|
14615 | // Apply config defaults
|
14616 | cfg = this.cfg.extend(cfg);
|
14617 |
|
14618 | // Convert string to CipherParams
|
14619 | ciphertext = this._parse(ciphertext, cfg.format);
|
14620 |
|
14621 | // Decrypt
|
14622 | var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext);
|
14623 |
|
14624 | return plaintext;
|
14625 | },
|
14626 |
|
14627 | /**
|
14628 | * Converts serialized ciphertext to CipherParams,
|
14629 | * else assumed CipherParams already and returns ciphertext unchanged.
|
14630 | *
|
14631 | * @param {CipherParams|string} ciphertext The ciphertext.
|
14632 | * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext.
|
14633 | *
|
14634 | * @return {CipherParams} The unserialized ciphertext.
|
14635 | *
|
14636 | * @static
|
14637 | *
|
14638 | * @example
|
14639 | *
|
14640 | * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format);
|
14641 | */
|
14642 | _parse: function (ciphertext, format) {
|
14643 | if (typeof ciphertext == 'string') {
|
14644 | return format.parse(ciphertext, this);
|
14645 | } else {
|
14646 | return ciphertext;
|
14647 | }
|
14648 | }
|
14649 | });
|
14650 |
|
14651 | /**
|
14652 | * Key derivation function namespace.
|
14653 | */
|
14654 | var C_kdf = C.kdf = {};
|
14655 |
|
14656 | /**
|
14657 | * OpenSSL key derivation function.
|
14658 | */
|
14659 | var OpenSSLKdf = C_kdf.OpenSSL = {
|
14660 | /**
|
14661 | * Derives a key and IV from a password.
|
14662 | *
|
14663 | * @param {string} password The password to derive from.
|
14664 | * @param {number} keySize The size in words of the key to generate.
|
14665 | * @param {number} ivSize The size in words of the IV to generate.
|
14666 | * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly.
|
14667 | *
|
14668 | * @return {CipherParams} A cipher params object with the key, IV, and salt.
|
14669 | *
|
14670 | * @static
|
14671 | *
|
14672 | * @example
|
14673 | *
|
14674 | * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32);
|
14675 | * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt');
|
14676 | */
|
14677 | execute: function (password, keySize, ivSize, salt) {
|
14678 | // Generate random salt
|
14679 | if (!salt) {
|
14680 | salt = WordArray.random(64/8);
|
14681 | }
|
14682 |
|
14683 | // Derive key and IV
|
14684 | var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt);
|
14685 |
|
14686 | // Separate key and IV
|
14687 | var iv = WordArray.create(key.words.slice(keySize), ivSize * 4);
|
14688 | key.sigBytes = keySize * 4;
|
14689 |
|
14690 | // Return params
|
14691 | return CipherParams.create({ key: key, iv: iv, salt: salt });
|
14692 | }
|
14693 | };
|
14694 |
|
14695 | /**
|
14696 | * A serializable cipher wrapper that derives the key from a password,
|
14697 | * and returns ciphertext as a serializable cipher params object.
|
14698 | */
|
14699 | var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({
|
14700 | /**
|
14701 | * Configuration options.
|
14702 | *
|
14703 | * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL
|
14704 | */
|
14705 | cfg: SerializableCipher.cfg.extend({
|
14706 | kdf: OpenSSLKdf
|
14707 | }),
|
14708 |
|
14709 | /**
|
14710 | * Encrypts a message using a password.
|
14711 | *
|
14712 | * @param {Cipher} cipher The cipher algorithm to use.
|
14713 | * @param {WordArray|string} message The message to encrypt.
|
14714 | * @param {string} password The password.
|
14715 | * @param {Object} cfg (Optional) The configuration options to use for this operation.
|
14716 | *
|
14717 | * @return {CipherParams} A cipher params object.
|
14718 | *
|
14719 | * @static
|
14720 | *
|
14721 | * @example
|
14722 | *
|
14723 | * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password');
|
14724 | * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL });
|
14725 | */
|
14726 | encrypt: function (cipher, message, password, cfg) {
|
14727 | // Apply config defaults
|
14728 | cfg = this.cfg.extend(cfg);
|
14729 |
|
14730 | // Derive key and other params
|
14731 | var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize);
|
14732 |
|
14733 | // Add IV to config
|
14734 | cfg.iv = derivedParams.iv;
|
14735 |
|
14736 | // Encrypt
|
14737 | var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg);
|
14738 |
|
14739 | // Mix in derived params
|
14740 | ciphertext.mixIn(derivedParams);
|
14741 |
|
14742 | return ciphertext;
|
14743 | },
|
14744 |
|
14745 | /**
|
14746 | * Decrypts serialized ciphertext using a password.
|
14747 | *
|
14748 | * @param {Cipher} cipher The cipher algorithm to use.
|
14749 | * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
|
14750 | * @param {string} password The password.
|
14751 | * @param {Object} cfg (Optional) The configuration options to use for this operation.
|
14752 | *
|
14753 | * @return {WordArray} The plaintext.
|
14754 | *
|
14755 | * @static
|
14756 | *
|
14757 | * @example
|
14758 | *
|
14759 | * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL });
|
14760 | * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL });
|
14761 | */
|
14762 | decrypt: function (cipher, ciphertext, password, cfg) {
|
14763 | // Apply config defaults
|
14764 | cfg = this.cfg.extend(cfg);
|
14765 |
|
14766 | // Convert string to CipherParams
|
14767 | ciphertext = this._parse(ciphertext, cfg.format);
|
14768 |
|
14769 | // Derive key and other params
|
14770 | var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt);
|
14771 |
|
14772 | // Add IV to config
|
14773 | cfg.iv = derivedParams.iv;
|
14774 |
|
14775 | // Decrypt
|
14776 | var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg);
|
14777 |
|
14778 | return plaintext;
|
14779 | }
|
14780 | });
|
14781 | }());
|
14782 |
|
14783 |
|
14784 | }));
|
14785 |
|
14786 | /***/ }),
|
14787 | /* 23 */
|
14788 | /***/ (function(module, exports, __webpack_require__) {
|
14789 |
|
14790 | var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (root, factory) {
|
14791 | if (true) {
|
14792 | !(__WEBPACK_AMD_DEFINE_FACTORY__ = (factory),
|
14793 | __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
|
14794 | (__WEBPACK_AMD_DEFINE_FACTORY__.call(exports, __webpack_require__, exports, module)) :
|
14795 | __WEBPACK_AMD_DEFINE_FACTORY__),
|
14796 | __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
14797 | } else {}
|
14798 | }(this, function (root) {
|
14799 | 'use strict';
|
14800 |
|
14801 | var merge = function (target) {
|
14802 | var i = 1;
|
14803 | var length = arguments.length;
|
14804 | var key;
|
14805 | for (; i < length; i++) {
|
14806 | for (key in arguments[i]) {
|
14807 | if (Object.prototype.hasOwnProperty.call(arguments[i], key)) {
|
14808 | target[key] = arguments[i][key];
|
14809 | }
|
14810 | }
|
14811 | }
|
14812 | return target;
|
14813 | };
|
14814 |
|
14815 | var defaults = {
|
14816 | template: '[%t] %l:',
|
14817 | levelFormatter: function (level) {
|
14818 | return level.toUpperCase();
|
14819 | },
|
14820 | nameFormatter: function (name) {
|
14821 | return name || 'root';
|
14822 | },
|
14823 | timestampFormatter: function (date) {
|
14824 | return date.toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, '$1');
|
14825 | },
|
14826 | format: undefined
|
14827 | };
|
14828 |
|
14829 | var loglevel;
|
14830 | var configs = {};
|
14831 |
|
14832 | var reg = function (rootLogger) {
|
14833 | if (!rootLogger || !rootLogger.getLogger) {
|
14834 | throw new TypeError('Argument is not a root logger');
|
14835 | }
|
14836 | loglevel = rootLogger;
|
14837 | };
|
14838 |
|
14839 | var apply = function (logger, config) {
|
14840 | if (!logger || !logger.setLevel) {
|
14841 | throw new TypeError('Argument is not a logger');
|
14842 | }
|
14843 |
|
14844 | /* eslint-disable vars-on-top */
|
14845 | var originalFactory = logger.methodFactory;
|
14846 | var name = logger.name || '';
|
14847 | var parent = configs[name] || configs[''] || defaults;
|
14848 | /* eslint-enable vars-on-top */
|
14849 |
|
14850 | function methodFactory(methodName, logLevel, loggerName) {
|
14851 | var originalMethod = originalFactory(methodName, logLevel, loggerName);
|
14852 | var options = configs[loggerName] || configs[''];
|
14853 |
|
14854 | var hasTimestamp = options.template.indexOf('%t') !== -1;
|
14855 | var hasLevel = options.template.indexOf('%l') !== -1;
|
14856 | var hasName = options.template.indexOf('%n') !== -1;
|
14857 |
|
14858 | return function () {
|
14859 | var content = '';
|
14860 |
|
14861 | var length = arguments.length;
|
14862 | var args = Array(length);
|
14863 | var key = 0;
|
14864 | for (; key < length; key++) {
|
14865 | args[key] = arguments[key];
|
14866 | }
|
14867 |
|
14868 | // skip the root method for child loggers to prevent duplicate logic
|
14869 | if (name || !configs[loggerName]) {
|
14870 | /* eslint-disable vars-on-top */
|
14871 | var timestamp = options.timestampFormatter(new Date());
|
14872 | var level = options.levelFormatter(methodName);
|
14873 | var lname = options.nameFormatter(loggerName);
|
14874 | /* eslint-enable vars-on-top */
|
14875 |
|
14876 | if (options.format) {
|
14877 | content += options.format(level, lname, timestamp);
|
14878 | } else {
|
14879 | content += options.template;
|
14880 | if (hasTimestamp) {
|
14881 | content = content.replace(/%t/, timestamp);
|
14882 | }
|
14883 | if (hasLevel) content = content.replace(/%l/, level);
|
14884 | if (hasName) content = content.replace(/%n/, lname);
|
14885 | }
|
14886 |
|
14887 | if (args.length && typeof args[0] === 'string') {
|
14888 | // concat prefix with first argument to support string substitutions
|
14889 | args[0] = content + ' ' + args[0];
|
14890 | } else {
|
14891 | args.unshift(content);
|
14892 | }
|
14893 | }
|
14894 |
|
14895 | originalMethod.apply(undefined, args);
|
14896 | };
|
14897 | }
|
14898 |
|
14899 | if (!configs[name]) {
|
14900 | logger.methodFactory = methodFactory;
|
14901 | }
|
14902 |
|
14903 | // for remove inherited format option if template option preset
|
14904 | config = config || {};
|
14905 | if (config.template) config.format = undefined;
|
14906 |
|
14907 | configs[name] = merge({}, parent, config);
|
14908 |
|
14909 | logger.setLevel(logger.getLevel());
|
14910 |
|
14911 | if (!loglevel) {
|
14912 | logger.warn(
|
14913 | 'It is necessary to call the function reg() of loglevel-plugin-prefix before calling apply. From the next release, it will throw an error. See more: https://github.com/kutuluk/loglevel-plugin-prefix/blob/master/README.md'
|
14914 | );
|
14915 | }
|
14916 |
|
14917 | return logger;
|
14918 | };
|
14919 |
|
14920 | var api = {
|
14921 | reg: reg,
|
14922 | apply: apply
|
14923 | };
|
14924 |
|
14925 | var save;
|
14926 |
|
14927 | if (root) {
|
14928 | save = root.prefix;
|
14929 | api.noConflict = function () {
|
14930 | if (root.prefix === api) {
|
14931 | root.prefix = save;
|
14932 | }
|
14933 | return api;
|
14934 | };
|
14935 | }
|
14936 |
|
14937 | return api;
|
14938 | }));
|
14939 |
|
14940 |
|
14941 | /***/ }),
|
14942 | /* 24 */
|
14943 | /***/ (function(module, exports, __webpack_require__) {
|
14944 |
|
14945 | var bs58check = __webpack_require__(17)
|
14946 |
|
14947 | function decodeRaw (buffer, version) {
|
14948 | // check version only if defined
|
14949 | if (version !== undefined && buffer[0] !== version) throw new Error('Invalid network version')
|
14950 |
|
14951 | // uncompressed
|
14952 | if (buffer.length === 33) {
|
14953 | return {
|
14954 | version: buffer[0],
|
14955 | privateKey: buffer.slice(1, 33),
|
14956 | compressed: false
|
14957 | }
|
14958 | }
|
14959 |
|
14960 | // invalid length
|
14961 | if (buffer.length !== 34) throw new Error('Invalid WIF length')
|
14962 |
|
14963 | // invalid compression flag
|
14964 | if (buffer[33] !== 0x01) throw new Error('Invalid compression flag')
|
14965 |
|
14966 | return {
|
14967 | version: buffer[0],
|
14968 | privateKey: buffer.slice(1, 33),
|
14969 | compressed: true
|
14970 | }
|
14971 | }
|
14972 |
|
14973 | function encodeRaw (version, privateKey, compressed) {
|
14974 | var result = new Buffer(compressed ? 34 : 33)
|
14975 |
|
14976 | result.writeUInt8(version, 0)
|
14977 | privateKey.copy(result, 1)
|
14978 |
|
14979 | if (compressed) {
|
14980 | result[33] = 0x01
|
14981 | }
|
14982 |
|
14983 | return result
|
14984 | }
|
14985 |
|
14986 | function decode (string, version) {
|
14987 | return decodeRaw(bs58check.decode(string), version)
|
14988 | }
|
14989 |
|
14990 | function encode (version, privateKey, compressed) {
|
14991 | if (typeof version === 'number') return bs58check.encode(encodeRaw(version, privateKey, compressed))
|
14992 |
|
14993 | return bs58check.encode(
|
14994 | encodeRaw(
|
14995 | version.version,
|
14996 | version.privateKey,
|
14997 | version.compressed
|
14998 | )
|
14999 | )
|
15000 | }
|
15001 |
|
15002 | module.exports = {
|
15003 | decode: decode,
|
15004 | decodeRaw: decodeRaw,
|
15005 | encode: encode,
|
15006 | encodeRaw: encodeRaw
|
15007 | }
|
15008 |
|
15009 |
|
15010 | /***/ }),
|
15011 | /* 25 */
|
15012 | /***/ (function(module, exports, __webpack_require__) {
|
15013 |
|
15014 | ;(function (root, factory, undef) {
|
15015 | if (true) {
|
15016 | // CommonJS
|
15017 | module.exports = exports = factory(__webpack_require__(4), __webpack_require__(106), __webpack_require__(107), __webpack_require__(44), __webpack_require__(22));
|
15018 | }
|
15019 | else {}
|
15020 | }(this, function (CryptoJS) {
|
15021 |
|
15022 | (function () {
|
15023 | // Shortcuts
|
15024 | var C = CryptoJS;
|
15025 | var C_lib = C.lib;
|
15026 | var BlockCipher = C_lib.BlockCipher;
|
15027 | var C_algo = C.algo;
|
15028 |
|
15029 | // Lookup tables
|
15030 | var SBOX = [];
|
15031 | var INV_SBOX = [];
|
15032 | var SUB_MIX_0 = [];
|
15033 | var SUB_MIX_1 = [];
|
15034 | var SUB_MIX_2 = [];
|
15035 | var SUB_MIX_3 = [];
|
15036 | var INV_SUB_MIX_0 = [];
|
15037 | var INV_SUB_MIX_1 = [];
|
15038 | var INV_SUB_MIX_2 = [];
|
15039 | var INV_SUB_MIX_3 = [];
|
15040 |
|
15041 | // Compute lookup tables
|
15042 | (function () {
|
15043 | // Compute double table
|
15044 | var d = [];
|
15045 | for (var i = 0; i < 256; i++) {
|
15046 | if (i < 128) {
|
15047 | d[i] = i << 1;
|
15048 | } else {
|
15049 | d[i] = (i << 1) ^ 0x11b;
|
15050 | }
|
15051 | }
|
15052 |
|
15053 | // Walk GF(2^8)
|
15054 | var x = 0;
|
15055 | var xi = 0;
|
15056 | for (var i = 0; i < 256; i++) {
|
15057 | // Compute sbox
|
15058 | var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4);
|
15059 | sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63;
|
15060 | SBOX[x] = sx;
|
15061 | INV_SBOX[sx] = x;
|
15062 |
|
15063 | // Compute multiplication
|
15064 | var x2 = d[x];
|
15065 | var x4 = d[x2];
|
15066 | var x8 = d[x4];
|
15067 |
|
15068 | // Compute sub bytes, mix columns tables
|
15069 | var t = (d[sx] * 0x101) ^ (sx * 0x1010100);
|
15070 | SUB_MIX_0[x] = (t << 24) | (t >>> 8);
|
15071 | SUB_MIX_1[x] = (t << 16) | (t >>> 16);
|
15072 | SUB_MIX_2[x] = (t << 8) | (t >>> 24);
|
15073 | SUB_MIX_3[x] = t;
|
15074 |
|
15075 | // Compute inv sub bytes, inv mix columns tables
|
15076 | var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100);
|
15077 | INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8);
|
15078 | INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16);
|
15079 | INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24);
|
15080 | INV_SUB_MIX_3[sx] = t;
|
15081 |
|
15082 | // Compute next counter
|
15083 | if (!x) {
|
15084 | x = xi = 1;
|
15085 | } else {
|
15086 | x = x2 ^ d[d[d[x8 ^ x2]]];
|
15087 | xi ^= d[d[xi]];
|
15088 | }
|
15089 | }
|
15090 | }());
|
15091 |
|
15092 | // Precomputed Rcon lookup
|
15093 | var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36];
|
15094 |
|
15095 | /**
|
15096 | * AES block cipher algorithm.
|
15097 | */
|
15098 | var AES = C_algo.AES = BlockCipher.extend({
|
15099 | _doReset: function () {
|
15100 | // Skip reset of nRounds has been set before and key did not change
|
15101 | if (this._nRounds && this._keyPriorReset === this._key) {
|
15102 | return;
|
15103 | }
|
15104 |
|
15105 | // Shortcuts
|
15106 | var key = this._keyPriorReset = this._key;
|
15107 | var keyWords = key.words;
|
15108 | var keySize = key.sigBytes / 4;
|
15109 |
|
15110 | // Compute number of rounds
|
15111 | var nRounds = this._nRounds = keySize + 6;
|
15112 |
|
15113 | // Compute number of key schedule rows
|
15114 | var ksRows = (nRounds + 1) * 4;
|
15115 |
|
15116 | // Compute key schedule
|
15117 | var keySchedule = this._keySchedule = [];
|
15118 | for (var ksRow = 0; ksRow < ksRows; ksRow++) {
|
15119 | if (ksRow < keySize) {
|
15120 | keySchedule[ksRow] = keyWords[ksRow];
|
15121 | } else {
|
15122 | var t = keySchedule[ksRow - 1];
|
15123 |
|
15124 | if (!(ksRow % keySize)) {
|
15125 | // Rot word
|
15126 | t = (t << 8) | (t >>> 24);
|
15127 |
|
15128 | // Sub word
|
15129 | t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
|
15130 |
|
15131 | // Mix Rcon
|
15132 | t ^= RCON[(ksRow / keySize) | 0] << 24;
|
15133 | } else if (keySize > 6 && ksRow % keySize == 4) {
|
15134 | // Sub word
|
15135 | t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
|
15136 | }
|
15137 |
|
15138 | keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t;
|
15139 | }
|
15140 | }
|
15141 |
|
15142 | // Compute inv key schedule
|
15143 | var invKeySchedule = this._invKeySchedule = [];
|
15144 | for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) {
|
15145 | var ksRow = ksRows - invKsRow;
|
15146 |
|
15147 | if (invKsRow % 4) {
|
15148 | var t = keySchedule[ksRow];
|
15149 | } else {
|
15150 | var t = keySchedule[ksRow - 4];
|
15151 | }
|
15152 |
|
15153 | if (invKsRow < 4 || ksRow <= 4) {
|
15154 | invKeySchedule[invKsRow] = t;
|
15155 | } else {
|
15156 | invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^
|
15157 | INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]];
|
15158 | }
|
15159 | }
|
15160 | },
|
15161 |
|
15162 | encryptBlock: function (M, offset) {
|
15163 | this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX);
|
15164 | },
|
15165 |
|
15166 | decryptBlock: function (M, offset) {
|
15167 | // Swap 2nd and 4th rows
|
15168 | var t = M[offset + 1];
|
15169 | M[offset + 1] = M[offset + 3];
|
15170 | M[offset + 3] = t;
|
15171 |
|
15172 | this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX);
|
15173 |
|
15174 | // Inv swap 2nd and 4th rows
|
15175 | var t = M[offset + 1];
|
15176 | M[offset + 1] = M[offset + 3];
|
15177 | M[offset + 3] = t;
|
15178 | },
|
15179 |
|
15180 | _doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) {
|
15181 | // Shortcut
|
15182 | var nRounds = this._nRounds;
|
15183 |
|
15184 | // Get input, add round key
|
15185 | var s0 = M[offset] ^ keySchedule[0];
|
15186 | var s1 = M[offset + 1] ^ keySchedule[1];
|
15187 | var s2 = M[offset + 2] ^ keySchedule[2];
|
15188 | var s3 = M[offset + 3] ^ keySchedule[3];
|
15189 |
|
15190 | // Key schedule row counter
|
15191 | var ksRow = 4;
|
15192 |
|
15193 | // Rounds
|
15194 | for (var round = 1; round < nRounds; round++) {
|
15195 | // Shift rows, sub bytes, mix columns, add round key
|
15196 | var t0 = SUB_MIX_0[s0 >>> 24] ^ SUB_MIX_1[(s1 >>> 16) & 0xff] ^ SUB_MIX_2[(s2 >>> 8) & 0xff] ^ SUB_MIX_3[s3 & 0xff] ^ keySchedule[ksRow++];
|
15197 | var t1 = SUB_MIX_0[s1 >>> 24] ^ SUB_MIX_1[(s2 >>> 16) & 0xff] ^ SUB_MIX_2[(s3 >>> 8) & 0xff] ^ SUB_MIX_3[s0 & 0xff] ^ keySchedule[ksRow++];
|
15198 | var t2 = SUB_MIX_0[s2 >>> 24] ^ SUB_MIX_1[(s3 >>> 16) & 0xff] ^ SUB_MIX_2[(s0 >>> 8) & 0xff] ^ SUB_MIX_3[s1 & 0xff] ^ keySchedule[ksRow++];
|
15199 | var t3 = SUB_MIX_0[s3 >>> 24] ^ SUB_MIX_1[(s0 >>> 16) & 0xff] ^ SUB_MIX_2[(s1 >>> 8) & 0xff] ^ SUB_MIX_3[s2 & 0xff] ^ keySchedule[ksRow++];
|
15200 |
|
15201 | // Update state
|
15202 | s0 = t0;
|
15203 | s1 = t1;
|
15204 | s2 = t2;
|
15205 | s3 = t3;
|
15206 | }
|
15207 |
|
15208 | // Shift rows, sub bytes, add round key
|
15209 | var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++];
|
15210 | var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++];
|
15211 | var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++];
|
15212 | var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++];
|
15213 |
|
15214 | // Set output
|
15215 | M[offset] = t0;
|
15216 | M[offset + 1] = t1;
|
15217 | M[offset + 2] = t2;
|
15218 | M[offset + 3] = t3;
|
15219 | },
|
15220 |
|
15221 | keySize: 256/32
|
15222 | });
|
15223 |
|
15224 | /**
|
15225 | * Shortcut functions to the cipher's object interface.
|
15226 | *
|
15227 | * @example
|
15228 | *
|
15229 | * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg);
|
15230 | * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg);
|
15231 | */
|
15232 | C.AES = BlockCipher._createHelper(AES);
|
15233 | }());
|
15234 |
|
15235 |
|
15236 | return CryptoJS.AES;
|
15237 |
|
15238 | }));
|
15239 |
|
15240 | /***/ }),
|
15241 | /* 26 */
|
15242 | /***/ (function(module, exports, __webpack_require__) {
|
15243 |
|
15244 | "use strict";
|
15245 |
|
15246 |
|
15247 | (function(root) {
|
15248 | var MAX_VALUE = 0x7fffffff;
|
15249 |
|
15250 | // The SHA256 and PBKDF2 implementation are from scrypt-async-js:
|
15251 | // See: https://github.com/dchest/scrypt-async-js
|
15252 | function SHA256(m) {
|
15253 | var K = [
|
15254 | 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b,
|
15255 | 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01,
|
15256 | 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7,
|
15257 | 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
|
15258 | 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152,
|
15259 | 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
|
15260 | 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc,
|
15261 | 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
15262 | 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819,
|
15263 | 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08,
|
15264 | 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f,
|
15265 | 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
15266 | 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
15267 | ];
|
15268 |
|
15269 | var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372, h3 = 0xa54ff53a;
|
15270 | var h4 = 0x510e527f, h5 = 0x9b05688c, h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
|
15271 | var w = new Array(64);
|
15272 |
|
15273 | function blocks(p) {
|
15274 | var off = 0, len = p.length;
|
15275 | while (len >= 64) {
|
15276 | var a = h0, b = h1, c = h2, d = h3, e = h4, f = h5, g = h6, h = h7, u, i, j, t1, t2;
|
15277 |
|
15278 | for (i = 0; i < 16; i++) {
|
15279 | j = off + i*4;
|
15280 | w[i] = ((p[j] & 0xff)<<24) | ((p[j+1] & 0xff)<<16) |
|
15281 | ((p[j+2] & 0xff)<<8) | (p[j+3] & 0xff);
|
15282 | }
|
15283 |
|
15284 | for (i = 16; i < 64; i++) {
|
15285 | u = w[i-2];
|
15286 | t1 = ((u>>>17) | (u<<(32-17))) ^ ((u>>>19) | (u<<(32-19))) ^ (u>>>10);
|
15287 |
|
15288 | u = w[i-15];
|
15289 | t2 = ((u>>>7) | (u<<(32-7))) ^ ((u>>>18) | (u<<(32-18))) ^ (u>>>3);
|
15290 |
|
15291 | w[i] = (((t1 + w[i-7]) | 0) + ((t2 + w[i-16]) | 0)) | 0;
|
15292 | }
|
15293 |
|
15294 | for (i = 0; i < 64; i++) {
|
15295 | t1 = ((((((e>>>6) | (e<<(32-6))) ^ ((e>>>11) | (e<<(32-11))) ^
|
15296 | ((e>>>25) | (e<<(32-25)))) + ((e & f) ^ (~e & g))) | 0) +
|
15297 | ((h + ((K[i] + w[i]) | 0)) | 0)) | 0;
|
15298 |
|
15299 | t2 = ((((a>>>2) | (a<<(32-2))) ^ ((a>>>13) | (a<<(32-13))) ^
|
15300 | ((a>>>22) | (a<<(32-22)))) + ((a & b) ^ (a & c) ^ (b & c))) | 0;
|
15301 |
|
15302 | h = g;
|
15303 | g = f;
|
15304 | f = e;
|
15305 | e = (d + t1) | 0;
|
15306 | d = c;
|
15307 | c = b;
|
15308 | b = a;
|
15309 | a = (t1 + t2) | 0;
|
15310 | }
|
15311 |
|
15312 | h0 = (h0 + a) | 0;
|
15313 | h1 = (h1 + b) | 0;
|
15314 | h2 = (h2 + c) | 0;
|
15315 | h3 = (h3 + d) | 0;
|
15316 | h4 = (h4 + e) | 0;
|
15317 | h5 = (h5 + f) | 0;
|
15318 | h6 = (h6 + g) | 0;
|
15319 | h7 = (h7 + h) | 0;
|
15320 |
|
15321 | off += 64;
|
15322 | len -= 64;
|
15323 | }
|
15324 | }
|
15325 |
|
15326 | blocks(m);
|
15327 |
|
15328 | var i, bytesLeft = m.length % 64,
|
15329 | bitLenHi = (m.length / 0x20000000) | 0,
|
15330 | bitLenLo = m.length << 3,
|
15331 | numZeros = (bytesLeft < 56) ? 56 : 120,
|
15332 | p = m.slice(m.length - bytesLeft, m.length);
|
15333 |
|
15334 | p.push(0x80);
|
15335 | for (i = bytesLeft + 1; i < numZeros; i++) { p.push(0); }
|
15336 | p.push((bitLenHi>>>24) & 0xff);
|
15337 | p.push((bitLenHi>>>16) & 0xff);
|
15338 | p.push((bitLenHi>>>8) & 0xff);
|
15339 | p.push((bitLenHi>>>0) & 0xff);
|
15340 | p.push((bitLenLo>>>24) & 0xff);
|
15341 | p.push((bitLenLo>>>16) & 0xff);
|
15342 | p.push((bitLenLo>>>8) & 0xff);
|
15343 | p.push((bitLenLo>>>0) & 0xff);
|
15344 |
|
15345 | blocks(p);
|
15346 |
|
15347 | return [
|
15348 | (h0>>>24) & 0xff, (h0>>>16) & 0xff, (h0>>>8) & 0xff, (h0>>>0) & 0xff,
|
15349 | (h1>>>24) & 0xff, (h1>>>16) & 0xff, (h1>>>8) & 0xff, (h1>>>0) & 0xff,
|
15350 | (h2>>>24) & 0xff, (h2>>>16) & 0xff, (h2>>>8) & 0xff, (h2>>>0) & 0xff,
|
15351 | (h3>>>24) & 0xff, (h3>>>16) & 0xff, (h3>>>8) & 0xff, (h3>>>0) & 0xff,
|
15352 | (h4>>>24) & 0xff, (h4>>>16) & 0xff, (h4>>>8) & 0xff, (h4>>>0) & 0xff,
|
15353 | (h5>>>24) & 0xff, (h5>>>16) & 0xff, (h5>>>8) & 0xff, (h5>>>0) & 0xff,
|
15354 | (h6>>>24) & 0xff, (h6>>>16) & 0xff, (h6>>>8) & 0xff, (h6>>>0) & 0xff,
|
15355 | (h7>>>24) & 0xff, (h7>>>16) & 0xff, (h7>>>8) & 0xff, (h7>>>0) & 0xff
|
15356 | ];
|
15357 | }
|
15358 |
|
15359 | function PBKDF2_HMAC_SHA256_OneIter(password, salt, dkLen) {
|
15360 | // compress password if it's longer than hash block length
|
15361 | password = password.length <= 64 ? password : SHA256(password);
|
15362 |
|
15363 | var i;
|
15364 | var innerLen = 64 + salt.length + 4;
|
15365 | var inner = new Array(innerLen);
|
15366 | var outerKey = new Array(64);
|
15367 | var dk = [];
|
15368 |
|
15369 | // inner = (password ^ ipad) || salt || counter
|
15370 | for (i = 0; i < 64; i++) inner[i] = 0x36;
|
15371 | for (i = 0; i < password.length; i++) inner[i] ^= password[i];
|
15372 | for (i = 0; i < salt.length; i++) inner[64+i] = salt[i];
|
15373 | for (i = innerLen - 4; i < innerLen; i++) inner[i] = 0;
|
15374 |
|
15375 | // outerKey = password ^ opad
|
15376 | for (i = 0; i < 64; i++) outerKey[i] = 0x5c;
|
15377 | for (i = 0; i < password.length; i++) outerKey[i] ^= password[i];
|
15378 |
|
15379 | // increments counter inside inner
|
15380 | function incrementCounter() {
|
15381 | for (var i = innerLen-1; i >= innerLen-4; i--) {
|
15382 | inner[i]++;
|
15383 | if (inner[i] <= 0xff) return;
|
15384 | inner[i] = 0;
|
15385 | }
|
15386 | }
|
15387 |
|
15388 | // output blocks = SHA256(outerKey || SHA256(inner)) ...
|
15389 | while (dkLen >= 32) {
|
15390 | incrementCounter();
|
15391 | dk = dk.concat(SHA256(outerKey.concat(SHA256(inner))));
|
15392 | dkLen -= 32;
|
15393 | }
|
15394 | if (dkLen > 0) {
|
15395 | incrementCounter();
|
15396 | dk = dk.concat(SHA256(outerKey.concat(SHA256(inner))).slice(0, dkLen));
|
15397 | }
|
15398 |
|
15399 | return dk;
|
15400 | }
|
15401 |
|
15402 | // The following is an adaptation of scryptsy
|
15403 | // See: https://www.npmjs.com/package/scryptsy
|
15404 | function blockmix_salsa8(BY, Yi, r, x, _X) {
|
15405 | var i;
|
15406 |
|
15407 | arraycopy(BY, (2 * r - 1) * 16, _X, 0, 16);
|
15408 | for (i = 0; i < 2 * r; i++) {
|
15409 | blockxor(BY, i * 16, _X, 16);
|
15410 | salsa20_8(_X, x);
|
15411 | arraycopy(_X, 0, BY, Yi + (i * 16), 16);
|
15412 | }
|
15413 |
|
15414 | for (i = 0; i < r; i++) {
|
15415 | arraycopy(BY, Yi + (i * 2) * 16, BY, (i * 16), 16);
|
15416 | }
|
15417 |
|
15418 | for (i = 0; i < r; i++) {
|
15419 | arraycopy(BY, Yi + (i * 2 + 1) * 16, BY, (i + r) * 16, 16);
|
15420 | }
|
15421 | }
|
15422 |
|
15423 | function R(a, b) {
|
15424 | return (a << b) | (a >>> (32 - b));
|
15425 | }
|
15426 |
|
15427 | function salsa20_8(B, x) {
|
15428 | arraycopy(B, 0, x, 0, 16);
|
15429 |
|
15430 | for (var i = 8; i > 0; i -= 2) {
|
15431 | x[ 4] ^= R(x[ 0] + x[12], 7);
|
15432 | x[ 8] ^= R(x[ 4] + x[ 0], 9);
|
15433 | x[12] ^= R(x[ 8] + x[ 4], 13);
|
15434 | x[ 0] ^= R(x[12] + x[ 8], 18);
|
15435 | x[ 9] ^= R(x[ 5] + x[ 1], 7);
|
15436 | x[13] ^= R(x[ 9] + x[ 5], 9);
|
15437 | x[ 1] ^= R(x[13] + x[ 9], 13);
|
15438 | x[ 5] ^= R(x[ 1] + x[13], 18);
|
15439 | x[14] ^= R(x[10] + x[ 6], 7);
|
15440 | x[ 2] ^= R(x[14] + x[10], 9);
|
15441 | x[ 6] ^= R(x[ 2] + x[14], 13);
|
15442 | x[10] ^= R(x[ 6] + x[ 2], 18);
|
15443 | x[ 3] ^= R(x[15] + x[11], 7);
|
15444 | x[ 7] ^= R(x[ 3] + x[15], 9);
|
15445 | x[11] ^= R(x[ 7] + x[ 3], 13);
|
15446 | x[15] ^= R(x[11] + x[ 7], 18);
|
15447 | x[ 1] ^= R(x[ 0] + x[ 3], 7);
|
15448 | x[ 2] ^= R(x[ 1] + x[ 0], 9);
|
15449 | x[ 3] ^= R(x[ 2] + x[ 1], 13);
|
15450 | x[ 0] ^= R(x[ 3] + x[ 2], 18);
|
15451 | x[ 6] ^= R(x[ 5] + x[ 4], 7);
|
15452 | x[ 7] ^= R(x[ 6] + x[ 5], 9);
|
15453 | x[ 4] ^= R(x[ 7] + x[ 6], 13);
|
15454 | x[ 5] ^= R(x[ 4] + x[ 7], 18);
|
15455 | x[11] ^= R(x[10] + x[ 9], 7);
|
15456 | x[ 8] ^= R(x[11] + x[10], 9);
|
15457 | x[ 9] ^= R(x[ 8] + x[11], 13);
|
15458 | x[10] ^= R(x[ 9] + x[ 8], 18);
|
15459 | x[12] ^= R(x[15] + x[14], 7);
|
15460 | x[13] ^= R(x[12] + x[15], 9);
|
15461 | x[14] ^= R(x[13] + x[12], 13);
|
15462 | x[15] ^= R(x[14] + x[13], 18);
|
15463 | }
|
15464 |
|
15465 | for (i = 0; i < 16; ++i) {
|
15466 | B[i] += x[i];
|
15467 | }
|
15468 | }
|
15469 |
|
15470 | // naive approach... going back to loop unrolling may yield additional performance
|
15471 | function blockxor(S, Si, D, len) {
|
15472 | for (var i = 0; i < len; i++) {
|
15473 | D[i] ^= S[Si + i]
|
15474 | }
|
15475 | }
|
15476 |
|
15477 | function arraycopy(src, srcPos, dest, destPos, length) {
|
15478 | while (length--) {
|
15479 | dest[destPos++] = src[srcPos++];
|
15480 | }
|
15481 | }
|
15482 |
|
15483 | function checkBufferish(o) {
|
15484 | if (!o || typeof(o.length) !== 'number') {
|
15485 | return false;
|
15486 | }
|
15487 | for (var i = 0; i < o.length; i++) {
|
15488 | if (typeof(o[i]) !== 'number') { return false; }
|
15489 |
|
15490 | var v = parseInt(o[i]);
|
15491 | if (v != o[i] || v < 0 || v >= 256) {
|
15492 | return false;
|
15493 | }
|
15494 | }
|
15495 | return true;
|
15496 | }
|
15497 |
|
15498 | function ensureInteger(value, name) {
|
15499 | var intValue = parseInt(value);
|
15500 | if (value != intValue) { throw new Error('invalid ' + name); }
|
15501 | return intValue;
|
15502 | }
|
15503 |
|
15504 | // N = Cpu cost, r = Memory cost, p = parallelization cost
|
15505 | // callback(error, progress, key)
|
15506 | function scrypt(password, salt, N, r, p, dkLen, callback) {
|
15507 |
|
15508 | if (!callback) { throw new Error('missing callback'); }
|
15509 |
|
15510 | N = ensureInteger(N, 'N');
|
15511 | r = ensureInteger(r, 'r');
|
15512 | p = ensureInteger(p, 'p');
|
15513 |
|
15514 | dkLen = ensureInteger(dkLen, 'dkLen');
|
15515 |
|
15516 | if (N === 0 || (N & (N - 1)) !== 0) { throw new Error('N must be power of 2'); }
|
15517 |
|
15518 | if (N > MAX_VALUE / 128 / r) { throw new Error('N too large'); }
|
15519 | if (r > MAX_VALUE / 128 / p) { throw new Error('r too large'); }
|
15520 |
|
15521 | if (!checkBufferish(password)) {
|
15522 | throw new Error('password must be an array or buffer');
|
15523 | }
|
15524 | password = Array.prototype.slice.call(password);
|
15525 |
|
15526 | if (!checkBufferish(salt)) {
|
15527 | throw new Error('salt must be an array or buffer');
|
15528 | }
|
15529 | salt = Array.prototype.slice.call(salt);
|
15530 |
|
15531 | var b = PBKDF2_HMAC_SHA256_OneIter(password, salt, p * 128 * r);
|
15532 | var B = new Uint32Array(p * 32 * r)
|
15533 | for (var i = 0; i < B.length; i++) {
|
15534 | var j = i * 4;
|
15535 | B[i] = ((b[j + 3] & 0xff) << 24) |
|
15536 | ((b[j + 2] & 0xff) << 16) |
|
15537 | ((b[j + 1] & 0xff) << 8) |
|
15538 | ((b[j + 0] & 0xff) << 0);
|
15539 | }
|
15540 |
|
15541 | var XY = new Uint32Array(64 * r);
|
15542 | var V = new Uint32Array(32 * r * N);
|
15543 |
|
15544 | var Yi = 32 * r;
|
15545 |
|
15546 | // scratch space
|
15547 | var x = new Uint32Array(16); // salsa20_8
|
15548 | var _X = new Uint32Array(16); // blockmix_salsa8
|
15549 |
|
15550 | var totalOps = p * N * 2;
|
15551 | var currentOp = 0;
|
15552 | var lastPercent10 = null;
|
15553 |
|
15554 | // Set this to true to abandon the scrypt on the next step
|
15555 | var stop = false;
|
15556 |
|
15557 | // State information
|
15558 | var state = 0;
|
15559 | var i0 = 0, i1;
|
15560 | var Bi;
|
15561 |
|
15562 | // How many blockmix_salsa8 can we do per step?
|
15563 | var limit = parseInt(1000 / r);
|
15564 |
|
15565 | // Trick from scrypt-async; if there is a setImmediate shim in place, use it
|
15566 | var nextTick = (typeof(setImmediate) !== 'undefined') ? setImmediate : setTimeout;
|
15567 |
|
15568 | // This is really all I changed; making scryptsy a state machine so we occasionally
|
15569 | // stop and give other evnts on the evnt loop a chance to run. ~RicMoo
|
15570 | var incrementalSMix = function() {
|
15571 | if (stop) {
|
15572 | return callback(new Error('cancelled'), currentOp / totalOps);
|
15573 | }
|
15574 |
|
15575 | switch (state) {
|
15576 | case 0:
|
15577 | // for (var i = 0; i < p; i++)...
|
15578 | Bi = i0 * 32 * r;
|
15579 |
|
15580 | arraycopy(B, Bi, XY, 0, Yi); // ROMix - 1
|
15581 |
|
15582 | state = 1; // Move to ROMix 2
|
15583 | i1 = 0;
|
15584 |
|
15585 | // Fall through
|
15586 |
|
15587 | case 1:
|
15588 |
|
15589 | // Run up to 1000 steps of the first inner smix loop
|
15590 | var steps = N - i1;
|
15591 | if (steps > limit) { steps = limit; }
|
15592 | for (var i = 0; i < steps; i++) { // ROMix - 2
|
15593 | arraycopy(XY, 0, V, (i1 + i) * Yi, Yi) // ROMix - 3
|
15594 | blockmix_salsa8(XY, Yi, r, x, _X); // ROMix - 4
|
15595 | }
|
15596 |
|
15597 | // for (var i = 0; i < N; i++)
|
15598 | i1 += steps;
|
15599 | currentOp += steps;
|
15600 |
|
15601 | // Call the callback with the progress (optionally stopping us)
|
15602 | var percent10 = parseInt(1000 * currentOp / totalOps);
|
15603 | if (percent10 !== lastPercent10) {
|
15604 | stop = callback(null, currentOp / totalOps);
|
15605 | if (stop) { break; }
|
15606 | lastPercent10 = percent10;
|
15607 | }
|
15608 |
|
15609 | if (i1 < N) {
|
15610 | break;
|
15611 | }
|
15612 |
|
15613 | i1 = 0; // Move to ROMix 6
|
15614 | state = 2;
|
15615 |
|
15616 | // Fall through
|
15617 |
|
15618 | case 2:
|
15619 |
|
15620 | // Run up to 1000 steps of the second inner smix loop
|
15621 | var steps = N - i1;
|
15622 | if (steps > limit) { steps = limit; }
|
15623 | for (var i = 0; i < steps; i++) { // ROMix - 6
|
15624 | var offset = (2 * r - 1) * 16; // ROMix - 7
|
15625 | var j = XY[offset] & (N - 1);
|
15626 | blockxor(V, j * Yi, XY, Yi); // ROMix - 8 (inner)
|
15627 | blockmix_salsa8(XY, Yi, r, x, _X); // ROMix - 9 (outer)
|
15628 | }
|
15629 |
|
15630 | // for (var i = 0; i < N; i++)...
|
15631 | i1 += steps;
|
15632 | currentOp += steps;
|
15633 |
|
15634 | // Call the callback with the progress (optionally stopping us)
|
15635 | var percent10 = parseInt(1000 * currentOp / totalOps);
|
15636 | if (percent10 !== lastPercent10) {
|
15637 | stop = callback(null, currentOp / totalOps);
|
15638 | if (stop) { break; }
|
15639 | lastPercent10 = percent10;
|
15640 | }
|
15641 |
|
15642 | if (i1 < N) {
|
15643 | break;
|
15644 | }
|
15645 |
|
15646 | arraycopy(XY, 0, B, Bi, Yi); // ROMix - 10
|
15647 |
|
15648 | // for (var i = 0; i < p; i++)...
|
15649 | i0++;
|
15650 | if (i0 < p) {
|
15651 | state = 0;
|
15652 | break;
|
15653 | }
|
15654 |
|
15655 | b = [];
|
15656 | for (var i = 0; i < B.length; i++) {
|
15657 | b.push((B[i] >> 0) & 0xff);
|
15658 | b.push((B[i] >> 8) & 0xff);
|
15659 | b.push((B[i] >> 16) & 0xff);
|
15660 | b.push((B[i] >> 24) & 0xff);
|
15661 | }
|
15662 |
|
15663 | var derivedKey = PBKDF2_HMAC_SHA256_OneIter(password, b, dkLen);
|
15664 |
|
15665 | // Done; don't break (which would reschedule)
|
15666 | return callback(null, 1.0, derivedKey);
|
15667 | }
|
15668 |
|
15669 | // Schedule the next steps
|
15670 | nextTick(incrementalSMix);
|
15671 | }
|
15672 |
|
15673 | // Bootstrap the incremental smix
|
15674 | incrementalSMix();
|
15675 | }
|
15676 |
|
15677 | // node.js
|
15678 | if (true) {
|
15679 | module.exports = scrypt;
|
15680 |
|
15681 | // RequireJS/AMD
|
15682 | // http://www.requirejs.org/docs/api.html
|
15683 | // https://github.com/amdjs/amdjs-api/wiki/AMD
|
15684 | } else {}
|
15685 |
|
15686 | })(this);
|
15687 |
|
15688 |
|
15689 | /***/ }),
|
15690 | /* 27 */
|
15691 | /***/ (function(module, exports, __webpack_require__) {
|
15692 |
|
15693 | "use strict";
|
15694 |
|
15695 |
|
15696 | module.exports = function bind(fn, thisArg) {
|
15697 | return function wrap() {
|
15698 | var args = new Array(arguments.length);
|
15699 | for (var i = 0; i < args.length; i++) {
|
15700 | args[i] = arguments[i];
|
15701 | }
|
15702 | return fn.apply(thisArg, args);
|
15703 | };
|
15704 | };
|
15705 |
|
15706 |
|
15707 | /***/ }),
|
15708 | /* 28 */
|
15709 | /***/ (function(module, exports, __webpack_require__) {
|
15710 |
|
15711 | "use strict";
|
15712 |
|
15713 |
|
15714 | module.exports = function isCancel(value) {
|
15715 | return !!(value && value.__CANCEL__);
|
15716 | };
|
15717 |
|
15718 |
|
15719 | /***/ }),
|
15720 | /* 29 */
|
15721 | /***/ (function(module, exports, __webpack_require__) {
|
15722 |
|
15723 | "use strict";
|
15724 |
|
15725 |
|
15726 | var utils = __webpack_require__(2);
|
15727 | var normalizeHeaderName = __webpack_require__(57);
|
15728 |
|
15729 | var DEFAULT_CONTENT_TYPE = {
|
15730 | 'Content-Type': 'application/x-www-form-urlencoded'
|
15731 | };
|
15732 |
|
15733 | function setContentTypeIfUnset(headers, value) {
|
15734 | if (!utils.isUndefined(headers) && utils.isUndefined(headers['Content-Type'])) {
|
15735 | headers['Content-Type'] = value;
|
15736 | }
|
15737 | }
|
15738 |
|
15739 | function getDefaultAdapter() {
|
15740 | var adapter;
|
15741 | // Only Node.JS has a process variable that is of [[Class]] process
|
15742 | if (typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]') {
|
15743 | // For node use HTTP adapter
|
15744 | adapter = __webpack_require__(58);
|
15745 | } else if (typeof XMLHttpRequest !== 'undefined') {
|
15746 | // For browsers use XHR adapter
|
15747 | adapter = __webpack_require__(71);
|
15748 | }
|
15749 | return adapter;
|
15750 | }
|
15751 |
|
15752 | var defaults = {
|
15753 | adapter: getDefaultAdapter(),
|
15754 |
|
15755 | transformRequest: [function transformRequest(data, headers) {
|
15756 | normalizeHeaderName(headers, 'Accept');
|
15757 | normalizeHeaderName(headers, 'Content-Type');
|
15758 | if (utils.isFormData(data) ||
|
15759 | utils.isArrayBuffer(data) ||
|
15760 | utils.isBuffer(data) ||
|
15761 | utils.isStream(data) ||
|
15762 | utils.isFile(data) ||
|
15763 | utils.isBlob(data)
|
15764 | ) {
|
15765 | return data;
|
15766 | }
|
15767 | if (utils.isArrayBufferView(data)) {
|
15768 | return data.buffer;
|
15769 | }
|
15770 | if (utils.isURLSearchParams(data)) {
|
15771 | setContentTypeIfUnset(headers, 'application/x-www-form-urlencoded;charset=utf-8');
|
15772 | return data.toString();
|
15773 | }
|
15774 | if (utils.isObject(data)) {
|
15775 | setContentTypeIfUnset(headers, 'application/json;charset=utf-8');
|
15776 | return JSON.stringify(data);
|
15777 | }
|
15778 | return data;
|
15779 | }],
|
15780 |
|
15781 | transformResponse: [function transformResponse(data) {
|
15782 | /*eslint no-param-reassign:0*/
|
15783 | if (typeof data === 'string') {
|
15784 | try {
|
15785 | data = JSON.parse(data);
|
15786 | } catch (e) { /* Ignore */ }
|
15787 | }
|
15788 | return data;
|
15789 | }],
|
15790 |
|
15791 | /**
|
15792 | * A timeout in milliseconds to abort a request. If set to 0 (default) a
|
15793 | * timeout is not created.
|
15794 | */
|
15795 | timeout: 0,
|
15796 |
|
15797 | xsrfCookieName: 'XSRF-TOKEN',
|
15798 | xsrfHeaderName: 'X-XSRF-TOKEN',
|
15799 |
|
15800 | maxContentLength: -1,
|
15801 |
|
15802 | validateStatus: function validateStatus(status) {
|
15803 | return status >= 200 && status < 300;
|
15804 | }
|
15805 | };
|
15806 |
|
15807 | defaults.headers = {
|
15808 | common: {
|
15809 | 'Accept': 'application/json, text/plain, */*'
|
15810 | }
|
15811 | };
|
15812 |
|
15813 | utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
|
15814 | defaults.headers[method] = {};
|
15815 | });
|
15816 |
|
15817 | utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
15818 | defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
|
15819 | });
|
15820 |
|
15821 | module.exports = defaults;
|
15822 |
|
15823 |
|
15824 | /***/ }),
|
15825 | /* 30 */
|
15826 | /***/ (function(module, exports, __webpack_require__) {
|
15827 |
|
15828 | "use strict";
|
15829 |
|
15830 |
|
15831 | var createError = __webpack_require__(19);
|
15832 |
|
15833 | /**
|
15834 | * Resolve or reject a Promise based on response status.
|
15835 | *
|
15836 | * @param {Function} resolve A function that resolves the promise.
|
15837 | * @param {Function} reject A function that rejects the promise.
|
15838 | * @param {object} response The response.
|
15839 | */
|
15840 | module.exports = function settle(resolve, reject, response) {
|
15841 | var validateStatus = response.config.validateStatus;
|
15842 | if (!validateStatus || validateStatus(response.status)) {
|
15843 | resolve(response);
|
15844 | } else {
|
15845 | reject(createError(
|
15846 | 'Request failed with status code ' + response.status,
|
15847 | response.config,
|
15848 | null,
|
15849 | response.request,
|
15850 | response
|
15851 | ));
|
15852 | }
|
15853 | };
|
15854 |
|
15855 |
|
15856 | /***/ }),
|
15857 | /* 31 */
|
15858 | /***/ (function(module, exports, __webpack_require__) {
|
15859 |
|
15860 | "use strict";
|
15861 |
|
15862 |
|
15863 | /**
|
15864 | * Update an Error with the specified config, error code, and response.
|
15865 | *
|
15866 | * @param {Error} error The error to update.
|
15867 | * @param {Object} config The config.
|
15868 | * @param {string} [code] The error code (for example, 'ECONNABORTED').
|
15869 | * @param {Object} [request] The request.
|
15870 | * @param {Object} [response] The response.
|
15871 | * @returns {Error} The error.
|
15872 | */
|
15873 | module.exports = function enhanceError(error, config, code, request, response) {
|
15874 | error.config = config;
|
15875 | if (code) {
|
15876 | error.code = code;
|
15877 | }
|
15878 |
|
15879 | error.request = request;
|
15880 | error.response = response;
|
15881 | error.isAxiosError = true;
|
15882 |
|
15883 | error.toJSON = function() {
|
15884 | return {
|
15885 | // Standard
|
15886 | message: this.message,
|
15887 | name: this.name,
|
15888 | // Microsoft
|
15889 | description: this.description,
|
15890 | number: this.number,
|
15891 | // Mozilla
|
15892 | fileName: this.fileName,
|
15893 | lineNumber: this.lineNumber,
|
15894 | columnNumber: this.columnNumber,
|
15895 | stack: this.stack,
|
15896 | // Axios
|
15897 | config: this.config,
|
15898 | code: this.code
|
15899 | };
|
15900 | };
|
15901 | return error;
|
15902 | };
|
15903 |
|
15904 |
|
15905 | /***/ }),
|
15906 | /* 32 */
|
15907 | /***/ (function(module, exports) {
|
15908 |
|
15909 | module.exports = require("http");
|
15910 |
|
15911 | /***/ }),
|
15912 | /* 33 */
|
15913 | /***/ (function(module, exports) {
|
15914 |
|
15915 | module.exports = require("https");
|
15916 |
|
15917 | /***/ }),
|
15918 | /* 34 */
|
15919 | /***/ (function(module, exports, __webpack_require__) {
|
15920 |
|
15921 | var url = __webpack_require__(35);
|
15922 | var http = __webpack_require__(32);
|
15923 | var https = __webpack_require__(33);
|
15924 | var assert = __webpack_require__(59);
|
15925 | var Writable = __webpack_require__(60).Writable;
|
15926 | var debug = __webpack_require__(61)("follow-redirects");
|
15927 |
|
15928 | // RFC7231§4.2.1: Of the request methods defined by this specification,
|
15929 | // the GET, HEAD, OPTIONS, and TRACE methods are defined to be safe.
|
15930 | var SAFE_METHODS = { GET: true, HEAD: true, OPTIONS: true, TRACE: true };
|
15931 |
|
15932 | // Create handlers that pass events from native requests
|
15933 | var eventHandlers = Object.create(null);
|
15934 | ["abort", "aborted", "error", "socket", "timeout"].forEach(function (event) {
|
15935 | eventHandlers[event] = function (arg) {
|
15936 | this._redirectable.emit(event, arg);
|
15937 | };
|
15938 | });
|
15939 |
|
15940 | // An HTTP(S) request that can be redirected
|
15941 | function RedirectableRequest(options, responseCallback) {
|
15942 | // Initialize the request
|
15943 | Writable.call(this);
|
15944 | options.headers = options.headers || {};
|
15945 | this._options = options;
|
15946 | this._redirectCount = 0;
|
15947 | this._redirects = [];
|
15948 | this._requestBodyLength = 0;
|
15949 | this._requestBodyBuffers = [];
|
15950 |
|
15951 | // Since http.request treats host as an alias of hostname,
|
15952 | // but the url module interprets host as hostname plus port,
|
15953 | // eliminate the host property to avoid confusion.
|
15954 | if (options.host) {
|
15955 | // Use hostname if set, because it has precedence
|
15956 | if (!options.hostname) {
|
15957 | options.hostname = options.host;
|
15958 | }
|
15959 | delete options.host;
|
15960 | }
|
15961 |
|
15962 | // Attach a callback if passed
|
15963 | if (responseCallback) {
|
15964 | this.on("response", responseCallback);
|
15965 | }
|
15966 |
|
15967 | // React to responses of native requests
|
15968 | var self = this;
|
15969 | this._onNativeResponse = function (response) {
|
15970 | self._processResponse(response);
|
15971 | };
|
15972 |
|
15973 | // Complete the URL object when necessary
|
15974 | if (!options.pathname && options.path) {
|
15975 | var searchPos = options.path.indexOf("?");
|
15976 | if (searchPos < 0) {
|
15977 | options.pathname = options.path;
|
15978 | }
|
15979 | else {
|
15980 | options.pathname = options.path.substring(0, searchPos);
|
15981 | options.search = options.path.substring(searchPos);
|
15982 | }
|
15983 | }
|
15984 |
|
15985 | // Perform the first request
|
15986 | this._performRequest();
|
15987 | }
|
15988 | RedirectableRequest.prototype = Object.create(Writable.prototype);
|
15989 |
|
15990 | // Writes buffered data to the current native request
|
15991 | RedirectableRequest.prototype.write = function (data, encoding, callback) {
|
15992 | // Validate input and shift parameters if necessary
|
15993 | if (!(typeof data === "string" || typeof data === "object" && ("length" in data))) {
|
15994 | throw new Error("data should be a string, Buffer or Uint8Array");
|
15995 | }
|
15996 | if (typeof encoding === "function") {
|
15997 | callback = encoding;
|
15998 | encoding = null;
|
15999 | }
|
16000 |
|
16001 | // Ignore empty buffers, since writing them doesn't invoke the callback
|
16002 | // https://github.com/nodejs/node/issues/22066
|
16003 | if (data.length === 0) {
|
16004 | if (callback) {
|
16005 | callback();
|
16006 | }
|
16007 | return;
|
16008 | }
|
16009 | // Only write when we don't exceed the maximum body length
|
16010 | if (this._requestBodyLength + data.length <= this._options.maxBodyLength) {
|
16011 | this._requestBodyLength += data.length;
|
16012 | this._requestBodyBuffers.push({ data: data, encoding: encoding });
|
16013 | this._currentRequest.write(data, encoding, callback);
|
16014 | }
|
16015 | // Error when we exceed the maximum body length
|
16016 | else {
|
16017 | this.emit("error", new Error("Request body larger than maxBodyLength limit"));
|
16018 | this.abort();
|
16019 | }
|
16020 | };
|
16021 |
|
16022 | // Ends the current native request
|
16023 | RedirectableRequest.prototype.end = function (data, encoding, callback) {
|
16024 | // Shift parameters if necessary
|
16025 | if (typeof data === "function") {
|
16026 | callback = data;
|
16027 | data = encoding = null;
|
16028 | }
|
16029 | else if (typeof encoding === "function") {
|
16030 | callback = encoding;
|
16031 | encoding = null;
|
16032 | }
|
16033 |
|
16034 | // Write data and end
|
16035 | var currentRequest = this._currentRequest;
|
16036 | this.write(data || "", encoding, function () {
|
16037 | currentRequest.end(null, null, callback);
|
16038 | });
|
16039 | };
|
16040 |
|
16041 | // Sets a header value on the current native request
|
16042 | RedirectableRequest.prototype.setHeader = function (name, value) {
|
16043 | this._options.headers[name] = value;
|
16044 | this._currentRequest.setHeader(name, value);
|
16045 | };
|
16046 |
|
16047 | // Clears a header value on the current native request
|
16048 | RedirectableRequest.prototype.removeHeader = function (name) {
|
16049 | delete this._options.headers[name];
|
16050 | this._currentRequest.removeHeader(name);
|
16051 | };
|
16052 |
|
16053 | // Proxy all other public ClientRequest methods
|
16054 | [
|
16055 | "abort", "flushHeaders", "getHeader",
|
16056 | "setNoDelay", "setSocketKeepAlive", "setTimeout",
|
16057 | ].forEach(function (method) {
|
16058 | RedirectableRequest.prototype[method] = function (a, b) {
|
16059 | return this._currentRequest[method](a, b);
|
16060 | };
|
16061 | });
|
16062 |
|
16063 | // Proxy all public ClientRequest properties
|
16064 | ["aborted", "connection", "socket"].forEach(function (property) {
|
16065 | Object.defineProperty(RedirectableRequest.prototype, property, {
|
16066 | get: function () { return this._currentRequest[property]; },
|
16067 | });
|
16068 | });
|
16069 |
|
16070 | // Executes the next native request (initial or redirect)
|
16071 | RedirectableRequest.prototype._performRequest = function () {
|
16072 | // Load the native protocol
|
16073 | var protocol = this._options.protocol;
|
16074 | var nativeProtocol = this._options.nativeProtocols[protocol];
|
16075 | if (!nativeProtocol) {
|
16076 | this.emit("error", new Error("Unsupported protocol " + protocol));
|
16077 | return;
|
16078 | }
|
16079 |
|
16080 | // If specified, use the agent corresponding to the protocol
|
16081 | // (HTTP and HTTPS use different types of agents)
|
16082 | if (this._options.agents) {
|
16083 | var scheme = protocol.substr(0, protocol.length - 1);
|
16084 | this._options.agent = this._options.agents[scheme];
|
16085 | }
|
16086 |
|
16087 | // Create the native request
|
16088 | var request = this._currentRequest =
|
16089 | nativeProtocol.request(this._options, this._onNativeResponse);
|
16090 | this._currentUrl = url.format(this._options);
|
16091 |
|
16092 | // Set up event handlers
|
16093 | request._redirectable = this;
|
16094 | for (var event in eventHandlers) {
|
16095 | /* istanbul ignore else */
|
16096 | if (event) {
|
16097 | request.on(event, eventHandlers[event]);
|
16098 | }
|
16099 | }
|
16100 |
|
16101 | // End a redirected request
|
16102 | // (The first request must be ended explicitly with RedirectableRequest#end)
|
16103 | if (this._isRedirect) {
|
16104 | // Write the request entity and end.
|
16105 | var i = 0;
|
16106 | var buffers = this._requestBodyBuffers;
|
16107 | (function writeNext() {
|
16108 | if (i < buffers.length) {
|
16109 | var buffer = buffers[i++];
|
16110 | request.write(buffer.data, buffer.encoding, writeNext);
|
16111 | }
|
16112 | else {
|
16113 | request.end();
|
16114 | }
|
16115 | }());
|
16116 | }
|
16117 | };
|
16118 |
|
16119 | // Processes a response from the current native request
|
16120 | RedirectableRequest.prototype._processResponse = function (response) {
|
16121 | // Store the redirected response
|
16122 | if (this._options.trackRedirects) {
|
16123 | this._redirects.push({
|
16124 | url: this._currentUrl,
|
16125 | headers: response.headers,
|
16126 | statusCode: response.statusCode,
|
16127 | });
|
16128 | }
|
16129 |
|
16130 | // RFC7231§6.4: The 3xx (Redirection) class of status code indicates
|
16131 | // that further action needs to be taken by the user agent in order to
|
16132 | // fulfill the request. If a Location header field is provided,
|
16133 | // the user agent MAY automatically redirect its request to the URI
|
16134 | // referenced by the Location field value,
|
16135 | // even if the specific status code is not understood.
|
16136 | var location = response.headers.location;
|
16137 | if (location && this._options.followRedirects !== false &&
|
16138 | response.statusCode >= 300 && response.statusCode < 400) {
|
16139 | // RFC7231§6.4: A client SHOULD detect and intervene
|
16140 | // in cyclical redirections (i.e., "infinite" redirection loops).
|
16141 | if (++this._redirectCount > this._options.maxRedirects) {
|
16142 | this.emit("error", new Error("Max redirects exceeded."));
|
16143 | return;
|
16144 | }
|
16145 |
|
16146 | // RFC7231§6.4: Automatic redirection needs to done with
|
16147 | // care for methods not known to be safe […],
|
16148 | // since the user might not wish to redirect an unsafe request.
|
16149 | // RFC7231§6.4.7: The 307 (Temporary Redirect) status code indicates
|
16150 | // that the target resource resides temporarily under a different URI
|
16151 | // and the user agent MUST NOT change the request method
|
16152 | // if it performs an automatic redirection to that URI.
|
16153 | var header;
|
16154 | var headers = this._options.headers;
|
16155 | if (response.statusCode !== 307 && !(this._options.method in SAFE_METHODS)) {
|
16156 | this._options.method = "GET";
|
16157 | // Drop a possible entity and headers related to it
|
16158 | this._requestBodyBuffers = [];
|
16159 | for (header in headers) {
|
16160 | if (/^content-/i.test(header)) {
|
16161 | delete headers[header];
|
16162 | }
|
16163 | }
|
16164 | }
|
16165 |
|
16166 | // Drop the Host header, as the redirect might lead to a different host
|
16167 | if (!this._isRedirect) {
|
16168 | for (header in headers) {
|
16169 | if (/^host$/i.test(header)) {
|
16170 | delete headers[header];
|
16171 | }
|
16172 | }
|
16173 | }
|
16174 |
|
16175 | // Perform the redirected request
|
16176 | var redirectUrl = url.resolve(this._currentUrl, location);
|
16177 | debug("redirecting to", redirectUrl);
|
16178 | Object.assign(this._options, url.parse(redirectUrl));
|
16179 | this._isRedirect = true;
|
16180 | this._performRequest();
|
16181 |
|
16182 | // Discard the remainder of the response to avoid waiting for data
|
16183 | response.destroy();
|
16184 | }
|
16185 | else {
|
16186 | // The response is not a redirect; return it as-is
|
16187 | response.responseUrl = this._currentUrl;
|
16188 | response.redirects = this._redirects;
|
16189 | this.emit("response", response);
|
16190 |
|
16191 | // Clean up
|
16192 | this._requestBodyBuffers = [];
|
16193 | }
|
16194 | };
|
16195 |
|
16196 | // Wraps the key/value object of protocols with redirect functionality
|
16197 | function wrap(protocols) {
|
16198 | // Default settings
|
16199 | var exports = {
|
16200 | maxRedirects: 21,
|
16201 | maxBodyLength: 10 * 1024 * 1024,
|
16202 | };
|
16203 |
|
16204 | // Wrap each protocol
|
16205 | var nativeProtocols = {};
|
16206 | Object.keys(protocols).forEach(function (scheme) {
|
16207 | var protocol = scheme + ":";
|
16208 | var nativeProtocol = nativeProtocols[protocol] = protocols[scheme];
|
16209 | var wrappedProtocol = exports[scheme] = Object.create(nativeProtocol);
|
16210 |
|
16211 | // Executes a request, following redirects
|
16212 | wrappedProtocol.request = function (options, callback) {
|
16213 | if (typeof options === "string") {
|
16214 | options = url.parse(options);
|
16215 | options.maxRedirects = exports.maxRedirects;
|
16216 | }
|
16217 | else {
|
16218 | options = Object.assign({
|
16219 | protocol: protocol,
|
16220 | maxRedirects: exports.maxRedirects,
|
16221 | maxBodyLength: exports.maxBodyLength,
|
16222 | }, options);
|
16223 | }
|
16224 | options.nativeProtocols = nativeProtocols;
|
16225 | assert.equal(options.protocol, protocol, "protocol mismatch");
|
16226 | debug("options", options);
|
16227 | return new RedirectableRequest(options, callback);
|
16228 | };
|
16229 |
|
16230 | // Executes a GET request, following redirects
|
16231 | wrappedProtocol.get = function (options, callback) {
|
16232 | var request = wrappedProtocol.request(options, callback);
|
16233 | request.end();
|
16234 | return request;
|
16235 | };
|
16236 | });
|
16237 | return exports;
|
16238 | }
|
16239 |
|
16240 | // Exports
|
16241 | module.exports = wrap({ http: http, https: https });
|
16242 | module.exports.wrap = wrap;
|
16243 |
|
16244 |
|
16245 | /***/ }),
|
16246 | /* 35 */
|
16247 | /***/ (function(module, exports) {
|
16248 |
|
16249 | module.exports = require("url");
|
16250 |
|
16251 | /***/ }),
|
16252 | /* 36 */
|
16253 | /***/ (function(module, exports, __webpack_require__) {
|
16254 |
|
16255 |
|
16256 | /**
|
16257 | * This is the common logic for both the Node.js and web browser
|
16258 | * implementations of `debug()`.
|
16259 | *
|
16260 | * Expose `debug()` as the module.
|
16261 | */
|
16262 |
|
16263 | exports = module.exports = createDebug.debug = createDebug['default'] = createDebug;
|
16264 | exports.coerce = coerce;
|
16265 | exports.disable = disable;
|
16266 | exports.enable = enable;
|
16267 | exports.enabled = enabled;
|
16268 | exports.humanize = __webpack_require__(63);
|
16269 |
|
16270 | /**
|
16271 | * Active `debug` instances.
|
16272 | */
|
16273 | exports.instances = [];
|
16274 |
|
16275 | /**
|
16276 | * The currently active debug mode names, and names to skip.
|
16277 | */
|
16278 |
|
16279 | exports.names = [];
|
16280 | exports.skips = [];
|
16281 |
|
16282 | /**
|
16283 | * Map of special "%n" handling functions, for the debug "format" argument.
|
16284 | *
|
16285 | * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
|
16286 | */
|
16287 |
|
16288 | exports.formatters = {};
|
16289 |
|
16290 | /**
|
16291 | * Select a color.
|
16292 | * @param {String} namespace
|
16293 | * @return {Number}
|
16294 | * @api private
|
16295 | */
|
16296 |
|
16297 | function selectColor(namespace) {
|
16298 | var hash = 0, i;
|
16299 |
|
16300 | for (i in namespace) {
|
16301 | hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
|
16302 | hash |= 0; // Convert to 32bit integer
|
16303 | }
|
16304 |
|
16305 | return exports.colors[Math.abs(hash) % exports.colors.length];
|
16306 | }
|
16307 |
|
16308 | /**
|
16309 | * Create a debugger with the given `namespace`.
|
16310 | *
|
16311 | * @param {String} namespace
|
16312 | * @return {Function}
|
16313 | * @api public
|
16314 | */
|
16315 |
|
16316 | function createDebug(namespace) {
|
16317 |
|
16318 | var prevTime;
|
16319 |
|
16320 | function debug() {
|
16321 | // disabled?
|
16322 | if (!debug.enabled) return;
|
16323 |
|
16324 | var self = debug;
|
16325 |
|
16326 | // set `diff` timestamp
|
16327 | var curr = +new Date();
|
16328 | var ms = curr - (prevTime || curr);
|
16329 | self.diff = ms;
|
16330 | self.prev = prevTime;
|
16331 | self.curr = curr;
|
16332 | prevTime = curr;
|
16333 |
|
16334 | // turn the `arguments` into a proper Array
|
16335 | var args = new Array(arguments.length);
|
16336 | for (var i = 0; i < args.length; i++) {
|
16337 | args[i] = arguments[i];
|
16338 | }
|
16339 |
|
16340 | args[0] = exports.coerce(args[0]);
|
16341 |
|
16342 | if ('string' !== typeof args[0]) {
|
16343 | // anything else let's inspect with %O
|
16344 | args.unshift('%O');
|
16345 | }
|
16346 |
|
16347 | // apply any `formatters` transformations
|
16348 | var index = 0;
|
16349 | args[0] = args[0].replace(/%([a-zA-Z%])/g, function(match, format) {
|
16350 | // if we encounter an escaped % then don't increase the array index
|
16351 | if (match === '%%') return match;
|
16352 | index++;
|
16353 | var formatter = exports.formatters[format];
|
16354 | if ('function' === typeof formatter) {
|
16355 | var val = args[index];
|
16356 | match = formatter.call(self, val);
|
16357 |
|
16358 | // now we need to remove `args[index]` since it's inlined in the `format`
|
16359 | args.splice(index, 1);
|
16360 | index--;
|
16361 | }
|
16362 | return match;
|
16363 | });
|
16364 |
|
16365 | // apply env-specific formatting (colors, etc.)
|
16366 | exports.formatArgs.call(self, args);
|
16367 |
|
16368 | var logFn = debug.log || exports.log || console.log.bind(console);
|
16369 | logFn.apply(self, args);
|
16370 | }
|
16371 |
|
16372 | debug.namespace = namespace;
|
16373 | debug.enabled = exports.enabled(namespace);
|
16374 | debug.useColors = exports.useColors();
|
16375 | debug.color = selectColor(namespace);
|
16376 | debug.destroy = destroy;
|
16377 |
|
16378 | // env-specific initialization logic for debug instances
|
16379 | if ('function' === typeof exports.init) {
|
16380 | exports.init(debug);
|
16381 | }
|
16382 |
|
16383 | exports.instances.push(debug);
|
16384 |
|
16385 | return debug;
|
16386 | }
|
16387 |
|
16388 | function destroy () {
|
16389 | var index = exports.instances.indexOf(this);
|
16390 | if (index !== -1) {
|
16391 | exports.instances.splice(index, 1);
|
16392 | return true;
|
16393 | } else {
|
16394 | return false;
|
16395 | }
|
16396 | }
|
16397 |
|
16398 | /**
|
16399 | * Enables a debug mode by namespaces. This can include modes
|
16400 | * separated by a colon and wildcards.
|
16401 | *
|
16402 | * @param {String} namespaces
|
16403 | * @api public
|
16404 | */
|
16405 |
|
16406 | function enable(namespaces) {
|
16407 | exports.save(namespaces);
|
16408 |
|
16409 | exports.names = [];
|
16410 | exports.skips = [];
|
16411 |
|
16412 | var i;
|
16413 | var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
|
16414 | var len = split.length;
|
16415 |
|
16416 | for (i = 0; i < len; i++) {
|
16417 | if (!split[i]) continue; // ignore empty strings
|
16418 | namespaces = split[i].replace(/\*/g, '.*?');
|
16419 | if (namespaces[0] === '-') {
|
16420 | exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
|
16421 | } else {
|
16422 | exports.names.push(new RegExp('^' + namespaces + '$'));
|
16423 | }
|
16424 | }
|
16425 |
|
16426 | for (i = 0; i < exports.instances.length; i++) {
|
16427 | var instance = exports.instances[i];
|
16428 | instance.enabled = exports.enabled(instance.namespace);
|
16429 | }
|
16430 | }
|
16431 |
|
16432 | /**
|
16433 | * Disable debug output.
|
16434 | *
|
16435 | * @api public
|
16436 | */
|
16437 |
|
16438 | function disable() {
|
16439 | exports.enable('');
|
16440 | }
|
16441 |
|
16442 | /**
|
16443 | * Returns true if the given mode name is enabled, false otherwise.
|
16444 | *
|
16445 | * @param {String} name
|
16446 | * @return {Boolean}
|
16447 | * @api public
|
16448 | */
|
16449 |
|
16450 | function enabled(name) {
|
16451 | if (name[name.length - 1] === '*') {
|
16452 | return true;
|
16453 | }
|
16454 | var i, len;
|
16455 | for (i = 0, len = exports.skips.length; i < len; i++) {
|
16456 | if (exports.skips[i].test(name)) {
|
16457 | return false;
|
16458 | }
|
16459 | }
|
16460 | for (i = 0, len = exports.names.length; i < len; i++) {
|
16461 | if (exports.names[i].test(name)) {
|
16462 | return true;
|
16463 | }
|
16464 | }
|
16465 | return false;
|
16466 | }
|
16467 |
|
16468 | /**
|
16469 | * Coerce `val`.
|
16470 | *
|
16471 | * @param {Mixed} val
|
16472 | * @return {Mixed}
|
16473 | * @api private
|
16474 | */
|
16475 |
|
16476 | function coerce(val) {
|
16477 | if (val instanceof Error) return val.stack || val.message;
|
16478 | return val;
|
16479 | }
|
16480 |
|
16481 |
|
16482 | /***/ }),
|
16483 | /* 37 */
|
16484 | /***/ (function(module, exports, __webpack_require__) {
|
16485 |
|
16486 | "use strict";
|
16487 |
|
16488 |
|
16489 | var utils = __webpack_require__(2);
|
16490 |
|
16491 | /**
|
16492 | * Config-specific merge-function which creates a new config-object
|
16493 | * by merging two configuration objects together.
|
16494 | *
|
16495 | * @param {Object} config1
|
16496 | * @param {Object} config2
|
16497 | * @returns {Object} New object resulting from merging config2 to config1
|
16498 | */
|
16499 | module.exports = function mergeConfig(config1, config2) {
|
16500 | // eslint-disable-next-line no-param-reassign
|
16501 | config2 = config2 || {};
|
16502 | var config = {};
|
16503 |
|
16504 | utils.forEach(['url', 'method', 'params', 'data'], function valueFromConfig2(prop) {
|
16505 | if (typeof config2[prop] !== 'undefined') {
|
16506 | config[prop] = config2[prop];
|
16507 | }
|
16508 | });
|
16509 |
|
16510 | utils.forEach(['headers', 'auth', 'proxy'], function mergeDeepProperties(prop) {
|
16511 | if (utils.isObject(config2[prop])) {
|
16512 | config[prop] = utils.deepMerge(config1[prop], config2[prop]);
|
16513 | } else if (typeof config2[prop] !== 'undefined') {
|
16514 | config[prop] = config2[prop];
|
16515 | } else if (utils.isObject(config1[prop])) {
|
16516 | config[prop] = utils.deepMerge(config1[prop]);
|
16517 | } else if (typeof config1[prop] !== 'undefined') {
|
16518 | config[prop] = config1[prop];
|
16519 | }
|
16520 | });
|
16521 |
|
16522 | utils.forEach([
|
16523 | 'baseURL', 'transformRequest', 'transformResponse', 'paramsSerializer',
|
16524 | 'timeout', 'withCredentials', 'adapter', 'responseType', 'xsrfCookieName',
|
16525 | 'xsrfHeaderName', 'onUploadProgress', 'onDownloadProgress', 'maxContentLength',
|
16526 | 'validateStatus', 'maxRedirects', 'httpAgent', 'httpsAgent', 'cancelToken',
|
16527 | 'socketPath'
|
16528 | ], function defaultToConfig2(prop) {
|
16529 | if (typeof config2[prop] !== 'undefined') {
|
16530 | config[prop] = config2[prop];
|
16531 | } else if (typeof config1[prop] !== 'undefined') {
|
16532 | config[prop] = config1[prop];
|
16533 | }
|
16534 | });
|
16535 |
|
16536 | return config;
|
16537 | };
|
16538 |
|
16539 |
|
16540 | /***/ }),
|
16541 | /* 38 */
|
16542 | /***/ (function(module, exports, __webpack_require__) {
|
16543 |
|
16544 | "use strict";
|
16545 |
|
16546 |
|
16547 | /**
|
16548 | * A `Cancel` is an object that is thrown when an operation is canceled.
|
16549 | *
|
16550 | * @class
|
16551 | * @param {string=} message The message.
|
16552 | */
|
16553 | function Cancel(message) {
|
16554 | this.message = message;
|
16555 | }
|
16556 |
|
16557 | Cancel.prototype.toString = function toString() {
|
16558 | return 'Cancel' + (this.message ? ': ' + this.message : '');
|
16559 | };
|
16560 |
|
16561 | Cancel.prototype.__CANCEL__ = true;
|
16562 |
|
16563 | module.exports = Cancel;
|
16564 |
|
16565 |
|
16566 | /***/ }),
|
16567 | /* 39 */
|
16568 | /***/ (function(module, exports, __webpack_require__) {
|
16569 |
|
16570 | /* eslint-disable node/no-deprecated-api */
|
16571 | var buffer = __webpack_require__(9)
|
16572 | var Buffer = buffer.Buffer
|
16573 |
|
16574 | // alternative to using Object.keys for old browsers
|
16575 | function copyProps (src, dst) {
|
16576 | for (var key in src) {
|
16577 | dst[key] = src[key]
|
16578 | }
|
16579 | }
|
16580 | if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
|
16581 | module.exports = buffer
|
16582 | } else {
|
16583 | // Copy properties from require('buffer')
|
16584 | copyProps(buffer, exports)
|
16585 | exports.Buffer = SafeBuffer
|
16586 | }
|
16587 |
|
16588 | function SafeBuffer (arg, encodingOrOffset, length) {
|
16589 | return Buffer(arg, encodingOrOffset, length)
|
16590 | }
|
16591 |
|
16592 | // Copy static methods from Buffer
|
16593 | copyProps(Buffer, SafeBuffer)
|
16594 |
|
16595 | SafeBuffer.from = function (arg, encodingOrOffset, length) {
|
16596 | if (typeof arg === 'number') {
|
16597 | throw new TypeError('Argument must not be a number')
|
16598 | }
|
16599 | return Buffer(arg, encodingOrOffset, length)
|
16600 | }
|
16601 |
|
16602 | SafeBuffer.alloc = function (size, fill, encoding) {
|
16603 | if (typeof size !== 'number') {
|
16604 | throw new TypeError('Argument must be a number')
|
16605 | }
|
16606 | var buf = Buffer(size)
|
16607 | if (fill !== undefined) {
|
16608 | if (typeof encoding === 'string') {
|
16609 | buf.fill(fill, encoding)
|
16610 | } else {
|
16611 | buf.fill(fill)
|
16612 | }
|
16613 | } else {
|
16614 | buf.fill(0)
|
16615 | }
|
16616 | return buf
|
16617 | }
|
16618 |
|
16619 | SafeBuffer.allocUnsafe = function (size) {
|
16620 | if (typeof size !== 'number') {
|
16621 | throw new TypeError('Argument must be a number')
|
16622 | }
|
16623 | return Buffer(size)
|
16624 | }
|
16625 |
|
16626 | SafeBuffer.allocUnsafeSlow = function (size) {
|
16627 | if (typeof size !== 'number') {
|
16628 | throw new TypeError('Argument must be a number')
|
16629 | }
|
16630 | return buffer.SlowBuffer(size)
|
16631 | }
|
16632 |
|
16633 |
|
16634 | /***/ }),
|
16635 | /* 40 */
|
16636 | /***/ (function(module, exports, __webpack_require__) {
|
16637 |
|
16638 | "use strict";
|
16639 |
|
16640 |
|
16641 | var utils = exports;
|
16642 |
|
16643 | function toArray(msg, enc) {
|
16644 | if (Array.isArray(msg))
|
16645 | return msg.slice();
|
16646 | if (!msg)
|
16647 | return [];
|
16648 | var res = [];
|
16649 | if (typeof msg !== 'string') {
|
16650 | for (var i = 0; i < msg.length; i++)
|
16651 | res[i] = msg[i] | 0;
|
16652 | return res;
|
16653 | }
|
16654 | if (enc === 'hex') {
|
16655 | msg = msg.replace(/[^a-z0-9]+/ig, '');
|
16656 | if (msg.length % 2 !== 0)
|
16657 | msg = '0' + msg;
|
16658 | for (var i = 0; i < msg.length; i += 2)
|
16659 | res.push(parseInt(msg[i] + msg[i + 1], 16));
|
16660 | } else {
|
16661 | for (var i = 0; i < msg.length; i++) {
|
16662 | var c = msg.charCodeAt(i);
|
16663 | var hi = c >> 8;
|
16664 | var lo = c & 0xff;
|
16665 | if (hi)
|
16666 | res.push(hi, lo);
|
16667 | else
|
16668 | res.push(lo);
|
16669 | }
|
16670 | }
|
16671 | return res;
|
16672 | }
|
16673 | utils.toArray = toArray;
|
16674 |
|
16675 | function zero2(word) {
|
16676 | if (word.length === 1)
|
16677 | return '0' + word;
|
16678 | else
|
16679 | return word;
|
16680 | }
|
16681 | utils.zero2 = zero2;
|
16682 |
|
16683 | function toHex(msg) {
|
16684 | var res = '';
|
16685 | for (var i = 0; i < msg.length; i++)
|
16686 | res += zero2(msg[i].toString(16));
|
16687 | return res;
|
16688 | }
|
16689 | utils.toHex = toHex;
|
16690 |
|
16691 | utils.encode = function encode(arr, enc) {
|
16692 | if (enc === 'hex')
|
16693 | return toHex(arr);
|
16694 | else
|
16695 | return arr;
|
16696 | };
|
16697 |
|
16698 |
|
16699 | /***/ }),
|
16700 | /* 41 */
|
16701 | /***/ (function(module, exports, __webpack_require__) {
|
16702 |
|
16703 | "use strict";
|
16704 |
|
16705 |
|
16706 | var utils = __webpack_require__(6);
|
16707 | var rotr32 = utils.rotr32;
|
16708 |
|
16709 | function ft_1(s, x, y, z) {
|
16710 | if (s === 0)
|
16711 | return ch32(x, y, z);
|
16712 | if (s === 1 || s === 3)
|
16713 | return p32(x, y, z);
|
16714 | if (s === 2)
|
16715 | return maj32(x, y, z);
|
16716 | }
|
16717 | exports.ft_1 = ft_1;
|
16718 |
|
16719 | function ch32(x, y, z) {
|
16720 | return (x & y) ^ ((~x) & z);
|
16721 | }
|
16722 | exports.ch32 = ch32;
|
16723 |
|
16724 | function maj32(x, y, z) {
|
16725 | return (x & y) ^ (x & z) ^ (y & z);
|
16726 | }
|
16727 | exports.maj32 = maj32;
|
16728 |
|
16729 | function p32(x, y, z) {
|
16730 | return x ^ y ^ z;
|
16731 | }
|
16732 | exports.p32 = p32;
|
16733 |
|
16734 | function s0_256(x) {
|
16735 | return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22);
|
16736 | }
|
16737 | exports.s0_256 = s0_256;
|
16738 |
|
16739 | function s1_256(x) {
|
16740 | return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25);
|
16741 | }
|
16742 | exports.s1_256 = s1_256;
|
16743 |
|
16744 | function g0_256(x) {
|
16745 | return rotr32(x, 7) ^ rotr32(x, 18) ^ (x >>> 3);
|
16746 | }
|
16747 | exports.g0_256 = g0_256;
|
16748 |
|
16749 | function g1_256(x) {
|
16750 | return rotr32(x, 17) ^ rotr32(x, 19) ^ (x >>> 10);
|
16751 | }
|
16752 | exports.g1_256 = g1_256;
|
16753 |
|
16754 |
|
16755 | /***/ }),
|
16756 | /* 42 */
|
16757 | /***/ (function(module, exports, __webpack_require__) {
|
16758 |
|
16759 | "use strict";
|
16760 |
|
16761 |
|
16762 | var utils = __webpack_require__(6);
|
16763 | var common = __webpack_require__(13);
|
16764 | var shaCommon = __webpack_require__(41);
|
16765 | var assert = __webpack_require__(8);
|
16766 |
|
16767 | var sum32 = utils.sum32;
|
16768 | var sum32_4 = utils.sum32_4;
|
16769 | var sum32_5 = utils.sum32_5;
|
16770 | var ch32 = shaCommon.ch32;
|
16771 | var maj32 = shaCommon.maj32;
|
16772 | var s0_256 = shaCommon.s0_256;
|
16773 | var s1_256 = shaCommon.s1_256;
|
16774 | var g0_256 = shaCommon.g0_256;
|
16775 | var g1_256 = shaCommon.g1_256;
|
16776 |
|
16777 | var BlockHash = common.BlockHash;
|
16778 |
|
16779 | var sha256_K = [
|
16780 | 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
|
16781 | 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
16782 | 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
16783 | 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
16784 | 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
|
16785 | 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
16786 | 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
|
16787 | 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
16788 | 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
16789 | 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
16790 | 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
|
16791 | 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
16792 | 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
|
16793 | 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
16794 | 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
16795 | 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
16796 | ];
|
16797 |
|
16798 | function SHA256() {
|
16799 | if (!(this instanceof SHA256))
|
16800 | return new SHA256();
|
16801 |
|
16802 | BlockHash.call(this);
|
16803 | this.h = [
|
16804 | 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
|
16805 | 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
16806 | ];
|
16807 | this.k = sha256_K;
|
16808 | this.W = new Array(64);
|
16809 | }
|
16810 | utils.inherits(SHA256, BlockHash);
|
16811 | module.exports = SHA256;
|
16812 |
|
16813 | SHA256.blockSize = 512;
|
16814 | SHA256.outSize = 256;
|
16815 | SHA256.hmacStrength = 192;
|
16816 | SHA256.padLength = 64;
|
16817 |
|
16818 | SHA256.prototype._update = function _update(msg, start) {
|
16819 | var W = this.W;
|
16820 |
|
16821 | for (var i = 0; i < 16; i++)
|
16822 | W[i] = msg[start + i];
|
16823 | for (; i < W.length; i++)
|
16824 | W[i] = sum32_4(g1_256(W[i - 2]), W[i - 7], g0_256(W[i - 15]), W[i - 16]);
|
16825 |
|
16826 | var a = this.h[0];
|
16827 | var b = this.h[1];
|
16828 | var c = this.h[2];
|
16829 | var d = this.h[3];
|
16830 | var e = this.h[4];
|
16831 | var f = this.h[5];
|
16832 | var g = this.h[6];
|
16833 | var h = this.h[7];
|
16834 |
|
16835 | assert(this.k.length === W.length);
|
16836 | for (i = 0; i < W.length; i++) {
|
16837 | var T1 = sum32_5(h, s1_256(e), ch32(e, f, g), this.k[i], W[i]);
|
16838 | var T2 = sum32(s0_256(a), maj32(a, b, c));
|
16839 | h = g;
|
16840 | g = f;
|
16841 | f = e;
|
16842 | e = sum32(d, T1);
|
16843 | d = c;
|
16844 | c = b;
|
16845 | b = a;
|
16846 | a = sum32(T1, T2);
|
16847 | }
|
16848 |
|
16849 | this.h[0] = sum32(this.h[0], a);
|
16850 | this.h[1] = sum32(this.h[1], b);
|
16851 | this.h[2] = sum32(this.h[2], c);
|
16852 | this.h[3] = sum32(this.h[3], d);
|
16853 | this.h[4] = sum32(this.h[4], e);
|
16854 | this.h[5] = sum32(this.h[5], f);
|
16855 | this.h[6] = sum32(this.h[6], g);
|
16856 | this.h[7] = sum32(this.h[7], h);
|
16857 | };
|
16858 |
|
16859 | SHA256.prototype._digest = function digest(enc) {
|
16860 | if (enc === 'hex')
|
16861 | return utils.toHex32(this.h, 'big');
|
16862 | else
|
16863 | return utils.split32(this.h, 'big');
|
16864 | };
|
16865 |
|
16866 |
|
16867 | /***/ }),
|
16868 | /* 43 */
|
16869 | /***/ (function(module, exports, __webpack_require__) {
|
16870 |
|
16871 | "use strict";
|
16872 |
|
16873 |
|
16874 | var utils = __webpack_require__(6);
|
16875 | var common = __webpack_require__(13);
|
16876 | var assert = __webpack_require__(8);
|
16877 |
|
16878 | var rotr64_hi = utils.rotr64_hi;
|
16879 | var rotr64_lo = utils.rotr64_lo;
|
16880 | var shr64_hi = utils.shr64_hi;
|
16881 | var shr64_lo = utils.shr64_lo;
|
16882 | var sum64 = utils.sum64;
|
16883 | var sum64_hi = utils.sum64_hi;
|
16884 | var sum64_lo = utils.sum64_lo;
|
16885 | var sum64_4_hi = utils.sum64_4_hi;
|
16886 | var sum64_4_lo = utils.sum64_4_lo;
|
16887 | var sum64_5_hi = utils.sum64_5_hi;
|
16888 | var sum64_5_lo = utils.sum64_5_lo;
|
16889 |
|
16890 | var BlockHash = common.BlockHash;
|
16891 |
|
16892 | var sha512_K = [
|
16893 | 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
|
16894 | 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
|
16895 | 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
|
16896 | 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
|
16897 | 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
|
16898 | 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
|
16899 | 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
|
16900 | 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
|
16901 | 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
|
16902 | 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
|
16903 | 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
|
16904 | 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
|
16905 | 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
|
16906 | 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
|
16907 | 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
|
16908 | 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
|
16909 | 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
|
16910 | 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
|
16911 | 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
|
16912 | 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
|
16913 | 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
|
16914 | 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
|
16915 | 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
|
16916 | 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
|
16917 | 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
|
16918 | 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
|
16919 | 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
|
16920 | 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
|
16921 | 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
|
16922 | 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
|
16923 | 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
|
16924 | 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
|
16925 | 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
|
16926 | 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
|
16927 | 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
|
16928 | 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
|
16929 | 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
|
16930 | 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
|
16931 | 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
|
16932 | 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
|
16933 | ];
|
16934 |
|
16935 | function SHA512() {
|
16936 | if (!(this instanceof SHA512))
|
16937 | return new SHA512();
|
16938 |
|
16939 | BlockHash.call(this);
|
16940 | this.h = [
|
16941 | 0x6a09e667, 0xf3bcc908,
|
16942 | 0xbb67ae85, 0x84caa73b,
|
16943 | 0x3c6ef372, 0xfe94f82b,
|
16944 | 0xa54ff53a, 0x5f1d36f1,
|
16945 | 0x510e527f, 0xade682d1,
|
16946 | 0x9b05688c, 0x2b3e6c1f,
|
16947 | 0x1f83d9ab, 0xfb41bd6b,
|
16948 | 0x5be0cd19, 0x137e2179 ];
|
16949 | this.k = sha512_K;
|
16950 | this.W = new Array(160);
|
16951 | }
|
16952 | utils.inherits(SHA512, BlockHash);
|
16953 | module.exports = SHA512;
|
16954 |
|
16955 | SHA512.blockSize = 1024;
|
16956 | SHA512.outSize = 512;
|
16957 | SHA512.hmacStrength = 192;
|
16958 | SHA512.padLength = 128;
|
16959 |
|
16960 | SHA512.prototype._prepareBlock = function _prepareBlock(msg, start) {
|
16961 | var W = this.W;
|
16962 |
|
16963 | // 32 x 32bit words
|
16964 | for (var i = 0; i < 32; i++)
|
16965 | W[i] = msg[start + i];
|
16966 | for (; i < W.length; i += 2) {
|
16967 | var c0_hi = g1_512_hi(W[i - 4], W[i - 3]); // i - 2
|
16968 | var c0_lo = g1_512_lo(W[i - 4], W[i - 3]);
|
16969 | var c1_hi = W[i - 14]; // i - 7
|
16970 | var c1_lo = W[i - 13];
|
16971 | var c2_hi = g0_512_hi(W[i - 30], W[i - 29]); // i - 15
|
16972 | var c2_lo = g0_512_lo(W[i - 30], W[i - 29]);
|
16973 | var c3_hi = W[i - 32]; // i - 16
|
16974 | var c3_lo = W[i - 31];
|
16975 |
|
16976 | W[i] = sum64_4_hi(
|
16977 | c0_hi, c0_lo,
|
16978 | c1_hi, c1_lo,
|
16979 | c2_hi, c2_lo,
|
16980 | c3_hi, c3_lo);
|
16981 | W[i + 1] = sum64_4_lo(
|
16982 | c0_hi, c0_lo,
|
16983 | c1_hi, c1_lo,
|
16984 | c2_hi, c2_lo,
|
16985 | c3_hi, c3_lo);
|
16986 | }
|
16987 | };
|
16988 |
|
16989 | SHA512.prototype._update = function _update(msg, start) {
|
16990 | this._prepareBlock(msg, start);
|
16991 |
|
16992 | var W = this.W;
|
16993 |
|
16994 | var ah = this.h[0];
|
16995 | var al = this.h[1];
|
16996 | var bh = this.h[2];
|
16997 | var bl = this.h[3];
|
16998 | var ch = this.h[4];
|
16999 | var cl = this.h[5];
|
17000 | var dh = this.h[6];
|
17001 | var dl = this.h[7];
|
17002 | var eh = this.h[8];
|
17003 | var el = this.h[9];
|
17004 | var fh = this.h[10];
|
17005 | var fl = this.h[11];
|
17006 | var gh = this.h[12];
|
17007 | var gl = this.h[13];
|
17008 | var hh = this.h[14];
|
17009 | var hl = this.h[15];
|
17010 |
|
17011 | assert(this.k.length === W.length);
|
17012 | for (var i = 0; i < W.length; i += 2) {
|
17013 | var c0_hi = hh;
|
17014 | var c0_lo = hl;
|
17015 | var c1_hi = s1_512_hi(eh, el);
|
17016 | var c1_lo = s1_512_lo(eh, el);
|
17017 | var c2_hi = ch64_hi(eh, el, fh, fl, gh, gl);
|
17018 | var c2_lo = ch64_lo(eh, el, fh, fl, gh, gl);
|
17019 | var c3_hi = this.k[i];
|
17020 | var c3_lo = this.k[i + 1];
|
17021 | var c4_hi = W[i];
|
17022 | var c4_lo = W[i + 1];
|
17023 |
|
17024 | var T1_hi = sum64_5_hi(
|
17025 | c0_hi, c0_lo,
|
17026 | c1_hi, c1_lo,
|
17027 | c2_hi, c2_lo,
|
17028 | c3_hi, c3_lo,
|
17029 | c4_hi, c4_lo);
|
17030 | var T1_lo = sum64_5_lo(
|
17031 | c0_hi, c0_lo,
|
17032 | c1_hi, c1_lo,
|
17033 | c2_hi, c2_lo,
|
17034 | c3_hi, c3_lo,
|
17035 | c4_hi, c4_lo);
|
17036 |
|
17037 | c0_hi = s0_512_hi(ah, al);
|
17038 | c0_lo = s0_512_lo(ah, al);
|
17039 | c1_hi = maj64_hi(ah, al, bh, bl, ch, cl);
|
17040 | c1_lo = maj64_lo(ah, al, bh, bl, ch, cl);
|
17041 |
|
17042 | var T2_hi = sum64_hi(c0_hi, c0_lo, c1_hi, c1_lo);
|
17043 | var T2_lo = sum64_lo(c0_hi, c0_lo, c1_hi, c1_lo);
|
17044 |
|
17045 | hh = gh;
|
17046 | hl = gl;
|
17047 |
|
17048 | gh = fh;
|
17049 | gl = fl;
|
17050 |
|
17051 | fh = eh;
|
17052 | fl = el;
|
17053 |
|
17054 | eh = sum64_hi(dh, dl, T1_hi, T1_lo);
|
17055 | el = sum64_lo(dl, dl, T1_hi, T1_lo);
|
17056 |
|
17057 | dh = ch;
|
17058 | dl = cl;
|
17059 |
|
17060 | ch = bh;
|
17061 | cl = bl;
|
17062 |
|
17063 | bh = ah;
|
17064 | bl = al;
|
17065 |
|
17066 | ah = sum64_hi(T1_hi, T1_lo, T2_hi, T2_lo);
|
17067 | al = sum64_lo(T1_hi, T1_lo, T2_hi, T2_lo);
|
17068 | }
|
17069 |
|
17070 | sum64(this.h, 0, ah, al);
|
17071 | sum64(this.h, 2, bh, bl);
|
17072 | sum64(this.h, 4, ch, cl);
|
17073 | sum64(this.h, 6, dh, dl);
|
17074 | sum64(this.h, 8, eh, el);
|
17075 | sum64(this.h, 10, fh, fl);
|
17076 | sum64(this.h, 12, gh, gl);
|
17077 | sum64(this.h, 14, hh, hl);
|
17078 | };
|
17079 |
|
17080 | SHA512.prototype._digest = function digest(enc) {
|
17081 | if (enc === 'hex')
|
17082 | return utils.toHex32(this.h, 'big');
|
17083 | else
|
17084 | return utils.split32(this.h, 'big');
|
17085 | };
|
17086 |
|
17087 | function ch64_hi(xh, xl, yh, yl, zh) {
|
17088 | var r = (xh & yh) ^ ((~xh) & zh);
|
17089 | if (r < 0)
|
17090 | r += 0x100000000;
|
17091 | return r;
|
17092 | }
|
17093 |
|
17094 | function ch64_lo(xh, xl, yh, yl, zh, zl) {
|
17095 | var r = (xl & yl) ^ ((~xl) & zl);
|
17096 | if (r < 0)
|
17097 | r += 0x100000000;
|
17098 | return r;
|
17099 | }
|
17100 |
|
17101 | function maj64_hi(xh, xl, yh, yl, zh) {
|
17102 | var r = (xh & yh) ^ (xh & zh) ^ (yh & zh);
|
17103 | if (r < 0)
|
17104 | r += 0x100000000;
|
17105 | return r;
|
17106 | }
|
17107 |
|
17108 | function maj64_lo(xh, xl, yh, yl, zh, zl) {
|
17109 | var r = (xl & yl) ^ (xl & zl) ^ (yl & zl);
|
17110 | if (r < 0)
|
17111 | r += 0x100000000;
|
17112 | return r;
|
17113 | }
|
17114 |
|
17115 | function s0_512_hi(xh, xl) {
|
17116 | var c0_hi = rotr64_hi(xh, xl, 28);
|
17117 | var c1_hi = rotr64_hi(xl, xh, 2); // 34
|
17118 | var c2_hi = rotr64_hi(xl, xh, 7); // 39
|
17119 |
|
17120 | var r = c0_hi ^ c1_hi ^ c2_hi;
|
17121 | if (r < 0)
|
17122 | r += 0x100000000;
|
17123 | return r;
|
17124 | }
|
17125 |
|
17126 | function s0_512_lo(xh, xl) {
|
17127 | var c0_lo = rotr64_lo(xh, xl, 28);
|
17128 | var c1_lo = rotr64_lo(xl, xh, 2); // 34
|
17129 | var c2_lo = rotr64_lo(xl, xh, 7); // 39
|
17130 |
|
17131 | var r = c0_lo ^ c1_lo ^ c2_lo;
|
17132 | if (r < 0)
|
17133 | r += 0x100000000;
|
17134 | return r;
|
17135 | }
|
17136 |
|
17137 | function s1_512_hi(xh, xl) {
|
17138 | var c0_hi = rotr64_hi(xh, xl, 14);
|
17139 | var c1_hi = rotr64_hi(xh, xl, 18);
|
17140 | var c2_hi = rotr64_hi(xl, xh, 9); // 41
|
17141 |
|
17142 | var r = c0_hi ^ c1_hi ^ c2_hi;
|
17143 | if (r < 0)
|
17144 | r += 0x100000000;
|
17145 | return r;
|
17146 | }
|
17147 |
|
17148 | function s1_512_lo(xh, xl) {
|
17149 | var c0_lo = rotr64_lo(xh, xl, 14);
|
17150 | var c1_lo = rotr64_lo(xh, xl, 18);
|
17151 | var c2_lo = rotr64_lo(xl, xh, 9); // 41
|
17152 |
|
17153 | var r = c0_lo ^ c1_lo ^ c2_lo;
|
17154 | if (r < 0)
|
17155 | r += 0x100000000;
|
17156 | return r;
|
17157 | }
|
17158 |
|
17159 | function g0_512_hi(xh, xl) {
|
17160 | var c0_hi = rotr64_hi(xh, xl, 1);
|
17161 | var c1_hi = rotr64_hi(xh, xl, 8);
|
17162 | var c2_hi = shr64_hi(xh, xl, 7);
|
17163 |
|
17164 | var r = c0_hi ^ c1_hi ^ c2_hi;
|
17165 | if (r < 0)
|
17166 | r += 0x100000000;
|
17167 | return r;
|
17168 | }
|
17169 |
|
17170 | function g0_512_lo(xh, xl) {
|
17171 | var c0_lo = rotr64_lo(xh, xl, 1);
|
17172 | var c1_lo = rotr64_lo(xh, xl, 8);
|
17173 | var c2_lo = shr64_lo(xh, xl, 7);
|
17174 |
|
17175 | var r = c0_lo ^ c1_lo ^ c2_lo;
|
17176 | if (r < 0)
|
17177 | r += 0x100000000;
|
17178 | return r;
|
17179 | }
|
17180 |
|
17181 | function g1_512_hi(xh, xl) {
|
17182 | var c0_hi = rotr64_hi(xh, xl, 19);
|
17183 | var c1_hi = rotr64_hi(xl, xh, 29); // 61
|
17184 | var c2_hi = shr64_hi(xh, xl, 6);
|
17185 |
|
17186 | var r = c0_hi ^ c1_hi ^ c2_hi;
|
17187 | if (r < 0)
|
17188 | r += 0x100000000;
|
17189 | return r;
|
17190 | }
|
17191 |
|
17192 | function g1_512_lo(xh, xl) {
|
17193 | var c0_lo = rotr64_lo(xh, xl, 19);
|
17194 | var c1_lo = rotr64_lo(xl, xh, 29); // 61
|
17195 | var c2_lo = shr64_lo(xh, xl, 6);
|
17196 |
|
17197 | var r = c0_lo ^ c1_lo ^ c2_lo;
|
17198 | if (r < 0)
|
17199 | r += 0x100000000;
|
17200 | return r;
|
17201 | }
|
17202 |
|
17203 |
|
17204 | /***/ }),
|
17205 | /* 44 */
|
17206 | /***/ (function(module, exports, __webpack_require__) {
|
17207 |
|
17208 | ;(function (root, factory, undef) {
|
17209 | if (true) {
|
17210 | // CommonJS
|
17211 | module.exports = exports = factory(__webpack_require__(4), __webpack_require__(108), __webpack_require__(109));
|
17212 | }
|
17213 | else {}
|
17214 | }(this, function (CryptoJS) {
|
17215 |
|
17216 | (function () {
|
17217 | // Shortcuts
|
17218 | var C = CryptoJS;
|
17219 | var C_lib = C.lib;
|
17220 | var Base = C_lib.Base;
|
17221 | var WordArray = C_lib.WordArray;
|
17222 | var C_algo = C.algo;
|
17223 | var MD5 = C_algo.MD5;
|
17224 |
|
17225 | /**
|
17226 | * This key derivation function is meant to conform with EVP_BytesToKey.
|
17227 | * www.openssl.org/docs/crypto/EVP_BytesToKey.html
|
17228 | */
|
17229 | var EvpKDF = C_algo.EvpKDF = Base.extend({
|
17230 | /**
|
17231 | * Configuration options.
|
17232 | *
|
17233 | * @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
|
17234 | * @property {Hasher} hasher The hash algorithm to use. Default: MD5
|
17235 | * @property {number} iterations The number of iterations to perform. Default: 1
|
17236 | */
|
17237 | cfg: Base.extend({
|
17238 | keySize: 128/32,
|
17239 | hasher: MD5,
|
17240 | iterations: 1
|
17241 | }),
|
17242 |
|
17243 | /**
|
17244 | * Initializes a newly created key derivation function.
|
17245 | *
|
17246 | * @param {Object} cfg (Optional) The configuration options to use for the derivation.
|
17247 | *
|
17248 | * @example
|
17249 | *
|
17250 | * var kdf = CryptoJS.algo.EvpKDF.create();
|
17251 | * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 });
|
17252 | * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 });
|
17253 | */
|
17254 | init: function (cfg) {
|
17255 | this.cfg = this.cfg.extend(cfg);
|
17256 | },
|
17257 |
|
17258 | /**
|
17259 | * Derives a key from a password.
|
17260 | *
|
17261 | * @param {WordArray|string} password The password.
|
17262 | * @param {WordArray|string} salt A salt.
|
17263 | *
|
17264 | * @return {WordArray} The derived key.
|
17265 | *
|
17266 | * @example
|
17267 | *
|
17268 | * var key = kdf.compute(password, salt);
|
17269 | */
|
17270 | compute: function (password, salt) {
|
17271 | // Shortcut
|
17272 | var cfg = this.cfg;
|
17273 |
|
17274 | // Init hasher
|
17275 | var hasher = cfg.hasher.create();
|
17276 |
|
17277 | // Initial values
|
17278 | var derivedKey = WordArray.create();
|
17279 |
|
17280 | // Shortcuts
|
17281 | var derivedKeyWords = derivedKey.words;
|
17282 | var keySize = cfg.keySize;
|
17283 | var iterations = cfg.iterations;
|
17284 |
|
17285 | // Generate key
|
17286 | while (derivedKeyWords.length < keySize) {
|
17287 | if (block) {
|
17288 | hasher.update(block);
|
17289 | }
|
17290 | var block = hasher.update(password).finalize(salt);
|
17291 | hasher.reset();
|
17292 |
|
17293 | // Iterations
|
17294 | for (var i = 1; i < iterations; i++) {
|
17295 | block = hasher.finalize(block);
|
17296 | hasher.reset();
|
17297 | }
|
17298 |
|
17299 | derivedKey.concat(block);
|
17300 | }
|
17301 | derivedKey.sigBytes = keySize * 4;
|
17302 |
|
17303 | return derivedKey;
|
17304 | }
|
17305 | });
|
17306 |
|
17307 | /**
|
17308 | * Derives a key from a password.
|
17309 | *
|
17310 | * @param {WordArray|string} password The password.
|
17311 | * @param {WordArray|string} salt A salt.
|
17312 | * @param {Object} cfg (Optional) The configuration options to use for this computation.
|
17313 | *
|
17314 | * @return {WordArray} The derived key.
|
17315 | *
|
17316 | * @static
|
17317 | *
|
17318 | * @example
|
17319 | *
|
17320 | * var key = CryptoJS.EvpKDF(password, salt);
|
17321 | * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 });
|
17322 | * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 });
|
17323 | */
|
17324 | C.EvpKDF = function (password, salt, cfg) {
|
17325 | return EvpKDF.create(cfg).compute(password, salt);
|
17326 | };
|
17327 | }());
|
17328 |
|
17329 |
|
17330 | return CryptoJS.EvpKDF;
|
17331 |
|
17332 | }));
|
17333 |
|
17334 | /***/ }),
|
17335 | /* 45 */
|
17336 | /***/ (function(module, exports, __webpack_require__) {
|
17337 |
|
17338 | ;(function (root, factory) {
|
17339 | if (true) {
|
17340 | // CommonJS
|
17341 | module.exports = exports = factory(__webpack_require__(4));
|
17342 | }
|
17343 | else {}
|
17344 | }(this, function (CryptoJS) {
|
17345 |
|
17346 | /** @preserve
|
17347 | (c) 2012 by Cédric Mesnil. All rights reserved.
|
17348 |
|
17349 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
17350 |
|
17351 | - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
17352 | - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
17353 |
|
17354 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
17355 | */
|
17356 |
|
17357 | (function (Math) {
|
17358 | // Shortcuts
|
17359 | var C = CryptoJS;
|
17360 | var C_lib = C.lib;
|
17361 | var WordArray = C_lib.WordArray;
|
17362 | var Hasher = C_lib.Hasher;
|
17363 | var C_algo = C.algo;
|
17364 |
|
17365 | // Constants table
|
17366 | var _zl = WordArray.create([
|
17367 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
17368 | 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
|
17369 | 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
|
17370 | 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
|
17371 | 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]);
|
17372 | var _zr = WordArray.create([
|
17373 | 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
|
17374 | 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
|
17375 | 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
|
17376 | 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
|
17377 | 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]);
|
17378 | var _sl = WordArray.create([
|
17379 | 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
|
17380 | 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
|
17381 | 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
|
17382 | 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
|
17383 | 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 ]);
|
17384 | var _sr = WordArray.create([
|
17385 | 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
|
17386 | 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
|
17387 | 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
|
17388 | 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
|
17389 | 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 ]);
|
17390 |
|
17391 | var _hl = WordArray.create([ 0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]);
|
17392 | var _hr = WordArray.create([ 0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]);
|
17393 |
|
17394 | /**
|
17395 | * RIPEMD160 hash algorithm.
|
17396 | */
|
17397 | var RIPEMD160 = C_algo.RIPEMD160 = Hasher.extend({
|
17398 | _doReset: function () {
|
17399 | this._hash = WordArray.create([0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]);
|
17400 | },
|
17401 |
|
17402 | _doProcessBlock: function (M, offset) {
|
17403 |
|
17404 | // Swap endian
|
17405 | for (var i = 0; i < 16; i++) {
|
17406 | // Shortcuts
|
17407 | var offset_i = offset + i;
|
17408 | var M_offset_i = M[offset_i];
|
17409 |
|
17410 | // Swap
|
17411 | M[offset_i] = (
|
17412 | (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
|
17413 | (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
|
17414 | );
|
17415 | }
|
17416 | // Shortcut
|
17417 | var H = this._hash.words;
|
17418 | var hl = _hl.words;
|
17419 | var hr = _hr.words;
|
17420 | var zl = _zl.words;
|
17421 | var zr = _zr.words;
|
17422 | var sl = _sl.words;
|
17423 | var sr = _sr.words;
|
17424 |
|
17425 | // Working variables
|
17426 | var al, bl, cl, dl, el;
|
17427 | var ar, br, cr, dr, er;
|
17428 |
|
17429 | ar = al = H[0];
|
17430 | br = bl = H[1];
|
17431 | cr = cl = H[2];
|
17432 | dr = dl = H[3];
|
17433 | er = el = H[4];
|
17434 | // Computation
|
17435 | var t;
|
17436 | for (var i = 0; i < 80; i += 1) {
|
17437 | t = (al + M[offset+zl[i]])|0;
|
17438 | if (i<16){
|
17439 | t += f1(bl,cl,dl) + hl[0];
|
17440 | } else if (i<32) {
|
17441 | t += f2(bl,cl,dl) + hl[1];
|
17442 | } else if (i<48) {
|
17443 | t += f3(bl,cl,dl) + hl[2];
|
17444 | } else if (i<64) {
|
17445 | t += f4(bl,cl,dl) + hl[3];
|
17446 | } else {// if (i<80) {
|
17447 | t += f5(bl,cl,dl) + hl[4];
|
17448 | }
|
17449 | t = t|0;
|
17450 | t = rotl(t,sl[i]);
|
17451 | t = (t+el)|0;
|
17452 | al = el;
|
17453 | el = dl;
|
17454 | dl = rotl(cl, 10);
|
17455 | cl = bl;
|
17456 | bl = t;
|
17457 |
|
17458 | t = (ar + M[offset+zr[i]])|0;
|
17459 | if (i<16){
|
17460 | t += f5(br,cr,dr) + hr[0];
|
17461 | } else if (i<32) {
|
17462 | t += f4(br,cr,dr) + hr[1];
|
17463 | } else if (i<48) {
|
17464 | t += f3(br,cr,dr) + hr[2];
|
17465 | } else if (i<64) {
|
17466 | t += f2(br,cr,dr) + hr[3];
|
17467 | } else {// if (i<80) {
|
17468 | t += f1(br,cr,dr) + hr[4];
|
17469 | }
|
17470 | t = t|0;
|
17471 | t = rotl(t,sr[i]) ;
|
17472 | t = (t+er)|0;
|
17473 | ar = er;
|
17474 | er = dr;
|
17475 | dr = rotl(cr, 10);
|
17476 | cr = br;
|
17477 | br = t;
|
17478 | }
|
17479 | // Intermediate hash value
|
17480 | t = (H[1] + cl + dr)|0;
|
17481 | H[1] = (H[2] + dl + er)|0;
|
17482 | H[2] = (H[3] + el + ar)|0;
|
17483 | H[3] = (H[4] + al + br)|0;
|
17484 | H[4] = (H[0] + bl + cr)|0;
|
17485 | H[0] = t;
|
17486 | },
|
17487 |
|
17488 | _doFinalize: function () {
|
17489 | // Shortcuts
|
17490 | var data = this._data;
|
17491 | var dataWords = data.words;
|
17492 |
|
17493 | var nBitsTotal = this._nDataBytes * 8;
|
17494 | var nBitsLeft = data.sigBytes * 8;
|
17495 |
|
17496 | // Add padding
|
17497 | dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
|
17498 | dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
|
17499 | (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) |
|
17500 | (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00)
|
17501 | );
|
17502 | data.sigBytes = (dataWords.length + 1) * 4;
|
17503 |
|
17504 | // Hash final blocks
|
17505 | this._process();
|
17506 |
|
17507 | // Shortcuts
|
17508 | var hash = this._hash;
|
17509 | var H = hash.words;
|
17510 |
|
17511 | // Swap endian
|
17512 | for (var i = 0; i < 5; i++) {
|
17513 | // Shortcut
|
17514 | var H_i = H[i];
|
17515 |
|
17516 | // Swap
|
17517 | H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
|
17518 | (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00);
|
17519 | }
|
17520 |
|
17521 | // Return final computed hash
|
17522 | return hash;
|
17523 | },
|
17524 |
|
17525 | clone: function () {
|
17526 | var clone = Hasher.clone.call(this);
|
17527 | clone._hash = this._hash.clone();
|
17528 |
|
17529 | return clone;
|
17530 | }
|
17531 | });
|
17532 |
|
17533 |
|
17534 | function f1(x, y, z) {
|
17535 | return ((x) ^ (y) ^ (z));
|
17536 |
|
17537 | }
|
17538 |
|
17539 | function f2(x, y, z) {
|
17540 | return (((x)&(y)) | ((~x)&(z)));
|
17541 | }
|
17542 |
|
17543 | function f3(x, y, z) {
|
17544 | return (((x) | (~(y))) ^ (z));
|
17545 | }
|
17546 |
|
17547 | function f4(x, y, z) {
|
17548 | return (((x) & (z)) | ((y)&(~(z))));
|
17549 | }
|
17550 |
|
17551 | function f5(x, y, z) {
|
17552 | return ((x) ^ ((y) |(~(z))));
|
17553 |
|
17554 | }
|
17555 |
|
17556 | function rotl(x,n) {
|
17557 | return (x<<n) | (x>>>(32-n));
|
17558 | }
|
17559 |
|
17560 |
|
17561 | /**
|
17562 | * Shortcut function to the hasher's object interface.
|
17563 | *
|
17564 | * @param {WordArray|string} message The message to hash.
|
17565 | *
|
17566 | * @return {WordArray} The hash.
|
17567 | *
|
17568 | * @static
|
17569 | *
|
17570 | * @example
|
17571 | *
|
17572 | * var hash = CryptoJS.RIPEMD160('message');
|
17573 | * var hash = CryptoJS.RIPEMD160(wordArray);
|
17574 | */
|
17575 | C.RIPEMD160 = Hasher._createHelper(RIPEMD160);
|
17576 |
|
17577 | /**
|
17578 | * Shortcut function to the HMAC's object interface.
|
17579 | *
|
17580 | * @param {WordArray|string} message The message to hash.
|
17581 | * @param {WordArray|string} key The secret key.
|
17582 | *
|
17583 | * @return {WordArray} The HMAC.
|
17584 | *
|
17585 | * @static
|
17586 | *
|
17587 | * @example
|
17588 | *
|
17589 | * var hmac = CryptoJS.HmacRIPEMD160(message, key);
|
17590 | */
|
17591 | C.HmacRIPEMD160 = Hasher._createHmacHelper(RIPEMD160);
|
17592 | }(Math));
|
17593 |
|
17594 |
|
17595 | return CryptoJS.RIPEMD160;
|
17596 |
|
17597 | }));
|
17598 |
|
17599 | /***/ }),
|
17600 | /* 46 */
|
17601 | /***/ (function(module, exports, __webpack_require__) {
|
17602 |
|
17603 | var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!function(globals){
|
17604 | 'use strict'
|
17605 |
|
17606 | //*** UMD BEGIN
|
17607 | if (true) { //require.js / AMD
|
17608 | !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = (function() {
|
17609 | return secureRandom
|
17610 | }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
|
17611 | __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__))
|
17612 | } else {}
|
17613 | //*** UMD END
|
17614 |
|
17615 | //options.type is the only valid option
|
17616 | function secureRandom(count, options) {
|
17617 | options = options || {type: 'Array'}
|
17618 | //we check for process.pid to prevent browserify from tricking us
|
17619 | if (typeof process != 'undefined' && typeof process.pid == 'number') {
|
17620 | return nodeRandom(count, options)
|
17621 | } else {
|
17622 | var crypto = window.crypto || window.msCrypto
|
17623 | if (!crypto) throw new Error("Your browser does not support window.crypto.")
|
17624 | return browserRandom(count, options)
|
17625 | }
|
17626 | }
|
17627 |
|
17628 | function nodeRandom(count, options) {
|
17629 | var crypto = __webpack_require__(20)
|
17630 | var buf = crypto.randomBytes(count)
|
17631 |
|
17632 | switch (options.type) {
|
17633 | case 'Array':
|
17634 | return [].slice.call(buf)
|
17635 | case 'Buffer':
|
17636 | return buf
|
17637 | case 'Uint8Array':
|
17638 | var arr = new Uint8Array(count)
|
17639 | for (var i = 0; i < count; ++i) { arr[i] = buf.readUInt8(i) }
|
17640 | return arr
|
17641 | default:
|
17642 | throw new Error(options.type + " is unsupported.")
|
17643 | }
|
17644 | }
|
17645 |
|
17646 | function browserRandom(count, options) {
|
17647 | var nativeArr = new Uint8Array(count)
|
17648 | var crypto = window.crypto || window.msCrypto
|
17649 | crypto.getRandomValues(nativeArr)
|
17650 |
|
17651 | switch (options.type) {
|
17652 | case 'Array':
|
17653 | return [].slice.call(nativeArr)
|
17654 | case 'Buffer':
|
17655 | try { var b = new Buffer(1) } catch(e) { throw new Error('Buffer not supported in this environment. Use Node.js or Browserify for browser support.')}
|
17656 | return new Buffer(nativeArr)
|
17657 | case 'Uint8Array':
|
17658 | return nativeArr
|
17659 | default:
|
17660 | throw new Error(options.type + " is unsupported.")
|
17661 | }
|
17662 | }
|
17663 |
|
17664 | secureRandom.randomArray = function(byteCount) {
|
17665 | return secureRandom(byteCount, {type: 'Array'})
|
17666 | }
|
17667 |
|
17668 | secureRandom.randomUint8Array = function(byteCount) {
|
17669 | return secureRandom(byteCount, {type: 'Uint8Array'})
|
17670 | }
|
17671 |
|
17672 | secureRandom.randomBuffer = function(byteCount) {
|
17673 | return secureRandom(byteCount, {type: 'Buffer'})
|
17674 | }
|
17675 |
|
17676 |
|
17677 | }(this);
|
17678 |
|
17679 |
|
17680 | /***/ }),
|
17681 | /* 47 */
|
17682 | /***/ (function(module, exports, __webpack_require__) {
|
17683 |
|
17684 | ;(function (root, factory) {
|
17685 | if (true) {
|
17686 | // CommonJS
|
17687 | module.exports = exports = factory(__webpack_require__(4));
|
17688 | }
|
17689 | else {}
|
17690 | }(this, function (CryptoJS) {
|
17691 |
|
17692 | return CryptoJS.enc.Latin1;
|
17693 |
|
17694 | }));
|
17695 |
|
17696 | /***/ }),
|
17697 | /* 48 */
|
17698 | /***/ (function(module, exports, __webpack_require__) {
|
17699 |
|
17700 | ;(function (root, factory, undef) {
|
17701 | if (true) {
|
17702 | // CommonJS
|
17703 | module.exports = exports = factory(__webpack_require__(4), __webpack_require__(22));
|
17704 | }
|
17705 | else {}
|
17706 | }(this, function (CryptoJS) {
|
17707 |
|
17708 | /**
|
17709 | * Electronic Codebook block mode.
|
17710 | */
|
17711 | CryptoJS.mode.ECB = (function () {
|
17712 | var ECB = CryptoJS.lib.BlockCipherMode.extend();
|
17713 |
|
17714 | ECB.Encryptor = ECB.extend({
|
17715 | processBlock: function (words, offset) {
|
17716 | this._cipher.encryptBlock(words, offset);
|
17717 | }
|
17718 | });
|
17719 |
|
17720 | ECB.Decryptor = ECB.extend({
|
17721 | processBlock: function (words, offset) {
|
17722 | this._cipher.decryptBlock(words, offset);
|
17723 | }
|
17724 | });
|
17725 |
|
17726 | return ECB;
|
17727 | }());
|
17728 |
|
17729 |
|
17730 | return CryptoJS.mode.ECB;
|
17731 |
|
17732 | }));
|
17733 |
|
17734 | /***/ }),
|
17735 | /* 49 */
|
17736 | /***/ (function(module, exports, __webpack_require__) {
|
17737 |
|
17738 | ;(function (root, factory, undef) {
|
17739 | if (true) {
|
17740 | // CommonJS
|
17741 | module.exports = exports = factory(__webpack_require__(4), __webpack_require__(22));
|
17742 | }
|
17743 | else {}
|
17744 | }(this, function (CryptoJS) {
|
17745 |
|
17746 | /**
|
17747 | * A noop padding strategy.
|
17748 | */
|
17749 | CryptoJS.pad.NoPadding = {
|
17750 | pad: function () {
|
17751 | },
|
17752 |
|
17753 | unpad: function () {
|
17754 | }
|
17755 | };
|
17756 |
|
17757 |
|
17758 | return CryptoJS.pad.NoPadding;
|
17759 |
|
17760 | }));
|
17761 |
|
17762 | /***/ }),
|
17763 | /* 50 */
|
17764 | /***/ (function(module, exports, __webpack_require__) {
|
17765 |
|
17766 | "use strict";
|
17767 |
|
17768 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
17769 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
17770 | };
|
17771 | var __importStar = (this && this.__importStar) || function (mod) {
|
17772 | if (mod && mod.__esModule) return mod;
|
17773 | var result = {};
|
17774 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
17775 | result["default"] = mod;
|
17776 | return result;
|
17777 | };
|
17778 | Object.defineProperty(exports, "__esModule", { value: true });
|
17779 | const neon_api_1 = __importDefault(__webpack_require__(111));
|
17780 | const neonCore = __importStar(__webpack_require__(0));
|
17781 | const neon_nep5_1 = __importDefault(__webpack_require__(112));
|
17782 | const neonWithApi = neon_api_1.default(neonCore);
|
17783 | const neonJs = neon_nep5_1.default(neonWithApi);
|
17784 | exports.api = neonJs.api, exports.nep5 = neonJs.nep5, exports.settings = neonJs.settings, exports.sc = neonJs.sc, exports.rpc = neonJs.rpc, exports.wallet = neonJs.wallet, exports.CONST = neonJs.CONST, exports.u = neonJs.u, exports.tx = neonJs.tx, exports.logging = neonJs.logging;
|
17785 | const networks_1 = __importDefault(__webpack_require__(110));
|
17786 | const bootstrap = networks_1.default;
|
17787 | Object.keys(bootstrap).map(key => {
|
17788 | exports.settings.networks[key] = new exports.rpc.Network(bootstrap[key]);
|
17789 | });
|
17790 | /**
|
17791 | * Semantic path for creation of a resource.
|
17792 | */
|
17793 | const create = {
|
17794 | account: (k) => new exports.wallet.Account(k),
|
17795 | privateKey: exports.wallet.generatePrivateKey,
|
17796 | signature: exports.wallet.generateSignature,
|
17797 | wallet: (k) => new exports.wallet.Wallet(k),
|
17798 | claimTx: () => new exports.tx.ClaimTransaction(),
|
17799 | contractTx: () => new exports.tx.ContractTransaction(),
|
17800 | invocationTx: () => new exports.tx.InvocationTransaction(),
|
17801 | stateTx: () => new exports.tx.StateTransaction(),
|
17802 | contractParam: (type, value) => new exports.sc.ContractParam(type, value),
|
17803 | script: exports.sc.createScript,
|
17804 | scriptBuilder: () => new exports.sc.ScriptBuilder(),
|
17805 | deployScript: (args) => exports.sc.generateDeployScript(args),
|
17806 | rpcClient: (net, version) => new exports.rpc.RPCClient(net, version),
|
17807 | query: (req) => new exports.rpc.Query(req),
|
17808 | network: (net) => new exports.rpc.Network(net),
|
17809 | stringStream: (str) => new exports.u.StringStream(str),
|
17810 | fixed8: (i) => new exports.u.Fixed8(i)
|
17811 | };
|
17812 | /**
|
17813 | * Semantic path for verification of a type.
|
17814 | */
|
17815 | const is = {
|
17816 | address: exports.wallet.isAddress,
|
17817 | publicKey: exports.wallet.isPublicKey,
|
17818 | encryptedKey: exports.wallet.isNEP2,
|
17819 | privateKey: exports.wallet.isPrivateKey,
|
17820 | wif: exports.wallet.isWIF,
|
17821 | scriptHash: exports.wallet.isScriptHash
|
17822 | };
|
17823 | /**
|
17824 | * Semantic path for deserialization of object.
|
17825 | */
|
17826 | const deserialize = {
|
17827 | attribute: exports.tx.TransactionAttribute.deserialize,
|
17828 | input: exports.tx.TransactionInput.deserialize,
|
17829 | output: exports.tx.TransactionOutput.deserialize,
|
17830 | script: exports.tx.Witness.deserialize,
|
17831 | tx: exports.tx.Transaction.deserialize
|
17832 | };
|
17833 | /**
|
17834 | * Semantic path for signing using private key.
|
17835 | */
|
17836 | const sign = {
|
17837 | hex: exports.wallet.sign,
|
17838 | message: (msg, privateKey) => {
|
17839 | const hex = exports.u.str2hexstring(msg);
|
17840 | return exports.wallet.sign(hex, privateKey);
|
17841 | }
|
17842 | };
|
17843 | /**
|
17844 | * Semantic path for verifying signatures using public key.
|
17845 | */
|
17846 | const verify = {
|
17847 | hex: exports.wallet.verify,
|
17848 | message: (msg, sig, publicKey) => {
|
17849 | const hex = exports.u.str2hexstring(msg);
|
17850 | return exports.wallet.verify(hex, sig, publicKey);
|
17851 | }
|
17852 | };
|
17853 | exports.default = {
|
17854 | sendAsset: exports.api.sendAsset,
|
17855 | claimGas: exports.api.claimGas,
|
17856 | doInvoke: exports.api.doInvoke,
|
17857 | setupVote: exports.api.setupVote,
|
17858 | create,
|
17859 | deserialize,
|
17860 | is,
|
17861 | sign,
|
17862 | verify,
|
17863 | encrypt: {
|
17864 | privateKey: exports.wallet.encrypt
|
17865 | },
|
17866 | decrypt: {
|
17867 | privateKey: exports.wallet.decrypt
|
17868 | },
|
17869 | add: {
|
17870 | network: (network, override = false) => {
|
17871 | if (override && exports.settings.networks[network.name]) {
|
17872 | return false;
|
17873 | }
|
17874 | exports.settings.networks[network.name] = network;
|
17875 | return true;
|
17876 | }
|
17877 | },
|
17878 | remove: {
|
17879 | network: (name) => {
|
17880 | if (exports.settings.networks[name]) {
|
17881 | delete exports.settings.networks[name];
|
17882 | return true;
|
17883 | }
|
17884 | return false;
|
17885 | }
|
17886 | },
|
17887 | u: exports.u,
|
17888 | CONST: exports.CONST
|
17889 | };
|
17890 |
|
17891 |
|
17892 | /***/ }),
|
17893 | /* 51 */
|
17894 | /***/ (function(module, exports, __webpack_require__) {
|
17895 |
|
17896 | "use strict";
|
17897 |
|
17898 |
|
17899 | var utils = __webpack_require__(2);
|
17900 | var bind = __webpack_require__(27);
|
17901 | var Axios = __webpack_require__(53);
|
17902 | var mergeConfig = __webpack_require__(37);
|
17903 | var defaults = __webpack_require__(29);
|
17904 |
|
17905 | /**
|
17906 | * Create an instance of Axios
|
17907 | *
|
17908 | * @param {Object} defaultConfig The default config for the instance
|
17909 | * @return {Axios} A new instance of Axios
|
17910 | */
|
17911 | function createInstance(defaultConfig) {
|
17912 | var context = new Axios(defaultConfig);
|
17913 | var instance = bind(Axios.prototype.request, context);
|
17914 |
|
17915 | // Copy axios.prototype to instance
|
17916 | utils.extend(instance, Axios.prototype, context);
|
17917 |
|
17918 | // Copy context to instance
|
17919 | utils.extend(instance, context);
|
17920 |
|
17921 | return instance;
|
17922 | }
|
17923 |
|
17924 | // Create the default instance to be exported
|
17925 | var axios = createInstance(defaults);
|
17926 |
|
17927 | // Expose Axios class to allow class inheritance
|
17928 | axios.Axios = Axios;
|
17929 |
|
17930 | // Factory for creating new instances
|
17931 | axios.create = function create(instanceConfig) {
|
17932 | return createInstance(mergeConfig(axios.defaults, instanceConfig));
|
17933 | };
|
17934 |
|
17935 | // Expose Cancel & CancelToken
|
17936 | axios.Cancel = __webpack_require__(38);
|
17937 | axios.CancelToken = __webpack_require__(77);
|
17938 | axios.isCancel = __webpack_require__(28);
|
17939 |
|
17940 | // Expose all/spread
|
17941 | axios.all = function all(promises) {
|
17942 | return Promise.all(promises);
|
17943 | };
|
17944 | axios.spread = __webpack_require__(78);
|
17945 |
|
17946 | module.exports = axios;
|
17947 |
|
17948 | // Allow use of default import syntax in TypeScript
|
17949 | module.exports.default = axios;
|
17950 |
|
17951 |
|
17952 | /***/ }),
|
17953 | /* 52 */
|
17954 | /***/ (function(module, exports) {
|
17955 |
|
17956 | /*!
|
17957 | * Determine if an object is a Buffer
|
17958 | *
|
17959 | * @author Feross Aboukhadijeh <https://feross.org>
|
17960 | * @license MIT
|
17961 | */
|
17962 |
|
17963 | module.exports = function isBuffer (obj) {
|
17964 | return obj != null && obj.constructor != null &&
|
17965 | typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
|
17966 | }
|
17967 |
|
17968 |
|
17969 | /***/ }),
|
17970 | /* 53 */
|
17971 | /***/ (function(module, exports, __webpack_require__) {
|
17972 |
|
17973 | "use strict";
|
17974 |
|
17975 |
|
17976 | var utils = __webpack_require__(2);
|
17977 | var buildURL = __webpack_require__(18);
|
17978 | var InterceptorManager = __webpack_require__(54);
|
17979 | var dispatchRequest = __webpack_require__(55);
|
17980 | var mergeConfig = __webpack_require__(37);
|
17981 |
|
17982 | /**
|
17983 | * Create a new instance of Axios
|
17984 | *
|
17985 | * @param {Object} instanceConfig The default config for the instance
|
17986 | */
|
17987 | function Axios(instanceConfig) {
|
17988 | this.defaults = instanceConfig;
|
17989 | this.interceptors = {
|
17990 | request: new InterceptorManager(),
|
17991 | response: new InterceptorManager()
|
17992 | };
|
17993 | }
|
17994 |
|
17995 | /**
|
17996 | * Dispatch a request
|
17997 | *
|
17998 | * @param {Object} config The config specific for this request (merged with this.defaults)
|
17999 | */
|
18000 | Axios.prototype.request = function request(config) {
|
18001 | /*eslint no-param-reassign:0*/
|
18002 | // Allow for axios('example/url'[, config]) a la fetch API
|
18003 | if (typeof config === 'string') {
|
18004 | config = arguments[1] || {};
|
18005 | config.url = arguments[0];
|
18006 | } else {
|
18007 | config = config || {};
|
18008 | }
|
18009 |
|
18010 | config = mergeConfig(this.defaults, config);
|
18011 | config.method = config.method ? config.method.toLowerCase() : 'get';
|
18012 |
|
18013 | // Hook up interceptors middleware
|
18014 | var chain = [dispatchRequest, undefined];
|
18015 | var promise = Promise.resolve(config);
|
18016 |
|
18017 | this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
|
18018 | chain.unshift(interceptor.fulfilled, interceptor.rejected);
|
18019 | });
|
18020 |
|
18021 | this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
|
18022 | chain.push(interceptor.fulfilled, interceptor.rejected);
|
18023 | });
|
18024 |
|
18025 | while (chain.length) {
|
18026 | promise = promise.then(chain.shift(), chain.shift());
|
18027 | }
|
18028 |
|
18029 | return promise;
|
18030 | };
|
18031 |
|
18032 | Axios.prototype.getUri = function getUri(config) {
|
18033 | config = mergeConfig(this.defaults, config);
|
18034 | return buildURL(config.url, config.params, config.paramsSerializer).replace(/^\?/, '');
|
18035 | };
|
18036 |
|
18037 | // Provide aliases for supported request methods
|
18038 | utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
|
18039 | /*eslint func-names:0*/
|
18040 | Axios.prototype[method] = function(url, config) {
|
18041 | return this.request(utils.merge(config || {}, {
|
18042 | method: method,
|
18043 | url: url
|
18044 | }));
|
18045 | };
|
18046 | });
|
18047 |
|
18048 | utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
18049 | /*eslint func-names:0*/
|
18050 | Axios.prototype[method] = function(url, data, config) {
|
18051 | return this.request(utils.merge(config || {}, {
|
18052 | method: method,
|
18053 | url: url,
|
18054 | data: data
|
18055 | }));
|
18056 | };
|
18057 | });
|
18058 |
|
18059 | module.exports = Axios;
|
18060 |
|
18061 |
|
18062 | /***/ }),
|
18063 | /* 54 */
|
18064 | /***/ (function(module, exports, __webpack_require__) {
|
18065 |
|
18066 | "use strict";
|
18067 |
|
18068 |
|
18069 | var utils = __webpack_require__(2);
|
18070 |
|
18071 | function InterceptorManager() {
|
18072 | this.handlers = [];
|
18073 | }
|
18074 |
|
18075 | /**
|
18076 | * Add a new interceptor to the stack
|
18077 | *
|
18078 | * @param {Function} fulfilled The function to handle `then` for a `Promise`
|
18079 | * @param {Function} rejected The function to handle `reject` for a `Promise`
|
18080 | *
|
18081 | * @return {Number} An ID used to remove interceptor later
|
18082 | */
|
18083 | InterceptorManager.prototype.use = function use(fulfilled, rejected) {
|
18084 | this.handlers.push({
|
18085 | fulfilled: fulfilled,
|
18086 | rejected: rejected
|
18087 | });
|
18088 | return this.handlers.length - 1;
|
18089 | };
|
18090 |
|
18091 | /**
|
18092 | * Remove an interceptor from the stack
|
18093 | *
|
18094 | * @param {Number} id The ID that was returned by `use`
|
18095 | */
|
18096 | InterceptorManager.prototype.eject = function eject(id) {
|
18097 | if (this.handlers[id]) {
|
18098 | this.handlers[id] = null;
|
18099 | }
|
18100 | };
|
18101 |
|
18102 | /**
|
18103 | * Iterate over all the registered interceptors
|
18104 | *
|
18105 | * This method is particularly useful for skipping over any
|
18106 | * interceptors that may have become `null` calling `eject`.
|
18107 | *
|
18108 | * @param {Function} fn The function to call for each interceptor
|
18109 | */
|
18110 | InterceptorManager.prototype.forEach = function forEach(fn) {
|
18111 | utils.forEach(this.handlers, function forEachHandler(h) {
|
18112 | if (h !== null) {
|
18113 | fn(h);
|
18114 | }
|
18115 | });
|
18116 | };
|
18117 |
|
18118 | module.exports = InterceptorManager;
|
18119 |
|
18120 |
|
18121 | /***/ }),
|
18122 | /* 55 */
|
18123 | /***/ (function(module, exports, __webpack_require__) {
|
18124 |
|
18125 | "use strict";
|
18126 |
|
18127 |
|
18128 | var utils = __webpack_require__(2);
|
18129 | var transformData = __webpack_require__(56);
|
18130 | var isCancel = __webpack_require__(28);
|
18131 | var defaults = __webpack_require__(29);
|
18132 | var isAbsoluteURL = __webpack_require__(75);
|
18133 | var combineURLs = __webpack_require__(76);
|
18134 |
|
18135 | /**
|
18136 | * Throws a `Cancel` if cancellation has been requested.
|
18137 | */
|
18138 | function throwIfCancellationRequested(config) {
|
18139 | if (config.cancelToken) {
|
18140 | config.cancelToken.throwIfRequested();
|
18141 | }
|
18142 | }
|
18143 |
|
18144 | /**
|
18145 | * Dispatch a request to the server using the configured adapter.
|
18146 | *
|
18147 | * @param {object} config The config that is to be used for the request
|
18148 | * @returns {Promise} The Promise to be fulfilled
|
18149 | */
|
18150 | module.exports = function dispatchRequest(config) {
|
18151 | throwIfCancellationRequested(config);
|
18152 |
|
18153 | // Support baseURL config
|
18154 | if (config.baseURL && !isAbsoluteURL(config.url)) {
|
18155 | config.url = combineURLs(config.baseURL, config.url);
|
18156 | }
|
18157 |
|
18158 | // Ensure headers exist
|
18159 | config.headers = config.headers || {};
|
18160 |
|
18161 | // Transform request data
|
18162 | config.data = transformData(
|
18163 | config.data,
|
18164 | config.headers,
|
18165 | config.transformRequest
|
18166 | );
|
18167 |
|
18168 | // Flatten headers
|
18169 | config.headers = utils.merge(
|
18170 | config.headers.common || {},
|
18171 | config.headers[config.method] || {},
|
18172 | config.headers || {}
|
18173 | );
|
18174 |
|
18175 | utils.forEach(
|
18176 | ['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
|
18177 | function cleanHeaderConfig(method) {
|
18178 | delete config.headers[method];
|
18179 | }
|
18180 | );
|
18181 |
|
18182 | var adapter = config.adapter || defaults.adapter;
|
18183 |
|
18184 | return adapter(config).then(function onAdapterResolution(response) {
|
18185 | throwIfCancellationRequested(config);
|
18186 |
|
18187 | // Transform response data
|
18188 | response.data = transformData(
|
18189 | response.data,
|
18190 | response.headers,
|
18191 | config.transformResponse
|
18192 | );
|
18193 |
|
18194 | return response;
|
18195 | }, function onAdapterRejection(reason) {
|
18196 | if (!isCancel(reason)) {
|
18197 | throwIfCancellationRequested(config);
|
18198 |
|
18199 | // Transform response data
|
18200 | if (reason && reason.response) {
|
18201 | reason.response.data = transformData(
|
18202 | reason.response.data,
|
18203 | reason.response.headers,
|
18204 | config.transformResponse
|
18205 | );
|
18206 | }
|
18207 | }
|
18208 |
|
18209 | return Promise.reject(reason);
|
18210 | });
|
18211 | };
|
18212 |
|
18213 |
|
18214 | /***/ }),
|
18215 | /* 56 */
|
18216 | /***/ (function(module, exports, __webpack_require__) {
|
18217 |
|
18218 | "use strict";
|
18219 |
|
18220 |
|
18221 | var utils = __webpack_require__(2);
|
18222 |
|
18223 | /**
|
18224 | * Transform the data for a request or a response
|
18225 | *
|
18226 | * @param {Object|String} data The data to be transformed
|
18227 | * @param {Array} headers The headers for the request or response
|
18228 | * @param {Array|Function} fns A single function or Array of functions
|
18229 | * @returns {*} The resulting transformed data
|
18230 | */
|
18231 | module.exports = function transformData(data, headers, fns) {
|
18232 | /*eslint no-param-reassign:0*/
|
18233 | utils.forEach(fns, function transform(fn) {
|
18234 | data = fn(data, headers);
|
18235 | });
|
18236 |
|
18237 | return data;
|
18238 | };
|
18239 |
|
18240 |
|
18241 | /***/ }),
|
18242 | /* 57 */
|
18243 | /***/ (function(module, exports, __webpack_require__) {
|
18244 |
|
18245 | "use strict";
|
18246 |
|
18247 |
|
18248 | var utils = __webpack_require__(2);
|
18249 |
|
18250 | module.exports = function normalizeHeaderName(headers, normalizedName) {
|
18251 | utils.forEach(headers, function processHeader(value, name) {
|
18252 | if (name !== normalizedName && name.toUpperCase() === normalizedName.toUpperCase()) {
|
18253 | headers[normalizedName] = value;
|
18254 | delete headers[name];
|
18255 | }
|
18256 | });
|
18257 | };
|
18258 |
|
18259 |
|
18260 | /***/ }),
|
18261 | /* 58 */
|
18262 | /***/ (function(module, exports, __webpack_require__) {
|
18263 |
|
18264 | "use strict";
|
18265 |
|
18266 |
|
18267 | var utils = __webpack_require__(2);
|
18268 | var settle = __webpack_require__(30);
|
18269 | var buildURL = __webpack_require__(18);
|
18270 | var http = __webpack_require__(32);
|
18271 | var https = __webpack_require__(33);
|
18272 | var httpFollow = __webpack_require__(34).http;
|
18273 | var httpsFollow = __webpack_require__(34).https;
|
18274 | var url = __webpack_require__(35);
|
18275 | var zlib = __webpack_require__(69);
|
18276 | var pkg = __webpack_require__(70);
|
18277 | var createError = __webpack_require__(19);
|
18278 | var enhanceError = __webpack_require__(31);
|
18279 |
|
18280 | var isHttps = /https:?/;
|
18281 |
|
18282 | /*eslint consistent-return:0*/
|
18283 | module.exports = function httpAdapter(config) {
|
18284 | return new Promise(function dispatchHttpRequest(resolvePromise, rejectPromise) {
|
18285 | var timer;
|
18286 | var resolve = function resolve(value) {
|
18287 | clearTimeout(timer);
|
18288 | resolvePromise(value);
|
18289 | };
|
18290 | var reject = function reject(value) {
|
18291 | clearTimeout(timer);
|
18292 | rejectPromise(value);
|
18293 | };
|
18294 | var data = config.data;
|
18295 | var headers = config.headers;
|
18296 |
|
18297 | // Set User-Agent (required by some servers)
|
18298 | // Only set header if it hasn't been set in config
|
18299 | // See https://github.com/axios/axios/issues/69
|
18300 | if (!headers['User-Agent'] && !headers['user-agent']) {
|
18301 | headers['User-Agent'] = 'axios/' + pkg.version;
|
18302 | }
|
18303 |
|
18304 | if (data && !utils.isStream(data)) {
|
18305 | if (Buffer.isBuffer(data)) {
|
18306 | // Nothing to do...
|
18307 | } else if (utils.isArrayBuffer(data)) {
|
18308 | data = Buffer.from(new Uint8Array(data));
|
18309 | } else if (utils.isString(data)) {
|
18310 | data = Buffer.from(data, 'utf-8');
|
18311 | } else {
|
18312 | return reject(createError(
|
18313 | 'Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream',
|
18314 | config
|
18315 | ));
|
18316 | }
|
18317 |
|
18318 | // Add Content-Length header if data exists
|
18319 | headers['Content-Length'] = data.length;
|
18320 | }
|
18321 |
|
18322 | // HTTP basic authentication
|
18323 | var auth = undefined;
|
18324 | if (config.auth) {
|
18325 | var username = config.auth.username || '';
|
18326 | var password = config.auth.password || '';
|
18327 | auth = username + ':' + password;
|
18328 | }
|
18329 |
|
18330 | // Parse url
|
18331 | var parsed = url.parse(config.url);
|
18332 | var protocol = parsed.protocol || 'http:';
|
18333 |
|
18334 | if (!auth && parsed.auth) {
|
18335 | var urlAuth = parsed.auth.split(':');
|
18336 | var urlUsername = urlAuth[0] || '';
|
18337 | var urlPassword = urlAuth[1] || '';
|
18338 | auth = urlUsername + ':' + urlPassword;
|
18339 | }
|
18340 |
|
18341 | if (auth) {
|
18342 | delete headers.Authorization;
|
18343 | }
|
18344 |
|
18345 | var isHttpsRequest = isHttps.test(protocol);
|
18346 | var agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
|
18347 |
|
18348 | var options = {
|
18349 | path: buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, ''),
|
18350 | method: config.method.toUpperCase(),
|
18351 | headers: headers,
|
18352 | agent: agent,
|
18353 | auth: auth
|
18354 | };
|
18355 |
|
18356 | if (config.socketPath) {
|
18357 | options.socketPath = config.socketPath;
|
18358 | } else {
|
18359 | options.hostname = parsed.hostname;
|
18360 | options.port = parsed.port;
|
18361 | }
|
18362 |
|
18363 | var proxy = config.proxy;
|
18364 | if (!proxy && proxy !== false) {
|
18365 | var proxyEnv = protocol.slice(0, -1) + '_proxy';
|
18366 | var proxyUrl = process.env[proxyEnv] || process.env[proxyEnv.toUpperCase()];
|
18367 | if (proxyUrl) {
|
18368 | var parsedProxyUrl = url.parse(proxyUrl);
|
18369 | var noProxyEnv = process.env.no_proxy || process.env.NO_PROXY;
|
18370 | var shouldProxy = true;
|
18371 |
|
18372 | if (noProxyEnv) {
|
18373 | var noProxy = noProxyEnv.split(',').map(function trim(s) {
|
18374 | return s.trim();
|
18375 | });
|
18376 |
|
18377 | shouldProxy = !noProxy.some(function proxyMatch(proxyElement) {
|
18378 | if (!proxyElement) {
|
18379 | return false;
|
18380 | }
|
18381 | if (proxyElement === '*') {
|
18382 | return true;
|
18383 | }
|
18384 | if (proxyElement[0] === '.' &&
|
18385 | parsed.hostname.substr(parsed.hostname.length - proxyElement.length) === proxyElement &&
|
18386 | proxyElement.match(/\./g).length === parsed.hostname.match(/\./g).length) {
|
18387 | return true;
|
18388 | }
|
18389 |
|
18390 | return parsed.hostname === proxyElement;
|
18391 | });
|
18392 | }
|
18393 |
|
18394 |
|
18395 | if (shouldProxy) {
|
18396 | proxy = {
|
18397 | host: parsedProxyUrl.hostname,
|
18398 | port: parsedProxyUrl.port
|
18399 | };
|
18400 |
|
18401 | if (parsedProxyUrl.auth) {
|
18402 | var proxyUrlAuth = parsedProxyUrl.auth.split(':');
|
18403 | proxy.auth = {
|
18404 | username: proxyUrlAuth[0],
|
18405 | password: proxyUrlAuth[1]
|
18406 | };
|
18407 | }
|
18408 | }
|
18409 | }
|
18410 | }
|
18411 |
|
18412 | if (proxy) {
|
18413 | options.hostname = proxy.host;
|
18414 | options.host = proxy.host;
|
18415 | options.headers.host = parsed.hostname + (parsed.port ? ':' + parsed.port : '');
|
18416 | options.port = proxy.port;
|
18417 | options.path = protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path;
|
18418 |
|
18419 | // Basic proxy authorization
|
18420 | if (proxy.auth) {
|
18421 | var base64 = Buffer.from(proxy.auth.username + ':' + proxy.auth.password, 'utf8').toString('base64');
|
18422 | options.headers['Proxy-Authorization'] = 'Basic ' + base64;
|
18423 | }
|
18424 | }
|
18425 |
|
18426 | var transport;
|
18427 | var isHttpsProxy = isHttpsRequest && (proxy ? isHttps.test(proxy.protocol) : true);
|
18428 | if (config.transport) {
|
18429 | transport = config.transport;
|
18430 | } else if (config.maxRedirects === 0) {
|
18431 | transport = isHttpsProxy ? https : http;
|
18432 | } else {
|
18433 | if (config.maxRedirects) {
|
18434 | options.maxRedirects = config.maxRedirects;
|
18435 | }
|
18436 | transport = isHttpsProxy ? httpsFollow : httpFollow;
|
18437 | }
|
18438 |
|
18439 | if (config.maxContentLength && config.maxContentLength > -1) {
|
18440 | options.maxBodyLength = config.maxContentLength;
|
18441 | }
|
18442 |
|
18443 | // Create the request
|
18444 | var req = transport.request(options, function handleResponse(res) {
|
18445 | if (req.aborted) return;
|
18446 |
|
18447 | // uncompress the response body transparently if required
|
18448 | var stream = res;
|
18449 | switch (res.headers['content-encoding']) {
|
18450 | /*eslint default-case:0*/
|
18451 | case 'gzip':
|
18452 | case 'compress':
|
18453 | case 'deflate':
|
18454 | // add the unzipper to the body stream processing pipeline
|
18455 | stream = (res.statusCode === 204) ? stream : stream.pipe(zlib.createUnzip());
|
18456 |
|
18457 | // remove the content-encoding in order to not confuse downstream operations
|
18458 | delete res.headers['content-encoding'];
|
18459 | break;
|
18460 | }
|
18461 |
|
18462 | // return the last request in case of redirects
|
18463 | var lastRequest = res.req || req;
|
18464 |
|
18465 | var response = {
|
18466 | status: res.statusCode,
|
18467 | statusText: res.statusMessage,
|
18468 | headers: res.headers,
|
18469 | config: config,
|
18470 | request: lastRequest
|
18471 | };
|
18472 |
|
18473 | if (config.responseType === 'stream') {
|
18474 | response.data = stream;
|
18475 | settle(resolve, reject, response);
|
18476 | } else {
|
18477 | var responseBuffer = [];
|
18478 | stream.on('data', function handleStreamData(chunk) {
|
18479 | responseBuffer.push(chunk);
|
18480 |
|
18481 | // make sure the content length is not over the maxContentLength if specified
|
18482 | if (config.maxContentLength > -1 && Buffer.concat(responseBuffer).length > config.maxContentLength) {
|
18483 | stream.destroy();
|
18484 | reject(createError('maxContentLength size of ' + config.maxContentLength + ' exceeded',
|
18485 | config, null, lastRequest));
|
18486 | }
|
18487 | });
|
18488 |
|
18489 | stream.on('error', function handleStreamError(err) {
|
18490 | if (req.aborted) return;
|
18491 | reject(enhanceError(err, config, null, lastRequest));
|
18492 | });
|
18493 |
|
18494 | stream.on('end', function handleStreamEnd() {
|
18495 | var responseData = Buffer.concat(responseBuffer);
|
18496 | if (config.responseType !== 'arraybuffer') {
|
18497 | responseData = responseData.toString(config.responseEncoding);
|
18498 | }
|
18499 |
|
18500 | response.data = responseData;
|
18501 | settle(resolve, reject, response);
|
18502 | });
|
18503 | }
|
18504 | });
|
18505 |
|
18506 | // Handle errors
|
18507 | req.on('error', function handleRequestError(err) {
|
18508 | if (req.aborted) return;
|
18509 | reject(enhanceError(err, config, null, req));
|
18510 | });
|
18511 |
|
18512 | // Handle request timeout
|
18513 | if (config.timeout) {
|
18514 | timer = setTimeout(function handleRequestTimeout() {
|
18515 | req.abort();
|
18516 | reject(createError('timeout of ' + config.timeout + 'ms exceeded', config, 'ECONNABORTED', req));
|
18517 | }, config.timeout);
|
18518 | }
|
18519 |
|
18520 | if (config.cancelToken) {
|
18521 | // Handle cancellation
|
18522 | config.cancelToken.promise.then(function onCanceled(cancel) {
|
18523 | if (req.aborted) return;
|
18524 |
|
18525 | req.abort();
|
18526 | reject(cancel);
|
18527 | });
|
18528 | }
|
18529 |
|
18530 | // Send the request
|
18531 | if (utils.isStream(data)) {
|
18532 | data.on('error', function handleStreamError(err) {
|
18533 | reject(enhanceError(err, config, null, req));
|
18534 | }).pipe(req);
|
18535 | } else {
|
18536 | req.end(data);
|
18537 | }
|
18538 | });
|
18539 | };
|
18540 |
|
18541 |
|
18542 | /***/ }),
|
18543 | /* 59 */
|
18544 | /***/ (function(module, exports) {
|
18545 |
|
18546 | module.exports = require("assert");
|
18547 |
|
18548 | /***/ }),
|
18549 | /* 60 */
|
18550 | /***/ (function(module, exports) {
|
18551 |
|
18552 | module.exports = require("stream");
|
18553 |
|
18554 | /***/ }),
|
18555 | /* 61 */
|
18556 | /***/ (function(module, exports, __webpack_require__) {
|
18557 |
|
18558 | /**
|
18559 | * Detect Electron renderer process, which is node, but we should
|
18560 | * treat as a browser.
|
18561 | */
|
18562 |
|
18563 | if (typeof process === 'undefined' || process.type === 'renderer') {
|
18564 | module.exports = __webpack_require__(62);
|
18565 | } else {
|
18566 | module.exports = __webpack_require__(64);
|
18567 | }
|
18568 |
|
18569 |
|
18570 | /***/ }),
|
18571 | /* 62 */
|
18572 | /***/ (function(module, exports, __webpack_require__) {
|
18573 |
|
18574 | /**
|
18575 | * This is the web browser implementation of `debug()`.
|
18576 | *
|
18577 | * Expose `debug()` as the module.
|
18578 | */
|
18579 |
|
18580 | exports = module.exports = __webpack_require__(36);
|
18581 | exports.log = log;
|
18582 | exports.formatArgs = formatArgs;
|
18583 | exports.save = save;
|
18584 | exports.load = load;
|
18585 | exports.useColors = useColors;
|
18586 | exports.storage = 'undefined' != typeof chrome
|
18587 | && 'undefined' != typeof chrome.storage
|
18588 | ? chrome.storage.local
|
18589 | : localstorage();
|
18590 |
|
18591 | /**
|
18592 | * Colors.
|
18593 | */
|
18594 |
|
18595 | exports.colors = [
|
18596 | '#0000CC', '#0000FF', '#0033CC', '#0033FF', '#0066CC', '#0066FF', '#0099CC',
|
18597 | '#0099FF', '#00CC00', '#00CC33', '#00CC66', '#00CC99', '#00CCCC', '#00CCFF',
|
18598 | '#3300CC', '#3300FF', '#3333CC', '#3333FF', '#3366CC', '#3366FF', '#3399CC',
|
18599 | '#3399FF', '#33CC00', '#33CC33', '#33CC66', '#33CC99', '#33CCCC', '#33CCFF',
|
18600 | '#6600CC', '#6600FF', '#6633CC', '#6633FF', '#66CC00', '#66CC33', '#9900CC',
|
18601 | '#9900FF', '#9933CC', '#9933FF', '#99CC00', '#99CC33', '#CC0000', '#CC0033',
|
18602 | '#CC0066', '#CC0099', '#CC00CC', '#CC00FF', '#CC3300', '#CC3333', '#CC3366',
|
18603 | '#CC3399', '#CC33CC', '#CC33FF', '#CC6600', '#CC6633', '#CC9900', '#CC9933',
|
18604 | '#CCCC00', '#CCCC33', '#FF0000', '#FF0033', '#FF0066', '#FF0099', '#FF00CC',
|
18605 | '#FF00FF', '#FF3300', '#FF3333', '#FF3366', '#FF3399', '#FF33CC', '#FF33FF',
|
18606 | '#FF6600', '#FF6633', '#FF9900', '#FF9933', '#FFCC00', '#FFCC33'
|
18607 | ];
|
18608 |
|
18609 | /**
|
18610 | * Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
18611 | * and the Firebug extension (any Firefox version) are known
|
18612 | * to support "%c" CSS customizations.
|
18613 | *
|
18614 | * TODO: add a `localStorage` variable to explicitly enable/disable colors
|
18615 | */
|
18616 |
|
18617 | function useColors() {
|
18618 | // NB: In an Electron preload script, document will be defined but not fully
|
18619 | // initialized. Since we know we're in Chrome, we'll just detect this case
|
18620 | // explicitly
|
18621 | if (typeof window !== 'undefined' && window.process && window.process.type === 'renderer') {
|
18622 | return true;
|
18623 | }
|
18624 |
|
18625 | // Internet Explorer and Edge do not support colors.
|
18626 | if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
18627 | return false;
|
18628 | }
|
18629 |
|
18630 | // is webkit? http://stackoverflow.com/a/16459606/376773
|
18631 | // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
18632 | return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
|
18633 | // is firebug? http://stackoverflow.com/a/398120/376773
|
18634 | (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
|
18635 | // is firefox >= v31?
|
18636 | // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
18637 | (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
|
18638 | // double check webkit in userAgent just in case we are in a worker
|
18639 | (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
|
18640 | }
|
18641 |
|
18642 | /**
|
18643 | * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
18644 | */
|
18645 |
|
18646 | exports.formatters.j = function(v) {
|
18647 | try {
|
18648 | return JSON.stringify(v);
|
18649 | } catch (err) {
|
18650 | return '[UnexpectedJSONParseError]: ' + err.message;
|
18651 | }
|
18652 | };
|
18653 |
|
18654 |
|
18655 | /**
|
18656 | * Colorize log arguments if enabled.
|
18657 | *
|
18658 | * @api public
|
18659 | */
|
18660 |
|
18661 | function formatArgs(args) {
|
18662 | var useColors = this.useColors;
|
18663 |
|
18664 | args[0] = (useColors ? '%c' : '')
|
18665 | + this.namespace
|
18666 | + (useColors ? ' %c' : ' ')
|
18667 | + args[0]
|
18668 | + (useColors ? '%c ' : ' ')
|
18669 | + '+' + exports.humanize(this.diff);
|
18670 |
|
18671 | if (!useColors) return;
|
18672 |
|
18673 | var c = 'color: ' + this.color;
|
18674 | args.splice(1, 0, c, 'color: inherit')
|
18675 |
|
18676 | // the final "%c" is somewhat tricky, because there could be other
|
18677 | // arguments passed either before or after the %c, so we need to
|
18678 | // figure out the correct index to insert the CSS into
|
18679 | var index = 0;
|
18680 | var lastC = 0;
|
18681 | args[0].replace(/%[a-zA-Z%]/g, function(match) {
|
18682 | if ('%%' === match) return;
|
18683 | index++;
|
18684 | if ('%c' === match) {
|
18685 | // we only are interested in the *last* %c
|
18686 | // (the user may have provided their own)
|
18687 | lastC = index;
|
18688 | }
|
18689 | });
|
18690 |
|
18691 | args.splice(lastC, 0, c);
|
18692 | }
|
18693 |
|
18694 | /**
|
18695 | * Invokes `console.log()` when available.
|
18696 | * No-op when `console.log` is not a "function".
|
18697 | *
|
18698 | * @api public
|
18699 | */
|
18700 |
|
18701 | function log() {
|
18702 | // this hackery is required for IE8/9, where
|
18703 | // the `console.log` function doesn't have 'apply'
|
18704 | return 'object' === typeof console
|
18705 | && console.log
|
18706 | && Function.prototype.apply.call(console.log, console, arguments);
|
18707 | }
|
18708 |
|
18709 | /**
|
18710 | * Save `namespaces`.
|
18711 | *
|
18712 | * @param {String} namespaces
|
18713 | * @api private
|
18714 | */
|
18715 |
|
18716 | function save(namespaces) {
|
18717 | try {
|
18718 | if (null == namespaces) {
|
18719 | exports.storage.removeItem('debug');
|
18720 | } else {
|
18721 | exports.storage.debug = namespaces;
|
18722 | }
|
18723 | } catch(e) {}
|
18724 | }
|
18725 |
|
18726 | /**
|
18727 | * Load `namespaces`.
|
18728 | *
|
18729 | * @return {String} returns the previously persisted debug modes
|
18730 | * @api private
|
18731 | */
|
18732 |
|
18733 | function load() {
|
18734 | var r;
|
18735 | try {
|
18736 | r = exports.storage.debug;
|
18737 | } catch(e) {}
|
18738 |
|
18739 | // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
|
18740 | if (!r && typeof process !== 'undefined' && 'env' in process) {
|
18741 | r = process.env.DEBUG;
|
18742 | }
|
18743 |
|
18744 | return r;
|
18745 | }
|
18746 |
|
18747 | /**
|
18748 | * Enable namespaces listed in `localStorage.debug` initially.
|
18749 | */
|
18750 |
|
18751 | exports.enable(load());
|
18752 |
|
18753 | /**
|
18754 | * Localstorage attempts to return the localstorage.
|
18755 | *
|
18756 | * This is necessary because safari throws
|
18757 | * when a user disables cookies/localstorage
|
18758 | * and you attempt to access it.
|
18759 | *
|
18760 | * @return {LocalStorage}
|
18761 | * @api private
|
18762 | */
|
18763 |
|
18764 | function localstorage() {
|
18765 | try {
|
18766 | return window.localStorage;
|
18767 | } catch (e) {}
|
18768 | }
|
18769 |
|
18770 |
|
18771 | /***/ }),
|
18772 | /* 63 */
|
18773 | /***/ (function(module, exports) {
|
18774 |
|
18775 | /**
|
18776 | * Helpers.
|
18777 | */
|
18778 |
|
18779 | var s = 1000;
|
18780 | var m = s * 60;
|
18781 | var h = m * 60;
|
18782 | var d = h * 24;
|
18783 | var y = d * 365.25;
|
18784 |
|
18785 | /**
|
18786 | * Parse or format the given `val`.
|
18787 | *
|
18788 | * Options:
|
18789 | *
|
18790 | * - `long` verbose formatting [false]
|
18791 | *
|
18792 | * @param {String|Number} val
|
18793 | * @param {Object} [options]
|
18794 | * @throws {Error} throw an error if val is not a non-empty string or a number
|
18795 | * @return {String|Number}
|
18796 | * @api public
|
18797 | */
|
18798 |
|
18799 | module.exports = function(val, options) {
|
18800 | options = options || {};
|
18801 | var type = typeof val;
|
18802 | if (type === 'string' && val.length > 0) {
|
18803 | return parse(val);
|
18804 | } else if (type === 'number' && isNaN(val) === false) {
|
18805 | return options.long ? fmtLong(val) : fmtShort(val);
|
18806 | }
|
18807 | throw new Error(
|
18808 | 'val is not a non-empty string or a valid number. val=' +
|
18809 | JSON.stringify(val)
|
18810 | );
|
18811 | };
|
18812 |
|
18813 | /**
|
18814 | * Parse the given `str` and return milliseconds.
|
18815 | *
|
18816 | * @param {String} str
|
18817 | * @return {Number}
|
18818 | * @api private
|
18819 | */
|
18820 |
|
18821 | function parse(str) {
|
18822 | str = String(str);
|
18823 | if (str.length > 100) {
|
18824 | return;
|
18825 | }
|
18826 | var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(
|
18827 | str
|
18828 | );
|
18829 | if (!match) {
|
18830 | return;
|
18831 | }
|
18832 | var n = parseFloat(match[1]);
|
18833 | var type = (match[2] || 'ms').toLowerCase();
|
18834 | switch (type) {
|
18835 | case 'years':
|
18836 | case 'year':
|
18837 | case 'yrs':
|
18838 | case 'yr':
|
18839 | case 'y':
|
18840 | return n * y;
|
18841 | case 'days':
|
18842 | case 'day':
|
18843 | case 'd':
|
18844 | return n * d;
|
18845 | case 'hours':
|
18846 | case 'hour':
|
18847 | case 'hrs':
|
18848 | case 'hr':
|
18849 | case 'h':
|
18850 | return n * h;
|
18851 | case 'minutes':
|
18852 | case 'minute':
|
18853 | case 'mins':
|
18854 | case 'min':
|
18855 | case 'm':
|
18856 | return n * m;
|
18857 | case 'seconds':
|
18858 | case 'second':
|
18859 | case 'secs':
|
18860 | case 'sec':
|
18861 | case 's':
|
18862 | return n * s;
|
18863 | case 'milliseconds':
|
18864 | case 'millisecond':
|
18865 | case 'msecs':
|
18866 | case 'msec':
|
18867 | case 'ms':
|
18868 | return n;
|
18869 | default:
|
18870 | return undefined;
|
18871 | }
|
18872 | }
|
18873 |
|
18874 | /**
|
18875 | * Short format for `ms`.
|
18876 | *
|
18877 | * @param {Number} ms
|
18878 | * @return {String}
|
18879 | * @api private
|
18880 | */
|
18881 |
|
18882 | function fmtShort(ms) {
|
18883 | if (ms >= d) {
|
18884 | return Math.round(ms / d) + 'd';
|
18885 | }
|
18886 | if (ms >= h) {
|
18887 | return Math.round(ms / h) + 'h';
|
18888 | }
|
18889 | if (ms >= m) {
|
18890 | return Math.round(ms / m) + 'm';
|
18891 | }
|
18892 | if (ms >= s) {
|
18893 | return Math.round(ms / s) + 's';
|
18894 | }
|
18895 | return ms + 'ms';
|
18896 | }
|
18897 |
|
18898 | /**
|
18899 | * Long format for `ms`.
|
18900 | *
|
18901 | * @param {Number} ms
|
18902 | * @return {String}
|
18903 | * @api private
|
18904 | */
|
18905 |
|
18906 | function fmtLong(ms) {
|
18907 | return plural(ms, d, 'day') ||
|
18908 | plural(ms, h, 'hour') ||
|
18909 | plural(ms, m, 'minute') ||
|
18910 | plural(ms, s, 'second') ||
|
18911 | ms + ' ms';
|
18912 | }
|
18913 |
|
18914 | /**
|
18915 | * Pluralization helper.
|
18916 | */
|
18917 |
|
18918 | function plural(ms, n, name) {
|
18919 | if (ms < n) {
|
18920 | return;
|
18921 | }
|
18922 | if (ms < n * 1.5) {
|
18923 | return Math.floor(ms / n) + ' ' + name;
|
18924 | }
|
18925 | return Math.ceil(ms / n) + ' ' + name + 's';
|
18926 | }
|
18927 |
|
18928 |
|
18929 | /***/ }),
|
18930 | /* 64 */
|
18931 | /***/ (function(module, exports, __webpack_require__) {
|
18932 |
|
18933 | /**
|
18934 | * Module dependencies.
|
18935 | */
|
18936 |
|
18937 | var tty = __webpack_require__(65);
|
18938 | var util = __webpack_require__(12);
|
18939 |
|
18940 | /**
|
18941 | * This is the Node.js implementation of `debug()`.
|
18942 | *
|
18943 | * Expose `debug()` as the module.
|
18944 | */
|
18945 |
|
18946 | exports = module.exports = __webpack_require__(36);
|
18947 | exports.init = init;
|
18948 | exports.log = log;
|
18949 | exports.formatArgs = formatArgs;
|
18950 | exports.save = save;
|
18951 | exports.load = load;
|
18952 | exports.useColors = useColors;
|
18953 |
|
18954 | /**
|
18955 | * Colors.
|
18956 | */
|
18957 |
|
18958 | exports.colors = [ 6, 2, 3, 4, 5, 1 ];
|
18959 |
|
18960 | try {
|
18961 | var supportsColor = __webpack_require__(66);
|
18962 | if (supportsColor && supportsColor.level >= 2) {
|
18963 | exports.colors = [
|
18964 | 20, 21, 26, 27, 32, 33, 38, 39, 40, 41, 42, 43, 44, 45, 56, 57, 62, 63, 68,
|
18965 | 69, 74, 75, 76, 77, 78, 79, 80, 81, 92, 93, 98, 99, 112, 113, 128, 129, 134,
|
18966 | 135, 148, 149, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171,
|
18967 | 172, 173, 178, 179, 184, 185, 196, 197, 198, 199, 200, 201, 202, 203, 204,
|
18968 | 205, 206, 207, 208, 209, 214, 215, 220, 221
|
18969 | ];
|
18970 | }
|
18971 | } catch (err) {
|
18972 | // swallow - we only care if `supports-color` is available; it doesn't have to be.
|
18973 | }
|
18974 |
|
18975 | /**
|
18976 | * Build up the default `inspectOpts` object from the environment variables.
|
18977 | *
|
18978 | * $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
|
18979 | */
|
18980 |
|
18981 | exports.inspectOpts = Object.keys(process.env).filter(function (key) {
|
18982 | return /^debug_/i.test(key);
|
18983 | }).reduce(function (obj, key) {
|
18984 | // camel-case
|
18985 | var prop = key
|
18986 | .substring(6)
|
18987 | .toLowerCase()
|
18988 | .replace(/_([a-z])/g, function (_, k) { return k.toUpperCase() });
|
18989 |
|
18990 | // coerce string value into JS value
|
18991 | var val = process.env[key];
|
18992 | if (/^(yes|on|true|enabled)$/i.test(val)) val = true;
|
18993 | else if (/^(no|off|false|disabled)$/i.test(val)) val = false;
|
18994 | else if (val === 'null') val = null;
|
18995 | else val = Number(val);
|
18996 |
|
18997 | obj[prop] = val;
|
18998 | return obj;
|
18999 | }, {});
|
19000 |
|
19001 | /**
|
19002 | * Is stdout a TTY? Colored output is enabled when `true`.
|
19003 | */
|
19004 |
|
19005 | function useColors() {
|
19006 | return 'colors' in exports.inspectOpts
|
19007 | ? Boolean(exports.inspectOpts.colors)
|
19008 | : tty.isatty(process.stderr.fd);
|
19009 | }
|
19010 |
|
19011 | /**
|
19012 | * Map %o to `util.inspect()`, all on a single line.
|
19013 | */
|
19014 |
|
19015 | exports.formatters.o = function(v) {
|
19016 | this.inspectOpts.colors = this.useColors;
|
19017 | return util.inspect(v, this.inspectOpts)
|
19018 | .split('\n').map(function(str) {
|
19019 | return str.trim()
|
19020 | }).join(' ');
|
19021 | };
|
19022 |
|
19023 | /**
|
19024 | * Map %o to `util.inspect()`, allowing multiple lines if needed.
|
19025 | */
|
19026 |
|
19027 | exports.formatters.O = function(v) {
|
19028 | this.inspectOpts.colors = this.useColors;
|
19029 | return util.inspect(v, this.inspectOpts);
|
19030 | };
|
19031 |
|
19032 | /**
|
19033 | * Adds ANSI color escape codes if enabled.
|
19034 | *
|
19035 | * @api public
|
19036 | */
|
19037 |
|
19038 | function formatArgs(args) {
|
19039 | var name = this.namespace;
|
19040 | var useColors = this.useColors;
|
19041 |
|
19042 | if (useColors) {
|
19043 | var c = this.color;
|
19044 | var colorCode = '\u001b[3' + (c < 8 ? c : '8;5;' + c);
|
19045 | var prefix = ' ' + colorCode + ';1m' + name + ' ' + '\u001b[0m';
|
19046 |
|
19047 | args[0] = prefix + args[0].split('\n').join('\n' + prefix);
|
19048 | args.push(colorCode + 'm+' + exports.humanize(this.diff) + '\u001b[0m');
|
19049 | } else {
|
19050 | args[0] = getDate() + name + ' ' + args[0];
|
19051 | }
|
19052 | }
|
19053 |
|
19054 | function getDate() {
|
19055 | if (exports.inspectOpts.hideDate) {
|
19056 | return '';
|
19057 | } else {
|
19058 | return new Date().toISOString() + ' ';
|
19059 | }
|
19060 | }
|
19061 |
|
19062 | /**
|
19063 | * Invokes `util.format()` with the specified arguments and writes to stderr.
|
19064 | */
|
19065 |
|
19066 | function log() {
|
19067 | return process.stderr.write(util.format.apply(util, arguments) + '\n');
|
19068 | }
|
19069 |
|
19070 | /**
|
19071 | * Save `namespaces`.
|
19072 | *
|
19073 | * @param {String} namespaces
|
19074 | * @api private
|
19075 | */
|
19076 |
|
19077 | function save(namespaces) {
|
19078 | if (null == namespaces) {
|
19079 | // If you set a process.env field to null or undefined, it gets cast to the
|
19080 | // string 'null' or 'undefined'. Just delete instead.
|
19081 | delete process.env.DEBUG;
|
19082 | } else {
|
19083 | process.env.DEBUG = namespaces;
|
19084 | }
|
19085 | }
|
19086 |
|
19087 | /**
|
19088 | * Load `namespaces`.
|
19089 | *
|
19090 | * @return {String} returns the previously persisted debug modes
|
19091 | * @api private
|
19092 | */
|
19093 |
|
19094 | function load() {
|
19095 | return process.env.DEBUG;
|
19096 | }
|
19097 |
|
19098 | /**
|
19099 | * Init logic for `debug` instances.
|
19100 | *
|
19101 | * Create a new `inspectOpts` object in case `useColors` is set
|
19102 | * differently for a particular `debug` instance.
|
19103 | */
|
19104 |
|
19105 | function init (debug) {
|
19106 | debug.inspectOpts = {};
|
19107 |
|
19108 | var keys = Object.keys(exports.inspectOpts);
|
19109 | for (var i = 0; i < keys.length; i++) {
|
19110 | debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
|
19111 | }
|
19112 | }
|
19113 |
|
19114 | /**
|
19115 | * Enable namespaces listed in `process.env.DEBUG` initially.
|
19116 | */
|
19117 |
|
19118 | exports.enable(load());
|
19119 |
|
19120 |
|
19121 | /***/ }),
|
19122 | /* 65 */
|
19123 | /***/ (function(module, exports) {
|
19124 |
|
19125 | module.exports = require("tty");
|
19126 |
|
19127 | /***/ }),
|
19128 | /* 66 */
|
19129 | /***/ (function(module, exports, __webpack_require__) {
|
19130 |
|
19131 | "use strict";
|
19132 |
|
19133 | const os = __webpack_require__(67);
|
19134 | const hasFlag = __webpack_require__(68);
|
19135 |
|
19136 | const {env} = process;
|
19137 |
|
19138 | let forceColor;
|
19139 | if (hasFlag('no-color') ||
|
19140 | hasFlag('no-colors') ||
|
19141 | hasFlag('color=false') ||
|
19142 | hasFlag('color=never')) {
|
19143 | forceColor = 0;
|
19144 | } else if (hasFlag('color') ||
|
19145 | hasFlag('colors') ||
|
19146 | hasFlag('color=true') ||
|
19147 | hasFlag('color=always')) {
|
19148 | forceColor = 1;
|
19149 | }
|
19150 | if ('FORCE_COLOR' in env) {
|
19151 | if (env.FORCE_COLOR === true || env.FORCE_COLOR === 'true') {
|
19152 | forceColor = 1;
|
19153 | } else if (env.FORCE_COLOR === false || env.FORCE_COLOR === 'false') {
|
19154 | forceColor = 0;
|
19155 | } else {
|
19156 | forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
|
19157 | }
|
19158 | }
|
19159 |
|
19160 | function translateLevel(level) {
|
19161 | if (level === 0) {
|
19162 | return false;
|
19163 | }
|
19164 |
|
19165 | return {
|
19166 | level,
|
19167 | hasBasic: true,
|
19168 | has256: level >= 2,
|
19169 | has16m: level >= 3
|
19170 | };
|
19171 | }
|
19172 |
|
19173 | function supportsColor(stream) {
|
19174 | if (forceColor === 0) {
|
19175 | return 0;
|
19176 | }
|
19177 |
|
19178 | if (hasFlag('color=16m') ||
|
19179 | hasFlag('color=full') ||
|
19180 | hasFlag('color=truecolor')) {
|
19181 | return 3;
|
19182 | }
|
19183 |
|
19184 | if (hasFlag('color=256')) {
|
19185 | return 2;
|
19186 | }
|
19187 |
|
19188 | if (stream && !stream.isTTY && forceColor === undefined) {
|
19189 | return 0;
|
19190 | }
|
19191 |
|
19192 | const min = forceColor || 0;
|
19193 |
|
19194 | if (env.TERM === 'dumb') {
|
19195 | return min;
|
19196 | }
|
19197 |
|
19198 | if (process.platform === 'win32') {
|
19199 | // Node.js 7.5.0 is the first version of Node.js to include a patch to
|
19200 | // libuv that enables 256 color output on Windows. Anything earlier and it
|
19201 | // won't work. However, here we target Node.js 8 at minimum as it is an LTS
|
19202 | // release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
|
19203 | // release that supports 256 colors. Windows 10 build 14931 is the first release
|
19204 | // that supports 16m/TrueColor.
|
19205 | const osRelease = os.release().split('.');
|
19206 | if (
|
19207 | Number(process.versions.node.split('.')[0]) >= 8 &&
|
19208 | Number(osRelease[0]) >= 10 &&
|
19209 | Number(osRelease[2]) >= 10586
|
19210 | ) {
|
19211 | return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
19212 | }
|
19213 |
|
19214 | return 1;
|
19215 | }
|
19216 |
|
19217 | if ('CI' in env) {
|
19218 | if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
|
19219 | return 1;
|
19220 | }
|
19221 |
|
19222 | return min;
|
19223 | }
|
19224 |
|
19225 | if ('TEAMCITY_VERSION' in env) {
|
19226 | return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
19227 | }
|
19228 |
|
19229 | if (env.COLORTERM === 'truecolor') {
|
19230 | return 3;
|
19231 | }
|
19232 |
|
19233 | if ('TERM_PROGRAM' in env) {
|
19234 | const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
|
19235 |
|
19236 | switch (env.TERM_PROGRAM) {
|
19237 | case 'iTerm.app':
|
19238 | return version >= 3 ? 3 : 2;
|
19239 | case 'Apple_Terminal':
|
19240 | return 2;
|
19241 | // No default
|
19242 | }
|
19243 | }
|
19244 |
|
19245 | if (/-256(color)?$/i.test(env.TERM)) {
|
19246 | return 2;
|
19247 | }
|
19248 |
|
19249 | if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
19250 | return 1;
|
19251 | }
|
19252 |
|
19253 | if ('COLORTERM' in env) {
|
19254 | return 1;
|
19255 | }
|
19256 |
|
19257 | return min;
|
19258 | }
|
19259 |
|
19260 | function getSupportLevel(stream) {
|
19261 | const level = supportsColor(stream);
|
19262 | return translateLevel(level);
|
19263 | }
|
19264 |
|
19265 | module.exports = {
|
19266 | supportsColor: getSupportLevel,
|
19267 | stdout: getSupportLevel(process.stdout),
|
19268 | stderr: getSupportLevel(process.stderr)
|
19269 | };
|
19270 |
|
19271 |
|
19272 | /***/ }),
|
19273 | /* 67 */
|
19274 | /***/ (function(module, exports) {
|
19275 |
|
19276 | module.exports = require("os");
|
19277 |
|
19278 | /***/ }),
|
19279 | /* 68 */
|
19280 | /***/ (function(module, exports, __webpack_require__) {
|
19281 |
|
19282 | "use strict";
|
19283 |
|
19284 | module.exports = (flag, argv) => {
|
19285 | argv = argv || process.argv;
|
19286 | const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');
|
19287 | const pos = argv.indexOf(prefix + flag);
|
19288 | const terminatorPos = argv.indexOf('--');
|
19289 | return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
|
19290 | };
|
19291 |
|
19292 |
|
19293 | /***/ }),
|
19294 | /* 69 */
|
19295 | /***/ (function(module, exports) {
|
19296 |
|
19297 | module.exports = require("zlib");
|
19298 |
|
19299 | /***/ }),
|
19300 | /* 70 */
|
19301 | /***/ (function(module) {
|
19302 |
|
19303 | module.exports = JSON.parse("{\"name\":\"axios\",\"version\":\"0.19.0\",\"description\":\"Promise based HTTP client for the browser and node.js\",\"main\":\"index.js\",\"scripts\":{\"test\":\"grunt test && bundlesize\",\"start\":\"node ./sandbox/server.js\",\"build\":\"NODE_ENV=production grunt build\",\"preversion\":\"npm test\",\"version\":\"npm run build && grunt version && git add -A dist && git add CHANGELOG.md bower.json package.json\",\"postversion\":\"git push && git push --tags\",\"examples\":\"node ./examples/server.js\",\"coveralls\":\"cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js\",\"fix\":\"eslint --fix lib/**/*.js\"},\"repository\":{\"type\":\"git\",\"url\":\"https://github.com/axios/axios.git\"},\"keywords\":[\"xhr\",\"http\",\"ajax\",\"promise\",\"node\"],\"author\":\"Matt Zabriskie\",\"license\":\"MIT\",\"bugs\":{\"url\":\"https://github.com/axios/axios/issues\"},\"homepage\":\"https://github.com/axios/axios\",\"devDependencies\":{\"bundlesize\":\"^0.17.0\",\"coveralls\":\"^3.0.0\",\"es6-promise\":\"^4.2.4\",\"grunt\":\"^1.0.2\",\"grunt-banner\":\"^0.6.0\",\"grunt-cli\":\"^1.2.0\",\"grunt-contrib-clean\":\"^1.1.0\",\"grunt-contrib-watch\":\"^1.0.0\",\"grunt-eslint\":\"^20.1.0\",\"grunt-karma\":\"^2.0.0\",\"grunt-mocha-test\":\"^0.13.3\",\"grunt-ts\":\"^6.0.0-beta.19\",\"grunt-webpack\":\"^1.0.18\",\"istanbul-instrumenter-loader\":\"^1.0.0\",\"jasmine-core\":\"^2.4.1\",\"karma\":\"^1.3.0\",\"karma-chrome-launcher\":\"^2.2.0\",\"karma-coverage\":\"^1.1.1\",\"karma-firefox-launcher\":\"^1.1.0\",\"karma-jasmine\":\"^1.1.1\",\"karma-jasmine-ajax\":\"^0.1.13\",\"karma-opera-launcher\":\"^1.0.0\",\"karma-safari-launcher\":\"^1.0.0\",\"karma-sauce-launcher\":\"^1.2.0\",\"karma-sinon\":\"^1.0.5\",\"karma-sourcemap-loader\":\"^0.3.7\",\"karma-webpack\":\"^1.7.0\",\"load-grunt-tasks\":\"^3.5.2\",\"minimist\":\"^1.2.0\",\"mocha\":\"^5.2.0\",\"sinon\":\"^4.5.0\",\"typescript\":\"^2.8.1\",\"url-search-params\":\"^0.10.0\",\"webpack\":\"^1.13.1\",\"webpack-dev-server\":\"^1.14.1\"},\"browser\":{\"./lib/adapters/http.js\":\"./lib/adapters/xhr.js\"},\"typings\":\"./index.d.ts\",\"dependencies\":{\"follow-redirects\":\"1.5.10\",\"is-buffer\":\"^2.0.2\"},\"bundlesize\":[{\"path\":\"./dist/axios.min.js\",\"threshold\":\"5kB\"}]}");
|
19304 |
|
19305 | /***/ }),
|
19306 | /* 71 */
|
19307 | /***/ (function(module, exports, __webpack_require__) {
|
19308 |
|
19309 | "use strict";
|
19310 |
|
19311 |
|
19312 | var utils = __webpack_require__(2);
|
19313 | var settle = __webpack_require__(30);
|
19314 | var buildURL = __webpack_require__(18);
|
19315 | var parseHeaders = __webpack_require__(72);
|
19316 | var isURLSameOrigin = __webpack_require__(73);
|
19317 | var createError = __webpack_require__(19);
|
19318 |
|
19319 | module.exports = function xhrAdapter(config) {
|
19320 | return new Promise(function dispatchXhrRequest(resolve, reject) {
|
19321 | var requestData = config.data;
|
19322 | var requestHeaders = config.headers;
|
19323 |
|
19324 | if (utils.isFormData(requestData)) {
|
19325 | delete requestHeaders['Content-Type']; // Let the browser set it
|
19326 | }
|
19327 |
|
19328 | var request = new XMLHttpRequest();
|
19329 |
|
19330 | // HTTP basic authentication
|
19331 | if (config.auth) {
|
19332 | var username = config.auth.username || '';
|
19333 | var password = config.auth.password || '';
|
19334 | requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
|
19335 | }
|
19336 |
|
19337 | request.open(config.method.toUpperCase(), buildURL(config.url, config.params, config.paramsSerializer), true);
|
19338 |
|
19339 | // Set the request timeout in MS
|
19340 | request.timeout = config.timeout;
|
19341 |
|
19342 | // Listen for ready state
|
19343 | request.onreadystatechange = function handleLoad() {
|
19344 | if (!request || request.readyState !== 4) {
|
19345 | return;
|
19346 | }
|
19347 |
|
19348 | // The request errored out and we didn't get a response, this will be
|
19349 | // handled by onerror instead
|
19350 | // With one exception: request that using file: protocol, most browsers
|
19351 | // will return status as 0 even though it's a successful request
|
19352 | if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
|
19353 | return;
|
19354 | }
|
19355 |
|
19356 | // Prepare the response
|
19357 | var responseHeaders = 'getAllResponseHeaders' in request ? parseHeaders(request.getAllResponseHeaders()) : null;
|
19358 | var responseData = !config.responseType || config.responseType === 'text' ? request.responseText : request.response;
|
19359 | var response = {
|
19360 | data: responseData,
|
19361 | status: request.status,
|
19362 | statusText: request.statusText,
|
19363 | headers: responseHeaders,
|
19364 | config: config,
|
19365 | request: request
|
19366 | };
|
19367 |
|
19368 | settle(resolve, reject, response);
|
19369 |
|
19370 | // Clean up request
|
19371 | request = null;
|
19372 | };
|
19373 |
|
19374 | // Handle browser request cancellation (as opposed to a manual cancellation)
|
19375 | request.onabort = function handleAbort() {
|
19376 | if (!request) {
|
19377 | return;
|
19378 | }
|
19379 |
|
19380 | reject(createError('Request aborted', config, 'ECONNABORTED', request));
|
19381 |
|
19382 | // Clean up request
|
19383 | request = null;
|
19384 | };
|
19385 |
|
19386 | // Handle low level network errors
|
19387 | request.onerror = function handleError() {
|
19388 | // Real errors are hidden from us by the browser
|
19389 | // onerror should only fire if it's a network error
|
19390 | reject(createError('Network Error', config, null, request));
|
19391 |
|
19392 | // Clean up request
|
19393 | request = null;
|
19394 | };
|
19395 |
|
19396 | // Handle timeout
|
19397 | request.ontimeout = function handleTimeout() {
|
19398 | reject(createError('timeout of ' + config.timeout + 'ms exceeded', config, 'ECONNABORTED',
|
19399 | request));
|
19400 |
|
19401 | // Clean up request
|
19402 | request = null;
|
19403 | };
|
19404 |
|
19405 | // Add xsrf header
|
19406 | // This is only done if running in a standard browser environment.
|
19407 | // Specifically not if we're in a web worker, or react-native.
|
19408 | if (utils.isStandardBrowserEnv()) {
|
19409 | var cookies = __webpack_require__(74);
|
19410 |
|
19411 | // Add xsrf header
|
19412 | var xsrfValue = (config.withCredentials || isURLSameOrigin(config.url)) && config.xsrfCookieName ?
|
19413 | cookies.read(config.xsrfCookieName) :
|
19414 | undefined;
|
19415 |
|
19416 | if (xsrfValue) {
|
19417 | requestHeaders[config.xsrfHeaderName] = xsrfValue;
|
19418 | }
|
19419 | }
|
19420 |
|
19421 | // Add headers to the request
|
19422 | if ('setRequestHeader' in request) {
|
19423 | utils.forEach(requestHeaders, function setRequestHeader(val, key) {
|
19424 | if (typeof requestData === 'undefined' && key.toLowerCase() === 'content-type') {
|
19425 | // Remove Content-Type if data is undefined
|
19426 | delete requestHeaders[key];
|
19427 | } else {
|
19428 | // Otherwise add header to the request
|
19429 | request.setRequestHeader(key, val);
|
19430 | }
|
19431 | });
|
19432 | }
|
19433 |
|
19434 | // Add withCredentials to request if needed
|
19435 | if (config.withCredentials) {
|
19436 | request.withCredentials = true;
|
19437 | }
|
19438 |
|
19439 | // Add responseType to request if needed
|
19440 | if (config.responseType) {
|
19441 | try {
|
19442 | request.responseType = config.responseType;
|
19443 | } catch (e) {
|
19444 | // Expected DOMException thrown by browsers not compatible XMLHttpRequest Level 2.
|
19445 | // But, this can be suppressed for 'json' type as it can be parsed by default 'transformResponse' function.
|
19446 | if (config.responseType !== 'json') {
|
19447 | throw e;
|
19448 | }
|
19449 | }
|
19450 | }
|
19451 |
|
19452 | // Handle progress if needed
|
19453 | if (typeof config.onDownloadProgress === 'function') {
|
19454 | request.addEventListener('progress', config.onDownloadProgress);
|
19455 | }
|
19456 |
|
19457 | // Not all browsers support upload events
|
19458 | if (typeof config.onUploadProgress === 'function' && request.upload) {
|
19459 | request.upload.addEventListener('progress', config.onUploadProgress);
|
19460 | }
|
19461 |
|
19462 | if (config.cancelToken) {
|
19463 | // Handle cancellation
|
19464 | config.cancelToken.promise.then(function onCanceled(cancel) {
|
19465 | if (!request) {
|
19466 | return;
|
19467 | }
|
19468 |
|
19469 | request.abort();
|
19470 | reject(cancel);
|
19471 | // Clean up request
|
19472 | request = null;
|
19473 | });
|
19474 | }
|
19475 |
|
19476 | if (requestData === undefined) {
|
19477 | requestData = null;
|
19478 | }
|
19479 |
|
19480 | // Send the request
|
19481 | request.send(requestData);
|
19482 | });
|
19483 | };
|
19484 |
|
19485 |
|
19486 | /***/ }),
|
19487 | /* 72 */
|
19488 | /***/ (function(module, exports, __webpack_require__) {
|
19489 |
|
19490 | "use strict";
|
19491 |
|
19492 |
|
19493 | var utils = __webpack_require__(2);
|
19494 |
|
19495 | // Headers whose duplicates are ignored by node
|
19496 | // c.f. https://nodejs.org/api/http.html#http_message_headers
|
19497 | var ignoreDuplicateOf = [
|
19498 | 'age', 'authorization', 'content-length', 'content-type', 'etag',
|
19499 | 'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since',
|
19500 | 'last-modified', 'location', 'max-forwards', 'proxy-authorization',
|
19501 | 'referer', 'retry-after', 'user-agent'
|
19502 | ];
|
19503 |
|
19504 | /**
|
19505 | * Parse headers into an object
|
19506 | *
|
19507 | * ```
|
19508 | * Date: Wed, 27 Aug 2014 08:58:49 GMT
|
19509 | * Content-Type: application/json
|
19510 | * Connection: keep-alive
|
19511 | * Transfer-Encoding: chunked
|
19512 | * ```
|
19513 | *
|
19514 | * @param {String} headers Headers needing to be parsed
|
19515 | * @returns {Object} Headers parsed into an object
|
19516 | */
|
19517 | module.exports = function parseHeaders(headers) {
|
19518 | var parsed = {};
|
19519 | var key;
|
19520 | var val;
|
19521 | var i;
|
19522 |
|
19523 | if (!headers) { return parsed; }
|
19524 |
|
19525 | utils.forEach(headers.split('\n'), function parser(line) {
|
19526 | i = line.indexOf(':');
|
19527 | key = utils.trim(line.substr(0, i)).toLowerCase();
|
19528 | val = utils.trim(line.substr(i + 1));
|
19529 |
|
19530 | if (key) {
|
19531 | if (parsed[key] && ignoreDuplicateOf.indexOf(key) >= 0) {
|
19532 | return;
|
19533 | }
|
19534 | if (key === 'set-cookie') {
|
19535 | parsed[key] = (parsed[key] ? parsed[key] : []).concat([val]);
|
19536 | } else {
|
19537 | parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
|
19538 | }
|
19539 | }
|
19540 | });
|
19541 |
|
19542 | return parsed;
|
19543 | };
|
19544 |
|
19545 |
|
19546 | /***/ }),
|
19547 | /* 73 */
|
19548 | /***/ (function(module, exports, __webpack_require__) {
|
19549 |
|
19550 | "use strict";
|
19551 |
|
19552 |
|
19553 | var utils = __webpack_require__(2);
|
19554 |
|
19555 | module.exports = (
|
19556 | utils.isStandardBrowserEnv() ?
|
19557 |
|
19558 | // Standard browser envs have full support of the APIs needed to test
|
19559 | // whether the request URL is of the same origin as current location.
|
19560 | (function standardBrowserEnv() {
|
19561 | var msie = /(msie|trident)/i.test(navigator.userAgent);
|
19562 | var urlParsingNode = document.createElement('a');
|
19563 | var originURL;
|
19564 |
|
19565 | /**
|
19566 | * Parse a URL to discover it's components
|
19567 | *
|
19568 | * @param {String} url The URL to be parsed
|
19569 | * @returns {Object}
|
19570 | */
|
19571 | function resolveURL(url) {
|
19572 | var href = url;
|
19573 |
|
19574 | if (msie) {
|
19575 | // IE needs attribute set twice to normalize properties
|
19576 | urlParsingNode.setAttribute('href', href);
|
19577 | href = urlParsingNode.href;
|
19578 | }
|
19579 |
|
19580 | urlParsingNode.setAttribute('href', href);
|
19581 |
|
19582 | // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
|
19583 | return {
|
19584 | href: urlParsingNode.href,
|
19585 | protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
|
19586 | host: urlParsingNode.host,
|
19587 | search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
|
19588 | hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
|
19589 | hostname: urlParsingNode.hostname,
|
19590 | port: urlParsingNode.port,
|
19591 | pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
|
19592 | urlParsingNode.pathname :
|
19593 | '/' + urlParsingNode.pathname
|
19594 | };
|
19595 | }
|
19596 |
|
19597 | originURL = resolveURL(window.location.href);
|
19598 |
|
19599 | /**
|
19600 | * Determine if a URL shares the same origin as the current location
|
19601 | *
|
19602 | * @param {String} requestURL The URL to test
|
19603 | * @returns {boolean} True if URL shares the same origin, otherwise false
|
19604 | */
|
19605 | return function isURLSameOrigin(requestURL) {
|
19606 | var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
|
19607 | return (parsed.protocol === originURL.protocol &&
|
19608 | parsed.host === originURL.host);
|
19609 | };
|
19610 | })() :
|
19611 |
|
19612 | // Non standard browser envs (web workers, react-native) lack needed support.
|
19613 | (function nonStandardBrowserEnv() {
|
19614 | return function isURLSameOrigin() {
|
19615 | return true;
|
19616 | };
|
19617 | })()
|
19618 | );
|
19619 |
|
19620 |
|
19621 | /***/ }),
|
19622 | /* 74 */
|
19623 | /***/ (function(module, exports, __webpack_require__) {
|
19624 |
|
19625 | "use strict";
|
19626 |
|
19627 |
|
19628 | var utils = __webpack_require__(2);
|
19629 |
|
19630 | module.exports = (
|
19631 | utils.isStandardBrowserEnv() ?
|
19632 |
|
19633 | // Standard browser envs support document.cookie
|
19634 | (function standardBrowserEnv() {
|
19635 | return {
|
19636 | write: function write(name, value, expires, path, domain, secure) {
|
19637 | var cookie = [];
|
19638 | cookie.push(name + '=' + encodeURIComponent(value));
|
19639 |
|
19640 | if (utils.isNumber(expires)) {
|
19641 | cookie.push('expires=' + new Date(expires).toGMTString());
|
19642 | }
|
19643 |
|
19644 | if (utils.isString(path)) {
|
19645 | cookie.push('path=' + path);
|
19646 | }
|
19647 |
|
19648 | if (utils.isString(domain)) {
|
19649 | cookie.push('domain=' + domain);
|
19650 | }
|
19651 |
|
19652 | if (secure === true) {
|
19653 | cookie.push('secure');
|
19654 | }
|
19655 |
|
19656 | document.cookie = cookie.join('; ');
|
19657 | },
|
19658 |
|
19659 | read: function read(name) {
|
19660 | var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
|
19661 | return (match ? decodeURIComponent(match[3]) : null);
|
19662 | },
|
19663 |
|
19664 | remove: function remove(name) {
|
19665 | this.write(name, '', Date.now() - 86400000);
|
19666 | }
|
19667 | };
|
19668 | })() :
|
19669 |
|
19670 | // Non standard browser env (web workers, react-native) lack needed support.
|
19671 | (function nonStandardBrowserEnv() {
|
19672 | return {
|
19673 | write: function write() {},
|
19674 | read: function read() { return null; },
|
19675 | remove: function remove() {}
|
19676 | };
|
19677 | })()
|
19678 | );
|
19679 |
|
19680 |
|
19681 | /***/ }),
|
19682 | /* 75 */
|
19683 | /***/ (function(module, exports, __webpack_require__) {
|
19684 |
|
19685 | "use strict";
|
19686 |
|
19687 |
|
19688 | /**
|
19689 | * Determines whether the specified URL is absolute
|
19690 | *
|
19691 | * @param {string} url The URL to test
|
19692 | * @returns {boolean} True if the specified URL is absolute, otherwise false
|
19693 | */
|
19694 | module.exports = function isAbsoluteURL(url) {
|
19695 | // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
|
19696 | // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
|
19697 | // by any combination of letters, digits, plus, period, or hyphen.
|
19698 | return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url);
|
19699 | };
|
19700 |
|
19701 |
|
19702 | /***/ }),
|
19703 | /* 76 */
|
19704 | /***/ (function(module, exports, __webpack_require__) {
|
19705 |
|
19706 | "use strict";
|
19707 |
|
19708 |
|
19709 | /**
|
19710 | * Creates a new URL by combining the specified URLs
|
19711 | *
|
19712 | * @param {string} baseURL The base URL
|
19713 | * @param {string} relativeURL The relative URL
|
19714 | * @returns {string} The combined URL
|
19715 | */
|
19716 | module.exports = function combineURLs(baseURL, relativeURL) {
|
19717 | return relativeURL
|
19718 | ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
|
19719 | : baseURL;
|
19720 | };
|
19721 |
|
19722 |
|
19723 | /***/ }),
|
19724 | /* 77 */
|
19725 | /***/ (function(module, exports, __webpack_require__) {
|
19726 |
|
19727 | "use strict";
|
19728 |
|
19729 |
|
19730 | var Cancel = __webpack_require__(38);
|
19731 |
|
19732 | /**
|
19733 | * A `CancelToken` is an object that can be used to request cancellation of an operation.
|
19734 | *
|
19735 | * @class
|
19736 | * @param {Function} executor The executor function.
|
19737 | */
|
19738 | function CancelToken(executor) {
|
19739 | if (typeof executor !== 'function') {
|
19740 | throw new TypeError('executor must be a function.');
|
19741 | }
|
19742 |
|
19743 | var resolvePromise;
|
19744 | this.promise = new Promise(function promiseExecutor(resolve) {
|
19745 | resolvePromise = resolve;
|
19746 | });
|
19747 |
|
19748 | var token = this;
|
19749 | executor(function cancel(message) {
|
19750 | if (token.reason) {
|
19751 | // Cancellation has already been requested
|
19752 | return;
|
19753 | }
|
19754 |
|
19755 | token.reason = new Cancel(message);
|
19756 | resolvePromise(token.reason);
|
19757 | });
|
19758 | }
|
19759 |
|
19760 | /**
|
19761 | * Throws a `Cancel` if cancellation has been requested.
|
19762 | */
|
19763 | CancelToken.prototype.throwIfRequested = function throwIfRequested() {
|
19764 | if (this.reason) {
|
19765 | throw this.reason;
|
19766 | }
|
19767 | };
|
19768 |
|
19769 | /**
|
19770 | * Returns an object that contains a new `CancelToken` and a function that, when called,
|
19771 | * cancels the `CancelToken`.
|
19772 | */
|
19773 | CancelToken.source = function source() {
|
19774 | var cancel;
|
19775 | var token = new CancelToken(function executor(c) {
|
19776 | cancel = c;
|
19777 | });
|
19778 | return {
|
19779 | token: token,
|
19780 | cancel: cancel
|
19781 | };
|
19782 | };
|
19783 |
|
19784 | module.exports = CancelToken;
|
19785 |
|
19786 |
|
19787 | /***/ }),
|
19788 | /* 78 */
|
19789 | /***/ (function(module, exports, __webpack_require__) {
|
19790 |
|
19791 | "use strict";
|
19792 |
|
19793 |
|
19794 | /**
|
19795 | * Syntactic sugar for invoking a function and expanding an array for arguments.
|
19796 | *
|
19797 | * Common use case would be to use `Function.prototype.apply`.
|
19798 | *
|
19799 | * ```js
|
19800 | * function f(x, y, z) {}
|
19801 | * var args = [1, 2, 3];
|
19802 | * f.apply(null, args);
|
19803 | * ```
|
19804 | *
|
19805 | * With `spread` this example can be re-written.
|
19806 | *
|
19807 | * ```js
|
19808 | * spread(function(x, y, z) {})([1, 2, 3]);
|
19809 | * ```
|
19810 | *
|
19811 | * @param {Function} callback
|
19812 | * @returns {Function}
|
19813 | */
|
19814 | module.exports = function spread(callback) {
|
19815 | return function wrap(arr) {
|
19816 | return callback.apply(null, arr);
|
19817 | };
|
19818 | };
|
19819 |
|
19820 |
|
19821 | /***/ }),
|
19822 | /* 79 */
|
19823 | /***/ (function(module, exports, __webpack_require__) {
|
19824 |
|
19825 | // base-x encoding / decoding
|
19826 | // Copyright (c) 2018 base-x contributors
|
19827 | // Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
19828 | // Distributed under the MIT software license, see the accompanying
|
19829 | // file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
19830 |
|
19831 | const Buffer = __webpack_require__(39).Buffer
|
19832 |
|
19833 | module.exports = function base (ALPHABET) {
|
19834 | if (ALPHABET.length >= 255) throw new TypeError('Alphabet too long')
|
19835 |
|
19836 | const BASE_MAP = new Uint8Array(256)
|
19837 | BASE_MAP.fill(255)
|
19838 |
|
19839 | for (let i = 0; i < ALPHABET.length; i++) {
|
19840 | const x = ALPHABET.charAt(i)
|
19841 | const xc = x.charCodeAt(0)
|
19842 |
|
19843 | if (BASE_MAP[xc] !== 255) throw new TypeError(x + ' is ambiguous')
|
19844 | BASE_MAP[xc] = i
|
19845 | }
|
19846 |
|
19847 | const BASE = ALPHABET.length
|
19848 | const LEADER = ALPHABET.charAt(0)
|
19849 | const FACTOR = Math.log(BASE) / Math.log(256) // log(BASE) / log(256), rounded up
|
19850 | const iFACTOR = Math.log(256) / Math.log(BASE) // log(256) / log(BASE), rounded up
|
19851 |
|
19852 | function encode (source) {
|
19853 | if (!Buffer.isBuffer(source)) throw new TypeError('Expected Buffer')
|
19854 | if (source.length === 0) return ''
|
19855 |
|
19856 | // Skip & count leading zeroes.
|
19857 | let zeroes = 0
|
19858 | let length = 0
|
19859 | let pbegin = 0
|
19860 | const pend = source.length
|
19861 |
|
19862 | while (pbegin !== pend && source[pbegin] === 0) {
|
19863 | pbegin++
|
19864 | zeroes++
|
19865 | }
|
19866 |
|
19867 | // Allocate enough space in big-endian base58 representation.
|
19868 | const size = ((pend - pbegin) * iFACTOR + 1) >>> 0
|
19869 | const b58 = new Uint8Array(size)
|
19870 |
|
19871 | // Process the bytes.
|
19872 | while (pbegin !== pend) {
|
19873 | let carry = source[pbegin]
|
19874 |
|
19875 | // Apply "b58 = b58 * 256 + ch".
|
19876 | let i = 0
|
19877 | for (let it = size - 1; (carry !== 0 || i < length) && (it !== -1); it--, i++) {
|
19878 | carry += (256 * b58[it]) >>> 0
|
19879 | b58[it] = (carry % BASE) >>> 0
|
19880 | carry = (carry / BASE) >>> 0
|
19881 | }
|
19882 |
|
19883 | if (carry !== 0) throw new Error('Non-zero carry')
|
19884 | length = i
|
19885 | pbegin++
|
19886 | }
|
19887 |
|
19888 | // Skip leading zeroes in base58 result.
|
19889 | let it = size - length
|
19890 | while (it !== size && b58[it] === 0) {
|
19891 | it++
|
19892 | }
|
19893 |
|
19894 | // Translate the result into a string.
|
19895 | let str = LEADER.repeat(zeroes)
|
19896 | for (; it < size; ++it) str += ALPHABET.charAt(b58[it])
|
19897 |
|
19898 | return str
|
19899 | }
|
19900 |
|
19901 | function decodeUnsafe (source) {
|
19902 | if (typeof source !== 'string') throw new TypeError('Expected String')
|
19903 | if (source.length === 0) return Buffer.alloc(0)
|
19904 |
|
19905 | let psz = 0
|
19906 |
|
19907 | // Skip leading spaces.
|
19908 | if (source[psz] === ' ') return
|
19909 |
|
19910 | // Skip and count leading '1's.
|
19911 | let zeroes = 0
|
19912 | let length = 0
|
19913 | while (source[psz] === LEADER) {
|
19914 | zeroes++
|
19915 | psz++
|
19916 | }
|
19917 |
|
19918 | // Allocate enough space in big-endian base256 representation.
|
19919 | const size = (((source.length - psz) * FACTOR) + 1) >>> 0 // log(58) / log(256), rounded up.
|
19920 | const b256 = new Uint8Array(size)
|
19921 |
|
19922 | // Process the characters.
|
19923 | while (source[psz]) {
|
19924 | // Decode character
|
19925 | let carry = BASE_MAP[source.charCodeAt(psz)]
|
19926 |
|
19927 | // Invalid character
|
19928 | if (carry === 255) return
|
19929 |
|
19930 | let i = 0
|
19931 | for (let it = size - 1; (carry !== 0 || i < length) && (it !== -1); it--, i++) {
|
19932 | carry += (BASE * b256[it]) >>> 0
|
19933 | b256[it] = (carry % 256) >>> 0
|
19934 | carry = (carry / 256) >>> 0
|
19935 | }
|
19936 |
|
19937 | if (carry !== 0) throw new Error('Non-zero carry')
|
19938 | length = i
|
19939 | psz++
|
19940 | }
|
19941 |
|
19942 | // Skip trailing spaces.
|
19943 | if (source[psz] === ' ') return
|
19944 |
|
19945 | // Skip leading zeroes in b256.
|
19946 | let it = size - length
|
19947 | while (it !== size && b256[it] === 0) {
|
19948 | it++
|
19949 | }
|
19950 |
|
19951 | const vch = Buffer.allocUnsafe(zeroes + (size - it))
|
19952 | vch.fill(0x00, 0, zeroes)
|
19953 |
|
19954 | let j = zeroes
|
19955 | while (it !== size) {
|
19956 | vch[j++] = b256[it++]
|
19957 | }
|
19958 |
|
19959 | return vch
|
19960 | }
|
19961 |
|
19962 | function decode (string) {
|
19963 | const buffer = decodeUnsafe(string)
|
19964 | if (buffer) return buffer
|
19965 |
|
19966 | throw new Error('Non-base' + BASE + ' character')
|
19967 | }
|
19968 |
|
19969 | return {
|
19970 | encode: encode,
|
19971 | decodeUnsafe: decodeUnsafe,
|
19972 | decode: decode
|
19973 | }
|
19974 | }
|
19975 |
|
19976 |
|
19977 | /***/ }),
|
19978 | /* 80 */
|
19979 | /***/ (function(module, exports, __webpack_require__) {
|
19980 |
|
19981 | module.exports = __webpack_require__(20).createHash
|
19982 |
|
19983 |
|
19984 | /***/ }),
|
19985 | /* 81 */
|
19986 | /***/ (function(module, exports, __webpack_require__) {
|
19987 |
|
19988 | "use strict";
|
19989 |
|
19990 |
|
19991 | var base58 = __webpack_require__(7)
|
19992 | var Buffer = __webpack_require__(39).Buffer
|
19993 |
|
19994 | module.exports = function (checksumFn) {
|
19995 | // Encode a buffer as a base58-check encoded string
|
19996 | function encode (payload) {
|
19997 | var checksum = checksumFn(payload)
|
19998 |
|
19999 | return base58.encode(Buffer.concat([
|
20000 | payload,
|
20001 | checksum
|
20002 | ], payload.length + 4))
|
20003 | }
|
20004 |
|
20005 | function decodeRaw (buffer) {
|
20006 | var payload = buffer.slice(0, -4)
|
20007 | var checksum = buffer.slice(-4)
|
20008 | var newChecksum = checksumFn(payload)
|
20009 |
|
20010 | if (checksum[0] ^ newChecksum[0] |
|
20011 | checksum[1] ^ newChecksum[1] |
|
20012 | checksum[2] ^ newChecksum[2] |
|
20013 | checksum[3] ^ newChecksum[3]) return
|
20014 |
|
20015 | return payload
|
20016 | }
|
20017 |
|
20018 | // Decode a base58-check encoded string to a buffer, no result if checksum is wrong
|
20019 | function decodeUnsafe (string) {
|
20020 | var buffer = base58.decodeUnsafe(string)
|
20021 | if (!buffer) return
|
20022 |
|
20023 | return decodeRaw(buffer)
|
20024 | }
|
20025 |
|
20026 | function decode (string) {
|
20027 | var buffer = base58.decode(string)
|
20028 | var payload = decodeRaw(buffer, checksumFn)
|
20029 | if (!payload) throw new Error('Invalid checksum')
|
20030 | return payload
|
20031 | }
|
20032 |
|
20033 | return {
|
20034 | encode: encode,
|
20035 | decode: decode,
|
20036 | decodeUnsafe: decodeUnsafe
|
20037 | }
|
20038 | }
|
20039 |
|
20040 |
|
20041 | /***/ }),
|
20042 | /* 82 */
|
20043 | /***/ (function(module, exports) {
|
20044 |
|
20045 | module.exports = function(module) {
|
20046 | if (!module.webpackPolyfill) {
|
20047 | module.deprecate = function() {};
|
20048 | module.paths = [];
|
20049 | // module.parent = undefined by default
|
20050 | if (!module.children) module.children = [];
|
20051 | Object.defineProperty(module, "loaded", {
|
20052 | enumerable: true,
|
20053 | get: function() {
|
20054 | return module.l;
|
20055 | }
|
20056 | });
|
20057 | Object.defineProperty(module, "id", {
|
20058 | enumerable: true,
|
20059 | get: function() {
|
20060 | return module.i;
|
20061 | }
|
20062 | });
|
20063 | module.webpackPolyfill = 1;
|
20064 | }
|
20065 | return module;
|
20066 | };
|
20067 |
|
20068 |
|
20069 | /***/ }),
|
20070 | /* 83 */
|
20071 | /***/ (function(module) {
|
20072 |
|
20073 | module.exports = JSON.parse("{\"name\":\"elliptic\",\"version\":\"6.4.1\",\"description\":\"EC cryptography\",\"main\":\"lib/elliptic.js\",\"files\":[\"lib\"],\"scripts\":{\"jscs\":\"jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js\",\"jshint\":\"jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js\",\"lint\":\"npm run jscs && npm run jshint\",\"unit\":\"istanbul test _mocha --reporter=spec test/index.js\",\"test\":\"npm run lint && npm run unit\",\"version\":\"grunt dist && git add dist/\"},\"repository\":{\"type\":\"git\",\"url\":\"git@github.com:indutny/elliptic\"},\"keywords\":[\"EC\",\"Elliptic\",\"curve\",\"Cryptography\"],\"author\":\"Fedor Indutny <fedor@indutny.com>\",\"license\":\"MIT\",\"bugs\":{\"url\":\"https://github.com/indutny/elliptic/issues\"},\"homepage\":\"https://github.com/indutny/elliptic\",\"devDependencies\":{\"brfs\":\"^1.4.3\",\"coveralls\":\"^2.11.3\",\"grunt\":\"^0.4.5\",\"grunt-browserify\":\"^5.0.0\",\"grunt-cli\":\"^1.2.0\",\"grunt-contrib-connect\":\"^1.0.0\",\"grunt-contrib-copy\":\"^1.0.0\",\"grunt-contrib-uglify\":\"^1.0.1\",\"grunt-mocha-istanbul\":\"^3.0.1\",\"grunt-saucelabs\":\"^8.6.2\",\"istanbul\":\"^0.4.2\",\"jscs\":\"^2.9.0\",\"jshint\":\"^2.6.0\",\"mocha\":\"^2.1.0\"},\"dependencies\":{\"bn.js\":\"^4.4.0\",\"brorand\":\"^1.0.1\",\"hash.js\":\"^1.0.0\",\"hmac-drbg\":\"^1.0.0\",\"inherits\":\"^2.0.1\",\"minimalistic-assert\":\"^1.0.0\",\"minimalistic-crypto-utils\":\"^1.0.0\"}}");
|
20074 |
|
20075 | /***/ }),
|
20076 | /* 84 */
|
20077 | /***/ (function(module, exports, __webpack_require__) {
|
20078 |
|
20079 | "use strict";
|
20080 |
|
20081 |
|
20082 | var utils = exports;
|
20083 | var BN = __webpack_require__(3);
|
20084 | var minAssert = __webpack_require__(8);
|
20085 | var minUtils = __webpack_require__(40);
|
20086 |
|
20087 | utils.assert = minAssert;
|
20088 | utils.toArray = minUtils.toArray;
|
20089 | utils.zero2 = minUtils.zero2;
|
20090 | utils.toHex = minUtils.toHex;
|
20091 | utils.encode = minUtils.encode;
|
20092 |
|
20093 | // Represent num in a w-NAF form
|
20094 | function getNAF(num, w) {
|
20095 | var naf = [];
|
20096 | var ws = 1 << (w + 1);
|
20097 | var k = num.clone();
|
20098 | while (k.cmpn(1) >= 0) {
|
20099 | var z;
|
20100 | if (k.isOdd()) {
|
20101 | var mod = k.andln(ws - 1);
|
20102 | if (mod > (ws >> 1) - 1)
|
20103 | z = (ws >> 1) - mod;
|
20104 | else
|
20105 | z = mod;
|
20106 | k.isubn(z);
|
20107 | } else {
|
20108 | z = 0;
|
20109 | }
|
20110 | naf.push(z);
|
20111 |
|
20112 | // Optimization, shift by word if possible
|
20113 | var shift = (k.cmpn(0) !== 0 && k.andln(ws - 1) === 0) ? (w + 1) : 1;
|
20114 | for (var i = 1; i < shift; i++)
|
20115 | naf.push(0);
|
20116 | k.iushrn(shift);
|
20117 | }
|
20118 |
|
20119 | return naf;
|
20120 | }
|
20121 | utils.getNAF = getNAF;
|
20122 |
|
20123 | // Represent k1, k2 in a Joint Sparse Form
|
20124 | function getJSF(k1, k2) {
|
20125 | var jsf = [
|
20126 | [],
|
20127 | []
|
20128 | ];
|
20129 |
|
20130 | k1 = k1.clone();
|
20131 | k2 = k2.clone();
|
20132 | var d1 = 0;
|
20133 | var d2 = 0;
|
20134 | while (k1.cmpn(-d1) > 0 || k2.cmpn(-d2) > 0) {
|
20135 |
|
20136 | // First phase
|
20137 | var m14 = (k1.andln(3) + d1) & 3;
|
20138 | var m24 = (k2.andln(3) + d2) & 3;
|
20139 | if (m14 === 3)
|
20140 | m14 = -1;
|
20141 | if (m24 === 3)
|
20142 | m24 = -1;
|
20143 | var u1;
|
20144 | if ((m14 & 1) === 0) {
|
20145 | u1 = 0;
|
20146 | } else {
|
20147 | var m8 = (k1.andln(7) + d1) & 7;
|
20148 | if ((m8 === 3 || m8 === 5) && m24 === 2)
|
20149 | u1 = -m14;
|
20150 | else
|
20151 | u1 = m14;
|
20152 | }
|
20153 | jsf[0].push(u1);
|
20154 |
|
20155 | var u2;
|
20156 | if ((m24 & 1) === 0) {
|
20157 | u2 = 0;
|
20158 | } else {
|
20159 | var m8 = (k2.andln(7) + d2) & 7;
|
20160 | if ((m8 === 3 || m8 === 5) && m14 === 2)
|
20161 | u2 = -m24;
|
20162 | else
|
20163 | u2 = m24;
|
20164 | }
|
20165 | jsf[1].push(u2);
|
20166 |
|
20167 | // Second phase
|
20168 | if (2 * d1 === u1 + 1)
|
20169 | d1 = 1 - d1;
|
20170 | if (2 * d2 === u2 + 1)
|
20171 | d2 = 1 - d2;
|
20172 | k1.iushrn(1);
|
20173 | k2.iushrn(1);
|
20174 | }
|
20175 |
|
20176 | return jsf;
|
20177 | }
|
20178 | utils.getJSF = getJSF;
|
20179 |
|
20180 | function cachedProperty(obj, name, computer) {
|
20181 | var key = '_' + name;
|
20182 | obj.prototype[name] = function cachedProperty() {
|
20183 | return this[key] !== undefined ? this[key] :
|
20184 | this[key] = computer.call(this);
|
20185 | };
|
20186 | }
|
20187 | utils.cachedProperty = cachedProperty;
|
20188 |
|
20189 | function parseBytes(bytes) {
|
20190 | return typeof bytes === 'string' ? utils.toArray(bytes, 'hex') :
|
20191 | bytes;
|
20192 | }
|
20193 | utils.parseBytes = parseBytes;
|
20194 |
|
20195 | function intFromLE(bytes) {
|
20196 | return new BN(bytes, 'hex', 'le');
|
20197 | }
|
20198 | utils.intFromLE = intFromLE;
|
20199 |
|
20200 |
|
20201 |
|
20202 | /***/ }),
|
20203 | /* 85 */
|
20204 | /***/ (function(module, exports, __webpack_require__) {
|
20205 |
|
20206 | var r;
|
20207 |
|
20208 | module.exports = function rand(len) {
|
20209 | if (!r)
|
20210 | r = new Rand(null);
|
20211 |
|
20212 | return r.generate(len);
|
20213 | };
|
20214 |
|
20215 | function Rand(rand) {
|
20216 | this.rand = rand;
|
20217 | }
|
20218 | module.exports.Rand = Rand;
|
20219 |
|
20220 | Rand.prototype.generate = function generate(len) {
|
20221 | return this._rand(len);
|
20222 | };
|
20223 |
|
20224 | // Emulate crypto API using randy
|
20225 | Rand.prototype._rand = function _rand(n) {
|
20226 | if (this.rand.getBytes)
|
20227 | return this.rand.getBytes(n);
|
20228 |
|
20229 | var res = new Uint8Array(n);
|
20230 | for (var i = 0; i < res.length; i++)
|
20231 | res[i] = this.rand.getByte();
|
20232 | return res;
|
20233 | };
|
20234 |
|
20235 | if (typeof self === 'object') {
|
20236 | if (self.crypto && self.crypto.getRandomValues) {
|
20237 | // Modern browsers
|
20238 | Rand.prototype._rand = function _rand(n) {
|
20239 | var arr = new Uint8Array(n);
|
20240 | self.crypto.getRandomValues(arr);
|
20241 | return arr;
|
20242 | };
|
20243 | } else if (self.msCrypto && self.msCrypto.getRandomValues) {
|
20244 | // IE
|
20245 | Rand.prototype._rand = function _rand(n) {
|
20246 | var arr = new Uint8Array(n);
|
20247 | self.msCrypto.getRandomValues(arr);
|
20248 | return arr;
|
20249 | };
|
20250 |
|
20251 | // Safari's WebWorkers do not have `crypto`
|
20252 | } else if (typeof window === 'object') {
|
20253 | // Old junk
|
20254 | Rand.prototype._rand = function() {
|
20255 | throw new Error('Not implemented yet');
|
20256 | };
|
20257 | }
|
20258 | } else {
|
20259 | // Node.js or Web worker with no crypto support
|
20260 | try {
|
20261 | var crypto = __webpack_require__(20);
|
20262 | if (typeof crypto.randomBytes !== 'function')
|
20263 | throw new Error('Not supported');
|
20264 |
|
20265 | Rand.prototype._rand = function _rand(n) {
|
20266 | return crypto.randomBytes(n);
|
20267 | };
|
20268 | } catch (e) {
|
20269 | }
|
20270 | }
|
20271 |
|
20272 |
|
20273 | /***/ }),
|
20274 | /* 86 */
|
20275 | /***/ (function(module, exports, __webpack_require__) {
|
20276 |
|
20277 | "use strict";
|
20278 |
|
20279 |
|
20280 | var BN = __webpack_require__(3);
|
20281 | var elliptic = __webpack_require__(5);
|
20282 | var utils = elliptic.utils;
|
20283 | var getNAF = utils.getNAF;
|
20284 | var getJSF = utils.getJSF;
|
20285 | var assert = utils.assert;
|
20286 |
|
20287 | function BaseCurve(type, conf) {
|
20288 | this.type = type;
|
20289 | this.p = new BN(conf.p, 16);
|
20290 |
|
20291 | // Use Montgomery, when there is no fast reduction for the prime
|
20292 | this.red = conf.prime ? BN.red(conf.prime) : BN.mont(this.p);
|
20293 |
|
20294 | // Useful for many curves
|
20295 | this.zero = new BN(0).toRed(this.red);
|
20296 | this.one = new BN(1).toRed(this.red);
|
20297 | this.two = new BN(2).toRed(this.red);
|
20298 |
|
20299 | // Curve configuration, optional
|
20300 | this.n = conf.n && new BN(conf.n, 16);
|
20301 | this.g = conf.g && this.pointFromJSON(conf.g, conf.gRed);
|
20302 |
|
20303 | // Temporary arrays
|
20304 | this._wnafT1 = new Array(4);
|
20305 | this._wnafT2 = new Array(4);
|
20306 | this._wnafT3 = new Array(4);
|
20307 | this._wnafT4 = new Array(4);
|
20308 |
|
20309 | // Generalized Greg Maxwell's trick
|
20310 | var adjustCount = this.n && this.p.div(this.n);
|
20311 | if (!adjustCount || adjustCount.cmpn(100) > 0) {
|
20312 | this.redN = null;
|
20313 | } else {
|
20314 | this._maxwellTrick = true;
|
20315 | this.redN = this.n.toRed(this.red);
|
20316 | }
|
20317 | }
|
20318 | module.exports = BaseCurve;
|
20319 |
|
20320 | BaseCurve.prototype.point = function point() {
|
20321 | throw new Error('Not implemented');
|
20322 | };
|
20323 |
|
20324 | BaseCurve.prototype.validate = function validate() {
|
20325 | throw new Error('Not implemented');
|
20326 | };
|
20327 |
|
20328 | BaseCurve.prototype._fixedNafMul = function _fixedNafMul(p, k) {
|
20329 | assert(p.precomputed);
|
20330 | var doubles = p._getDoubles();
|
20331 |
|
20332 | var naf = getNAF(k, 1);
|
20333 | var I = (1 << (doubles.step + 1)) - (doubles.step % 2 === 0 ? 2 : 1);
|
20334 | I /= 3;
|
20335 |
|
20336 | // Translate into more windowed form
|
20337 | var repr = [];
|
20338 | for (var j = 0; j < naf.length; j += doubles.step) {
|
20339 | var nafW = 0;
|
20340 | for (var k = j + doubles.step - 1; k >= j; k--)
|
20341 | nafW = (nafW << 1) + naf[k];
|
20342 | repr.push(nafW);
|
20343 | }
|
20344 |
|
20345 | var a = this.jpoint(null, null, null);
|
20346 | var b = this.jpoint(null, null, null);
|
20347 | for (var i = I; i > 0; i--) {
|
20348 | for (var j = 0; j < repr.length; j++) {
|
20349 | var nafW = repr[j];
|
20350 | if (nafW === i)
|
20351 | b = b.mixedAdd(doubles.points[j]);
|
20352 | else if (nafW === -i)
|
20353 | b = b.mixedAdd(doubles.points[j].neg());
|
20354 | }
|
20355 | a = a.add(b);
|
20356 | }
|
20357 | return a.toP();
|
20358 | };
|
20359 |
|
20360 | BaseCurve.prototype._wnafMul = function _wnafMul(p, k) {
|
20361 | var w = 4;
|
20362 |
|
20363 | // Precompute window
|
20364 | var nafPoints = p._getNAFPoints(w);
|
20365 | w = nafPoints.wnd;
|
20366 | var wnd = nafPoints.points;
|
20367 |
|
20368 | // Get NAF form
|
20369 | var naf = getNAF(k, w);
|
20370 |
|
20371 | // Add `this`*(N+1) for every w-NAF index
|
20372 | var acc = this.jpoint(null, null, null);
|
20373 | for (var i = naf.length - 1; i >= 0; i--) {
|
20374 | // Count zeroes
|
20375 | for (var k = 0; i >= 0 && naf[i] === 0; i--)
|
20376 | k++;
|
20377 | if (i >= 0)
|
20378 | k++;
|
20379 | acc = acc.dblp(k);
|
20380 |
|
20381 | if (i < 0)
|
20382 | break;
|
20383 | var z = naf[i];
|
20384 | assert(z !== 0);
|
20385 | if (p.type === 'affine') {
|
20386 | // J +- P
|
20387 | if (z > 0)
|
20388 | acc = acc.mixedAdd(wnd[(z - 1) >> 1]);
|
20389 | else
|
20390 | acc = acc.mixedAdd(wnd[(-z - 1) >> 1].neg());
|
20391 | } else {
|
20392 | // J +- J
|
20393 | if (z > 0)
|
20394 | acc = acc.add(wnd[(z - 1) >> 1]);
|
20395 | else
|
20396 | acc = acc.add(wnd[(-z - 1) >> 1].neg());
|
20397 | }
|
20398 | }
|
20399 | return p.type === 'affine' ? acc.toP() : acc;
|
20400 | };
|
20401 |
|
20402 | BaseCurve.prototype._wnafMulAdd = function _wnafMulAdd(defW,
|
20403 | points,
|
20404 | coeffs,
|
20405 | len,
|
20406 | jacobianResult) {
|
20407 | var wndWidth = this._wnafT1;
|
20408 | var wnd = this._wnafT2;
|
20409 | var naf = this._wnafT3;
|
20410 |
|
20411 | // Fill all arrays
|
20412 | var max = 0;
|
20413 | for (var i = 0; i < len; i++) {
|
20414 | var p = points[i];
|
20415 | var nafPoints = p._getNAFPoints(defW);
|
20416 | wndWidth[i] = nafPoints.wnd;
|
20417 | wnd[i] = nafPoints.points;
|
20418 | }
|
20419 |
|
20420 | // Comb small window NAFs
|
20421 | for (var i = len - 1; i >= 1; i -= 2) {
|
20422 | var a = i - 1;
|
20423 | var b = i;
|
20424 | if (wndWidth[a] !== 1 || wndWidth[b] !== 1) {
|
20425 | naf[a] = getNAF(coeffs[a], wndWidth[a]);
|
20426 | naf[b] = getNAF(coeffs[b], wndWidth[b]);
|
20427 | max = Math.max(naf[a].length, max);
|
20428 | max = Math.max(naf[b].length, max);
|
20429 | continue;
|
20430 | }
|
20431 |
|
20432 | var comb = [
|
20433 | points[a], /* 1 */
|
20434 | null, /* 3 */
|
20435 | null, /* 5 */
|
20436 | points[b] /* 7 */
|
20437 | ];
|
20438 |
|
20439 | // Try to avoid Projective points, if possible
|
20440 | if (points[a].y.cmp(points[b].y) === 0) {
|
20441 | comb[1] = points[a].add(points[b]);
|
20442 | comb[2] = points[a].toJ().mixedAdd(points[b].neg());
|
20443 | } else if (points[a].y.cmp(points[b].y.redNeg()) === 0) {
|
20444 | comb[1] = points[a].toJ().mixedAdd(points[b]);
|
20445 | comb[2] = points[a].add(points[b].neg());
|
20446 | } else {
|
20447 | comb[1] = points[a].toJ().mixedAdd(points[b]);
|
20448 | comb[2] = points[a].toJ().mixedAdd(points[b].neg());
|
20449 | }
|
20450 |
|
20451 | var index = [
|
20452 | -3, /* -1 -1 */
|
20453 | -1, /* -1 0 */
|
20454 | -5, /* -1 1 */
|
20455 | -7, /* 0 -1 */
|
20456 | 0, /* 0 0 */
|
20457 | 7, /* 0 1 */
|
20458 | 5, /* 1 -1 */
|
20459 | 1, /* 1 0 */
|
20460 | 3 /* 1 1 */
|
20461 | ];
|
20462 |
|
20463 | var jsf = getJSF(coeffs[a], coeffs[b]);
|
20464 | max = Math.max(jsf[0].length, max);
|
20465 | naf[a] = new Array(max);
|
20466 | naf[b] = new Array(max);
|
20467 | for (var j = 0; j < max; j++) {
|
20468 | var ja = jsf[0][j] | 0;
|
20469 | var jb = jsf[1][j] | 0;
|
20470 |
|
20471 | naf[a][j] = index[(ja + 1) * 3 + (jb + 1)];
|
20472 | naf[b][j] = 0;
|
20473 | wnd[a] = comb;
|
20474 | }
|
20475 | }
|
20476 |
|
20477 | var acc = this.jpoint(null, null, null);
|
20478 | var tmp = this._wnafT4;
|
20479 | for (var i = max; i >= 0; i--) {
|
20480 | var k = 0;
|
20481 |
|
20482 | while (i >= 0) {
|
20483 | var zero = true;
|
20484 | for (var j = 0; j < len; j++) {
|
20485 | tmp[j] = naf[j][i] | 0;
|
20486 | if (tmp[j] !== 0)
|
20487 | zero = false;
|
20488 | }
|
20489 | if (!zero)
|
20490 | break;
|
20491 | k++;
|
20492 | i--;
|
20493 | }
|
20494 | if (i >= 0)
|
20495 | k++;
|
20496 | acc = acc.dblp(k);
|
20497 | if (i < 0)
|
20498 | break;
|
20499 |
|
20500 | for (var j = 0; j < len; j++) {
|
20501 | var z = tmp[j];
|
20502 | var p;
|
20503 | if (z === 0)
|
20504 | continue;
|
20505 | else if (z > 0)
|
20506 | p = wnd[j][(z - 1) >> 1];
|
20507 | else if (z < 0)
|
20508 | p = wnd[j][(-z - 1) >> 1].neg();
|
20509 |
|
20510 | if (p.type === 'affine')
|
20511 | acc = acc.mixedAdd(p);
|
20512 | else
|
20513 | acc = acc.add(p);
|
20514 | }
|
20515 | }
|
20516 | // Zeroify references
|
20517 | for (var i = 0; i < len; i++)
|
20518 | wnd[i] = null;
|
20519 |
|
20520 | if (jacobianResult)
|
20521 | return acc;
|
20522 | else
|
20523 | return acc.toP();
|
20524 | };
|
20525 |
|
20526 | function BasePoint(curve, type) {
|
20527 | this.curve = curve;
|
20528 | this.type = type;
|
20529 | this.precomputed = null;
|
20530 | }
|
20531 | BaseCurve.BasePoint = BasePoint;
|
20532 |
|
20533 | BasePoint.prototype.eq = function eq(/*other*/) {
|
20534 | throw new Error('Not implemented');
|
20535 | };
|
20536 |
|
20537 | BasePoint.prototype.validate = function validate() {
|
20538 | return this.curve.validate(this);
|
20539 | };
|
20540 |
|
20541 | BaseCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
|
20542 | bytes = utils.toArray(bytes, enc);
|
20543 |
|
20544 | var len = this.p.byteLength();
|
20545 |
|
20546 | // uncompressed, hybrid-odd, hybrid-even
|
20547 | if ((bytes[0] === 0x04 || bytes[0] === 0x06 || bytes[0] === 0x07) &&
|
20548 | bytes.length - 1 === 2 * len) {
|
20549 | if (bytes[0] === 0x06)
|
20550 | assert(bytes[bytes.length - 1] % 2 === 0);
|
20551 | else if (bytes[0] === 0x07)
|
20552 | assert(bytes[bytes.length - 1] % 2 === 1);
|
20553 |
|
20554 | var res = this.point(bytes.slice(1, 1 + len),
|
20555 | bytes.slice(1 + len, 1 + 2 * len));
|
20556 |
|
20557 | return res;
|
20558 | } else if ((bytes[0] === 0x02 || bytes[0] === 0x03) &&
|
20559 | bytes.length - 1 === len) {
|
20560 | return this.pointFromX(bytes.slice(1, 1 + len), bytes[0] === 0x03);
|
20561 | }
|
20562 | throw new Error('Unknown point format');
|
20563 | };
|
20564 |
|
20565 | BasePoint.prototype.encodeCompressed = function encodeCompressed(enc) {
|
20566 | return this.encode(enc, true);
|
20567 | };
|
20568 |
|
20569 | BasePoint.prototype._encode = function _encode(compact) {
|
20570 | var len = this.curve.p.byteLength();
|
20571 | var x = this.getX().toArray('be', len);
|
20572 |
|
20573 | if (compact)
|
20574 | return [ this.getY().isEven() ? 0x02 : 0x03 ].concat(x);
|
20575 |
|
20576 | return [ 0x04 ].concat(x, this.getY().toArray('be', len)) ;
|
20577 | };
|
20578 |
|
20579 | BasePoint.prototype.encode = function encode(enc, compact) {
|
20580 | return utils.encode(this._encode(compact), enc);
|
20581 | };
|
20582 |
|
20583 | BasePoint.prototype.precompute = function precompute(power) {
|
20584 | if (this.precomputed)
|
20585 | return this;
|
20586 |
|
20587 | var precomputed = {
|
20588 | doubles: null,
|
20589 | naf: null,
|
20590 | beta: null
|
20591 | };
|
20592 | precomputed.naf = this._getNAFPoints(8);
|
20593 | precomputed.doubles = this._getDoubles(4, power);
|
20594 | precomputed.beta = this._getBeta();
|
20595 | this.precomputed = precomputed;
|
20596 |
|
20597 | return this;
|
20598 | };
|
20599 |
|
20600 | BasePoint.prototype._hasDoubles = function _hasDoubles(k) {
|
20601 | if (!this.precomputed)
|
20602 | return false;
|
20603 |
|
20604 | var doubles = this.precomputed.doubles;
|
20605 | if (!doubles)
|
20606 | return false;
|
20607 |
|
20608 | return doubles.points.length >= Math.ceil((k.bitLength() + 1) / doubles.step);
|
20609 | };
|
20610 |
|
20611 | BasePoint.prototype._getDoubles = function _getDoubles(step, power) {
|
20612 | if (this.precomputed && this.precomputed.doubles)
|
20613 | return this.precomputed.doubles;
|
20614 |
|
20615 | var doubles = [ this ];
|
20616 | var acc = this;
|
20617 | for (var i = 0; i < power; i += step) {
|
20618 | for (var j = 0; j < step; j++)
|
20619 | acc = acc.dbl();
|
20620 | doubles.push(acc);
|
20621 | }
|
20622 | return {
|
20623 | step: step,
|
20624 | points: doubles
|
20625 | };
|
20626 | };
|
20627 |
|
20628 | BasePoint.prototype._getNAFPoints = function _getNAFPoints(wnd) {
|
20629 | if (this.precomputed && this.precomputed.naf)
|
20630 | return this.precomputed.naf;
|
20631 |
|
20632 | var res = [ this ];
|
20633 | var max = (1 << wnd) - 1;
|
20634 | var dbl = max === 1 ? null : this.dbl();
|
20635 | for (var i = 1; i < max; i++)
|
20636 | res[i] = res[i - 1].add(dbl);
|
20637 | return {
|
20638 | wnd: wnd,
|
20639 | points: res
|
20640 | };
|
20641 | };
|
20642 |
|
20643 | BasePoint.prototype._getBeta = function _getBeta() {
|
20644 | return null;
|
20645 | };
|
20646 |
|
20647 | BasePoint.prototype.dblp = function dblp(k) {
|
20648 | var r = this;
|
20649 | for (var i = 0; i < k; i++)
|
20650 | r = r.dbl();
|
20651 | return r;
|
20652 | };
|
20653 |
|
20654 |
|
20655 | /***/ }),
|
20656 | /* 87 */
|
20657 | /***/ (function(module, exports, __webpack_require__) {
|
20658 |
|
20659 | "use strict";
|
20660 |
|
20661 |
|
20662 | var curve = __webpack_require__(15);
|
20663 | var elliptic = __webpack_require__(5);
|
20664 | var BN = __webpack_require__(3);
|
20665 | var inherits = __webpack_require__(16);
|
20666 | var Base = curve.base;
|
20667 |
|
20668 | var assert = elliptic.utils.assert;
|
20669 |
|
20670 | function ShortCurve(conf) {
|
20671 | Base.call(this, 'short', conf);
|
20672 |
|
20673 | this.a = new BN(conf.a, 16).toRed(this.red);
|
20674 | this.b = new BN(conf.b, 16).toRed(this.red);
|
20675 | this.tinv = this.two.redInvm();
|
20676 |
|
20677 | this.zeroA = this.a.fromRed().cmpn(0) === 0;
|
20678 | this.threeA = this.a.fromRed().sub(this.p).cmpn(-3) === 0;
|
20679 |
|
20680 | // If the curve is endomorphic, precalculate beta and lambda
|
20681 | this.endo = this._getEndomorphism(conf);
|
20682 | this._endoWnafT1 = new Array(4);
|
20683 | this._endoWnafT2 = new Array(4);
|
20684 | }
|
20685 | inherits(ShortCurve, Base);
|
20686 | module.exports = ShortCurve;
|
20687 |
|
20688 | ShortCurve.prototype._getEndomorphism = function _getEndomorphism(conf) {
|
20689 | // No efficient endomorphism
|
20690 | if (!this.zeroA || !this.g || !this.n || this.p.modn(3) !== 1)
|
20691 | return;
|
20692 |
|
20693 | // Compute beta and lambda, that lambda * P = (beta * Px; Py)
|
20694 | var beta;
|
20695 | var lambda;
|
20696 | if (conf.beta) {
|
20697 | beta = new BN(conf.beta, 16).toRed(this.red);
|
20698 | } else {
|
20699 | var betas = this._getEndoRoots(this.p);
|
20700 | // Choose the smallest beta
|
20701 | beta = betas[0].cmp(betas[1]) < 0 ? betas[0] : betas[1];
|
20702 | beta = beta.toRed(this.red);
|
20703 | }
|
20704 | if (conf.lambda) {
|
20705 | lambda = new BN(conf.lambda, 16);
|
20706 | } else {
|
20707 | // Choose the lambda that is matching selected beta
|
20708 | var lambdas = this._getEndoRoots(this.n);
|
20709 | if (this.g.mul(lambdas[0]).x.cmp(this.g.x.redMul(beta)) === 0) {
|
20710 | lambda = lambdas[0];
|
20711 | } else {
|
20712 | lambda = lambdas[1];
|
20713 | assert(this.g.mul(lambda).x.cmp(this.g.x.redMul(beta)) === 0);
|
20714 | }
|
20715 | }
|
20716 |
|
20717 | // Get basis vectors, used for balanced length-two representation
|
20718 | var basis;
|
20719 | if (conf.basis) {
|
20720 | basis = conf.basis.map(function(vec) {
|
20721 | return {
|
20722 | a: new BN(vec.a, 16),
|
20723 | b: new BN(vec.b, 16)
|
20724 | };
|
20725 | });
|
20726 | } else {
|
20727 | basis = this._getEndoBasis(lambda);
|
20728 | }
|
20729 |
|
20730 | return {
|
20731 | beta: beta,
|
20732 | lambda: lambda,
|
20733 | basis: basis
|
20734 | };
|
20735 | };
|
20736 |
|
20737 | ShortCurve.prototype._getEndoRoots = function _getEndoRoots(num) {
|
20738 | // Find roots of for x^2 + x + 1 in F
|
20739 | // Root = (-1 +- Sqrt(-3)) / 2
|
20740 | //
|
20741 | var red = num === this.p ? this.red : BN.mont(num);
|
20742 | var tinv = new BN(2).toRed(red).redInvm();
|
20743 | var ntinv = tinv.redNeg();
|
20744 |
|
20745 | var s = new BN(3).toRed(red).redNeg().redSqrt().redMul(tinv);
|
20746 |
|
20747 | var l1 = ntinv.redAdd(s).fromRed();
|
20748 | var l2 = ntinv.redSub(s).fromRed();
|
20749 | return [ l1, l2 ];
|
20750 | };
|
20751 |
|
20752 | ShortCurve.prototype._getEndoBasis = function _getEndoBasis(lambda) {
|
20753 | // aprxSqrt >= sqrt(this.n)
|
20754 | var aprxSqrt = this.n.ushrn(Math.floor(this.n.bitLength() / 2));
|
20755 |
|
20756 | // 3.74
|
20757 | // Run EGCD, until r(L + 1) < aprxSqrt
|
20758 | var u = lambda;
|
20759 | var v = this.n.clone();
|
20760 | var x1 = new BN(1);
|
20761 | var y1 = new BN(0);
|
20762 | var x2 = new BN(0);
|
20763 | var y2 = new BN(1);
|
20764 |
|
20765 | // NOTE: all vectors are roots of: a + b * lambda = 0 (mod n)
|
20766 | var a0;
|
20767 | var b0;
|
20768 | // First vector
|
20769 | var a1;
|
20770 | var b1;
|
20771 | // Second vector
|
20772 | var a2;
|
20773 | var b2;
|
20774 |
|
20775 | var prevR;
|
20776 | var i = 0;
|
20777 | var r;
|
20778 | var x;
|
20779 | while (u.cmpn(0) !== 0) {
|
20780 | var q = v.div(u);
|
20781 | r = v.sub(q.mul(u));
|
20782 | x = x2.sub(q.mul(x1));
|
20783 | var y = y2.sub(q.mul(y1));
|
20784 |
|
20785 | if (!a1 && r.cmp(aprxSqrt) < 0) {
|
20786 | a0 = prevR.neg();
|
20787 | b0 = x1;
|
20788 | a1 = r.neg();
|
20789 | b1 = x;
|
20790 | } else if (a1 && ++i === 2) {
|
20791 | break;
|
20792 | }
|
20793 | prevR = r;
|
20794 |
|
20795 | v = u;
|
20796 | u = r;
|
20797 | x2 = x1;
|
20798 | x1 = x;
|
20799 | y2 = y1;
|
20800 | y1 = y;
|
20801 | }
|
20802 | a2 = r.neg();
|
20803 | b2 = x;
|
20804 |
|
20805 | var len1 = a1.sqr().add(b1.sqr());
|
20806 | var len2 = a2.sqr().add(b2.sqr());
|
20807 | if (len2.cmp(len1) >= 0) {
|
20808 | a2 = a0;
|
20809 | b2 = b0;
|
20810 | }
|
20811 |
|
20812 | // Normalize signs
|
20813 | if (a1.negative) {
|
20814 | a1 = a1.neg();
|
20815 | b1 = b1.neg();
|
20816 | }
|
20817 | if (a2.negative) {
|
20818 | a2 = a2.neg();
|
20819 | b2 = b2.neg();
|
20820 | }
|
20821 |
|
20822 | return [
|
20823 | { a: a1, b: b1 },
|
20824 | { a: a2, b: b2 }
|
20825 | ];
|
20826 | };
|
20827 |
|
20828 | ShortCurve.prototype._endoSplit = function _endoSplit(k) {
|
20829 | var basis = this.endo.basis;
|
20830 | var v1 = basis[0];
|
20831 | var v2 = basis[1];
|
20832 |
|
20833 | var c1 = v2.b.mul(k).divRound(this.n);
|
20834 | var c2 = v1.b.neg().mul(k).divRound(this.n);
|
20835 |
|
20836 | var p1 = c1.mul(v1.a);
|
20837 | var p2 = c2.mul(v2.a);
|
20838 | var q1 = c1.mul(v1.b);
|
20839 | var q2 = c2.mul(v2.b);
|
20840 |
|
20841 | // Calculate answer
|
20842 | var k1 = k.sub(p1).sub(p2);
|
20843 | var k2 = q1.add(q2).neg();
|
20844 | return { k1: k1, k2: k2 };
|
20845 | };
|
20846 |
|
20847 | ShortCurve.prototype.pointFromX = function pointFromX(x, odd) {
|
20848 | x = new BN(x, 16);
|
20849 | if (!x.red)
|
20850 | x = x.toRed(this.red);
|
20851 |
|
20852 | var y2 = x.redSqr().redMul(x).redIAdd(x.redMul(this.a)).redIAdd(this.b);
|
20853 | var y = y2.redSqrt();
|
20854 | if (y.redSqr().redSub(y2).cmp(this.zero) !== 0)
|
20855 | throw new Error('invalid point');
|
20856 |
|
20857 | // XXX Is there any way to tell if the number is odd without converting it
|
20858 | // to non-red form?
|
20859 | var isOdd = y.fromRed().isOdd();
|
20860 | if (odd && !isOdd || !odd && isOdd)
|
20861 | y = y.redNeg();
|
20862 |
|
20863 | return this.point(x, y);
|
20864 | };
|
20865 |
|
20866 | ShortCurve.prototype.validate = function validate(point) {
|
20867 | if (point.inf)
|
20868 | return true;
|
20869 |
|
20870 | var x = point.x;
|
20871 | var y = point.y;
|
20872 |
|
20873 | var ax = this.a.redMul(x);
|
20874 | var rhs = x.redSqr().redMul(x).redIAdd(ax).redIAdd(this.b);
|
20875 | return y.redSqr().redISub(rhs).cmpn(0) === 0;
|
20876 | };
|
20877 |
|
20878 | ShortCurve.prototype._endoWnafMulAdd =
|
20879 | function _endoWnafMulAdd(points, coeffs, jacobianResult) {
|
20880 | var npoints = this._endoWnafT1;
|
20881 | var ncoeffs = this._endoWnafT2;
|
20882 | for (var i = 0; i < points.length; i++) {
|
20883 | var split = this._endoSplit(coeffs[i]);
|
20884 | var p = points[i];
|
20885 | var beta = p._getBeta();
|
20886 |
|
20887 | if (split.k1.negative) {
|
20888 | split.k1.ineg();
|
20889 | p = p.neg(true);
|
20890 | }
|
20891 | if (split.k2.negative) {
|
20892 | split.k2.ineg();
|
20893 | beta = beta.neg(true);
|
20894 | }
|
20895 |
|
20896 | npoints[i * 2] = p;
|
20897 | npoints[i * 2 + 1] = beta;
|
20898 | ncoeffs[i * 2] = split.k1;
|
20899 | ncoeffs[i * 2 + 1] = split.k2;
|
20900 | }
|
20901 | var res = this._wnafMulAdd(1, npoints, ncoeffs, i * 2, jacobianResult);
|
20902 |
|
20903 | // Clean-up references to points and coefficients
|
20904 | for (var j = 0; j < i * 2; j++) {
|
20905 | npoints[j] = null;
|
20906 | ncoeffs[j] = null;
|
20907 | }
|
20908 | return res;
|
20909 | };
|
20910 |
|
20911 | function Point(curve, x, y, isRed) {
|
20912 | Base.BasePoint.call(this, curve, 'affine');
|
20913 | if (x === null && y === null) {
|
20914 | this.x = null;
|
20915 | this.y = null;
|
20916 | this.inf = true;
|
20917 | } else {
|
20918 | this.x = new BN(x, 16);
|
20919 | this.y = new BN(y, 16);
|
20920 | // Force redgomery representation when loading from JSON
|
20921 | if (isRed) {
|
20922 | this.x.forceRed(this.curve.red);
|
20923 | this.y.forceRed(this.curve.red);
|
20924 | }
|
20925 | if (!this.x.red)
|
20926 | this.x = this.x.toRed(this.curve.red);
|
20927 | if (!this.y.red)
|
20928 | this.y = this.y.toRed(this.curve.red);
|
20929 | this.inf = false;
|
20930 | }
|
20931 | }
|
20932 | inherits(Point, Base.BasePoint);
|
20933 |
|
20934 | ShortCurve.prototype.point = function point(x, y, isRed) {
|
20935 | return new Point(this, x, y, isRed);
|
20936 | };
|
20937 |
|
20938 | ShortCurve.prototype.pointFromJSON = function pointFromJSON(obj, red) {
|
20939 | return Point.fromJSON(this, obj, red);
|
20940 | };
|
20941 |
|
20942 | Point.prototype._getBeta = function _getBeta() {
|
20943 | if (!this.curve.endo)
|
20944 | return;
|
20945 |
|
20946 | var pre = this.precomputed;
|
20947 | if (pre && pre.beta)
|
20948 | return pre.beta;
|
20949 |
|
20950 | var beta = this.curve.point(this.x.redMul(this.curve.endo.beta), this.y);
|
20951 | if (pre) {
|
20952 | var curve = this.curve;
|
20953 | var endoMul = function(p) {
|
20954 | return curve.point(p.x.redMul(curve.endo.beta), p.y);
|
20955 | };
|
20956 | pre.beta = beta;
|
20957 | beta.precomputed = {
|
20958 | beta: null,
|
20959 | naf: pre.naf && {
|
20960 | wnd: pre.naf.wnd,
|
20961 | points: pre.naf.points.map(endoMul)
|
20962 | },
|
20963 | doubles: pre.doubles && {
|
20964 | step: pre.doubles.step,
|
20965 | points: pre.doubles.points.map(endoMul)
|
20966 | }
|
20967 | };
|
20968 | }
|
20969 | return beta;
|
20970 | };
|
20971 |
|
20972 | Point.prototype.toJSON = function toJSON() {
|
20973 | if (!this.precomputed)
|
20974 | return [ this.x, this.y ];
|
20975 |
|
20976 | return [ this.x, this.y, this.precomputed && {
|
20977 | doubles: this.precomputed.doubles && {
|
20978 | step: this.precomputed.doubles.step,
|
20979 | points: this.precomputed.doubles.points.slice(1)
|
20980 | },
|
20981 | naf: this.precomputed.naf && {
|
20982 | wnd: this.precomputed.naf.wnd,
|
20983 | points: this.precomputed.naf.points.slice(1)
|
20984 | }
|
20985 | } ];
|
20986 | };
|
20987 |
|
20988 | Point.fromJSON = function fromJSON(curve, obj, red) {
|
20989 | if (typeof obj === 'string')
|
20990 | obj = JSON.parse(obj);
|
20991 | var res = curve.point(obj[0], obj[1], red);
|
20992 | if (!obj[2])
|
20993 | return res;
|
20994 |
|
20995 | function obj2point(obj) {
|
20996 | return curve.point(obj[0], obj[1], red);
|
20997 | }
|
20998 |
|
20999 | var pre = obj[2];
|
21000 | res.precomputed = {
|
21001 | beta: null,
|
21002 | doubles: pre.doubles && {
|
21003 | step: pre.doubles.step,
|
21004 | points: [ res ].concat(pre.doubles.points.map(obj2point))
|
21005 | },
|
21006 | naf: pre.naf && {
|
21007 | wnd: pre.naf.wnd,
|
21008 | points: [ res ].concat(pre.naf.points.map(obj2point))
|
21009 | }
|
21010 | };
|
21011 | return res;
|
21012 | };
|
21013 |
|
21014 | Point.prototype.inspect = function inspect() {
|
21015 | if (this.isInfinity())
|
21016 | return '<EC Point Infinity>';
|
21017 | return '<EC Point x: ' + this.x.fromRed().toString(16, 2) +
|
21018 | ' y: ' + this.y.fromRed().toString(16, 2) + '>';
|
21019 | };
|
21020 |
|
21021 | Point.prototype.isInfinity = function isInfinity() {
|
21022 | return this.inf;
|
21023 | };
|
21024 |
|
21025 | Point.prototype.add = function add(p) {
|
21026 | // O + P = P
|
21027 | if (this.inf)
|
21028 | return p;
|
21029 |
|
21030 | // P + O = P
|
21031 | if (p.inf)
|
21032 | return this;
|
21033 |
|
21034 | // P + P = 2P
|
21035 | if (this.eq(p))
|
21036 | return this.dbl();
|
21037 |
|
21038 | // P + (-P) = O
|
21039 | if (this.neg().eq(p))
|
21040 | return this.curve.point(null, null);
|
21041 |
|
21042 | // P + Q = O
|
21043 | if (this.x.cmp(p.x) === 0)
|
21044 | return this.curve.point(null, null);
|
21045 |
|
21046 | var c = this.y.redSub(p.y);
|
21047 | if (c.cmpn(0) !== 0)
|
21048 | c = c.redMul(this.x.redSub(p.x).redInvm());
|
21049 | var nx = c.redSqr().redISub(this.x).redISub(p.x);
|
21050 | var ny = c.redMul(this.x.redSub(nx)).redISub(this.y);
|
21051 | return this.curve.point(nx, ny);
|
21052 | };
|
21053 |
|
21054 | Point.prototype.dbl = function dbl() {
|
21055 | if (this.inf)
|
21056 | return this;
|
21057 |
|
21058 | // 2P = O
|
21059 | var ys1 = this.y.redAdd(this.y);
|
21060 | if (ys1.cmpn(0) === 0)
|
21061 | return this.curve.point(null, null);
|
21062 |
|
21063 | var a = this.curve.a;
|
21064 |
|
21065 | var x2 = this.x.redSqr();
|
21066 | var dyinv = ys1.redInvm();
|
21067 | var c = x2.redAdd(x2).redIAdd(x2).redIAdd(a).redMul(dyinv);
|
21068 |
|
21069 | var nx = c.redSqr().redISub(this.x.redAdd(this.x));
|
21070 | var ny = c.redMul(this.x.redSub(nx)).redISub(this.y);
|
21071 | return this.curve.point(nx, ny);
|
21072 | };
|
21073 |
|
21074 | Point.prototype.getX = function getX() {
|
21075 | return this.x.fromRed();
|
21076 | };
|
21077 |
|
21078 | Point.prototype.getY = function getY() {
|
21079 | return this.y.fromRed();
|
21080 | };
|
21081 |
|
21082 | Point.prototype.mul = function mul(k) {
|
21083 | k = new BN(k, 16);
|
21084 |
|
21085 | if (this._hasDoubles(k))
|
21086 | return this.curve._fixedNafMul(this, k);
|
21087 | else if (this.curve.endo)
|
21088 | return this.curve._endoWnafMulAdd([ this ], [ k ]);
|
21089 | else
|
21090 | return this.curve._wnafMul(this, k);
|
21091 | };
|
21092 |
|
21093 | Point.prototype.mulAdd = function mulAdd(k1, p2, k2) {
|
21094 | var points = [ this, p2 ];
|
21095 | var coeffs = [ k1, k2 ];
|
21096 | if (this.curve.endo)
|
21097 | return this.curve._endoWnafMulAdd(points, coeffs);
|
21098 | else
|
21099 | return this.curve._wnafMulAdd(1, points, coeffs, 2);
|
21100 | };
|
21101 |
|
21102 | Point.prototype.jmulAdd = function jmulAdd(k1, p2, k2) {
|
21103 | var points = [ this, p2 ];
|
21104 | var coeffs = [ k1, k2 ];
|
21105 | if (this.curve.endo)
|
21106 | return this.curve._endoWnafMulAdd(points, coeffs, true);
|
21107 | else
|
21108 | return this.curve._wnafMulAdd(1, points, coeffs, 2, true);
|
21109 | };
|
21110 |
|
21111 | Point.prototype.eq = function eq(p) {
|
21112 | return this === p ||
|
21113 | this.inf === p.inf &&
|
21114 | (this.inf || this.x.cmp(p.x) === 0 && this.y.cmp(p.y) === 0);
|
21115 | };
|
21116 |
|
21117 | Point.prototype.neg = function neg(_precompute) {
|
21118 | if (this.inf)
|
21119 | return this;
|
21120 |
|
21121 | var res = this.curve.point(this.x, this.y.redNeg());
|
21122 | if (_precompute && this.precomputed) {
|
21123 | var pre = this.precomputed;
|
21124 | var negate = function(p) {
|
21125 | return p.neg();
|
21126 | };
|
21127 | res.precomputed = {
|
21128 | naf: pre.naf && {
|
21129 | wnd: pre.naf.wnd,
|
21130 | points: pre.naf.points.map(negate)
|
21131 | },
|
21132 | doubles: pre.doubles && {
|
21133 | step: pre.doubles.step,
|
21134 | points: pre.doubles.points.map(negate)
|
21135 | }
|
21136 | };
|
21137 | }
|
21138 | return res;
|
21139 | };
|
21140 |
|
21141 | Point.prototype.toJ = function toJ() {
|
21142 | if (this.inf)
|
21143 | return this.curve.jpoint(null, null, null);
|
21144 |
|
21145 | var res = this.curve.jpoint(this.x, this.y, this.curve.one);
|
21146 | return res;
|
21147 | };
|
21148 |
|
21149 | function JPoint(curve, x, y, z) {
|
21150 | Base.BasePoint.call(this, curve, 'jacobian');
|
21151 | if (x === null && y === null && z === null) {
|
21152 | this.x = this.curve.one;
|
21153 | this.y = this.curve.one;
|
21154 | this.z = new BN(0);
|
21155 | } else {
|
21156 | this.x = new BN(x, 16);
|
21157 | this.y = new BN(y, 16);
|
21158 | this.z = new BN(z, 16);
|
21159 | }
|
21160 | if (!this.x.red)
|
21161 | this.x = this.x.toRed(this.curve.red);
|
21162 | if (!this.y.red)
|
21163 | this.y = this.y.toRed(this.curve.red);
|
21164 | if (!this.z.red)
|
21165 | this.z = this.z.toRed(this.curve.red);
|
21166 |
|
21167 | this.zOne = this.z === this.curve.one;
|
21168 | }
|
21169 | inherits(JPoint, Base.BasePoint);
|
21170 |
|
21171 | ShortCurve.prototype.jpoint = function jpoint(x, y, z) {
|
21172 | return new JPoint(this, x, y, z);
|
21173 | };
|
21174 |
|
21175 | JPoint.prototype.toP = function toP() {
|
21176 | if (this.isInfinity())
|
21177 | return this.curve.point(null, null);
|
21178 |
|
21179 | var zinv = this.z.redInvm();
|
21180 | var zinv2 = zinv.redSqr();
|
21181 | var ax = this.x.redMul(zinv2);
|
21182 | var ay = this.y.redMul(zinv2).redMul(zinv);
|
21183 |
|
21184 | return this.curve.point(ax, ay);
|
21185 | };
|
21186 |
|
21187 | JPoint.prototype.neg = function neg() {
|
21188 | return this.curve.jpoint(this.x, this.y.redNeg(), this.z);
|
21189 | };
|
21190 |
|
21191 | JPoint.prototype.add = function add(p) {
|
21192 | // O + P = P
|
21193 | if (this.isInfinity())
|
21194 | return p;
|
21195 |
|
21196 | // P + O = P
|
21197 | if (p.isInfinity())
|
21198 | return this;
|
21199 |
|
21200 | // 12M + 4S + 7A
|
21201 | var pz2 = p.z.redSqr();
|
21202 | var z2 = this.z.redSqr();
|
21203 | var u1 = this.x.redMul(pz2);
|
21204 | var u2 = p.x.redMul(z2);
|
21205 | var s1 = this.y.redMul(pz2.redMul(p.z));
|
21206 | var s2 = p.y.redMul(z2.redMul(this.z));
|
21207 |
|
21208 | var h = u1.redSub(u2);
|
21209 | var r = s1.redSub(s2);
|
21210 | if (h.cmpn(0) === 0) {
|
21211 | if (r.cmpn(0) !== 0)
|
21212 | return this.curve.jpoint(null, null, null);
|
21213 | else
|
21214 | return this.dbl();
|
21215 | }
|
21216 |
|
21217 | var h2 = h.redSqr();
|
21218 | var h3 = h2.redMul(h);
|
21219 | var v = u1.redMul(h2);
|
21220 |
|
21221 | var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v);
|
21222 | var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));
|
21223 | var nz = this.z.redMul(p.z).redMul(h);
|
21224 |
|
21225 | return this.curve.jpoint(nx, ny, nz);
|
21226 | };
|
21227 |
|
21228 | JPoint.prototype.mixedAdd = function mixedAdd(p) {
|
21229 | // O + P = P
|
21230 | if (this.isInfinity())
|
21231 | return p.toJ();
|
21232 |
|
21233 | // P + O = P
|
21234 | if (p.isInfinity())
|
21235 | return this;
|
21236 |
|
21237 | // 8M + 3S + 7A
|
21238 | var z2 = this.z.redSqr();
|
21239 | var u1 = this.x;
|
21240 | var u2 = p.x.redMul(z2);
|
21241 | var s1 = this.y;
|
21242 | var s2 = p.y.redMul(z2).redMul(this.z);
|
21243 |
|
21244 | var h = u1.redSub(u2);
|
21245 | var r = s1.redSub(s2);
|
21246 | if (h.cmpn(0) === 0) {
|
21247 | if (r.cmpn(0) !== 0)
|
21248 | return this.curve.jpoint(null, null, null);
|
21249 | else
|
21250 | return this.dbl();
|
21251 | }
|
21252 |
|
21253 | var h2 = h.redSqr();
|
21254 | var h3 = h2.redMul(h);
|
21255 | var v = u1.redMul(h2);
|
21256 |
|
21257 | var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v);
|
21258 | var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));
|
21259 | var nz = this.z.redMul(h);
|
21260 |
|
21261 | return this.curve.jpoint(nx, ny, nz);
|
21262 | };
|
21263 |
|
21264 | JPoint.prototype.dblp = function dblp(pow) {
|
21265 | if (pow === 0)
|
21266 | return this;
|
21267 | if (this.isInfinity())
|
21268 | return this;
|
21269 | if (!pow)
|
21270 | return this.dbl();
|
21271 |
|
21272 | if (this.curve.zeroA || this.curve.threeA) {
|
21273 | var r = this;
|
21274 | for (var i = 0; i < pow; i++)
|
21275 | r = r.dbl();
|
21276 | return r;
|
21277 | }
|
21278 |
|
21279 | // 1M + 2S + 1A + N * (4S + 5M + 8A)
|
21280 | // N = 1 => 6M + 6S + 9A
|
21281 | var a = this.curve.a;
|
21282 | var tinv = this.curve.tinv;
|
21283 |
|
21284 | var jx = this.x;
|
21285 | var jy = this.y;
|
21286 | var jz = this.z;
|
21287 | var jz4 = jz.redSqr().redSqr();
|
21288 |
|
21289 | // Reuse results
|
21290 | var jyd = jy.redAdd(jy);
|
21291 | for (var i = 0; i < pow; i++) {
|
21292 | var jx2 = jx.redSqr();
|
21293 | var jyd2 = jyd.redSqr();
|
21294 | var jyd4 = jyd2.redSqr();
|
21295 | var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4));
|
21296 |
|
21297 | var t1 = jx.redMul(jyd2);
|
21298 | var nx = c.redSqr().redISub(t1.redAdd(t1));
|
21299 | var t2 = t1.redISub(nx);
|
21300 | var dny = c.redMul(t2);
|
21301 | dny = dny.redIAdd(dny).redISub(jyd4);
|
21302 | var nz = jyd.redMul(jz);
|
21303 | if (i + 1 < pow)
|
21304 | jz4 = jz4.redMul(jyd4);
|
21305 |
|
21306 | jx = nx;
|
21307 | jz = nz;
|
21308 | jyd = dny;
|
21309 | }
|
21310 |
|
21311 | return this.curve.jpoint(jx, jyd.redMul(tinv), jz);
|
21312 | };
|
21313 |
|
21314 | JPoint.prototype.dbl = function dbl() {
|
21315 | if (this.isInfinity())
|
21316 | return this;
|
21317 |
|
21318 | if (this.curve.zeroA)
|
21319 | return this._zeroDbl();
|
21320 | else if (this.curve.threeA)
|
21321 | return this._threeDbl();
|
21322 | else
|
21323 | return this._dbl();
|
21324 | };
|
21325 |
|
21326 | JPoint.prototype._zeroDbl = function _zeroDbl() {
|
21327 | var nx;
|
21328 | var ny;
|
21329 | var nz;
|
21330 | // Z = 1
|
21331 | if (this.zOne) {
|
21332 | // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html
|
21333 | // #doubling-mdbl-2007-bl
|
21334 | // 1M + 5S + 14A
|
21335 |
|
21336 | // XX = X1^2
|
21337 | var xx = this.x.redSqr();
|
21338 | // YY = Y1^2
|
21339 | var yy = this.y.redSqr();
|
21340 | // YYYY = YY^2
|
21341 | var yyyy = yy.redSqr();
|
21342 | // S = 2 * ((X1 + YY)^2 - XX - YYYY)
|
21343 | var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
|
21344 | s = s.redIAdd(s);
|
21345 | // M = 3 * XX + a; a = 0
|
21346 | var m = xx.redAdd(xx).redIAdd(xx);
|
21347 | // T = M ^ 2 - 2*S
|
21348 | var t = m.redSqr().redISub(s).redISub(s);
|
21349 |
|
21350 | // 8 * YYYY
|
21351 | var yyyy8 = yyyy.redIAdd(yyyy);
|
21352 | yyyy8 = yyyy8.redIAdd(yyyy8);
|
21353 | yyyy8 = yyyy8.redIAdd(yyyy8);
|
21354 |
|
21355 | // X3 = T
|
21356 | nx = t;
|
21357 | // Y3 = M * (S - T) - 8 * YYYY
|
21358 | ny = m.redMul(s.redISub(t)).redISub(yyyy8);
|
21359 | // Z3 = 2*Y1
|
21360 | nz = this.y.redAdd(this.y);
|
21361 | } else {
|
21362 | // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html
|
21363 | // #doubling-dbl-2009-l
|
21364 | // 2M + 5S + 13A
|
21365 |
|
21366 | // A = X1^2
|
21367 | var a = this.x.redSqr();
|
21368 | // B = Y1^2
|
21369 | var b = this.y.redSqr();
|
21370 | // C = B^2
|
21371 | var c = b.redSqr();
|
21372 | // D = 2 * ((X1 + B)^2 - A - C)
|
21373 | var d = this.x.redAdd(b).redSqr().redISub(a).redISub(c);
|
21374 | d = d.redIAdd(d);
|
21375 | // E = 3 * A
|
21376 | var e = a.redAdd(a).redIAdd(a);
|
21377 | // F = E^2
|
21378 | var f = e.redSqr();
|
21379 |
|
21380 | // 8 * C
|
21381 | var c8 = c.redIAdd(c);
|
21382 | c8 = c8.redIAdd(c8);
|
21383 | c8 = c8.redIAdd(c8);
|
21384 |
|
21385 | // X3 = F - 2 * D
|
21386 | nx = f.redISub(d).redISub(d);
|
21387 | // Y3 = E * (D - X3) - 8 * C
|
21388 | ny = e.redMul(d.redISub(nx)).redISub(c8);
|
21389 | // Z3 = 2 * Y1 * Z1
|
21390 | nz = this.y.redMul(this.z);
|
21391 | nz = nz.redIAdd(nz);
|
21392 | }
|
21393 |
|
21394 | return this.curve.jpoint(nx, ny, nz);
|
21395 | };
|
21396 |
|
21397 | JPoint.prototype._threeDbl = function _threeDbl() {
|
21398 | var nx;
|
21399 | var ny;
|
21400 | var nz;
|
21401 | // Z = 1
|
21402 | if (this.zOne) {
|
21403 | // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html
|
21404 | // #doubling-mdbl-2007-bl
|
21405 | // 1M + 5S + 15A
|
21406 |
|
21407 | // XX = X1^2
|
21408 | var xx = this.x.redSqr();
|
21409 | // YY = Y1^2
|
21410 | var yy = this.y.redSqr();
|
21411 | // YYYY = YY^2
|
21412 | var yyyy = yy.redSqr();
|
21413 | // S = 2 * ((X1 + YY)^2 - XX - YYYY)
|
21414 | var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
|
21415 | s = s.redIAdd(s);
|
21416 | // M = 3 * XX + a
|
21417 | var m = xx.redAdd(xx).redIAdd(xx).redIAdd(this.curve.a);
|
21418 | // T = M^2 - 2 * S
|
21419 | var t = m.redSqr().redISub(s).redISub(s);
|
21420 | // X3 = T
|
21421 | nx = t;
|
21422 | // Y3 = M * (S - T) - 8 * YYYY
|
21423 | var yyyy8 = yyyy.redIAdd(yyyy);
|
21424 | yyyy8 = yyyy8.redIAdd(yyyy8);
|
21425 | yyyy8 = yyyy8.redIAdd(yyyy8);
|
21426 | ny = m.redMul(s.redISub(t)).redISub(yyyy8);
|
21427 | // Z3 = 2 * Y1
|
21428 | nz = this.y.redAdd(this.y);
|
21429 | } else {
|
21430 | // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#doubling-dbl-2001-b
|
21431 | // 3M + 5S
|
21432 |
|
21433 | // delta = Z1^2
|
21434 | var delta = this.z.redSqr();
|
21435 | // gamma = Y1^2
|
21436 | var gamma = this.y.redSqr();
|
21437 | // beta = X1 * gamma
|
21438 | var beta = this.x.redMul(gamma);
|
21439 | // alpha = 3 * (X1 - delta) * (X1 + delta)
|
21440 | var alpha = this.x.redSub(delta).redMul(this.x.redAdd(delta));
|
21441 | alpha = alpha.redAdd(alpha).redIAdd(alpha);
|
21442 | // X3 = alpha^2 - 8 * beta
|
21443 | var beta4 = beta.redIAdd(beta);
|
21444 | beta4 = beta4.redIAdd(beta4);
|
21445 | var beta8 = beta4.redAdd(beta4);
|
21446 | nx = alpha.redSqr().redISub(beta8);
|
21447 | // Z3 = (Y1 + Z1)^2 - gamma - delta
|
21448 | nz = this.y.redAdd(this.z).redSqr().redISub(gamma).redISub(delta);
|
21449 | // Y3 = alpha * (4 * beta - X3) - 8 * gamma^2
|
21450 | var ggamma8 = gamma.redSqr();
|
21451 | ggamma8 = ggamma8.redIAdd(ggamma8);
|
21452 | ggamma8 = ggamma8.redIAdd(ggamma8);
|
21453 | ggamma8 = ggamma8.redIAdd(ggamma8);
|
21454 | ny = alpha.redMul(beta4.redISub(nx)).redISub(ggamma8);
|
21455 | }
|
21456 |
|
21457 | return this.curve.jpoint(nx, ny, nz);
|
21458 | };
|
21459 |
|
21460 | JPoint.prototype._dbl = function _dbl() {
|
21461 | var a = this.curve.a;
|
21462 |
|
21463 | // 4M + 6S + 10A
|
21464 | var jx = this.x;
|
21465 | var jy = this.y;
|
21466 | var jz = this.z;
|
21467 | var jz4 = jz.redSqr().redSqr();
|
21468 |
|
21469 | var jx2 = jx.redSqr();
|
21470 | var jy2 = jy.redSqr();
|
21471 |
|
21472 | var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4));
|
21473 |
|
21474 | var jxd4 = jx.redAdd(jx);
|
21475 | jxd4 = jxd4.redIAdd(jxd4);
|
21476 | var t1 = jxd4.redMul(jy2);
|
21477 | var nx = c.redSqr().redISub(t1.redAdd(t1));
|
21478 | var t2 = t1.redISub(nx);
|
21479 |
|
21480 | var jyd8 = jy2.redSqr();
|
21481 | jyd8 = jyd8.redIAdd(jyd8);
|
21482 | jyd8 = jyd8.redIAdd(jyd8);
|
21483 | jyd8 = jyd8.redIAdd(jyd8);
|
21484 | var ny = c.redMul(t2).redISub(jyd8);
|
21485 | var nz = jy.redAdd(jy).redMul(jz);
|
21486 |
|
21487 | return this.curve.jpoint(nx, ny, nz);
|
21488 | };
|
21489 |
|
21490 | JPoint.prototype.trpl = function trpl() {
|
21491 | if (!this.curve.zeroA)
|
21492 | return this.dbl().add(this);
|
21493 |
|
21494 | // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#tripling-tpl-2007-bl
|
21495 | // 5M + 10S + ...
|
21496 |
|
21497 | // XX = X1^2
|
21498 | var xx = this.x.redSqr();
|
21499 | // YY = Y1^2
|
21500 | var yy = this.y.redSqr();
|
21501 | // ZZ = Z1^2
|
21502 | var zz = this.z.redSqr();
|
21503 | // YYYY = YY^2
|
21504 | var yyyy = yy.redSqr();
|
21505 | // M = 3 * XX + a * ZZ2; a = 0
|
21506 | var m = xx.redAdd(xx).redIAdd(xx);
|
21507 | // MM = M^2
|
21508 | var mm = m.redSqr();
|
21509 | // E = 6 * ((X1 + YY)^2 - XX - YYYY) - MM
|
21510 | var e = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
|
21511 | e = e.redIAdd(e);
|
21512 | e = e.redAdd(e).redIAdd(e);
|
21513 | e = e.redISub(mm);
|
21514 | // EE = E^2
|
21515 | var ee = e.redSqr();
|
21516 | // T = 16*YYYY
|
21517 | var t = yyyy.redIAdd(yyyy);
|
21518 | t = t.redIAdd(t);
|
21519 | t = t.redIAdd(t);
|
21520 | t = t.redIAdd(t);
|
21521 | // U = (M + E)^2 - MM - EE - T
|
21522 | var u = m.redIAdd(e).redSqr().redISub(mm).redISub(ee).redISub(t);
|
21523 | // X3 = 4 * (X1 * EE - 4 * YY * U)
|
21524 | var yyu4 = yy.redMul(u);
|
21525 | yyu4 = yyu4.redIAdd(yyu4);
|
21526 | yyu4 = yyu4.redIAdd(yyu4);
|
21527 | var nx = this.x.redMul(ee).redISub(yyu4);
|
21528 | nx = nx.redIAdd(nx);
|
21529 | nx = nx.redIAdd(nx);
|
21530 | // Y3 = 8 * Y1 * (U * (T - U) - E * EE)
|
21531 | var ny = this.y.redMul(u.redMul(t.redISub(u)).redISub(e.redMul(ee)));
|
21532 | ny = ny.redIAdd(ny);
|
21533 | ny = ny.redIAdd(ny);
|
21534 | ny = ny.redIAdd(ny);
|
21535 | // Z3 = (Z1 + E)^2 - ZZ - EE
|
21536 | var nz = this.z.redAdd(e).redSqr().redISub(zz).redISub(ee);
|
21537 |
|
21538 | return this.curve.jpoint(nx, ny, nz);
|
21539 | };
|
21540 |
|
21541 | JPoint.prototype.mul = function mul(k, kbase) {
|
21542 | k = new BN(k, kbase);
|
21543 |
|
21544 | return this.curve._wnafMul(this, k);
|
21545 | };
|
21546 |
|
21547 | JPoint.prototype.eq = function eq(p) {
|
21548 | if (p.type === 'affine')
|
21549 | return this.eq(p.toJ());
|
21550 |
|
21551 | if (this === p)
|
21552 | return true;
|
21553 |
|
21554 | // x1 * z2^2 == x2 * z1^2
|
21555 | var z2 = this.z.redSqr();
|
21556 | var pz2 = p.z.redSqr();
|
21557 | if (this.x.redMul(pz2).redISub(p.x.redMul(z2)).cmpn(0) !== 0)
|
21558 | return false;
|
21559 |
|
21560 | // y1 * z2^3 == y2 * z1^3
|
21561 | var z3 = z2.redMul(this.z);
|
21562 | var pz3 = pz2.redMul(p.z);
|
21563 | return this.y.redMul(pz3).redISub(p.y.redMul(z3)).cmpn(0) === 0;
|
21564 | };
|
21565 |
|
21566 | JPoint.prototype.eqXToP = function eqXToP(x) {
|
21567 | var zs = this.z.redSqr();
|
21568 | var rx = x.toRed(this.curve.red).redMul(zs);
|
21569 | if (this.x.cmp(rx) === 0)
|
21570 | return true;
|
21571 |
|
21572 | var xc = x.clone();
|
21573 | var t = this.curve.redN.redMul(zs);
|
21574 | for (;;) {
|
21575 | xc.iadd(this.curve.n);
|
21576 | if (xc.cmp(this.curve.p) >= 0)
|
21577 | return false;
|
21578 |
|
21579 | rx.redIAdd(t);
|
21580 | if (this.x.cmp(rx) === 0)
|
21581 | return true;
|
21582 | }
|
21583 | };
|
21584 |
|
21585 | JPoint.prototype.inspect = function inspect() {
|
21586 | if (this.isInfinity())
|
21587 | return '<EC JPoint Infinity>';
|
21588 | return '<EC JPoint x: ' + this.x.toString(16, 2) +
|
21589 | ' y: ' + this.y.toString(16, 2) +
|
21590 | ' z: ' + this.z.toString(16, 2) + '>';
|
21591 | };
|
21592 |
|
21593 | JPoint.prototype.isInfinity = function isInfinity() {
|
21594 | // XXX This code assumes that zero is always zero in red
|
21595 | return this.z.cmpn(0) === 0;
|
21596 | };
|
21597 |
|
21598 |
|
21599 | /***/ }),
|
21600 | /* 88 */
|
21601 | /***/ (function(module, exports) {
|
21602 |
|
21603 | if (typeof Object.create === 'function') {
|
21604 | // implementation from standard node.js 'util' module
|
21605 | module.exports = function inherits(ctor, superCtor) {
|
21606 | ctor.super_ = superCtor
|
21607 | ctor.prototype = Object.create(superCtor.prototype, {
|
21608 | constructor: {
|
21609 | value: ctor,
|
21610 | enumerable: false,
|
21611 | writable: true,
|
21612 | configurable: true
|
21613 | }
|
21614 | });
|
21615 | };
|
21616 | } else {
|
21617 | // old school shim for old browsers
|
21618 | module.exports = function inherits(ctor, superCtor) {
|
21619 | ctor.super_ = superCtor
|
21620 | var TempCtor = function () {}
|
21621 | TempCtor.prototype = superCtor.prototype
|
21622 | ctor.prototype = new TempCtor()
|
21623 | ctor.prototype.constructor = ctor
|
21624 | }
|
21625 | }
|
21626 |
|
21627 |
|
21628 | /***/ }),
|
21629 | /* 89 */
|
21630 | /***/ (function(module, exports, __webpack_require__) {
|
21631 |
|
21632 | "use strict";
|
21633 |
|
21634 |
|
21635 | var curve = __webpack_require__(15);
|
21636 | var BN = __webpack_require__(3);
|
21637 | var inherits = __webpack_require__(16);
|
21638 | var Base = curve.base;
|
21639 |
|
21640 | var elliptic = __webpack_require__(5);
|
21641 | var utils = elliptic.utils;
|
21642 |
|
21643 | function MontCurve(conf) {
|
21644 | Base.call(this, 'mont', conf);
|
21645 |
|
21646 | this.a = new BN(conf.a, 16).toRed(this.red);
|
21647 | this.b = new BN(conf.b, 16).toRed(this.red);
|
21648 | this.i4 = new BN(4).toRed(this.red).redInvm();
|
21649 | this.two = new BN(2).toRed(this.red);
|
21650 | this.a24 = this.i4.redMul(this.a.redAdd(this.two));
|
21651 | }
|
21652 | inherits(MontCurve, Base);
|
21653 | module.exports = MontCurve;
|
21654 |
|
21655 | MontCurve.prototype.validate = function validate(point) {
|
21656 | var x = point.normalize().x;
|
21657 | var x2 = x.redSqr();
|
21658 | var rhs = x2.redMul(x).redAdd(x2.redMul(this.a)).redAdd(x);
|
21659 | var y = rhs.redSqrt();
|
21660 |
|
21661 | return y.redSqr().cmp(rhs) === 0;
|
21662 | };
|
21663 |
|
21664 | function Point(curve, x, z) {
|
21665 | Base.BasePoint.call(this, curve, 'projective');
|
21666 | if (x === null && z === null) {
|
21667 | this.x = this.curve.one;
|
21668 | this.z = this.curve.zero;
|
21669 | } else {
|
21670 | this.x = new BN(x, 16);
|
21671 | this.z = new BN(z, 16);
|
21672 | if (!this.x.red)
|
21673 | this.x = this.x.toRed(this.curve.red);
|
21674 | if (!this.z.red)
|
21675 | this.z = this.z.toRed(this.curve.red);
|
21676 | }
|
21677 | }
|
21678 | inherits(Point, Base.BasePoint);
|
21679 |
|
21680 | MontCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
|
21681 | return this.point(utils.toArray(bytes, enc), 1);
|
21682 | };
|
21683 |
|
21684 | MontCurve.prototype.point = function point(x, z) {
|
21685 | return new Point(this, x, z);
|
21686 | };
|
21687 |
|
21688 | MontCurve.prototype.pointFromJSON = function pointFromJSON(obj) {
|
21689 | return Point.fromJSON(this, obj);
|
21690 | };
|
21691 |
|
21692 | Point.prototype.precompute = function precompute() {
|
21693 | // No-op
|
21694 | };
|
21695 |
|
21696 | Point.prototype._encode = function _encode() {
|
21697 | return this.getX().toArray('be', this.curve.p.byteLength());
|
21698 | };
|
21699 |
|
21700 | Point.fromJSON = function fromJSON(curve, obj) {
|
21701 | return new Point(curve, obj[0], obj[1] || curve.one);
|
21702 | };
|
21703 |
|
21704 | Point.prototype.inspect = function inspect() {
|
21705 | if (this.isInfinity())
|
21706 | return '<EC Point Infinity>';
|
21707 | return '<EC Point x: ' + this.x.fromRed().toString(16, 2) +
|
21708 | ' z: ' + this.z.fromRed().toString(16, 2) + '>';
|
21709 | };
|
21710 |
|
21711 | Point.prototype.isInfinity = function isInfinity() {
|
21712 | // XXX This code assumes that zero is always zero in red
|
21713 | return this.z.cmpn(0) === 0;
|
21714 | };
|
21715 |
|
21716 | Point.prototype.dbl = function dbl() {
|
21717 | // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#doubling-dbl-1987-m-3
|
21718 | // 2M + 2S + 4A
|
21719 |
|
21720 | // A = X1 + Z1
|
21721 | var a = this.x.redAdd(this.z);
|
21722 | // AA = A^2
|
21723 | var aa = a.redSqr();
|
21724 | // B = X1 - Z1
|
21725 | var b = this.x.redSub(this.z);
|
21726 | // BB = B^2
|
21727 | var bb = b.redSqr();
|
21728 | // C = AA - BB
|
21729 | var c = aa.redSub(bb);
|
21730 | // X3 = AA * BB
|
21731 | var nx = aa.redMul(bb);
|
21732 | // Z3 = C * (BB + A24 * C)
|
21733 | var nz = c.redMul(bb.redAdd(this.curve.a24.redMul(c)));
|
21734 | return this.curve.point(nx, nz);
|
21735 | };
|
21736 |
|
21737 | Point.prototype.add = function add() {
|
21738 | throw new Error('Not supported on Montgomery curve');
|
21739 | };
|
21740 |
|
21741 | Point.prototype.diffAdd = function diffAdd(p, diff) {
|
21742 | // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#diffadd-dadd-1987-m-3
|
21743 | // 4M + 2S + 6A
|
21744 |
|
21745 | // A = X2 + Z2
|
21746 | var a = this.x.redAdd(this.z);
|
21747 | // B = X2 - Z2
|
21748 | var b = this.x.redSub(this.z);
|
21749 | // C = X3 + Z3
|
21750 | var c = p.x.redAdd(p.z);
|
21751 | // D = X3 - Z3
|
21752 | var d = p.x.redSub(p.z);
|
21753 | // DA = D * A
|
21754 | var da = d.redMul(a);
|
21755 | // CB = C * B
|
21756 | var cb = c.redMul(b);
|
21757 | // X5 = Z1 * (DA + CB)^2
|
21758 | var nx = diff.z.redMul(da.redAdd(cb).redSqr());
|
21759 | // Z5 = X1 * (DA - CB)^2
|
21760 | var nz = diff.x.redMul(da.redISub(cb).redSqr());
|
21761 | return this.curve.point(nx, nz);
|
21762 | };
|
21763 |
|
21764 | Point.prototype.mul = function mul(k) {
|
21765 | var t = k.clone();
|
21766 | var a = this; // (N / 2) * Q + Q
|
21767 | var b = this.curve.point(null, null); // (N / 2) * Q
|
21768 | var c = this; // Q
|
21769 |
|
21770 | for (var bits = []; t.cmpn(0) !== 0; t.iushrn(1))
|
21771 | bits.push(t.andln(1));
|
21772 |
|
21773 | for (var i = bits.length - 1; i >= 0; i--) {
|
21774 | if (bits[i] === 0) {
|
21775 | // N * Q + Q = ((N / 2) * Q + Q)) + (N / 2) * Q
|
21776 | a = a.diffAdd(b, c);
|
21777 | // N * Q = 2 * ((N / 2) * Q + Q))
|
21778 | b = b.dbl();
|
21779 | } else {
|
21780 | // N * Q = ((N / 2) * Q + Q) + ((N / 2) * Q)
|
21781 | b = a.diffAdd(b, c);
|
21782 | // N * Q + Q = 2 * ((N / 2) * Q + Q)
|
21783 | a = a.dbl();
|
21784 | }
|
21785 | }
|
21786 | return b;
|
21787 | };
|
21788 |
|
21789 | Point.prototype.mulAdd = function mulAdd() {
|
21790 | throw new Error('Not supported on Montgomery curve');
|
21791 | };
|
21792 |
|
21793 | Point.prototype.jumlAdd = function jumlAdd() {
|
21794 | throw new Error('Not supported on Montgomery curve');
|
21795 | };
|
21796 |
|
21797 | Point.prototype.eq = function eq(other) {
|
21798 | return this.getX().cmp(other.getX()) === 0;
|
21799 | };
|
21800 |
|
21801 | Point.prototype.normalize = function normalize() {
|
21802 | this.x = this.x.redMul(this.z.redInvm());
|
21803 | this.z = this.curve.one;
|
21804 | return this;
|
21805 | };
|
21806 |
|
21807 | Point.prototype.getX = function getX() {
|
21808 | // Normalize coordinates
|
21809 | this.normalize();
|
21810 |
|
21811 | return this.x.fromRed();
|
21812 | };
|
21813 |
|
21814 |
|
21815 | /***/ }),
|
21816 | /* 90 */
|
21817 | /***/ (function(module, exports, __webpack_require__) {
|
21818 |
|
21819 | "use strict";
|
21820 |
|
21821 |
|
21822 | var curve = __webpack_require__(15);
|
21823 | var elliptic = __webpack_require__(5);
|
21824 | var BN = __webpack_require__(3);
|
21825 | var inherits = __webpack_require__(16);
|
21826 | var Base = curve.base;
|
21827 |
|
21828 | var assert = elliptic.utils.assert;
|
21829 |
|
21830 | function EdwardsCurve(conf) {
|
21831 | // NOTE: Important as we are creating point in Base.call()
|
21832 | this.twisted = (conf.a | 0) !== 1;
|
21833 | this.mOneA = this.twisted && (conf.a | 0) === -1;
|
21834 | this.extended = this.mOneA;
|
21835 |
|
21836 | Base.call(this, 'edwards', conf);
|
21837 |
|
21838 | this.a = new BN(conf.a, 16).umod(this.red.m);
|
21839 | this.a = this.a.toRed(this.red);
|
21840 | this.c = new BN(conf.c, 16).toRed(this.red);
|
21841 | this.c2 = this.c.redSqr();
|
21842 | this.d = new BN(conf.d, 16).toRed(this.red);
|
21843 | this.dd = this.d.redAdd(this.d);
|
21844 |
|
21845 | assert(!this.twisted || this.c.fromRed().cmpn(1) === 0);
|
21846 | this.oneC = (conf.c | 0) === 1;
|
21847 | }
|
21848 | inherits(EdwardsCurve, Base);
|
21849 | module.exports = EdwardsCurve;
|
21850 |
|
21851 | EdwardsCurve.prototype._mulA = function _mulA(num) {
|
21852 | if (this.mOneA)
|
21853 | return num.redNeg();
|
21854 | else
|
21855 | return this.a.redMul(num);
|
21856 | };
|
21857 |
|
21858 | EdwardsCurve.prototype._mulC = function _mulC(num) {
|
21859 | if (this.oneC)
|
21860 | return num;
|
21861 | else
|
21862 | return this.c.redMul(num);
|
21863 | };
|
21864 |
|
21865 | // Just for compatibility with Short curve
|
21866 | EdwardsCurve.prototype.jpoint = function jpoint(x, y, z, t) {
|
21867 | return this.point(x, y, z, t);
|
21868 | };
|
21869 |
|
21870 | EdwardsCurve.prototype.pointFromX = function pointFromX(x, odd) {
|
21871 | x = new BN(x, 16);
|
21872 | if (!x.red)
|
21873 | x = x.toRed(this.red);
|
21874 |
|
21875 | var x2 = x.redSqr();
|
21876 | var rhs = this.c2.redSub(this.a.redMul(x2));
|
21877 | var lhs = this.one.redSub(this.c2.redMul(this.d).redMul(x2));
|
21878 |
|
21879 | var y2 = rhs.redMul(lhs.redInvm());
|
21880 | var y = y2.redSqrt();
|
21881 | if (y.redSqr().redSub(y2).cmp(this.zero) !== 0)
|
21882 | throw new Error('invalid point');
|
21883 |
|
21884 | var isOdd = y.fromRed().isOdd();
|
21885 | if (odd && !isOdd || !odd && isOdd)
|
21886 | y = y.redNeg();
|
21887 |
|
21888 | return this.point(x, y);
|
21889 | };
|
21890 |
|
21891 | EdwardsCurve.prototype.pointFromY = function pointFromY(y, odd) {
|
21892 | y = new BN(y, 16);
|
21893 | if (!y.red)
|
21894 | y = y.toRed(this.red);
|
21895 |
|
21896 | // x^2 = (y^2 - c^2) / (c^2 d y^2 - a)
|
21897 | var y2 = y.redSqr();
|
21898 | var lhs = y2.redSub(this.c2);
|
21899 | var rhs = y2.redMul(this.d).redMul(this.c2).redSub(this.a);
|
21900 | var x2 = lhs.redMul(rhs.redInvm());
|
21901 |
|
21902 | if (x2.cmp(this.zero) === 0) {
|
21903 | if (odd)
|
21904 | throw new Error('invalid point');
|
21905 | else
|
21906 | return this.point(this.zero, y);
|
21907 | }
|
21908 |
|
21909 | var x = x2.redSqrt();
|
21910 | if (x.redSqr().redSub(x2).cmp(this.zero) !== 0)
|
21911 | throw new Error('invalid point');
|
21912 |
|
21913 | if (x.fromRed().isOdd() !== odd)
|
21914 | x = x.redNeg();
|
21915 |
|
21916 | return this.point(x, y);
|
21917 | };
|
21918 |
|
21919 | EdwardsCurve.prototype.validate = function validate(point) {
|
21920 | if (point.isInfinity())
|
21921 | return true;
|
21922 |
|
21923 | // Curve: A * X^2 + Y^2 = C^2 * (1 + D * X^2 * Y^2)
|
21924 | point.normalize();
|
21925 |
|
21926 | var x2 = point.x.redSqr();
|
21927 | var y2 = point.y.redSqr();
|
21928 | var lhs = x2.redMul(this.a).redAdd(y2);
|
21929 | var rhs = this.c2.redMul(this.one.redAdd(this.d.redMul(x2).redMul(y2)));
|
21930 |
|
21931 | return lhs.cmp(rhs) === 0;
|
21932 | };
|
21933 |
|
21934 | function Point(curve, x, y, z, t) {
|
21935 | Base.BasePoint.call(this, curve, 'projective');
|
21936 | if (x === null && y === null && z === null) {
|
21937 | this.x = this.curve.zero;
|
21938 | this.y = this.curve.one;
|
21939 | this.z = this.curve.one;
|
21940 | this.t = this.curve.zero;
|
21941 | this.zOne = true;
|
21942 | } else {
|
21943 | this.x = new BN(x, 16);
|
21944 | this.y = new BN(y, 16);
|
21945 | this.z = z ? new BN(z, 16) : this.curve.one;
|
21946 | this.t = t && new BN(t, 16);
|
21947 | if (!this.x.red)
|
21948 | this.x = this.x.toRed(this.curve.red);
|
21949 | if (!this.y.red)
|
21950 | this.y = this.y.toRed(this.curve.red);
|
21951 | if (!this.z.red)
|
21952 | this.z = this.z.toRed(this.curve.red);
|
21953 | if (this.t && !this.t.red)
|
21954 | this.t = this.t.toRed(this.curve.red);
|
21955 | this.zOne = this.z === this.curve.one;
|
21956 |
|
21957 | // Use extended coordinates
|
21958 | if (this.curve.extended && !this.t) {
|
21959 | this.t = this.x.redMul(this.y);
|
21960 | if (!this.zOne)
|
21961 | this.t = this.t.redMul(this.z.redInvm());
|
21962 | }
|
21963 | }
|
21964 | }
|
21965 | inherits(Point, Base.BasePoint);
|
21966 |
|
21967 | EdwardsCurve.prototype.pointFromJSON = function pointFromJSON(obj) {
|
21968 | return Point.fromJSON(this, obj);
|
21969 | };
|
21970 |
|
21971 | EdwardsCurve.prototype.point = function point(x, y, z, t) {
|
21972 | return new Point(this, x, y, z, t);
|
21973 | };
|
21974 |
|
21975 | Point.fromJSON = function fromJSON(curve, obj) {
|
21976 | return new Point(curve, obj[0], obj[1], obj[2]);
|
21977 | };
|
21978 |
|
21979 | Point.prototype.inspect = function inspect() {
|
21980 | if (this.isInfinity())
|
21981 | return '<EC Point Infinity>';
|
21982 | return '<EC Point x: ' + this.x.fromRed().toString(16, 2) +
|
21983 | ' y: ' + this.y.fromRed().toString(16, 2) +
|
21984 | ' z: ' + this.z.fromRed().toString(16, 2) + '>';
|
21985 | };
|
21986 |
|
21987 | Point.prototype.isInfinity = function isInfinity() {
|
21988 | // XXX This code assumes that zero is always zero in red
|
21989 | return this.x.cmpn(0) === 0 &&
|
21990 | (this.y.cmp(this.z) === 0 ||
|
21991 | (this.zOne && this.y.cmp(this.curve.c) === 0));
|
21992 | };
|
21993 |
|
21994 | Point.prototype._extDbl = function _extDbl() {
|
21995 | // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html
|
21996 | // #doubling-dbl-2008-hwcd
|
21997 | // 4M + 4S
|
21998 |
|
21999 | // A = X1^2
|
22000 | var a = this.x.redSqr();
|
22001 | // B = Y1^2
|
22002 | var b = this.y.redSqr();
|
22003 | // C = 2 * Z1^2
|
22004 | var c = this.z.redSqr();
|
22005 | c = c.redIAdd(c);
|
22006 | // D = a * A
|
22007 | var d = this.curve._mulA(a);
|
22008 | // E = (X1 + Y1)^2 - A - B
|
22009 | var e = this.x.redAdd(this.y).redSqr().redISub(a).redISub(b);
|
22010 | // G = D + B
|
22011 | var g = d.redAdd(b);
|
22012 | // F = G - C
|
22013 | var f = g.redSub(c);
|
22014 | // H = D - B
|
22015 | var h = d.redSub(b);
|
22016 | // X3 = E * F
|
22017 | var nx = e.redMul(f);
|
22018 | // Y3 = G * H
|
22019 | var ny = g.redMul(h);
|
22020 | // T3 = E * H
|
22021 | var nt = e.redMul(h);
|
22022 | // Z3 = F * G
|
22023 | var nz = f.redMul(g);
|
22024 | return this.curve.point(nx, ny, nz, nt);
|
22025 | };
|
22026 |
|
22027 | Point.prototype._projDbl = function _projDbl() {
|
22028 | // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html
|
22029 | // #doubling-dbl-2008-bbjlp
|
22030 | // #doubling-dbl-2007-bl
|
22031 | // and others
|
22032 | // Generally 3M + 4S or 2M + 4S
|
22033 |
|
22034 | // B = (X1 + Y1)^2
|
22035 | var b = this.x.redAdd(this.y).redSqr();
|
22036 | // C = X1^2
|
22037 | var c = this.x.redSqr();
|
22038 | // D = Y1^2
|
22039 | var d = this.y.redSqr();
|
22040 |
|
22041 | var nx;
|
22042 | var ny;
|
22043 | var nz;
|
22044 | if (this.curve.twisted) {
|
22045 | // E = a * C
|
22046 | var e = this.curve._mulA(c);
|
22047 | // F = E + D
|
22048 | var f = e.redAdd(d);
|
22049 | if (this.zOne) {
|
22050 | // X3 = (B - C - D) * (F - 2)
|
22051 | nx = b.redSub(c).redSub(d).redMul(f.redSub(this.curve.two));
|
22052 | // Y3 = F * (E - D)
|
22053 | ny = f.redMul(e.redSub(d));
|
22054 | // Z3 = F^2 - 2 * F
|
22055 | nz = f.redSqr().redSub(f).redSub(f);
|
22056 | } else {
|
22057 | // H = Z1^2
|
22058 | var h = this.z.redSqr();
|
22059 | // J = F - 2 * H
|
22060 | var j = f.redSub(h).redISub(h);
|
22061 | // X3 = (B-C-D)*J
|
22062 | nx = b.redSub(c).redISub(d).redMul(j);
|
22063 | // Y3 = F * (E - D)
|
22064 | ny = f.redMul(e.redSub(d));
|
22065 | // Z3 = F * J
|
22066 | nz = f.redMul(j);
|
22067 | }
|
22068 | } else {
|
22069 | // E = C + D
|
22070 | var e = c.redAdd(d);
|
22071 | // H = (c * Z1)^2
|
22072 | var h = this.curve._mulC(this.z).redSqr();
|
22073 | // J = E - 2 * H
|
22074 | var j = e.redSub(h).redSub(h);
|
22075 | // X3 = c * (B - E) * J
|
22076 | nx = this.curve._mulC(b.redISub(e)).redMul(j);
|
22077 | // Y3 = c * E * (C - D)
|
22078 | ny = this.curve._mulC(e).redMul(c.redISub(d));
|
22079 | // Z3 = E * J
|
22080 | nz = e.redMul(j);
|
22081 | }
|
22082 | return this.curve.point(nx, ny, nz);
|
22083 | };
|
22084 |
|
22085 | Point.prototype.dbl = function dbl() {
|
22086 | if (this.isInfinity())
|
22087 | return this;
|
22088 |
|
22089 | // Double in extended coordinates
|
22090 | if (this.curve.extended)
|
22091 | return this._extDbl();
|
22092 | else
|
22093 | return this._projDbl();
|
22094 | };
|
22095 |
|
22096 | Point.prototype._extAdd = function _extAdd(p) {
|
22097 | // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html
|
22098 | // #addition-add-2008-hwcd-3
|
22099 | // 8M
|
22100 |
|
22101 | // A = (Y1 - X1) * (Y2 - X2)
|
22102 | var a = this.y.redSub(this.x).redMul(p.y.redSub(p.x));
|
22103 | // B = (Y1 + X1) * (Y2 + X2)
|
22104 | var b = this.y.redAdd(this.x).redMul(p.y.redAdd(p.x));
|
22105 | // C = T1 * k * T2
|
22106 | var c = this.t.redMul(this.curve.dd).redMul(p.t);
|
22107 | // D = Z1 * 2 * Z2
|
22108 | var d = this.z.redMul(p.z.redAdd(p.z));
|
22109 | // E = B - A
|
22110 | var e = b.redSub(a);
|
22111 | // F = D - C
|
22112 | var f = d.redSub(c);
|
22113 | // G = D + C
|
22114 | var g = d.redAdd(c);
|
22115 | // H = B + A
|
22116 | var h = b.redAdd(a);
|
22117 | // X3 = E * F
|
22118 | var nx = e.redMul(f);
|
22119 | // Y3 = G * H
|
22120 | var ny = g.redMul(h);
|
22121 | // T3 = E * H
|
22122 | var nt = e.redMul(h);
|
22123 | // Z3 = F * G
|
22124 | var nz = f.redMul(g);
|
22125 | return this.curve.point(nx, ny, nz, nt);
|
22126 | };
|
22127 |
|
22128 | Point.prototype._projAdd = function _projAdd(p) {
|
22129 | // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html
|
22130 | // #addition-add-2008-bbjlp
|
22131 | // #addition-add-2007-bl
|
22132 | // 10M + 1S
|
22133 |
|
22134 | // A = Z1 * Z2
|
22135 | var a = this.z.redMul(p.z);
|
22136 | // B = A^2
|
22137 | var b = a.redSqr();
|
22138 | // C = X1 * X2
|
22139 | var c = this.x.redMul(p.x);
|
22140 | // D = Y1 * Y2
|
22141 | var d = this.y.redMul(p.y);
|
22142 | // E = d * C * D
|
22143 | var e = this.curve.d.redMul(c).redMul(d);
|
22144 | // F = B - E
|
22145 | var f = b.redSub(e);
|
22146 | // G = B + E
|
22147 | var g = b.redAdd(e);
|
22148 | // X3 = A * F * ((X1 + Y1) * (X2 + Y2) - C - D)
|
22149 | var tmp = this.x.redAdd(this.y).redMul(p.x.redAdd(p.y)).redISub(c).redISub(d);
|
22150 | var nx = a.redMul(f).redMul(tmp);
|
22151 | var ny;
|
22152 | var nz;
|
22153 | if (this.curve.twisted) {
|
22154 | // Y3 = A * G * (D - a * C)
|
22155 | ny = a.redMul(g).redMul(d.redSub(this.curve._mulA(c)));
|
22156 | // Z3 = F * G
|
22157 | nz = f.redMul(g);
|
22158 | } else {
|
22159 | // Y3 = A * G * (D - C)
|
22160 | ny = a.redMul(g).redMul(d.redSub(c));
|
22161 | // Z3 = c * F * G
|
22162 | nz = this.curve._mulC(f).redMul(g);
|
22163 | }
|
22164 | return this.curve.point(nx, ny, nz);
|
22165 | };
|
22166 |
|
22167 | Point.prototype.add = function add(p) {
|
22168 | if (this.isInfinity())
|
22169 | return p;
|
22170 | if (p.isInfinity())
|
22171 | return this;
|
22172 |
|
22173 | if (this.curve.extended)
|
22174 | return this._extAdd(p);
|
22175 | else
|
22176 | return this._projAdd(p);
|
22177 | };
|
22178 |
|
22179 | Point.prototype.mul = function mul(k) {
|
22180 | if (this._hasDoubles(k))
|
22181 | return this.curve._fixedNafMul(this, k);
|
22182 | else
|
22183 | return this.curve._wnafMul(this, k);
|
22184 | };
|
22185 |
|
22186 | Point.prototype.mulAdd = function mulAdd(k1, p, k2) {
|
22187 | return this.curve._wnafMulAdd(1, [ this, p ], [ k1, k2 ], 2, false);
|
22188 | };
|
22189 |
|
22190 | Point.prototype.jmulAdd = function jmulAdd(k1, p, k2) {
|
22191 | return this.curve._wnafMulAdd(1, [ this, p ], [ k1, k2 ], 2, true);
|
22192 | };
|
22193 |
|
22194 | Point.prototype.normalize = function normalize() {
|
22195 | if (this.zOne)
|
22196 | return this;
|
22197 |
|
22198 | // Normalize coordinates
|
22199 | var zi = this.z.redInvm();
|
22200 | this.x = this.x.redMul(zi);
|
22201 | this.y = this.y.redMul(zi);
|
22202 | if (this.t)
|
22203 | this.t = this.t.redMul(zi);
|
22204 | this.z = this.curve.one;
|
22205 | this.zOne = true;
|
22206 | return this;
|
22207 | };
|
22208 |
|
22209 | Point.prototype.neg = function neg() {
|
22210 | return this.curve.point(this.x.redNeg(),
|
22211 | this.y,
|
22212 | this.z,
|
22213 | this.t && this.t.redNeg());
|
22214 | };
|
22215 |
|
22216 | Point.prototype.getX = function getX() {
|
22217 | this.normalize();
|
22218 | return this.x.fromRed();
|
22219 | };
|
22220 |
|
22221 | Point.prototype.getY = function getY() {
|
22222 | this.normalize();
|
22223 | return this.y.fromRed();
|
22224 | };
|
22225 |
|
22226 | Point.prototype.eq = function eq(other) {
|
22227 | return this === other ||
|
22228 | this.getX().cmp(other.getX()) === 0 &&
|
22229 | this.getY().cmp(other.getY()) === 0;
|
22230 | };
|
22231 |
|
22232 | Point.prototype.eqXToP = function eqXToP(x) {
|
22233 | var rx = x.toRed(this.curve.red).redMul(this.z);
|
22234 | if (this.x.cmp(rx) === 0)
|
22235 | return true;
|
22236 |
|
22237 | var xc = x.clone();
|
22238 | var t = this.curve.redN.redMul(this.z);
|
22239 | for (;;) {
|
22240 | xc.iadd(this.curve.n);
|
22241 | if (xc.cmp(this.curve.p) >= 0)
|
22242 | return false;
|
22243 |
|
22244 | rx.redIAdd(t);
|
22245 | if (this.x.cmp(rx) === 0)
|
22246 | return true;
|
22247 | }
|
22248 | };
|
22249 |
|
22250 | // Compatibility with BaseCurve
|
22251 | Point.prototype.toP = Point.prototype.normalize;
|
22252 | Point.prototype.mixedAdd = Point.prototype.add;
|
22253 |
|
22254 |
|
22255 | /***/ }),
|
22256 | /* 91 */
|
22257 | /***/ (function(module, exports, __webpack_require__) {
|
22258 |
|
22259 | "use strict";
|
22260 |
|
22261 |
|
22262 | var curves = exports;
|
22263 |
|
22264 | var hash = __webpack_require__(21);
|
22265 | var elliptic = __webpack_require__(5);
|
22266 |
|
22267 | var assert = elliptic.utils.assert;
|
22268 |
|
22269 | function PresetCurve(options) {
|
22270 | if (options.type === 'short')
|
22271 | this.curve = new elliptic.curve.short(options);
|
22272 | else if (options.type === 'edwards')
|
22273 | this.curve = new elliptic.curve.edwards(options);
|
22274 | else
|
22275 | this.curve = new elliptic.curve.mont(options);
|
22276 | this.g = this.curve.g;
|
22277 | this.n = this.curve.n;
|
22278 | this.hash = options.hash;
|
22279 |
|
22280 | assert(this.g.validate(), 'Invalid curve');
|
22281 | assert(this.g.mul(this.n).isInfinity(), 'Invalid curve, G*N != O');
|
22282 | }
|
22283 | curves.PresetCurve = PresetCurve;
|
22284 |
|
22285 | function defineCurve(name, options) {
|
22286 | Object.defineProperty(curves, name, {
|
22287 | configurable: true,
|
22288 | enumerable: true,
|
22289 | get: function() {
|
22290 | var curve = new PresetCurve(options);
|
22291 | Object.defineProperty(curves, name, {
|
22292 | configurable: true,
|
22293 | enumerable: true,
|
22294 | value: curve
|
22295 | });
|
22296 | return curve;
|
22297 | }
|
22298 | });
|
22299 | }
|
22300 |
|
22301 | defineCurve('p192', {
|
22302 | type: 'short',
|
22303 | prime: 'p192',
|
22304 | p: 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff',
|
22305 | a: 'ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc',
|
22306 | b: '64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1',
|
22307 | n: 'ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831',
|
22308 | hash: hash.sha256,
|
22309 | gRed: false,
|
22310 | g: [
|
22311 | '188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012',
|
22312 | '07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811'
|
22313 | ]
|
22314 | });
|
22315 |
|
22316 | defineCurve('p224', {
|
22317 | type: 'short',
|
22318 | prime: 'p224',
|
22319 | p: 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001',
|
22320 | a: 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe',
|
22321 | b: 'b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4',
|
22322 | n: 'ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d',
|
22323 | hash: hash.sha256,
|
22324 | gRed: false,
|
22325 | g: [
|
22326 | 'b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21',
|
22327 | 'bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34'
|
22328 | ]
|
22329 | });
|
22330 |
|
22331 | defineCurve('p256', {
|
22332 | type: 'short',
|
22333 | prime: null,
|
22334 | p: 'ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff',
|
22335 | a: 'ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc',
|
22336 | b: '5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b',
|
22337 | n: 'ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551',
|
22338 | hash: hash.sha256,
|
22339 | gRed: false,
|
22340 | g: [
|
22341 | '6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296',
|
22342 | '4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5'
|
22343 | ]
|
22344 | });
|
22345 |
|
22346 | defineCurve('p384', {
|
22347 | type: 'short',
|
22348 | prime: null,
|
22349 | p: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
|
22350 | 'fffffffe ffffffff 00000000 00000000 ffffffff',
|
22351 | a: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
|
22352 | 'fffffffe ffffffff 00000000 00000000 fffffffc',
|
22353 | b: 'b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f ' +
|
22354 | '5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef',
|
22355 | n: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 ' +
|
22356 | 'f4372ddf 581a0db2 48b0a77a ecec196a ccc52973',
|
22357 | hash: hash.sha384,
|
22358 | gRed: false,
|
22359 | g: [
|
22360 | 'aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 ' +
|
22361 | '5502f25d bf55296c 3a545e38 72760ab7',
|
22362 | '3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 ' +
|
22363 | '0a60b1ce 1d7e819d 7a431d7c 90ea0e5f'
|
22364 | ]
|
22365 | });
|
22366 |
|
22367 | defineCurve('p521', {
|
22368 | type: 'short',
|
22369 | prime: null,
|
22370 | p: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
|
22371 | 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
|
22372 | 'ffffffff ffffffff ffffffff ffffffff ffffffff',
|
22373 | a: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
|
22374 | 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
|
22375 | 'ffffffff ffffffff ffffffff ffffffff fffffffc',
|
22376 | b: '00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b ' +
|
22377 | '99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd ' +
|
22378 | '3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00',
|
22379 | n: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
|
22380 | 'ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 ' +
|
22381 | 'f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409',
|
22382 | hash: hash.sha512,
|
22383 | gRed: false,
|
22384 | g: [
|
22385 | '000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 ' +
|
22386 | '053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 ' +
|
22387 | 'a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66',
|
22388 | '00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 ' +
|
22389 | '579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 ' +
|
22390 | '3fad0761 353c7086 a272c240 88be9476 9fd16650'
|
22391 | ]
|
22392 | });
|
22393 |
|
22394 | defineCurve('curve25519', {
|
22395 | type: 'mont',
|
22396 | prime: 'p25519',
|
22397 | p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed',
|
22398 | a: '76d06',
|
22399 | b: '1',
|
22400 | n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed',
|
22401 | hash: hash.sha256,
|
22402 | gRed: false,
|
22403 | g: [
|
22404 | '9'
|
22405 | ]
|
22406 | });
|
22407 |
|
22408 | defineCurve('ed25519', {
|
22409 | type: 'edwards',
|
22410 | prime: 'p25519',
|
22411 | p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed',
|
22412 | a: '-1',
|
22413 | c: '1',
|
22414 | // -121665 * (121666^(-1)) (mod P)
|
22415 | d: '52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3',
|
22416 | n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed',
|
22417 | hash: hash.sha256,
|
22418 | gRed: false,
|
22419 | g: [
|
22420 | '216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a',
|
22421 |
|
22422 | // 4/5
|
22423 | '6666666666666666666666666666666666666666666666666666666666666658'
|
22424 | ]
|
22425 | });
|
22426 |
|
22427 | var pre;
|
22428 | try {
|
22429 | pre = __webpack_require__(98);
|
22430 | } catch (e) {
|
22431 | pre = undefined;
|
22432 | }
|
22433 |
|
22434 | defineCurve('secp256k1', {
|
22435 | type: 'short',
|
22436 | prime: 'k256',
|
22437 | p: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f',
|
22438 | a: '0',
|
22439 | b: '7',
|
22440 | n: 'ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141',
|
22441 | h: '1',
|
22442 | hash: hash.sha256,
|
22443 |
|
22444 | // Precomputed endomorphism
|
22445 | beta: '7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee',
|
22446 | lambda: '5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72',
|
22447 | basis: [
|
22448 | {
|
22449 | a: '3086d221a7d46bcde86c90e49284eb15',
|
22450 | b: '-e4437ed6010e88286f547fa90abfe4c3'
|
22451 | },
|
22452 | {
|
22453 | a: '114ca50f7a8e2f3f657c1108d9d44cfd8',
|
22454 | b: '3086d221a7d46bcde86c90e49284eb15'
|
22455 | }
|
22456 | ],
|
22457 |
|
22458 | gRed: false,
|
22459 | g: [
|
22460 | '79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
|
22461 | '483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8',
|
22462 | pre
|
22463 | ]
|
22464 | });
|
22465 |
|
22466 |
|
22467 | /***/ }),
|
22468 | /* 92 */
|
22469 | /***/ (function(module, exports, __webpack_require__) {
|
22470 |
|
22471 | "use strict";
|
22472 |
|
22473 |
|
22474 | exports.sha1 = __webpack_require__(93);
|
22475 | exports.sha224 = __webpack_require__(94);
|
22476 | exports.sha256 = __webpack_require__(42);
|
22477 | exports.sha384 = __webpack_require__(95);
|
22478 | exports.sha512 = __webpack_require__(43);
|
22479 |
|
22480 |
|
22481 | /***/ }),
|
22482 | /* 93 */
|
22483 | /***/ (function(module, exports, __webpack_require__) {
|
22484 |
|
22485 | "use strict";
|
22486 |
|
22487 |
|
22488 | var utils = __webpack_require__(6);
|
22489 | var common = __webpack_require__(13);
|
22490 | var shaCommon = __webpack_require__(41);
|
22491 |
|
22492 | var rotl32 = utils.rotl32;
|
22493 | var sum32 = utils.sum32;
|
22494 | var sum32_5 = utils.sum32_5;
|
22495 | var ft_1 = shaCommon.ft_1;
|
22496 | var BlockHash = common.BlockHash;
|
22497 |
|
22498 | var sha1_K = [
|
22499 | 0x5A827999, 0x6ED9EBA1,
|
22500 | 0x8F1BBCDC, 0xCA62C1D6
|
22501 | ];
|
22502 |
|
22503 | function SHA1() {
|
22504 | if (!(this instanceof SHA1))
|
22505 | return new SHA1();
|
22506 |
|
22507 | BlockHash.call(this);
|
22508 | this.h = [
|
22509 | 0x67452301, 0xefcdab89, 0x98badcfe,
|
22510 | 0x10325476, 0xc3d2e1f0 ];
|
22511 | this.W = new Array(80);
|
22512 | }
|
22513 |
|
22514 | utils.inherits(SHA1, BlockHash);
|
22515 | module.exports = SHA1;
|
22516 |
|
22517 | SHA1.blockSize = 512;
|
22518 | SHA1.outSize = 160;
|
22519 | SHA1.hmacStrength = 80;
|
22520 | SHA1.padLength = 64;
|
22521 |
|
22522 | SHA1.prototype._update = function _update(msg, start) {
|
22523 | var W = this.W;
|
22524 |
|
22525 | for (var i = 0; i < 16; i++)
|
22526 | W[i] = msg[start + i];
|
22527 |
|
22528 | for(; i < W.length; i++)
|
22529 | W[i] = rotl32(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);
|
22530 |
|
22531 | var a = this.h[0];
|
22532 | var b = this.h[1];
|
22533 | var c = this.h[2];
|
22534 | var d = this.h[3];
|
22535 | var e = this.h[4];
|
22536 |
|
22537 | for (i = 0; i < W.length; i++) {
|
22538 | var s = ~~(i / 20);
|
22539 | var t = sum32_5(rotl32(a, 5), ft_1(s, b, c, d), e, W[i], sha1_K[s]);
|
22540 | e = d;
|
22541 | d = c;
|
22542 | c = rotl32(b, 30);
|
22543 | b = a;
|
22544 | a = t;
|
22545 | }
|
22546 |
|
22547 | this.h[0] = sum32(this.h[0], a);
|
22548 | this.h[1] = sum32(this.h[1], b);
|
22549 | this.h[2] = sum32(this.h[2], c);
|
22550 | this.h[3] = sum32(this.h[3], d);
|
22551 | this.h[4] = sum32(this.h[4], e);
|
22552 | };
|
22553 |
|
22554 | SHA1.prototype._digest = function digest(enc) {
|
22555 | if (enc === 'hex')
|
22556 | return utils.toHex32(this.h, 'big');
|
22557 | else
|
22558 | return utils.split32(this.h, 'big');
|
22559 | };
|
22560 |
|
22561 |
|
22562 | /***/ }),
|
22563 | /* 94 */
|
22564 | /***/ (function(module, exports, __webpack_require__) {
|
22565 |
|
22566 | "use strict";
|
22567 |
|
22568 |
|
22569 | var utils = __webpack_require__(6);
|
22570 | var SHA256 = __webpack_require__(42);
|
22571 |
|
22572 | function SHA224() {
|
22573 | if (!(this instanceof SHA224))
|
22574 | return new SHA224();
|
22575 |
|
22576 | SHA256.call(this);
|
22577 | this.h = [
|
22578 | 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
|
22579 | 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 ];
|
22580 | }
|
22581 | utils.inherits(SHA224, SHA256);
|
22582 | module.exports = SHA224;
|
22583 |
|
22584 | SHA224.blockSize = 512;
|
22585 | SHA224.outSize = 224;
|
22586 | SHA224.hmacStrength = 192;
|
22587 | SHA224.padLength = 64;
|
22588 |
|
22589 | SHA224.prototype._digest = function digest(enc) {
|
22590 | // Just truncate output
|
22591 | if (enc === 'hex')
|
22592 | return utils.toHex32(this.h.slice(0, 7), 'big');
|
22593 | else
|
22594 | return utils.split32(this.h.slice(0, 7), 'big');
|
22595 | };
|
22596 |
|
22597 |
|
22598 |
|
22599 | /***/ }),
|
22600 | /* 95 */
|
22601 | /***/ (function(module, exports, __webpack_require__) {
|
22602 |
|
22603 | "use strict";
|
22604 |
|
22605 |
|
22606 | var utils = __webpack_require__(6);
|
22607 |
|
22608 | var SHA512 = __webpack_require__(43);
|
22609 |
|
22610 | function SHA384() {
|
22611 | if (!(this instanceof SHA384))
|
22612 | return new SHA384();
|
22613 |
|
22614 | SHA512.call(this);
|
22615 | this.h = [
|
22616 | 0xcbbb9d5d, 0xc1059ed8,
|
22617 | 0x629a292a, 0x367cd507,
|
22618 | 0x9159015a, 0x3070dd17,
|
22619 | 0x152fecd8, 0xf70e5939,
|
22620 | 0x67332667, 0xffc00b31,
|
22621 | 0x8eb44a87, 0x68581511,
|
22622 | 0xdb0c2e0d, 0x64f98fa7,
|
22623 | 0x47b5481d, 0xbefa4fa4 ];
|
22624 | }
|
22625 | utils.inherits(SHA384, SHA512);
|
22626 | module.exports = SHA384;
|
22627 |
|
22628 | SHA384.blockSize = 1024;
|
22629 | SHA384.outSize = 384;
|
22630 | SHA384.hmacStrength = 192;
|
22631 | SHA384.padLength = 128;
|
22632 |
|
22633 | SHA384.prototype._digest = function digest(enc) {
|
22634 | if (enc === 'hex')
|
22635 | return utils.toHex32(this.h.slice(0, 12), 'big');
|
22636 | else
|
22637 | return utils.split32(this.h.slice(0, 12), 'big');
|
22638 | };
|
22639 |
|
22640 |
|
22641 | /***/ }),
|
22642 | /* 96 */
|
22643 | /***/ (function(module, exports, __webpack_require__) {
|
22644 |
|
22645 | "use strict";
|
22646 |
|
22647 |
|
22648 | var utils = __webpack_require__(6);
|
22649 | var common = __webpack_require__(13);
|
22650 |
|
22651 | var rotl32 = utils.rotl32;
|
22652 | var sum32 = utils.sum32;
|
22653 | var sum32_3 = utils.sum32_3;
|
22654 | var sum32_4 = utils.sum32_4;
|
22655 | var BlockHash = common.BlockHash;
|
22656 |
|
22657 | function RIPEMD160() {
|
22658 | if (!(this instanceof RIPEMD160))
|
22659 | return new RIPEMD160();
|
22660 |
|
22661 | BlockHash.call(this);
|
22662 |
|
22663 | this.h = [ 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 ];
|
22664 | this.endian = 'little';
|
22665 | }
|
22666 | utils.inherits(RIPEMD160, BlockHash);
|
22667 | exports.ripemd160 = RIPEMD160;
|
22668 |
|
22669 | RIPEMD160.blockSize = 512;
|
22670 | RIPEMD160.outSize = 160;
|
22671 | RIPEMD160.hmacStrength = 192;
|
22672 | RIPEMD160.padLength = 64;
|
22673 |
|
22674 | RIPEMD160.prototype._update = function update(msg, start) {
|
22675 | var A = this.h[0];
|
22676 | var B = this.h[1];
|
22677 | var C = this.h[2];
|
22678 | var D = this.h[3];
|
22679 | var E = this.h[4];
|
22680 | var Ah = A;
|
22681 | var Bh = B;
|
22682 | var Ch = C;
|
22683 | var Dh = D;
|
22684 | var Eh = E;
|
22685 | for (var j = 0; j < 80; j++) {
|
22686 | var T = sum32(
|
22687 | rotl32(
|
22688 | sum32_4(A, f(j, B, C, D), msg[r[j] + start], K(j)),
|
22689 | s[j]),
|
22690 | E);
|
22691 | A = E;
|
22692 | E = D;
|
22693 | D = rotl32(C, 10);
|
22694 | C = B;
|
22695 | B = T;
|
22696 | T = sum32(
|
22697 | rotl32(
|
22698 | sum32_4(Ah, f(79 - j, Bh, Ch, Dh), msg[rh[j] + start], Kh(j)),
|
22699 | sh[j]),
|
22700 | Eh);
|
22701 | Ah = Eh;
|
22702 | Eh = Dh;
|
22703 | Dh = rotl32(Ch, 10);
|
22704 | Ch = Bh;
|
22705 | Bh = T;
|
22706 | }
|
22707 | T = sum32_3(this.h[1], C, Dh);
|
22708 | this.h[1] = sum32_3(this.h[2], D, Eh);
|
22709 | this.h[2] = sum32_3(this.h[3], E, Ah);
|
22710 | this.h[3] = sum32_3(this.h[4], A, Bh);
|
22711 | this.h[4] = sum32_3(this.h[0], B, Ch);
|
22712 | this.h[0] = T;
|
22713 | };
|
22714 |
|
22715 | RIPEMD160.prototype._digest = function digest(enc) {
|
22716 | if (enc === 'hex')
|
22717 | return utils.toHex32(this.h, 'little');
|
22718 | else
|
22719 | return utils.split32(this.h, 'little');
|
22720 | };
|
22721 |
|
22722 | function f(j, x, y, z) {
|
22723 | if (j <= 15)
|
22724 | return x ^ y ^ z;
|
22725 | else if (j <= 31)
|
22726 | return (x & y) | ((~x) & z);
|
22727 | else if (j <= 47)
|
22728 | return (x | (~y)) ^ z;
|
22729 | else if (j <= 63)
|
22730 | return (x & z) | (y & (~z));
|
22731 | else
|
22732 | return x ^ (y | (~z));
|
22733 | }
|
22734 |
|
22735 | function K(j) {
|
22736 | if (j <= 15)
|
22737 | return 0x00000000;
|
22738 | else if (j <= 31)
|
22739 | return 0x5a827999;
|
22740 | else if (j <= 47)
|
22741 | return 0x6ed9eba1;
|
22742 | else if (j <= 63)
|
22743 | return 0x8f1bbcdc;
|
22744 | else
|
22745 | return 0xa953fd4e;
|
22746 | }
|
22747 |
|
22748 | function Kh(j) {
|
22749 | if (j <= 15)
|
22750 | return 0x50a28be6;
|
22751 | else if (j <= 31)
|
22752 | return 0x5c4dd124;
|
22753 | else if (j <= 47)
|
22754 | return 0x6d703ef3;
|
22755 | else if (j <= 63)
|
22756 | return 0x7a6d76e9;
|
22757 | else
|
22758 | return 0x00000000;
|
22759 | }
|
22760 |
|
22761 | var r = [
|
22762 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
22763 | 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
|
22764 | 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
|
22765 | 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
|
22766 | 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
|
22767 | ];
|
22768 |
|
22769 | var rh = [
|
22770 | 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
|
22771 | 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
|
22772 | 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
|
22773 | 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
|
22774 | 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
|
22775 | ];
|
22776 |
|
22777 | var s = [
|
22778 | 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
|
22779 | 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
|
22780 | 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
|
22781 | 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
|
22782 | 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
|
22783 | ];
|
22784 |
|
22785 | var sh = [
|
22786 | 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
|
22787 | 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
|
22788 | 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
|
22789 | 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
|
22790 | 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
|
22791 | ];
|
22792 |
|
22793 |
|
22794 | /***/ }),
|
22795 | /* 97 */
|
22796 | /***/ (function(module, exports, __webpack_require__) {
|
22797 |
|
22798 | "use strict";
|
22799 |
|
22800 |
|
22801 | var utils = __webpack_require__(6);
|
22802 | var assert = __webpack_require__(8);
|
22803 |
|
22804 | function Hmac(hash, key, enc) {
|
22805 | if (!(this instanceof Hmac))
|
22806 | return new Hmac(hash, key, enc);
|
22807 | this.Hash = hash;
|
22808 | this.blockSize = hash.blockSize / 8;
|
22809 | this.outSize = hash.outSize / 8;
|
22810 | this.inner = null;
|
22811 | this.outer = null;
|
22812 |
|
22813 | this._init(utils.toArray(key, enc));
|
22814 | }
|
22815 | module.exports = Hmac;
|
22816 |
|
22817 | Hmac.prototype._init = function init(key) {
|
22818 | // Shorten key, if needed
|
22819 | if (key.length > this.blockSize)
|
22820 | key = new this.Hash().update(key).digest();
|
22821 | assert(key.length <= this.blockSize);
|
22822 |
|
22823 | // Add padding to key
|
22824 | for (var i = key.length; i < this.blockSize; i++)
|
22825 | key.push(0);
|
22826 |
|
22827 | for (i = 0; i < key.length; i++)
|
22828 | key[i] ^= 0x36;
|
22829 | this.inner = new this.Hash().update(key);
|
22830 |
|
22831 | // 0x36 ^ 0x5c = 0x6a
|
22832 | for (i = 0; i < key.length; i++)
|
22833 | key[i] ^= 0x6a;
|
22834 | this.outer = new this.Hash().update(key);
|
22835 | };
|
22836 |
|
22837 | Hmac.prototype.update = function update(msg, enc) {
|
22838 | this.inner.update(msg, enc);
|
22839 | return this;
|
22840 | };
|
22841 |
|
22842 | Hmac.prototype.digest = function digest(enc) {
|
22843 | this.outer.update(this.inner.digest());
|
22844 | return this.outer.digest(enc);
|
22845 | };
|
22846 |
|
22847 |
|
22848 | /***/ }),
|
22849 | /* 98 */
|
22850 | /***/ (function(module, exports) {
|
22851 |
|
22852 | module.exports = {
|
22853 | doubles: {
|
22854 | step: 4,
|
22855 | points: [
|
22856 | [
|
22857 | 'e60fce93b59e9ec53011aabc21c23e97b2a31369b87a5ae9c44ee89e2a6dec0a',
|
22858 | 'f7e3507399e595929db99f34f57937101296891e44d23f0be1f32cce69616821'
|
22859 | ],
|
22860 | [
|
22861 | '8282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508',
|
22862 | '11f8a8098557dfe45e8256e830b60ace62d613ac2f7b17bed31b6eaff6e26caf'
|
22863 | ],
|
22864 | [
|
22865 | '175e159f728b865a72f99cc6c6fc846de0b93833fd2222ed73fce5b551e5b739',
|
22866 | 'd3506e0d9e3c79eba4ef97a51ff71f5eacb5955add24345c6efa6ffee9fed695'
|
22867 | ],
|
22868 | [
|
22869 | '363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640',
|
22870 | '4e273adfc732221953b445397f3363145b9a89008199ecb62003c7f3bee9de9'
|
22871 | ],
|
22872 | [
|
22873 | '8b4b5f165df3c2be8c6244b5b745638843e4a781a15bcd1b69f79a55dffdf80c',
|
22874 | '4aad0a6f68d308b4b3fbd7813ab0da04f9e336546162ee56b3eff0c65fd4fd36'
|
22875 | ],
|
22876 | [
|
22877 | '723cbaa6e5db996d6bf771c00bd548c7b700dbffa6c0e77bcb6115925232fcda',
|
22878 | '96e867b5595cc498a921137488824d6e2660a0653779494801dc069d9eb39f5f'
|
22879 | ],
|
22880 | [
|
22881 | 'eebfa4d493bebf98ba5feec812c2d3b50947961237a919839a533eca0e7dd7fa',
|
22882 | '5d9a8ca3970ef0f269ee7edaf178089d9ae4cdc3a711f712ddfd4fdae1de8999'
|
22883 | ],
|
22884 | [
|
22885 | '100f44da696e71672791d0a09b7bde459f1215a29b3c03bfefd7835b39a48db0',
|
22886 | 'cdd9e13192a00b772ec8f3300c090666b7ff4a18ff5195ac0fbd5cd62bc65a09'
|
22887 | ],
|
22888 | [
|
22889 | 'e1031be262c7ed1b1dc9227a4a04c017a77f8d4464f3b3852c8acde6e534fd2d',
|
22890 | '9d7061928940405e6bb6a4176597535af292dd419e1ced79a44f18f29456a00d'
|
22891 | ],
|
22892 | [
|
22893 | 'feea6cae46d55b530ac2839f143bd7ec5cf8b266a41d6af52d5e688d9094696d',
|
22894 | 'e57c6b6c97dce1bab06e4e12bf3ecd5c981c8957cc41442d3155debf18090088'
|
22895 | ],
|
22896 | [
|
22897 | 'da67a91d91049cdcb367be4be6ffca3cfeed657d808583de33fa978bc1ec6cb1',
|
22898 | '9bacaa35481642bc41f463f7ec9780e5dec7adc508f740a17e9ea8e27a68be1d'
|
22899 | ],
|
22900 | [
|
22901 | '53904faa0b334cdda6e000935ef22151ec08d0f7bb11069f57545ccc1a37b7c0',
|
22902 | '5bc087d0bc80106d88c9eccac20d3c1c13999981e14434699dcb096b022771c8'
|
22903 | ],
|
22904 | [
|
22905 | '8e7bcd0bd35983a7719cca7764ca906779b53a043a9b8bcaeff959f43ad86047',
|
22906 | '10b7770b2a3da4b3940310420ca9514579e88e2e47fd68b3ea10047e8460372a'
|
22907 | ],
|
22908 | [
|
22909 | '385eed34c1cdff21e6d0818689b81bde71a7f4f18397e6690a841e1599c43862',
|
22910 | '283bebc3e8ea23f56701de19e9ebf4576b304eec2086dc8cc0458fe5542e5453'
|
22911 | ],
|
22912 | [
|
22913 | '6f9d9b803ecf191637c73a4413dfa180fddf84a5947fbc9c606ed86c3fac3a7',
|
22914 | '7c80c68e603059ba69b8e2a30e45c4d47ea4dd2f5c281002d86890603a842160'
|
22915 | ],
|
22916 | [
|
22917 | '3322d401243c4e2582a2147c104d6ecbf774d163db0f5e5313b7e0e742d0e6bd',
|
22918 | '56e70797e9664ef5bfb019bc4ddaf9b72805f63ea2873af624f3a2e96c28b2a0'
|
22919 | ],
|
22920 | [
|
22921 | '85672c7d2de0b7da2bd1770d89665868741b3f9af7643397721d74d28134ab83',
|
22922 | '7c481b9b5b43b2eb6374049bfa62c2e5e77f17fcc5298f44c8e3094f790313a6'
|
22923 | ],
|
22924 | [
|
22925 | '948bf809b1988a46b06c9f1919413b10f9226c60f668832ffd959af60c82a0a',
|
22926 | '53a562856dcb6646dc6b74c5d1c3418c6d4dff08c97cd2bed4cb7f88d8c8e589'
|
22927 | ],
|
22928 | [
|
22929 | '6260ce7f461801c34f067ce0f02873a8f1b0e44dfc69752accecd819f38fd8e8',
|
22930 | 'bc2da82b6fa5b571a7f09049776a1ef7ecd292238051c198c1a84e95b2b4ae17'
|
22931 | ],
|
22932 | [
|
22933 | 'e5037de0afc1d8d43d8348414bbf4103043ec8f575bfdc432953cc8d2037fa2d',
|
22934 | '4571534baa94d3b5f9f98d09fb990bddbd5f5b03ec481f10e0e5dc841d755bda'
|
22935 | ],
|
22936 | [
|
22937 | 'e06372b0f4a207adf5ea905e8f1771b4e7e8dbd1c6a6c5b725866a0ae4fce725',
|
22938 | '7a908974bce18cfe12a27bb2ad5a488cd7484a7787104870b27034f94eee31dd'
|
22939 | ],
|
22940 | [
|
22941 | '213c7a715cd5d45358d0bbf9dc0ce02204b10bdde2a3f58540ad6908d0559754',
|
22942 | '4b6dad0b5ae462507013ad06245ba190bb4850f5f36a7eeddff2c27534b458f2'
|
22943 | ],
|
22944 | [
|
22945 | '4e7c272a7af4b34e8dbb9352a5419a87e2838c70adc62cddf0cc3a3b08fbd53c',
|
22946 | '17749c766c9d0b18e16fd09f6def681b530b9614bff7dd33e0b3941817dcaae6'
|
22947 | ],
|
22948 | [
|
22949 | 'fea74e3dbe778b1b10f238ad61686aa5c76e3db2be43057632427e2840fb27b6',
|
22950 | '6e0568db9b0b13297cf674deccb6af93126b596b973f7b77701d3db7f23cb96f'
|
22951 | ],
|
22952 | [
|
22953 | '76e64113f677cf0e10a2570d599968d31544e179b760432952c02a4417bdde39',
|
22954 | 'c90ddf8dee4e95cf577066d70681f0d35e2a33d2b56d2032b4b1752d1901ac01'
|
22955 | ],
|
22956 | [
|
22957 | 'c738c56b03b2abe1e8281baa743f8f9a8f7cc643df26cbee3ab150242bcbb891',
|
22958 | '893fb578951ad2537f718f2eacbfbbbb82314eef7880cfe917e735d9699a84c3'
|
22959 | ],
|
22960 | [
|
22961 | 'd895626548b65b81e264c7637c972877d1d72e5f3a925014372e9f6588f6c14b',
|
22962 | 'febfaa38f2bc7eae728ec60818c340eb03428d632bb067e179363ed75d7d991f'
|
22963 | ],
|
22964 | [
|
22965 | 'b8da94032a957518eb0f6433571e8761ceffc73693e84edd49150a564f676e03',
|
22966 | '2804dfa44805a1e4d7c99cc9762808b092cc584d95ff3b511488e4e74efdf6e7'
|
22967 | ],
|
22968 | [
|
22969 | 'e80fea14441fb33a7d8adab9475d7fab2019effb5156a792f1a11778e3c0df5d',
|
22970 | 'eed1de7f638e00771e89768ca3ca94472d155e80af322ea9fcb4291b6ac9ec78'
|
22971 | ],
|
22972 | [
|
22973 | 'a301697bdfcd704313ba48e51d567543f2a182031efd6915ddc07bbcc4e16070',
|
22974 | '7370f91cfb67e4f5081809fa25d40f9b1735dbf7c0a11a130c0d1a041e177ea1'
|
22975 | ],
|
22976 | [
|
22977 | '90ad85b389d6b936463f9d0512678de208cc330b11307fffab7ac63e3fb04ed4',
|
22978 | 'e507a3620a38261affdcbd9427222b839aefabe1582894d991d4d48cb6ef150'
|
22979 | ],
|
22980 | [
|
22981 | '8f68b9d2f63b5f339239c1ad981f162ee88c5678723ea3351b7b444c9ec4c0da',
|
22982 | '662a9f2dba063986de1d90c2b6be215dbbea2cfe95510bfdf23cbf79501fff82'
|
22983 | ],
|
22984 | [
|
22985 | 'e4f3fb0176af85d65ff99ff9198c36091f48e86503681e3e6686fd5053231e11',
|
22986 | '1e63633ad0ef4f1c1661a6d0ea02b7286cc7e74ec951d1c9822c38576feb73bc'
|
22987 | ],
|
22988 | [
|
22989 | '8c00fa9b18ebf331eb961537a45a4266c7034f2f0d4e1d0716fb6eae20eae29e',
|
22990 | 'efa47267fea521a1a9dc343a3736c974c2fadafa81e36c54e7d2a4c66702414b'
|
22991 | ],
|
22992 | [
|
22993 | 'e7a26ce69dd4829f3e10cec0a9e98ed3143d084f308b92c0997fddfc60cb3e41',
|
22994 | '2a758e300fa7984b471b006a1aafbb18d0a6b2c0420e83e20e8a9421cf2cfd51'
|
22995 | ],
|
22996 | [
|
22997 | 'b6459e0ee3662ec8d23540c223bcbdc571cbcb967d79424f3cf29eb3de6b80ef',
|
22998 | '67c876d06f3e06de1dadf16e5661db3c4b3ae6d48e35b2ff30bf0b61a71ba45'
|
22999 | ],
|
23000 | [
|
23001 | 'd68a80c8280bb840793234aa118f06231d6f1fc67e73c5a5deda0f5b496943e8',
|
23002 | 'db8ba9fff4b586d00c4b1f9177b0e28b5b0e7b8f7845295a294c84266b133120'
|
23003 | ],
|
23004 | [
|
23005 | '324aed7df65c804252dc0270907a30b09612aeb973449cea4095980fc28d3d5d',
|
23006 | '648a365774b61f2ff130c0c35aec1f4f19213b0c7e332843967224af96ab7c84'
|
23007 | ],
|
23008 | [
|
23009 | '4df9c14919cde61f6d51dfdbe5fee5dceec4143ba8d1ca888e8bd373fd054c96',
|
23010 | '35ec51092d8728050974c23a1d85d4b5d506cdc288490192ebac06cad10d5d'
|
23011 | ],
|
23012 | [
|
23013 | '9c3919a84a474870faed8a9c1cc66021523489054d7f0308cbfc99c8ac1f98cd',
|
23014 | 'ddb84f0f4a4ddd57584f044bf260e641905326f76c64c8e6be7e5e03d4fc599d'
|
23015 | ],
|
23016 | [
|
23017 | '6057170b1dd12fdf8de05f281d8e06bb91e1493a8b91d4cc5a21382120a959e5',
|
23018 | '9a1af0b26a6a4807add9a2daf71df262465152bc3ee24c65e899be932385a2a8'
|
23019 | ],
|
23020 | [
|
23021 | 'a576df8e23a08411421439a4518da31880cef0fba7d4df12b1a6973eecb94266',
|
23022 | '40a6bf20e76640b2c92b97afe58cd82c432e10a7f514d9f3ee8be11ae1b28ec8'
|
23023 | ],
|
23024 | [
|
23025 | '7778a78c28dec3e30a05fe9629de8c38bb30d1f5cf9a3a208f763889be58ad71',
|
23026 | '34626d9ab5a5b22ff7098e12f2ff580087b38411ff24ac563b513fc1fd9f43ac'
|
23027 | ],
|
23028 | [
|
23029 | '928955ee637a84463729fd30e7afd2ed5f96274e5ad7e5cb09eda9c06d903ac',
|
23030 | 'c25621003d3f42a827b78a13093a95eeac3d26efa8a8d83fc5180e935bcd091f'
|
23031 | ],
|
23032 | [
|
23033 | '85d0fef3ec6db109399064f3a0e3b2855645b4a907ad354527aae75163d82751',
|
23034 | '1f03648413a38c0be29d496e582cf5663e8751e96877331582c237a24eb1f962'
|
23035 | ],
|
23036 | [
|
23037 | 'ff2b0dce97eece97c1c9b6041798b85dfdfb6d8882da20308f5404824526087e',
|
23038 | '493d13fef524ba188af4c4dc54d07936c7b7ed6fb90e2ceb2c951e01f0c29907'
|
23039 | ],
|
23040 | [
|
23041 | '827fbbe4b1e880ea9ed2b2e6301b212b57f1ee148cd6dd28780e5e2cf856e241',
|
23042 | 'c60f9c923c727b0b71bef2c67d1d12687ff7a63186903166d605b68baec293ec'
|
23043 | ],
|
23044 | [
|
23045 | 'eaa649f21f51bdbae7be4ae34ce6e5217a58fdce7f47f9aa7f3b58fa2120e2b3',
|
23046 | 'be3279ed5bbbb03ac69a80f89879aa5a01a6b965f13f7e59d47a5305ba5ad93d'
|
23047 | ],
|
23048 | [
|
23049 | 'e4a42d43c5cf169d9391df6decf42ee541b6d8f0c9a137401e23632dda34d24f',
|
23050 | '4d9f92e716d1c73526fc99ccfb8ad34ce886eedfa8d8e4f13a7f7131deba9414'
|
23051 | ],
|
23052 | [
|
23053 | '1ec80fef360cbdd954160fadab352b6b92b53576a88fea4947173b9d4300bf19',
|
23054 | 'aeefe93756b5340d2f3a4958a7abbf5e0146e77f6295a07b671cdc1cc107cefd'
|
23055 | ],
|
23056 | [
|
23057 | '146a778c04670c2f91b00af4680dfa8bce3490717d58ba889ddb5928366642be',
|
23058 | 'b318e0ec3354028add669827f9d4b2870aaa971d2f7e5ed1d0b297483d83efd0'
|
23059 | ],
|
23060 | [
|
23061 | 'fa50c0f61d22e5f07e3acebb1aa07b128d0012209a28b9776d76a8793180eef9',
|
23062 | '6b84c6922397eba9b72cd2872281a68a5e683293a57a213b38cd8d7d3f4f2811'
|
23063 | ],
|
23064 | [
|
23065 | 'da1d61d0ca721a11b1a5bf6b7d88e8421a288ab5d5bba5220e53d32b5f067ec2',
|
23066 | '8157f55a7c99306c79c0766161c91e2966a73899d279b48a655fba0f1ad836f1'
|
23067 | ],
|
23068 | [
|
23069 | 'a8e282ff0c9706907215ff98e8fd416615311de0446f1e062a73b0610d064e13',
|
23070 | '7f97355b8db81c09abfb7f3c5b2515888b679a3e50dd6bd6cef7c73111f4cc0c'
|
23071 | ],
|
23072 | [
|
23073 | '174a53b9c9a285872d39e56e6913cab15d59b1fa512508c022f382de8319497c',
|
23074 | 'ccc9dc37abfc9c1657b4155f2c47f9e6646b3a1d8cb9854383da13ac079afa73'
|
23075 | ],
|
23076 | [
|
23077 | '959396981943785c3d3e57edf5018cdbe039e730e4918b3d884fdff09475b7ba',
|
23078 | '2e7e552888c331dd8ba0386a4b9cd6849c653f64c8709385e9b8abf87524f2fd'
|
23079 | ],
|
23080 | [
|
23081 | 'd2a63a50ae401e56d645a1153b109a8fcca0a43d561fba2dbb51340c9d82b151',
|
23082 | 'e82d86fb6443fcb7565aee58b2948220a70f750af484ca52d4142174dcf89405'
|
23083 | ],
|
23084 | [
|
23085 | '64587e2335471eb890ee7896d7cfdc866bacbdbd3839317b3436f9b45617e073',
|
23086 | 'd99fcdd5bf6902e2ae96dd6447c299a185b90a39133aeab358299e5e9faf6589'
|
23087 | ],
|
23088 | [
|
23089 | '8481bde0e4e4d885b3a546d3e549de042f0aa6cea250e7fd358d6c86dd45e458',
|
23090 | '38ee7b8cba5404dd84a25bf39cecb2ca900a79c42b262e556d64b1b59779057e'
|
23091 | ],
|
23092 | [
|
23093 | '13464a57a78102aa62b6979ae817f4637ffcfed3c4b1ce30bcd6303f6caf666b',
|
23094 | '69be159004614580ef7e433453ccb0ca48f300a81d0942e13f495a907f6ecc27'
|
23095 | ],
|
23096 | [
|
23097 | 'bc4a9df5b713fe2e9aef430bcc1dc97a0cd9ccede2f28588cada3a0d2d83f366',
|
23098 | 'd3a81ca6e785c06383937adf4b798caa6e8a9fbfa547b16d758d666581f33c1'
|
23099 | ],
|
23100 | [
|
23101 | '8c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa',
|
23102 | '40a30463a3305193378fedf31f7cc0eb7ae784f0451cb9459e71dc73cbef9482'
|
23103 | ],
|
23104 | [
|
23105 | '8ea9666139527a8c1dd94ce4f071fd23c8b350c5a4bb33748c4ba111faccae0',
|
23106 | '620efabbc8ee2782e24e7c0cfb95c5d735b783be9cf0f8e955af34a30e62b945'
|
23107 | ],
|
23108 | [
|
23109 | 'dd3625faef5ba06074669716bbd3788d89bdde815959968092f76cc4eb9a9787',
|
23110 | '7a188fa3520e30d461da2501045731ca941461982883395937f68d00c644a573'
|
23111 | ],
|
23112 | [
|
23113 | 'f710d79d9eb962297e4f6232b40e8f7feb2bc63814614d692c12de752408221e',
|
23114 | 'ea98e67232d3b3295d3b535532115ccac8612c721851617526ae47a9c77bfc82'
|
23115 | ]
|
23116 | ]
|
23117 | },
|
23118 | naf: {
|
23119 | wnd: 7,
|
23120 | points: [
|
23121 | [
|
23122 | 'f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9',
|
23123 | '388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672'
|
23124 | ],
|
23125 | [
|
23126 | '2f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4',
|
23127 | 'd8ac222636e5e3d6d4dba9dda6c9c426f788271bab0d6840dca87d3aa6ac62d6'
|
23128 | ],
|
23129 | [
|
23130 | '5cbdf0646e5db4eaa398f365f2ea7a0e3d419b7e0330e39ce92bddedcac4f9bc',
|
23131 | '6aebca40ba255960a3178d6d861a54dba813d0b813fde7b5a5082628087264da'
|
23132 | ],
|
23133 | [
|
23134 | 'acd484e2f0c7f65309ad178a9f559abde09796974c57e714c35f110dfc27ccbe',
|
23135 | 'cc338921b0a7d9fd64380971763b61e9add888a4375f8e0f05cc262ac64f9c37'
|
23136 | ],
|
23137 | [
|
23138 | '774ae7f858a9411e5ef4246b70c65aac5649980be5c17891bbec17895da008cb',
|
23139 | 'd984a032eb6b5e190243dd56d7b7b365372db1e2dff9d6a8301d74c9c953c61b'
|
23140 | ],
|
23141 | [
|
23142 | 'f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8',
|
23143 | 'ab0902e8d880a89758212eb65cdaf473a1a06da521fa91f29b5cb52db03ed81'
|
23144 | ],
|
23145 | [
|
23146 | 'd7924d4f7d43ea965a465ae3095ff41131e5946f3c85f79e44adbcf8e27e080e',
|
23147 | '581e2872a86c72a683842ec228cc6defea40af2bd896d3a5c504dc9ff6a26b58'
|
23148 | ],
|
23149 | [
|
23150 | 'defdea4cdb677750a420fee807eacf21eb9898ae79b9768766e4faa04a2d4a34',
|
23151 | '4211ab0694635168e997b0ead2a93daeced1f4a04a95c0f6cfb199f69e56eb77'
|
23152 | ],
|
23153 | [
|
23154 | '2b4ea0a797a443d293ef5cff444f4979f06acfebd7e86d277475656138385b6c',
|
23155 | '85e89bc037945d93b343083b5a1c86131a01f60c50269763b570c854e5c09b7a'
|
23156 | ],
|
23157 | [
|
23158 | '352bbf4a4cdd12564f93fa332ce333301d9ad40271f8107181340aef25be59d5',
|
23159 | '321eb4075348f534d59c18259dda3e1f4a1b3b2e71b1039c67bd3d8bcf81998c'
|
23160 | ],
|
23161 | [
|
23162 | '2fa2104d6b38d11b0230010559879124e42ab8dfeff5ff29dc9cdadd4ecacc3f',
|
23163 | '2de1068295dd865b64569335bd5dd80181d70ecfc882648423ba76b532b7d67'
|
23164 | ],
|
23165 | [
|
23166 | '9248279b09b4d68dab21a9b066edda83263c3d84e09572e269ca0cd7f5453714',
|
23167 | '73016f7bf234aade5d1aa71bdea2b1ff3fc0de2a887912ffe54a32ce97cb3402'
|
23168 | ],
|
23169 | [
|
23170 | 'daed4f2be3a8bf278e70132fb0beb7522f570e144bf615c07e996d443dee8729',
|
23171 | 'a69dce4a7d6c98e8d4a1aca87ef8d7003f83c230f3afa726ab40e52290be1c55'
|
23172 | ],
|
23173 | [
|
23174 | 'c44d12c7065d812e8acf28d7cbb19f9011ecd9e9fdf281b0e6a3b5e87d22e7db',
|
23175 | '2119a460ce326cdc76c45926c982fdac0e106e861edf61c5a039063f0e0e6482'
|
23176 | ],
|
23177 | [
|
23178 | '6a245bf6dc698504c89a20cfded60853152b695336c28063b61c65cbd269e6b4',
|
23179 | 'e022cf42c2bd4a708b3f5126f16a24ad8b33ba48d0423b6efd5e6348100d8a82'
|
23180 | ],
|
23181 | [
|
23182 | '1697ffa6fd9de627c077e3d2fe541084ce13300b0bec1146f95ae57f0d0bd6a5',
|
23183 | 'b9c398f186806f5d27561506e4557433a2cf15009e498ae7adee9d63d01b2396'
|
23184 | ],
|
23185 | [
|
23186 | '605bdb019981718b986d0f07e834cb0d9deb8360ffb7f61df982345ef27a7479',
|
23187 | '2972d2de4f8d20681a78d93ec96fe23c26bfae84fb14db43b01e1e9056b8c49'
|
23188 | ],
|
23189 | [
|
23190 | '62d14dab4150bf497402fdc45a215e10dcb01c354959b10cfe31c7e9d87ff33d',
|
23191 | '80fc06bd8cc5b01098088a1950eed0db01aa132967ab472235f5642483b25eaf'
|
23192 | ],
|
23193 | [
|
23194 | '80c60ad0040f27dade5b4b06c408e56b2c50e9f56b9b8b425e555c2f86308b6f',
|
23195 | '1c38303f1cc5c30f26e66bad7fe72f70a65eed4cbe7024eb1aa01f56430bd57a'
|
23196 | ],
|
23197 | [
|
23198 | '7a9375ad6167ad54aa74c6348cc54d344cc5dc9487d847049d5eabb0fa03c8fb',
|
23199 | 'd0e3fa9eca8726909559e0d79269046bdc59ea10c70ce2b02d499ec224dc7f7'
|
23200 | ],
|
23201 | [
|
23202 | 'd528ecd9b696b54c907a9ed045447a79bb408ec39b68df504bb51f459bc3ffc9',
|
23203 | 'eecf41253136e5f99966f21881fd656ebc4345405c520dbc063465b521409933'
|
23204 | ],
|
23205 | [
|
23206 | '49370a4b5f43412ea25f514e8ecdad05266115e4a7ecb1387231808f8b45963',
|
23207 | '758f3f41afd6ed428b3081b0512fd62a54c3f3afbb5b6764b653052a12949c9a'
|
23208 | ],
|
23209 | [
|
23210 | '77f230936ee88cbbd73df930d64702ef881d811e0e1498e2f1c13eb1fc345d74',
|
23211 | '958ef42a7886b6400a08266e9ba1b37896c95330d97077cbbe8eb3c7671c60d6'
|
23212 | ],
|
23213 | [
|
23214 | 'f2dac991cc4ce4b9ea44887e5c7c0bce58c80074ab9d4dbaeb28531b7739f530',
|
23215 | 'e0dedc9b3b2f8dad4da1f32dec2531df9eb5fbeb0598e4fd1a117dba703a3c37'
|
23216 | ],
|
23217 | [
|
23218 | '463b3d9f662621fb1b4be8fbbe2520125a216cdfc9dae3debcba4850c690d45b',
|
23219 | '5ed430d78c296c3543114306dd8622d7c622e27c970a1de31cb377b01af7307e'
|
23220 | ],
|
23221 | [
|
23222 | 'f16f804244e46e2a09232d4aff3b59976b98fac14328a2d1a32496b49998f247',
|
23223 | 'cedabd9b82203f7e13d206fcdf4e33d92a6c53c26e5cce26d6579962c4e31df6'
|
23224 | ],
|
23225 | [
|
23226 | 'caf754272dc84563b0352b7a14311af55d245315ace27c65369e15f7151d41d1',
|
23227 | 'cb474660ef35f5f2a41b643fa5e460575f4fa9b7962232a5c32f908318a04476'
|
23228 | ],
|
23229 | [
|
23230 | '2600ca4b282cb986f85d0f1709979d8b44a09c07cb86d7c124497bc86f082120',
|
23231 | '4119b88753c15bd6a693b03fcddbb45d5ac6be74ab5f0ef44b0be9475a7e4b40'
|
23232 | ],
|
23233 | [
|
23234 | '7635ca72d7e8432c338ec53cd12220bc01c48685e24f7dc8c602a7746998e435',
|
23235 | '91b649609489d613d1d5e590f78e6d74ecfc061d57048bad9e76f302c5b9c61'
|
23236 | ],
|
23237 | [
|
23238 | '754e3239f325570cdbbf4a87deee8a66b7f2b33479d468fbc1a50743bf56cc18',
|
23239 | '673fb86e5bda30fb3cd0ed304ea49a023ee33d0197a695d0c5d98093c536683'
|
23240 | ],
|
23241 | [
|
23242 | 'e3e6bd1071a1e96aff57859c82d570f0330800661d1c952f9fe2694691d9b9e8',
|
23243 | '59c9e0bba394e76f40c0aa58379a3cb6a5a2283993e90c4167002af4920e37f5'
|
23244 | ],
|
23245 | [
|
23246 | '186b483d056a033826ae73d88f732985c4ccb1f32ba35f4b4cc47fdcf04aa6eb',
|
23247 | '3b952d32c67cf77e2e17446e204180ab21fb8090895138b4a4a797f86e80888b'
|
23248 | ],
|
23249 | [
|
23250 | 'df9d70a6b9876ce544c98561f4be4f725442e6d2b737d9c91a8321724ce0963f',
|
23251 | '55eb2dafd84d6ccd5f862b785dc39d4ab157222720ef9da217b8c45cf2ba2417'
|
23252 | ],
|
23253 | [
|
23254 | '5edd5cc23c51e87a497ca815d5dce0f8ab52554f849ed8995de64c5f34ce7143',
|
23255 | 'efae9c8dbc14130661e8cec030c89ad0c13c66c0d17a2905cdc706ab7399a868'
|
23256 | ],
|
23257 | [
|
23258 | '290798c2b6476830da12fe02287e9e777aa3fba1c355b17a722d362f84614fba',
|
23259 | 'e38da76dcd440621988d00bcf79af25d5b29c094db2a23146d003afd41943e7a'
|
23260 | ],
|
23261 | [
|
23262 | 'af3c423a95d9f5b3054754efa150ac39cd29552fe360257362dfdecef4053b45',
|
23263 | 'f98a3fd831eb2b749a93b0e6f35cfb40c8cd5aa667a15581bc2feded498fd9c6'
|
23264 | ],
|
23265 | [
|
23266 | '766dbb24d134e745cccaa28c99bf274906bb66b26dcf98df8d2fed50d884249a',
|
23267 | '744b1152eacbe5e38dcc887980da38b897584a65fa06cedd2c924f97cbac5996'
|
23268 | ],
|
23269 | [
|
23270 | '59dbf46f8c94759ba21277c33784f41645f7b44f6c596a58ce92e666191abe3e',
|
23271 | 'c534ad44175fbc300f4ea6ce648309a042ce739a7919798cd85e216c4a307f6e'
|
23272 | ],
|
23273 | [
|
23274 | 'f13ada95103c4537305e691e74e9a4a8dd647e711a95e73cb62dc6018cfd87b8',
|
23275 | 'e13817b44ee14de663bf4bc808341f326949e21a6a75c2570778419bdaf5733d'
|
23276 | ],
|
23277 | [
|
23278 | '7754b4fa0e8aced06d4167a2c59cca4cda1869c06ebadfb6488550015a88522c',
|
23279 | '30e93e864e669d82224b967c3020b8fa8d1e4e350b6cbcc537a48b57841163a2'
|
23280 | ],
|
23281 | [
|
23282 | '948dcadf5990e048aa3874d46abef9d701858f95de8041d2a6828c99e2262519',
|
23283 | 'e491a42537f6e597d5d28a3224b1bc25df9154efbd2ef1d2cbba2cae5347d57e'
|
23284 | ],
|
23285 | [
|
23286 | '7962414450c76c1689c7b48f8202ec37fb224cf5ac0bfa1570328a8a3d7c77ab',
|
23287 | '100b610ec4ffb4760d5c1fc133ef6f6b12507a051f04ac5760afa5b29db83437'
|
23288 | ],
|
23289 | [
|
23290 | '3514087834964b54b15b160644d915485a16977225b8847bb0dd085137ec47ca',
|
23291 | 'ef0afbb2056205448e1652c48e8127fc6039e77c15c2378b7e7d15a0de293311'
|
23292 | ],
|
23293 | [
|
23294 | 'd3cc30ad6b483e4bc79ce2c9dd8bc54993e947eb8df787b442943d3f7b527eaf',
|
23295 | '8b378a22d827278d89c5e9be8f9508ae3c2ad46290358630afb34db04eede0a4'
|
23296 | ],
|
23297 | [
|
23298 | '1624d84780732860ce1c78fcbfefe08b2b29823db913f6493975ba0ff4847610',
|
23299 | '68651cf9b6da903e0914448c6cd9d4ca896878f5282be4c8cc06e2a404078575'
|
23300 | ],
|
23301 | [
|
23302 | '733ce80da955a8a26902c95633e62a985192474b5af207da6df7b4fd5fc61cd4',
|
23303 | 'f5435a2bd2badf7d485a4d8b8db9fcce3e1ef8e0201e4578c54673bc1dc5ea1d'
|
23304 | ],
|
23305 | [
|
23306 | '15d9441254945064cf1a1c33bbd3b49f8966c5092171e699ef258dfab81c045c',
|
23307 | 'd56eb30b69463e7234f5137b73b84177434800bacebfc685fc37bbe9efe4070d'
|
23308 | ],
|
23309 | [
|
23310 | 'a1d0fcf2ec9de675b612136e5ce70d271c21417c9d2b8aaaac138599d0717940',
|
23311 | 'edd77f50bcb5a3cab2e90737309667f2641462a54070f3d519212d39c197a629'
|
23312 | ],
|
23313 | [
|
23314 | 'e22fbe15c0af8ccc5780c0735f84dbe9a790badee8245c06c7ca37331cb36980',
|
23315 | 'a855babad5cd60c88b430a69f53a1a7a38289154964799be43d06d77d31da06'
|
23316 | ],
|
23317 | [
|
23318 | '311091dd9860e8e20ee13473c1155f5f69635e394704eaa74009452246cfa9b3',
|
23319 | '66db656f87d1f04fffd1f04788c06830871ec5a64feee685bd80f0b1286d8374'
|
23320 | ],
|
23321 | [
|
23322 | '34c1fd04d301be89b31c0442d3e6ac24883928b45a9340781867d4232ec2dbdf',
|
23323 | '9414685e97b1b5954bd46f730174136d57f1ceeb487443dc5321857ba73abee'
|
23324 | ],
|
23325 | [
|
23326 | 'f219ea5d6b54701c1c14de5b557eb42a8d13f3abbcd08affcc2a5e6b049b8d63',
|
23327 | '4cb95957e83d40b0f73af4544cccf6b1f4b08d3c07b27fb8d8c2962a400766d1'
|
23328 | ],
|
23329 | [
|
23330 | 'd7b8740f74a8fbaab1f683db8f45de26543a5490bca627087236912469a0b448',
|
23331 | 'fa77968128d9c92ee1010f337ad4717eff15db5ed3c049b3411e0315eaa4593b'
|
23332 | ],
|
23333 | [
|
23334 | '32d31c222f8f6f0ef86f7c98d3a3335ead5bcd32abdd94289fe4d3091aa824bf',
|
23335 | '5f3032f5892156e39ccd3d7915b9e1da2e6dac9e6f26e961118d14b8462e1661'
|
23336 | ],
|
23337 | [
|
23338 | '7461f371914ab32671045a155d9831ea8793d77cd59592c4340f86cbc18347b5',
|
23339 | '8ec0ba238b96bec0cbdddcae0aa442542eee1ff50c986ea6b39847b3cc092ff6'
|
23340 | ],
|
23341 | [
|
23342 | 'ee079adb1df1860074356a25aa38206a6d716b2c3e67453d287698bad7b2b2d6',
|
23343 | '8dc2412aafe3be5c4c5f37e0ecc5f9f6a446989af04c4e25ebaac479ec1c8c1e'
|
23344 | ],
|
23345 | [
|
23346 | '16ec93e447ec83f0467b18302ee620f7e65de331874c9dc72bfd8616ba9da6b5',
|
23347 | '5e4631150e62fb40d0e8c2a7ca5804a39d58186a50e497139626778e25b0674d'
|
23348 | ],
|
23349 | [
|
23350 | 'eaa5f980c245f6f038978290afa70b6bd8855897f98b6aa485b96065d537bd99',
|
23351 | 'f65f5d3e292c2e0819a528391c994624d784869d7e6ea67fb18041024edc07dc'
|
23352 | ],
|
23353 | [
|
23354 | '78c9407544ac132692ee1910a02439958ae04877151342ea96c4b6b35a49f51',
|
23355 | 'f3e0319169eb9b85d5404795539a5e68fa1fbd583c064d2462b675f194a3ddb4'
|
23356 | ],
|
23357 | [
|
23358 | '494f4be219a1a77016dcd838431aea0001cdc8ae7a6fc688726578d9702857a5',
|
23359 | '42242a969283a5f339ba7f075e36ba2af925ce30d767ed6e55f4b031880d562c'
|
23360 | ],
|
23361 | [
|
23362 | 'a598a8030da6d86c6bc7f2f5144ea549d28211ea58faa70ebf4c1e665c1fe9b5',
|
23363 | '204b5d6f84822c307e4b4a7140737aec23fc63b65b35f86a10026dbd2d864e6b'
|
23364 | ],
|
23365 | [
|
23366 | 'c41916365abb2b5d09192f5f2dbeafec208f020f12570a184dbadc3e58595997',
|
23367 | '4f14351d0087efa49d245b328984989d5caf9450f34bfc0ed16e96b58fa9913'
|
23368 | ],
|
23369 | [
|
23370 | '841d6063a586fa475a724604da03bc5b92a2e0d2e0a36acfe4c73a5514742881',
|
23371 | '73867f59c0659e81904f9a1c7543698e62562d6744c169ce7a36de01a8d6154'
|
23372 | ],
|
23373 | [
|
23374 | '5e95bb399a6971d376026947f89bde2f282b33810928be4ded112ac4d70e20d5',
|
23375 | '39f23f366809085beebfc71181313775a99c9aed7d8ba38b161384c746012865'
|
23376 | ],
|
23377 | [
|
23378 | '36e4641a53948fd476c39f8a99fd974e5ec07564b5315d8bf99471bca0ef2f66',
|
23379 | 'd2424b1b1abe4eb8164227b085c9aa9456ea13493fd563e06fd51cf5694c78fc'
|
23380 | ],
|
23381 | [
|
23382 | '336581ea7bfbbb290c191a2f507a41cf5643842170e914faeab27c2c579f726',
|
23383 | 'ead12168595fe1be99252129b6e56b3391f7ab1410cd1e0ef3dcdcabd2fda224'
|
23384 | ],
|
23385 | [
|
23386 | '8ab89816dadfd6b6a1f2634fcf00ec8403781025ed6890c4849742706bd43ede',
|
23387 | '6fdcef09f2f6d0a044e654aef624136f503d459c3e89845858a47a9129cdd24e'
|
23388 | ],
|
23389 | [
|
23390 | '1e33f1a746c9c5778133344d9299fcaa20b0938e8acff2544bb40284b8c5fb94',
|
23391 | '60660257dd11b3aa9c8ed618d24edff2306d320f1d03010e33a7d2057f3b3b6'
|
23392 | ],
|
23393 | [
|
23394 | '85b7c1dcb3cec1b7ee7f30ded79dd20a0ed1f4cc18cbcfcfa410361fd8f08f31',
|
23395 | '3d98a9cdd026dd43f39048f25a8847f4fcafad1895d7a633c6fed3c35e999511'
|
23396 | ],
|
23397 | [
|
23398 | '29df9fbd8d9e46509275f4b125d6d45d7fbe9a3b878a7af872a2800661ac5f51',
|
23399 | 'b4c4fe99c775a606e2d8862179139ffda61dc861c019e55cd2876eb2a27d84b'
|
23400 | ],
|
23401 | [
|
23402 | 'a0b1cae06b0a847a3fea6e671aaf8adfdfe58ca2f768105c8082b2e449fce252',
|
23403 | 'ae434102edde0958ec4b19d917a6a28e6b72da1834aff0e650f049503a296cf2'
|
23404 | ],
|
23405 | [
|
23406 | '4e8ceafb9b3e9a136dc7ff67e840295b499dfb3b2133e4ba113f2e4c0e121e5',
|
23407 | 'cf2174118c8b6d7a4b48f6d534ce5c79422c086a63460502b827ce62a326683c'
|
23408 | ],
|
23409 | [
|
23410 | 'd24a44e047e19b6f5afb81c7ca2f69080a5076689a010919f42725c2b789a33b',
|
23411 | '6fb8d5591b466f8fc63db50f1c0f1c69013f996887b8244d2cdec417afea8fa3'
|
23412 | ],
|
23413 | [
|
23414 | 'ea01606a7a6c9cdd249fdfcfacb99584001edd28abbab77b5104e98e8e3b35d4',
|
23415 | '322af4908c7312b0cfbfe369f7a7b3cdb7d4494bc2823700cfd652188a3ea98d'
|
23416 | ],
|
23417 | [
|
23418 | 'af8addbf2b661c8a6c6328655eb96651252007d8c5ea31be4ad196de8ce2131f',
|
23419 | '6749e67c029b85f52a034eafd096836b2520818680e26ac8f3dfbcdb71749700'
|
23420 | ],
|
23421 | [
|
23422 | 'e3ae1974566ca06cc516d47e0fb165a674a3dabcfca15e722f0e3450f45889',
|
23423 | '2aeabe7e4531510116217f07bf4d07300de97e4874f81f533420a72eeb0bd6a4'
|
23424 | ],
|
23425 | [
|
23426 | '591ee355313d99721cf6993ffed1e3e301993ff3ed258802075ea8ced397e246',
|
23427 | 'b0ea558a113c30bea60fc4775460c7901ff0b053d25ca2bdeee98f1a4be5d196'
|
23428 | ],
|
23429 | [
|
23430 | '11396d55fda54c49f19aa97318d8da61fa8584e47b084945077cf03255b52984',
|
23431 | '998c74a8cd45ac01289d5833a7beb4744ff536b01b257be4c5767bea93ea57a4'
|
23432 | ],
|
23433 | [
|
23434 | '3c5d2a1ba39c5a1790000738c9e0c40b8dcdfd5468754b6405540157e017aa7a',
|
23435 | 'b2284279995a34e2f9d4de7396fc18b80f9b8b9fdd270f6661f79ca4c81bd257'
|
23436 | ],
|
23437 | [
|
23438 | 'cc8704b8a60a0defa3a99a7299f2e9c3fbc395afb04ac078425ef8a1793cc030',
|
23439 | 'bdd46039feed17881d1e0862db347f8cf395b74fc4bcdc4e940b74e3ac1f1b13'
|
23440 | ],
|
23441 | [
|
23442 | 'c533e4f7ea8555aacd9777ac5cad29b97dd4defccc53ee7ea204119b2889b197',
|
23443 | '6f0a256bc5efdf429a2fb6242f1a43a2d9b925bb4a4b3a26bb8e0f45eb596096'
|
23444 | ],
|
23445 | [
|
23446 | 'c14f8f2ccb27d6f109f6d08d03cc96a69ba8c34eec07bbcf566d48e33da6593',
|
23447 | 'c359d6923bb398f7fd4473e16fe1c28475b740dd098075e6c0e8649113dc3a38'
|
23448 | ],
|
23449 | [
|
23450 | 'a6cbc3046bc6a450bac24789fa17115a4c9739ed75f8f21ce441f72e0b90e6ef',
|
23451 | '21ae7f4680e889bb130619e2c0f95a360ceb573c70603139862afd617fa9b9f'
|
23452 | ],
|
23453 | [
|
23454 | '347d6d9a02c48927ebfb86c1359b1caf130a3c0267d11ce6344b39f99d43cc38',
|
23455 | '60ea7f61a353524d1c987f6ecec92f086d565ab687870cb12689ff1e31c74448'
|
23456 | ],
|
23457 | [
|
23458 | 'da6545d2181db8d983f7dcb375ef5866d47c67b1bf31c8cf855ef7437b72656a',
|
23459 | '49b96715ab6878a79e78f07ce5680c5d6673051b4935bd897fea824b77dc208a'
|
23460 | ],
|
23461 | [
|
23462 | 'c40747cc9d012cb1a13b8148309c6de7ec25d6945d657146b9d5994b8feb1111',
|
23463 | '5ca560753be2a12fc6de6caf2cb489565db936156b9514e1bb5e83037e0fa2d4'
|
23464 | ],
|
23465 | [
|
23466 | '4e42c8ec82c99798ccf3a610be870e78338c7f713348bd34c8203ef4037f3502',
|
23467 | '7571d74ee5e0fb92a7a8b33a07783341a5492144cc54bcc40a94473693606437'
|
23468 | ],
|
23469 | [
|
23470 | '3775ab7089bc6af823aba2e1af70b236d251cadb0c86743287522a1b3b0dedea',
|
23471 | 'be52d107bcfa09d8bcb9736a828cfa7fac8db17bf7a76a2c42ad961409018cf7'
|
23472 | ],
|
23473 | [
|
23474 | 'cee31cbf7e34ec379d94fb814d3d775ad954595d1314ba8846959e3e82f74e26',
|
23475 | '8fd64a14c06b589c26b947ae2bcf6bfa0149ef0be14ed4d80f448a01c43b1c6d'
|
23476 | ],
|
23477 | [
|
23478 | 'b4f9eaea09b6917619f6ea6a4eb5464efddb58fd45b1ebefcdc1a01d08b47986',
|
23479 | '39e5c9925b5a54b07433a4f18c61726f8bb131c012ca542eb24a8ac07200682a'
|
23480 | ],
|
23481 | [
|
23482 | 'd4263dfc3d2df923a0179a48966d30ce84e2515afc3dccc1b77907792ebcc60e',
|
23483 | '62dfaf07a0f78feb30e30d6295853ce189e127760ad6cf7fae164e122a208d54'
|
23484 | ],
|
23485 | [
|
23486 | '48457524820fa65a4f8d35eb6930857c0032acc0a4a2de422233eeda897612c4',
|
23487 | '25a748ab367979d98733c38a1fa1c2e7dc6cc07db2d60a9ae7a76aaa49bd0f77'
|
23488 | ],
|
23489 | [
|
23490 | 'dfeeef1881101f2cb11644f3a2afdfc2045e19919152923f367a1767c11cceda',
|
23491 | 'ecfb7056cf1de042f9420bab396793c0c390bde74b4bbdff16a83ae09a9a7517'
|
23492 | ],
|
23493 | [
|
23494 | '6d7ef6b17543f8373c573f44e1f389835d89bcbc6062ced36c82df83b8fae859',
|
23495 | 'cd450ec335438986dfefa10c57fea9bcc521a0959b2d80bbf74b190dca712d10'
|
23496 | ],
|
23497 | [
|
23498 | 'e75605d59102a5a2684500d3b991f2e3f3c88b93225547035af25af66e04541f',
|
23499 | 'f5c54754a8f71ee540b9b48728473e314f729ac5308b06938360990e2bfad125'
|
23500 | ],
|
23501 | [
|
23502 | 'eb98660f4c4dfaa06a2be453d5020bc99a0c2e60abe388457dd43fefb1ed620c',
|
23503 | '6cb9a8876d9cb8520609af3add26cd20a0a7cd8a9411131ce85f44100099223e'
|
23504 | ],
|
23505 | [
|
23506 | '13e87b027d8514d35939f2e6892b19922154596941888336dc3563e3b8dba942',
|
23507 | 'fef5a3c68059a6dec5d624114bf1e91aac2b9da568d6abeb2570d55646b8adf1'
|
23508 | ],
|
23509 | [
|
23510 | 'ee163026e9fd6fe017c38f06a5be6fc125424b371ce2708e7bf4491691e5764a',
|
23511 | '1acb250f255dd61c43d94ccc670d0f58f49ae3fa15b96623e5430da0ad6c62b2'
|
23512 | ],
|
23513 | [
|
23514 | 'b268f5ef9ad51e4d78de3a750c2dc89b1e626d43505867999932e5db33af3d80',
|
23515 | '5f310d4b3c99b9ebb19f77d41c1dee018cf0d34fd4191614003e945a1216e423'
|
23516 | ],
|
23517 | [
|
23518 | 'ff07f3118a9df035e9fad85eb6c7bfe42b02f01ca99ceea3bf7ffdba93c4750d',
|
23519 | '438136d603e858a3a5c440c38eccbaddc1d2942114e2eddd4740d098ced1f0d8'
|
23520 | ],
|
23521 | [
|
23522 | '8d8b9855c7c052a34146fd20ffb658bea4b9f69e0d825ebec16e8c3ce2b526a1',
|
23523 | 'cdb559eedc2d79f926baf44fb84ea4d44bcf50fee51d7ceb30e2e7f463036758'
|
23524 | ],
|
23525 | [
|
23526 | '52db0b5384dfbf05bfa9d472d7ae26dfe4b851ceca91b1eba54263180da32b63',
|
23527 | 'c3b997d050ee5d423ebaf66a6db9f57b3180c902875679de924b69d84a7b375'
|
23528 | ],
|
23529 | [
|
23530 | 'e62f9490d3d51da6395efd24e80919cc7d0f29c3f3fa48c6fff543becbd43352',
|
23531 | '6d89ad7ba4876b0b22c2ca280c682862f342c8591f1daf5170e07bfd9ccafa7d'
|
23532 | ],
|
23533 | [
|
23534 | '7f30ea2476b399b4957509c88f77d0191afa2ff5cb7b14fd6d8e7d65aaab1193',
|
23535 | 'ca5ef7d4b231c94c3b15389a5f6311e9daff7bb67b103e9880ef4bff637acaec'
|
23536 | ],
|
23537 | [
|
23538 | '5098ff1e1d9f14fb46a210fada6c903fef0fb7b4a1dd1d9ac60a0361800b7a00',
|
23539 | '9731141d81fc8f8084d37c6e7542006b3ee1b40d60dfe5362a5b132fd17ddc0'
|
23540 | ],
|
23541 | [
|
23542 | '32b78c7de9ee512a72895be6b9cbefa6e2f3c4ccce445c96b9f2c81e2778ad58',
|
23543 | 'ee1849f513df71e32efc3896ee28260c73bb80547ae2275ba497237794c8753c'
|
23544 | ],
|
23545 | [
|
23546 | 'e2cb74fddc8e9fbcd076eef2a7c72b0ce37d50f08269dfc074b581550547a4f7',
|
23547 | 'd3aa2ed71c9dd2247a62df062736eb0baddea9e36122d2be8641abcb005cc4a4'
|
23548 | ],
|
23549 | [
|
23550 | '8438447566d4d7bedadc299496ab357426009a35f235cb141be0d99cd10ae3a8',
|
23551 | 'c4e1020916980a4da5d01ac5e6ad330734ef0d7906631c4f2390426b2edd791f'
|
23552 | ],
|
23553 | [
|
23554 | '4162d488b89402039b584c6fc6c308870587d9c46f660b878ab65c82c711d67e',
|
23555 | '67163e903236289f776f22c25fb8a3afc1732f2b84b4e95dbda47ae5a0852649'
|
23556 | ],
|
23557 | [
|
23558 | '3fad3fa84caf0f34f0f89bfd2dcf54fc175d767aec3e50684f3ba4a4bf5f683d',
|
23559 | 'cd1bc7cb6cc407bb2f0ca647c718a730cf71872e7d0d2a53fa20efcdfe61826'
|
23560 | ],
|
23561 | [
|
23562 | '674f2600a3007a00568c1a7ce05d0816c1fb84bf1370798f1c69532faeb1a86b',
|
23563 | '299d21f9413f33b3edf43b257004580b70db57da0b182259e09eecc69e0d38a5'
|
23564 | ],
|
23565 | [
|
23566 | 'd32f4da54ade74abb81b815ad1fb3b263d82d6c692714bcff87d29bd5ee9f08f',
|
23567 | 'f9429e738b8e53b968e99016c059707782e14f4535359d582fc416910b3eea87'
|
23568 | ],
|
23569 | [
|
23570 | '30e4e670435385556e593657135845d36fbb6931f72b08cb1ed954f1e3ce3ff6',
|
23571 | '462f9bce619898638499350113bbc9b10a878d35da70740dc695a559eb88db7b'
|
23572 | ],
|
23573 | [
|
23574 | 'be2062003c51cc3004682904330e4dee7f3dcd10b01e580bf1971b04d4cad297',
|
23575 | '62188bc49d61e5428573d48a74e1c655b1c61090905682a0d5558ed72dccb9bc'
|
23576 | ],
|
23577 | [
|
23578 | '93144423ace3451ed29e0fb9ac2af211cb6e84a601df5993c419859fff5df04a',
|
23579 | '7c10dfb164c3425f5c71a3f9d7992038f1065224f72bb9d1d902a6d13037b47c'
|
23580 | ],
|
23581 | [
|
23582 | 'b015f8044f5fcbdcf21ca26d6c34fb8197829205c7b7d2a7cb66418c157b112c',
|
23583 | 'ab8c1e086d04e813744a655b2df8d5f83b3cdc6faa3088c1d3aea1454e3a1d5f'
|
23584 | ],
|
23585 | [
|
23586 | 'd5e9e1da649d97d89e4868117a465a3a4f8a18de57a140d36b3f2af341a21b52',
|
23587 | '4cb04437f391ed73111a13cc1d4dd0db1693465c2240480d8955e8592f27447a'
|
23588 | ],
|
23589 | [
|
23590 | 'd3ae41047dd7ca065dbf8ed77b992439983005cd72e16d6f996a5316d36966bb',
|
23591 | 'bd1aeb21ad22ebb22a10f0303417c6d964f8cdd7df0aca614b10dc14d125ac46'
|
23592 | ],
|
23593 | [
|
23594 | '463e2763d885f958fc66cdd22800f0a487197d0a82e377b49f80af87c897b065',
|
23595 | 'bfefacdb0e5d0fd7df3a311a94de062b26b80c61fbc97508b79992671ef7ca7f'
|
23596 | ],
|
23597 | [
|
23598 | '7985fdfd127c0567c6f53ec1bb63ec3158e597c40bfe747c83cddfc910641917',
|
23599 | '603c12daf3d9862ef2b25fe1de289aed24ed291e0ec6708703a5bd567f32ed03'
|
23600 | ],
|
23601 | [
|
23602 | '74a1ad6b5f76e39db2dd249410eac7f99e74c59cb83d2d0ed5ff1543da7703e9',
|
23603 | 'cc6157ef18c9c63cd6193d83631bbea0093e0968942e8c33d5737fd790e0db08'
|
23604 | ],
|
23605 | [
|
23606 | '30682a50703375f602d416664ba19b7fc9bab42c72747463a71d0896b22f6da3',
|
23607 | '553e04f6b018b4fa6c8f39e7f311d3176290d0e0f19ca73f17714d9977a22ff8'
|
23608 | ],
|
23609 | [
|
23610 | '9e2158f0d7c0d5f26c3791efefa79597654e7a2b2464f52b1ee6c1347769ef57',
|
23611 | '712fcdd1b9053f09003a3481fa7762e9ffd7c8ef35a38509e2fbf2629008373'
|
23612 | ],
|
23613 | [
|
23614 | '176e26989a43c9cfeba4029c202538c28172e566e3c4fce7322857f3be327d66',
|
23615 | 'ed8cc9d04b29eb877d270b4878dc43c19aefd31f4eee09ee7b47834c1fa4b1c3'
|
23616 | ],
|
23617 | [
|
23618 | '75d46efea3771e6e68abb89a13ad747ecf1892393dfc4f1b7004788c50374da8',
|
23619 | '9852390a99507679fd0b86fd2b39a868d7efc22151346e1a3ca4726586a6bed8'
|
23620 | ],
|
23621 | [
|
23622 | '809a20c67d64900ffb698c4c825f6d5f2310fb0451c869345b7319f645605721',
|
23623 | '9e994980d9917e22b76b061927fa04143d096ccc54963e6a5ebfa5f3f8e286c1'
|
23624 | ],
|
23625 | [
|
23626 | '1b38903a43f7f114ed4500b4eac7083fdefece1cf29c63528d563446f972c180',
|
23627 | '4036edc931a60ae889353f77fd53de4a2708b26b6f5da72ad3394119daf408f9'
|
23628 | ]
|
23629 | ]
|
23630 | }
|
23631 | };
|
23632 |
|
23633 |
|
23634 | /***/ }),
|
23635 | /* 99 */
|
23636 | /***/ (function(module, exports, __webpack_require__) {
|
23637 |
|
23638 | "use strict";
|
23639 |
|
23640 |
|
23641 | var BN = __webpack_require__(3);
|
23642 | var HmacDRBG = __webpack_require__(100);
|
23643 | var elliptic = __webpack_require__(5);
|
23644 | var utils = elliptic.utils;
|
23645 | var assert = utils.assert;
|
23646 |
|
23647 | var KeyPair = __webpack_require__(101);
|
23648 | var Signature = __webpack_require__(102);
|
23649 |
|
23650 | function EC(options) {
|
23651 | if (!(this instanceof EC))
|
23652 | return new EC(options);
|
23653 |
|
23654 | // Shortcut `elliptic.ec(curve-name)`
|
23655 | if (typeof options === 'string') {
|
23656 | assert(elliptic.curves.hasOwnProperty(options), 'Unknown curve ' + options);
|
23657 |
|
23658 | options = elliptic.curves[options];
|
23659 | }
|
23660 |
|
23661 | // Shortcut for `elliptic.ec(elliptic.curves.curveName)`
|
23662 | if (options instanceof elliptic.curves.PresetCurve)
|
23663 | options = { curve: options };
|
23664 |
|
23665 | this.curve = options.curve.curve;
|
23666 | this.n = this.curve.n;
|
23667 | this.nh = this.n.ushrn(1);
|
23668 | this.g = this.curve.g;
|
23669 |
|
23670 | // Point on curve
|
23671 | this.g = options.curve.g;
|
23672 | this.g.precompute(options.curve.n.bitLength() + 1);
|
23673 |
|
23674 | // Hash for function for DRBG
|
23675 | this.hash = options.hash || options.curve.hash;
|
23676 | }
|
23677 | module.exports = EC;
|
23678 |
|
23679 | EC.prototype.keyPair = function keyPair(options) {
|
23680 | return new KeyPair(this, options);
|
23681 | };
|
23682 |
|
23683 | EC.prototype.keyFromPrivate = function keyFromPrivate(priv, enc) {
|
23684 | return KeyPair.fromPrivate(this, priv, enc);
|
23685 | };
|
23686 |
|
23687 | EC.prototype.keyFromPublic = function keyFromPublic(pub, enc) {
|
23688 | return KeyPair.fromPublic(this, pub, enc);
|
23689 | };
|
23690 |
|
23691 | EC.prototype.genKeyPair = function genKeyPair(options) {
|
23692 | if (!options)
|
23693 | options = {};
|
23694 |
|
23695 | // Instantiate Hmac_DRBG
|
23696 | var drbg = new HmacDRBG({
|
23697 | hash: this.hash,
|
23698 | pers: options.pers,
|
23699 | persEnc: options.persEnc || 'utf8',
|
23700 | entropy: options.entropy || elliptic.rand(this.hash.hmacStrength),
|
23701 | entropyEnc: options.entropy && options.entropyEnc || 'utf8',
|
23702 | nonce: this.n.toArray()
|
23703 | });
|
23704 |
|
23705 | var bytes = this.n.byteLength();
|
23706 | var ns2 = this.n.sub(new BN(2));
|
23707 | do {
|
23708 | var priv = new BN(drbg.generate(bytes));
|
23709 | if (priv.cmp(ns2) > 0)
|
23710 | continue;
|
23711 |
|
23712 | priv.iaddn(1);
|
23713 | return this.keyFromPrivate(priv);
|
23714 | } while (true);
|
23715 | };
|
23716 |
|
23717 | EC.prototype._truncateToN = function truncateToN(msg, truncOnly) {
|
23718 | var delta = msg.byteLength() * 8 - this.n.bitLength();
|
23719 | if (delta > 0)
|
23720 | msg = msg.ushrn(delta);
|
23721 | if (!truncOnly && msg.cmp(this.n) >= 0)
|
23722 | return msg.sub(this.n);
|
23723 | else
|
23724 | return msg;
|
23725 | };
|
23726 |
|
23727 | EC.prototype.sign = function sign(msg, key, enc, options) {
|
23728 | if (typeof enc === 'object') {
|
23729 | options = enc;
|
23730 | enc = null;
|
23731 | }
|
23732 | if (!options)
|
23733 | options = {};
|
23734 |
|
23735 | key = this.keyFromPrivate(key, enc);
|
23736 | msg = this._truncateToN(new BN(msg, 16));
|
23737 |
|
23738 | // Zero-extend key to provide enough entropy
|
23739 | var bytes = this.n.byteLength();
|
23740 | var bkey = key.getPrivate().toArray('be', bytes);
|
23741 |
|
23742 | // Zero-extend nonce to have the same byte size as N
|
23743 | var nonce = msg.toArray('be', bytes);
|
23744 |
|
23745 | // Instantiate Hmac_DRBG
|
23746 | var drbg = new HmacDRBG({
|
23747 | hash: this.hash,
|
23748 | entropy: bkey,
|
23749 | nonce: nonce,
|
23750 | pers: options.pers,
|
23751 | persEnc: options.persEnc || 'utf8'
|
23752 | });
|
23753 |
|
23754 | // Number of bytes to generate
|
23755 | var ns1 = this.n.sub(new BN(1));
|
23756 |
|
23757 | for (var iter = 0; true; iter++) {
|
23758 | var k = options.k ?
|
23759 | options.k(iter) :
|
23760 | new BN(drbg.generate(this.n.byteLength()));
|
23761 | k = this._truncateToN(k, true);
|
23762 | if (k.cmpn(1) <= 0 || k.cmp(ns1) >= 0)
|
23763 | continue;
|
23764 |
|
23765 | var kp = this.g.mul(k);
|
23766 | if (kp.isInfinity())
|
23767 | continue;
|
23768 |
|
23769 | var kpX = kp.getX();
|
23770 | var r = kpX.umod(this.n);
|
23771 | if (r.cmpn(0) === 0)
|
23772 | continue;
|
23773 |
|
23774 | var s = k.invm(this.n).mul(r.mul(key.getPrivate()).iadd(msg));
|
23775 | s = s.umod(this.n);
|
23776 | if (s.cmpn(0) === 0)
|
23777 | continue;
|
23778 |
|
23779 | var recoveryParam = (kp.getY().isOdd() ? 1 : 0) |
|
23780 | (kpX.cmp(r) !== 0 ? 2 : 0);
|
23781 |
|
23782 | // Use complement of `s`, if it is > `n / 2`
|
23783 | if (options.canonical && s.cmp(this.nh) > 0) {
|
23784 | s = this.n.sub(s);
|
23785 | recoveryParam ^= 1;
|
23786 | }
|
23787 |
|
23788 | return new Signature({ r: r, s: s, recoveryParam: recoveryParam });
|
23789 | }
|
23790 | };
|
23791 |
|
23792 | EC.prototype.verify = function verify(msg, signature, key, enc) {
|
23793 | msg = this._truncateToN(new BN(msg, 16));
|
23794 | key = this.keyFromPublic(key, enc);
|
23795 | signature = new Signature(signature, 'hex');
|
23796 |
|
23797 | // Perform primitive values validation
|
23798 | var r = signature.r;
|
23799 | var s = signature.s;
|
23800 | if (r.cmpn(1) < 0 || r.cmp(this.n) >= 0)
|
23801 | return false;
|
23802 | if (s.cmpn(1) < 0 || s.cmp(this.n) >= 0)
|
23803 | return false;
|
23804 |
|
23805 | // Validate signature
|
23806 | var sinv = s.invm(this.n);
|
23807 | var u1 = sinv.mul(msg).umod(this.n);
|
23808 | var u2 = sinv.mul(r).umod(this.n);
|
23809 |
|
23810 | if (!this.curve._maxwellTrick) {
|
23811 | var p = this.g.mulAdd(u1, key.getPublic(), u2);
|
23812 | if (p.isInfinity())
|
23813 | return false;
|
23814 |
|
23815 | return p.getX().umod(this.n).cmp(r) === 0;
|
23816 | }
|
23817 |
|
23818 | // NOTE: Greg Maxwell's trick, inspired by:
|
23819 | // https://git.io/vad3K
|
23820 |
|
23821 | var p = this.g.jmulAdd(u1, key.getPublic(), u2);
|
23822 | if (p.isInfinity())
|
23823 | return false;
|
23824 |
|
23825 | // Compare `p.x` of Jacobian point with `r`,
|
23826 | // this will do `p.x == r * p.z^2` instead of multiplying `p.x` by the
|
23827 | // inverse of `p.z^2`
|
23828 | return p.eqXToP(r);
|
23829 | };
|
23830 |
|
23831 | EC.prototype.recoverPubKey = function(msg, signature, j, enc) {
|
23832 | assert((3 & j) === j, 'The recovery param is more than two bits');
|
23833 | signature = new Signature(signature, enc);
|
23834 |
|
23835 | var n = this.n;
|
23836 | var e = new BN(msg);
|
23837 | var r = signature.r;
|
23838 | var s = signature.s;
|
23839 |
|
23840 | // A set LSB signifies that the y-coordinate is odd
|
23841 | var isYOdd = j & 1;
|
23842 | var isSecondKey = j >> 1;
|
23843 | if (r.cmp(this.curve.p.umod(this.curve.n)) >= 0 && isSecondKey)
|
23844 | throw new Error('Unable to find sencond key candinate');
|
23845 |
|
23846 | // 1.1. Let x = r + jn.
|
23847 | if (isSecondKey)
|
23848 | r = this.curve.pointFromX(r.add(this.curve.n), isYOdd);
|
23849 | else
|
23850 | r = this.curve.pointFromX(r, isYOdd);
|
23851 |
|
23852 | var rInv = signature.r.invm(n);
|
23853 | var s1 = n.sub(e).mul(rInv).umod(n);
|
23854 | var s2 = s.mul(rInv).umod(n);
|
23855 |
|
23856 | // 1.6.1 Compute Q = r^-1 (sR - eG)
|
23857 | // Q = r^-1 (sR + -eG)
|
23858 | return this.g.mulAdd(s1, r, s2);
|
23859 | };
|
23860 |
|
23861 | EC.prototype.getKeyRecoveryParam = function(e, signature, Q, enc) {
|
23862 | signature = new Signature(signature, enc);
|
23863 | if (signature.recoveryParam !== null)
|
23864 | return signature.recoveryParam;
|
23865 |
|
23866 | for (var i = 0; i < 4; i++) {
|
23867 | var Qprime;
|
23868 | try {
|
23869 | Qprime = this.recoverPubKey(e, signature, i);
|
23870 | } catch (e) {
|
23871 | continue;
|
23872 | }
|
23873 |
|
23874 | if (Qprime.eq(Q))
|
23875 | return i;
|
23876 | }
|
23877 | throw new Error('Unable to find valid recovery factor');
|
23878 | };
|
23879 |
|
23880 |
|
23881 | /***/ }),
|
23882 | /* 100 */
|
23883 | /***/ (function(module, exports, __webpack_require__) {
|
23884 |
|
23885 | "use strict";
|
23886 |
|
23887 |
|
23888 | var hash = __webpack_require__(21);
|
23889 | var utils = __webpack_require__(40);
|
23890 | var assert = __webpack_require__(8);
|
23891 |
|
23892 | function HmacDRBG(options) {
|
23893 | if (!(this instanceof HmacDRBG))
|
23894 | return new HmacDRBG(options);
|
23895 | this.hash = options.hash;
|
23896 | this.predResist = !!options.predResist;
|
23897 |
|
23898 | this.outLen = this.hash.outSize;
|
23899 | this.minEntropy = options.minEntropy || this.hash.hmacStrength;
|
23900 |
|
23901 | this._reseed = null;
|
23902 | this.reseedInterval = null;
|
23903 | this.K = null;
|
23904 | this.V = null;
|
23905 |
|
23906 | var entropy = utils.toArray(options.entropy, options.entropyEnc || 'hex');
|
23907 | var nonce = utils.toArray(options.nonce, options.nonceEnc || 'hex');
|
23908 | var pers = utils.toArray(options.pers, options.persEnc || 'hex');
|
23909 | assert(entropy.length >= (this.minEntropy / 8),
|
23910 | 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
|
23911 | this._init(entropy, nonce, pers);
|
23912 | }
|
23913 | module.exports = HmacDRBG;
|
23914 |
|
23915 | HmacDRBG.prototype._init = function init(entropy, nonce, pers) {
|
23916 | var seed = entropy.concat(nonce).concat(pers);
|
23917 |
|
23918 | this.K = new Array(this.outLen / 8);
|
23919 | this.V = new Array(this.outLen / 8);
|
23920 | for (var i = 0; i < this.V.length; i++) {
|
23921 | this.K[i] = 0x00;
|
23922 | this.V[i] = 0x01;
|
23923 | }
|
23924 |
|
23925 | this._update(seed);
|
23926 | this._reseed = 1;
|
23927 | this.reseedInterval = 0x1000000000000; // 2^48
|
23928 | };
|
23929 |
|
23930 | HmacDRBG.prototype._hmac = function hmac() {
|
23931 | return new hash.hmac(this.hash, this.K);
|
23932 | };
|
23933 |
|
23934 | HmacDRBG.prototype._update = function update(seed) {
|
23935 | var kmac = this._hmac()
|
23936 | .update(this.V)
|
23937 | .update([ 0x00 ]);
|
23938 | if (seed)
|
23939 | kmac = kmac.update(seed);
|
23940 | this.K = kmac.digest();
|
23941 | this.V = this._hmac().update(this.V).digest();
|
23942 | if (!seed)
|
23943 | return;
|
23944 |
|
23945 | this.K = this._hmac()
|
23946 | .update(this.V)
|
23947 | .update([ 0x01 ])
|
23948 | .update(seed)
|
23949 | .digest();
|
23950 | this.V = this._hmac().update(this.V).digest();
|
23951 | };
|
23952 |
|
23953 | HmacDRBG.prototype.reseed = function reseed(entropy, entropyEnc, add, addEnc) {
|
23954 | // Optional entropy enc
|
23955 | if (typeof entropyEnc !== 'string') {
|
23956 | addEnc = add;
|
23957 | add = entropyEnc;
|
23958 | entropyEnc = null;
|
23959 | }
|
23960 |
|
23961 | entropy = utils.toArray(entropy, entropyEnc);
|
23962 | add = utils.toArray(add, addEnc);
|
23963 |
|
23964 | assert(entropy.length >= (this.minEntropy / 8),
|
23965 | 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
|
23966 |
|
23967 | this._update(entropy.concat(add || []));
|
23968 | this._reseed = 1;
|
23969 | };
|
23970 |
|
23971 | HmacDRBG.prototype.generate = function generate(len, enc, add, addEnc) {
|
23972 | if (this._reseed > this.reseedInterval)
|
23973 | throw new Error('Reseed is required');
|
23974 |
|
23975 | // Optional encoding
|
23976 | if (typeof enc !== 'string') {
|
23977 | addEnc = add;
|
23978 | add = enc;
|
23979 | enc = null;
|
23980 | }
|
23981 |
|
23982 | // Optional additional data
|
23983 | if (add) {
|
23984 | add = utils.toArray(add, addEnc || 'hex');
|
23985 | this._update(add);
|
23986 | }
|
23987 |
|
23988 | var temp = [];
|
23989 | while (temp.length < len) {
|
23990 | this.V = this._hmac().update(this.V).digest();
|
23991 | temp = temp.concat(this.V);
|
23992 | }
|
23993 |
|
23994 | var res = temp.slice(0, len);
|
23995 | this._update(add);
|
23996 | this._reseed++;
|
23997 | return utils.encode(res, enc);
|
23998 | };
|
23999 |
|
24000 |
|
24001 | /***/ }),
|
24002 | /* 101 */
|
24003 | /***/ (function(module, exports, __webpack_require__) {
|
24004 |
|
24005 | "use strict";
|
24006 |
|
24007 |
|
24008 | var BN = __webpack_require__(3);
|
24009 | var elliptic = __webpack_require__(5);
|
24010 | var utils = elliptic.utils;
|
24011 | var assert = utils.assert;
|
24012 |
|
24013 | function KeyPair(ec, options) {
|
24014 | this.ec = ec;
|
24015 | this.priv = null;
|
24016 | this.pub = null;
|
24017 |
|
24018 | // KeyPair(ec, { priv: ..., pub: ... })
|
24019 | if (options.priv)
|
24020 | this._importPrivate(options.priv, options.privEnc);
|
24021 | if (options.pub)
|
24022 | this._importPublic(options.pub, options.pubEnc);
|
24023 | }
|
24024 | module.exports = KeyPair;
|
24025 |
|
24026 | KeyPair.fromPublic = function fromPublic(ec, pub, enc) {
|
24027 | if (pub instanceof KeyPair)
|
24028 | return pub;
|
24029 |
|
24030 | return new KeyPair(ec, {
|
24031 | pub: pub,
|
24032 | pubEnc: enc
|
24033 | });
|
24034 | };
|
24035 |
|
24036 | KeyPair.fromPrivate = function fromPrivate(ec, priv, enc) {
|
24037 | if (priv instanceof KeyPair)
|
24038 | return priv;
|
24039 |
|
24040 | return new KeyPair(ec, {
|
24041 | priv: priv,
|
24042 | privEnc: enc
|
24043 | });
|
24044 | };
|
24045 |
|
24046 | KeyPair.prototype.validate = function validate() {
|
24047 | var pub = this.getPublic();
|
24048 |
|
24049 | if (pub.isInfinity())
|
24050 | return { result: false, reason: 'Invalid public key' };
|
24051 | if (!pub.validate())
|
24052 | return { result: false, reason: 'Public key is not a point' };
|
24053 | if (!pub.mul(this.ec.curve.n).isInfinity())
|
24054 | return { result: false, reason: 'Public key * N != O' };
|
24055 |
|
24056 | return { result: true, reason: null };
|
24057 | };
|
24058 |
|
24059 | KeyPair.prototype.getPublic = function getPublic(compact, enc) {
|
24060 | // compact is optional argument
|
24061 | if (typeof compact === 'string') {
|
24062 | enc = compact;
|
24063 | compact = null;
|
24064 | }
|
24065 |
|
24066 | if (!this.pub)
|
24067 | this.pub = this.ec.g.mul(this.priv);
|
24068 |
|
24069 | if (!enc)
|
24070 | return this.pub;
|
24071 |
|
24072 | return this.pub.encode(enc, compact);
|
24073 | };
|
24074 |
|
24075 | KeyPair.prototype.getPrivate = function getPrivate(enc) {
|
24076 | if (enc === 'hex')
|
24077 | return this.priv.toString(16, 2);
|
24078 | else
|
24079 | return this.priv;
|
24080 | };
|
24081 |
|
24082 | KeyPair.prototype._importPrivate = function _importPrivate(key, enc) {
|
24083 | this.priv = new BN(key, enc || 16);
|
24084 |
|
24085 | // Ensure that the priv won't be bigger than n, otherwise we may fail
|
24086 | // in fixed multiplication method
|
24087 | this.priv = this.priv.umod(this.ec.curve.n);
|
24088 | };
|
24089 |
|
24090 | KeyPair.prototype._importPublic = function _importPublic(key, enc) {
|
24091 | if (key.x || key.y) {
|
24092 | // Montgomery points only have an `x` coordinate.
|
24093 | // Weierstrass/Edwards points on the other hand have both `x` and
|
24094 | // `y` coordinates.
|
24095 | if (this.ec.curve.type === 'mont') {
|
24096 | assert(key.x, 'Need x coordinate');
|
24097 | } else if (this.ec.curve.type === 'short' ||
|
24098 | this.ec.curve.type === 'edwards') {
|
24099 | assert(key.x && key.y, 'Need both x and y coordinate');
|
24100 | }
|
24101 | this.pub = this.ec.curve.point(key.x, key.y);
|
24102 | return;
|
24103 | }
|
24104 | this.pub = this.ec.curve.decodePoint(key, enc);
|
24105 | };
|
24106 |
|
24107 | // ECDH
|
24108 | KeyPair.prototype.derive = function derive(pub) {
|
24109 | return pub.mul(this.priv).getX();
|
24110 | };
|
24111 |
|
24112 | // ECDSA
|
24113 | KeyPair.prototype.sign = function sign(msg, enc, options) {
|
24114 | return this.ec.sign(msg, this, enc, options);
|
24115 | };
|
24116 |
|
24117 | KeyPair.prototype.verify = function verify(msg, signature) {
|
24118 | return this.ec.verify(msg, signature, this);
|
24119 | };
|
24120 |
|
24121 | KeyPair.prototype.inspect = function inspect() {
|
24122 | return '<Key priv: ' + (this.priv && this.priv.toString(16, 2)) +
|
24123 | ' pub: ' + (this.pub && this.pub.inspect()) + ' >';
|
24124 | };
|
24125 |
|
24126 |
|
24127 | /***/ }),
|
24128 | /* 102 */
|
24129 | /***/ (function(module, exports, __webpack_require__) {
|
24130 |
|
24131 | "use strict";
|
24132 |
|
24133 |
|
24134 | var BN = __webpack_require__(3);
|
24135 |
|
24136 | var elliptic = __webpack_require__(5);
|
24137 | var utils = elliptic.utils;
|
24138 | var assert = utils.assert;
|
24139 |
|
24140 | function Signature(options, enc) {
|
24141 | if (options instanceof Signature)
|
24142 | return options;
|
24143 |
|
24144 | if (this._importDER(options, enc))
|
24145 | return;
|
24146 |
|
24147 | assert(options.r && options.s, 'Signature without r or s');
|
24148 | this.r = new BN(options.r, 16);
|
24149 | this.s = new BN(options.s, 16);
|
24150 | if (options.recoveryParam === undefined)
|
24151 | this.recoveryParam = null;
|
24152 | else
|
24153 | this.recoveryParam = options.recoveryParam;
|
24154 | }
|
24155 | module.exports = Signature;
|
24156 |
|
24157 | function Position() {
|
24158 | this.place = 0;
|
24159 | }
|
24160 |
|
24161 | function getLength(buf, p) {
|
24162 | var initial = buf[p.place++];
|
24163 | if (!(initial & 0x80)) {
|
24164 | return initial;
|
24165 | }
|
24166 | var octetLen = initial & 0xf;
|
24167 | var val = 0;
|
24168 | for (var i = 0, off = p.place; i < octetLen; i++, off++) {
|
24169 | val <<= 8;
|
24170 | val |= buf[off];
|
24171 | }
|
24172 | p.place = off;
|
24173 | return val;
|
24174 | }
|
24175 |
|
24176 | function rmPadding(buf) {
|
24177 | var i = 0;
|
24178 | var len = buf.length - 1;
|
24179 | while (!buf[i] && !(buf[i + 1] & 0x80) && i < len) {
|
24180 | i++;
|
24181 | }
|
24182 | if (i === 0) {
|
24183 | return buf;
|
24184 | }
|
24185 | return buf.slice(i);
|
24186 | }
|
24187 |
|
24188 | Signature.prototype._importDER = function _importDER(data, enc) {
|
24189 | data = utils.toArray(data, enc);
|
24190 | var p = new Position();
|
24191 | if (data[p.place++] !== 0x30) {
|
24192 | return false;
|
24193 | }
|
24194 | var len = getLength(data, p);
|
24195 | if ((len + p.place) !== data.length) {
|
24196 | return false;
|
24197 | }
|
24198 | if (data[p.place++] !== 0x02) {
|
24199 | return false;
|
24200 | }
|
24201 | var rlen = getLength(data, p);
|
24202 | var r = data.slice(p.place, rlen + p.place);
|
24203 | p.place += rlen;
|
24204 | if (data[p.place++] !== 0x02) {
|
24205 | return false;
|
24206 | }
|
24207 | var slen = getLength(data, p);
|
24208 | if (data.length !== slen + p.place) {
|
24209 | return false;
|
24210 | }
|
24211 | var s = data.slice(p.place, slen + p.place);
|
24212 | if (r[0] === 0 && (r[1] & 0x80)) {
|
24213 | r = r.slice(1);
|
24214 | }
|
24215 | if (s[0] === 0 && (s[1] & 0x80)) {
|
24216 | s = s.slice(1);
|
24217 | }
|
24218 |
|
24219 | this.r = new BN(r);
|
24220 | this.s = new BN(s);
|
24221 | this.recoveryParam = null;
|
24222 |
|
24223 | return true;
|
24224 | };
|
24225 |
|
24226 | function constructLength(arr, len) {
|
24227 | if (len < 0x80) {
|
24228 | arr.push(len);
|
24229 | return;
|
24230 | }
|
24231 | var octets = 1 + (Math.log(len) / Math.LN2 >>> 3);
|
24232 | arr.push(octets | 0x80);
|
24233 | while (--octets) {
|
24234 | arr.push((len >>> (octets << 3)) & 0xff);
|
24235 | }
|
24236 | arr.push(len);
|
24237 | }
|
24238 |
|
24239 | Signature.prototype.toDER = function toDER(enc) {
|
24240 | var r = this.r.toArray();
|
24241 | var s = this.s.toArray();
|
24242 |
|
24243 | // Pad values
|
24244 | if (r[0] & 0x80)
|
24245 | r = [ 0 ].concat(r);
|
24246 | // Pad values
|
24247 | if (s[0] & 0x80)
|
24248 | s = [ 0 ].concat(s);
|
24249 |
|
24250 | r = rmPadding(r);
|
24251 | s = rmPadding(s);
|
24252 |
|
24253 | while (!s[0] && !(s[1] & 0x80)) {
|
24254 | s = s.slice(1);
|
24255 | }
|
24256 | var arr = [ 0x02 ];
|
24257 | constructLength(arr, r.length);
|
24258 | arr = arr.concat(r);
|
24259 | arr.push(0x02);
|
24260 | constructLength(arr, s.length);
|
24261 | var backHalf = arr.concat(s);
|
24262 | var res = [ 0x30 ];
|
24263 | constructLength(res, backHalf.length);
|
24264 | res = res.concat(backHalf);
|
24265 | return utils.encode(res, enc);
|
24266 | };
|
24267 |
|
24268 |
|
24269 | /***/ }),
|
24270 | /* 103 */
|
24271 | /***/ (function(module, exports, __webpack_require__) {
|
24272 |
|
24273 | "use strict";
|
24274 |
|
24275 |
|
24276 | var hash = __webpack_require__(21);
|
24277 | var elliptic = __webpack_require__(5);
|
24278 | var utils = elliptic.utils;
|
24279 | var assert = utils.assert;
|
24280 | var parseBytes = utils.parseBytes;
|
24281 | var KeyPair = __webpack_require__(104);
|
24282 | var Signature = __webpack_require__(105);
|
24283 |
|
24284 | function EDDSA(curve) {
|
24285 | assert(curve === 'ed25519', 'only tested with ed25519 so far');
|
24286 |
|
24287 | if (!(this instanceof EDDSA))
|
24288 | return new EDDSA(curve);
|
24289 |
|
24290 | var curve = elliptic.curves[curve].curve;
|
24291 | this.curve = curve;
|
24292 | this.g = curve.g;
|
24293 | this.g.precompute(curve.n.bitLength() + 1);
|
24294 |
|
24295 | this.pointClass = curve.point().constructor;
|
24296 | this.encodingLength = Math.ceil(curve.n.bitLength() / 8);
|
24297 | this.hash = hash.sha512;
|
24298 | }
|
24299 |
|
24300 | module.exports = EDDSA;
|
24301 |
|
24302 | /**
|
24303 | * @param {Array|String} message - message bytes
|
24304 | * @param {Array|String|KeyPair} secret - secret bytes or a keypair
|
24305 | * @returns {Signature} - signature
|
24306 | */
|
24307 | EDDSA.prototype.sign = function sign(message, secret) {
|
24308 | message = parseBytes(message);
|
24309 | var key = this.keyFromSecret(secret);
|
24310 | var r = this.hashInt(key.messagePrefix(), message);
|
24311 | var R = this.g.mul(r);
|
24312 | var Rencoded = this.encodePoint(R);
|
24313 | var s_ = this.hashInt(Rencoded, key.pubBytes(), message)
|
24314 | .mul(key.priv());
|
24315 | var S = r.add(s_).umod(this.curve.n);
|
24316 | return this.makeSignature({ R: R, S: S, Rencoded: Rencoded });
|
24317 | };
|
24318 |
|
24319 | /**
|
24320 | * @param {Array} message - message bytes
|
24321 | * @param {Array|String|Signature} sig - sig bytes
|
24322 | * @param {Array|String|Point|KeyPair} pub - public key
|
24323 | * @returns {Boolean} - true if public key matches sig of message
|
24324 | */
|
24325 | EDDSA.prototype.verify = function verify(message, sig, pub) {
|
24326 | message = parseBytes(message);
|
24327 | sig = this.makeSignature(sig);
|
24328 | var key = this.keyFromPublic(pub);
|
24329 | var h = this.hashInt(sig.Rencoded(), key.pubBytes(), message);
|
24330 | var SG = this.g.mul(sig.S());
|
24331 | var RplusAh = sig.R().add(key.pub().mul(h));
|
24332 | return RplusAh.eq(SG);
|
24333 | };
|
24334 |
|
24335 | EDDSA.prototype.hashInt = function hashInt() {
|
24336 | var hash = this.hash();
|
24337 | for (var i = 0; i < arguments.length; i++)
|
24338 | hash.update(arguments[i]);
|
24339 | return utils.intFromLE(hash.digest()).umod(this.curve.n);
|
24340 | };
|
24341 |
|
24342 | EDDSA.prototype.keyFromPublic = function keyFromPublic(pub) {
|
24343 | return KeyPair.fromPublic(this, pub);
|
24344 | };
|
24345 |
|
24346 | EDDSA.prototype.keyFromSecret = function keyFromSecret(secret) {
|
24347 | return KeyPair.fromSecret(this, secret);
|
24348 | };
|
24349 |
|
24350 | EDDSA.prototype.makeSignature = function makeSignature(sig) {
|
24351 | if (sig instanceof Signature)
|
24352 | return sig;
|
24353 | return new Signature(this, sig);
|
24354 | };
|
24355 |
|
24356 | /**
|
24357 | * * https://tools.ietf.org/html/draft-josefsson-eddsa-ed25519-03#section-5.2
|
24358 | *
|
24359 | * EDDSA defines methods for encoding and decoding points and integers. These are
|
24360 | * helper convenience methods, that pass along to utility functions implied
|
24361 | * parameters.
|
24362 | *
|
24363 | */
|
24364 | EDDSA.prototype.encodePoint = function encodePoint(point) {
|
24365 | var enc = point.getY().toArray('le', this.encodingLength);
|
24366 | enc[this.encodingLength - 1] |= point.getX().isOdd() ? 0x80 : 0;
|
24367 | return enc;
|
24368 | };
|
24369 |
|
24370 | EDDSA.prototype.decodePoint = function decodePoint(bytes) {
|
24371 | bytes = utils.parseBytes(bytes);
|
24372 |
|
24373 | var lastIx = bytes.length - 1;
|
24374 | var normed = bytes.slice(0, lastIx).concat(bytes[lastIx] & ~0x80);
|
24375 | var xIsOdd = (bytes[lastIx] & 0x80) !== 0;
|
24376 |
|
24377 | var y = utils.intFromLE(normed);
|
24378 | return this.curve.pointFromY(y, xIsOdd);
|
24379 | };
|
24380 |
|
24381 | EDDSA.prototype.encodeInt = function encodeInt(num) {
|
24382 | return num.toArray('le', this.encodingLength);
|
24383 | };
|
24384 |
|
24385 | EDDSA.prototype.decodeInt = function decodeInt(bytes) {
|
24386 | return utils.intFromLE(bytes);
|
24387 | };
|
24388 |
|
24389 | EDDSA.prototype.isPoint = function isPoint(val) {
|
24390 | return val instanceof this.pointClass;
|
24391 | };
|
24392 |
|
24393 |
|
24394 | /***/ }),
|
24395 | /* 104 */
|
24396 | /***/ (function(module, exports, __webpack_require__) {
|
24397 |
|
24398 | "use strict";
|
24399 |
|
24400 |
|
24401 | var elliptic = __webpack_require__(5);
|
24402 | var utils = elliptic.utils;
|
24403 | var assert = utils.assert;
|
24404 | var parseBytes = utils.parseBytes;
|
24405 | var cachedProperty = utils.cachedProperty;
|
24406 |
|
24407 | /**
|
24408 | * @param {EDDSA} eddsa - instance
|
24409 | * @param {Object} params - public/private key parameters
|
24410 | *
|
24411 | * @param {Array<Byte>} [params.secret] - secret seed bytes
|
24412 | * @param {Point} [params.pub] - public key point (aka `A` in eddsa terms)
|
24413 | * @param {Array<Byte>} [params.pub] - public key point encoded as bytes
|
24414 | *
|
24415 | */
|
24416 | function KeyPair(eddsa, params) {
|
24417 | this.eddsa = eddsa;
|
24418 | this._secret = parseBytes(params.secret);
|
24419 | if (eddsa.isPoint(params.pub))
|
24420 | this._pub = params.pub;
|
24421 | else
|
24422 | this._pubBytes = parseBytes(params.pub);
|
24423 | }
|
24424 |
|
24425 | KeyPair.fromPublic = function fromPublic(eddsa, pub) {
|
24426 | if (pub instanceof KeyPair)
|
24427 | return pub;
|
24428 | return new KeyPair(eddsa, { pub: pub });
|
24429 | };
|
24430 |
|
24431 | KeyPair.fromSecret = function fromSecret(eddsa, secret) {
|
24432 | if (secret instanceof KeyPair)
|
24433 | return secret;
|
24434 | return new KeyPair(eddsa, { secret: secret });
|
24435 | };
|
24436 |
|
24437 | KeyPair.prototype.secret = function secret() {
|
24438 | return this._secret;
|
24439 | };
|
24440 |
|
24441 | cachedProperty(KeyPair, 'pubBytes', function pubBytes() {
|
24442 | return this.eddsa.encodePoint(this.pub());
|
24443 | });
|
24444 |
|
24445 | cachedProperty(KeyPair, 'pub', function pub() {
|
24446 | if (this._pubBytes)
|
24447 | return this.eddsa.decodePoint(this._pubBytes);
|
24448 | return this.eddsa.g.mul(this.priv());
|
24449 | });
|
24450 |
|
24451 | cachedProperty(KeyPair, 'privBytes', function privBytes() {
|
24452 | var eddsa = this.eddsa;
|
24453 | var hash = this.hash();
|
24454 | var lastIx = eddsa.encodingLength - 1;
|
24455 |
|
24456 | var a = hash.slice(0, eddsa.encodingLength);
|
24457 | a[0] &= 248;
|
24458 | a[lastIx] &= 127;
|
24459 | a[lastIx] |= 64;
|
24460 |
|
24461 | return a;
|
24462 | });
|
24463 |
|
24464 | cachedProperty(KeyPair, 'priv', function priv() {
|
24465 | return this.eddsa.decodeInt(this.privBytes());
|
24466 | });
|
24467 |
|
24468 | cachedProperty(KeyPair, 'hash', function hash() {
|
24469 | return this.eddsa.hash().update(this.secret()).digest();
|
24470 | });
|
24471 |
|
24472 | cachedProperty(KeyPair, 'messagePrefix', function messagePrefix() {
|
24473 | return this.hash().slice(this.eddsa.encodingLength);
|
24474 | });
|
24475 |
|
24476 | KeyPair.prototype.sign = function sign(message) {
|
24477 | assert(this._secret, 'KeyPair can only verify');
|
24478 | return this.eddsa.sign(message, this);
|
24479 | };
|
24480 |
|
24481 | KeyPair.prototype.verify = function verify(message, sig) {
|
24482 | return this.eddsa.verify(message, sig, this);
|
24483 | };
|
24484 |
|
24485 | KeyPair.prototype.getSecret = function getSecret(enc) {
|
24486 | assert(this._secret, 'KeyPair is public only');
|
24487 | return utils.encode(this.secret(), enc);
|
24488 | };
|
24489 |
|
24490 | KeyPair.prototype.getPublic = function getPublic(enc) {
|
24491 | return utils.encode(this.pubBytes(), enc);
|
24492 | };
|
24493 |
|
24494 | module.exports = KeyPair;
|
24495 |
|
24496 |
|
24497 | /***/ }),
|
24498 | /* 105 */
|
24499 | /***/ (function(module, exports, __webpack_require__) {
|
24500 |
|
24501 | "use strict";
|
24502 |
|
24503 |
|
24504 | var BN = __webpack_require__(3);
|
24505 | var elliptic = __webpack_require__(5);
|
24506 | var utils = elliptic.utils;
|
24507 | var assert = utils.assert;
|
24508 | var cachedProperty = utils.cachedProperty;
|
24509 | var parseBytes = utils.parseBytes;
|
24510 |
|
24511 | /**
|
24512 | * @param {EDDSA} eddsa - eddsa instance
|
24513 | * @param {Array<Bytes>|Object} sig -
|
24514 | * @param {Array<Bytes>|Point} [sig.R] - R point as Point or bytes
|
24515 | * @param {Array<Bytes>|bn} [sig.S] - S scalar as bn or bytes
|
24516 | * @param {Array<Bytes>} [sig.Rencoded] - R point encoded
|
24517 | * @param {Array<Bytes>} [sig.Sencoded] - S scalar encoded
|
24518 | */
|
24519 | function Signature(eddsa, sig) {
|
24520 | this.eddsa = eddsa;
|
24521 |
|
24522 | if (typeof sig !== 'object')
|
24523 | sig = parseBytes(sig);
|
24524 |
|
24525 | if (Array.isArray(sig)) {
|
24526 | sig = {
|
24527 | R: sig.slice(0, eddsa.encodingLength),
|
24528 | S: sig.slice(eddsa.encodingLength)
|
24529 | };
|
24530 | }
|
24531 |
|
24532 | assert(sig.R && sig.S, 'Signature without R or S');
|
24533 |
|
24534 | if (eddsa.isPoint(sig.R))
|
24535 | this._R = sig.R;
|
24536 | if (sig.S instanceof BN)
|
24537 | this._S = sig.S;
|
24538 |
|
24539 | this._Rencoded = Array.isArray(sig.R) ? sig.R : sig.Rencoded;
|
24540 | this._Sencoded = Array.isArray(sig.S) ? sig.S : sig.Sencoded;
|
24541 | }
|
24542 |
|
24543 | cachedProperty(Signature, 'S', function S() {
|
24544 | return this.eddsa.decodeInt(this.Sencoded());
|
24545 | });
|
24546 |
|
24547 | cachedProperty(Signature, 'R', function R() {
|
24548 | return this.eddsa.decodePoint(this.Rencoded());
|
24549 | });
|
24550 |
|
24551 | cachedProperty(Signature, 'Rencoded', function Rencoded() {
|
24552 | return this.eddsa.encodePoint(this.R());
|
24553 | });
|
24554 |
|
24555 | cachedProperty(Signature, 'Sencoded', function Sencoded() {
|
24556 | return this.eddsa.encodeInt(this.S());
|
24557 | });
|
24558 |
|
24559 | Signature.prototype.toBytes = function toBytes() {
|
24560 | return this.Rencoded().concat(this.Sencoded());
|
24561 | };
|
24562 |
|
24563 | Signature.prototype.toHex = function toHex() {
|
24564 | return utils.encode(this.toBytes(), 'hex').toUpperCase();
|
24565 | };
|
24566 |
|
24567 | module.exports = Signature;
|
24568 |
|
24569 |
|
24570 | /***/ }),
|
24571 | /* 106 */
|
24572 | /***/ (function(module, exports, __webpack_require__) {
|
24573 |
|
24574 | ;(function (root, factory) {
|
24575 | if (true) {
|
24576 | // CommonJS
|
24577 | module.exports = exports = factory(__webpack_require__(4));
|
24578 | }
|
24579 | else {}
|
24580 | }(this, function (CryptoJS) {
|
24581 |
|
24582 | (function () {
|
24583 | // Shortcuts
|
24584 | var C = CryptoJS;
|
24585 | var C_lib = C.lib;
|
24586 | var WordArray = C_lib.WordArray;
|
24587 | var C_enc = C.enc;
|
24588 |
|
24589 | /**
|
24590 | * Base64 encoding strategy.
|
24591 | */
|
24592 | var Base64 = C_enc.Base64 = {
|
24593 | /**
|
24594 | * Converts a word array to a Base64 string.
|
24595 | *
|
24596 | * @param {WordArray} wordArray The word array.
|
24597 | *
|
24598 | * @return {string} The Base64 string.
|
24599 | *
|
24600 | * @static
|
24601 | *
|
24602 | * @example
|
24603 | *
|
24604 | * var base64String = CryptoJS.enc.Base64.stringify(wordArray);
|
24605 | */
|
24606 | stringify: function (wordArray) {
|
24607 | // Shortcuts
|
24608 | var words = wordArray.words;
|
24609 | var sigBytes = wordArray.sigBytes;
|
24610 | var map = this._map;
|
24611 |
|
24612 | // Clamp excess bits
|
24613 | wordArray.clamp();
|
24614 |
|
24615 | // Convert
|
24616 | var base64Chars = [];
|
24617 | for (var i = 0; i < sigBytes; i += 3) {
|
24618 | var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
|
24619 | var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff;
|
24620 | var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff;
|
24621 |
|
24622 | var triplet = (byte1 << 16) | (byte2 << 8) | byte3;
|
24623 |
|
24624 | for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) {
|
24625 | base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f));
|
24626 | }
|
24627 | }
|
24628 |
|
24629 | // Add padding
|
24630 | var paddingChar = map.charAt(64);
|
24631 | if (paddingChar) {
|
24632 | while (base64Chars.length % 4) {
|
24633 | base64Chars.push(paddingChar);
|
24634 | }
|
24635 | }
|
24636 |
|
24637 | return base64Chars.join('');
|
24638 | },
|
24639 |
|
24640 | /**
|
24641 | * Converts a Base64 string to a word array.
|
24642 | *
|
24643 | * @param {string} base64Str The Base64 string.
|
24644 | *
|
24645 | * @return {WordArray} The word array.
|
24646 | *
|
24647 | * @static
|
24648 | *
|
24649 | * @example
|
24650 | *
|
24651 | * var wordArray = CryptoJS.enc.Base64.parse(base64String);
|
24652 | */
|
24653 | parse: function (base64Str) {
|
24654 | // Shortcuts
|
24655 | var base64StrLength = base64Str.length;
|
24656 | var map = this._map;
|
24657 | var reverseMap = this._reverseMap;
|
24658 |
|
24659 | if (!reverseMap) {
|
24660 | reverseMap = this._reverseMap = [];
|
24661 | for (var j = 0; j < map.length; j++) {
|
24662 | reverseMap[map.charCodeAt(j)] = j;
|
24663 | }
|
24664 | }
|
24665 |
|
24666 | // Ignore padding
|
24667 | var paddingChar = map.charAt(64);
|
24668 | if (paddingChar) {
|
24669 | var paddingIndex = base64Str.indexOf(paddingChar);
|
24670 | if (paddingIndex !== -1) {
|
24671 | base64StrLength = paddingIndex;
|
24672 | }
|
24673 | }
|
24674 |
|
24675 | // Convert
|
24676 | return parseLoop(base64Str, base64StrLength, reverseMap);
|
24677 |
|
24678 | },
|
24679 |
|
24680 | _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
|
24681 | };
|
24682 |
|
24683 | function parseLoop(base64Str, base64StrLength, reverseMap) {
|
24684 | var words = [];
|
24685 | var nBytes = 0;
|
24686 | for (var i = 0; i < base64StrLength; i++) {
|
24687 | if (i % 4) {
|
24688 | var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2);
|
24689 | var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2);
|
24690 | words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8);
|
24691 | nBytes++;
|
24692 | }
|
24693 | }
|
24694 | return WordArray.create(words, nBytes);
|
24695 | }
|
24696 | }());
|
24697 |
|
24698 |
|
24699 | return CryptoJS.enc.Base64;
|
24700 |
|
24701 | }));
|
24702 |
|
24703 | /***/ }),
|
24704 | /* 107 */
|
24705 | /***/ (function(module, exports, __webpack_require__) {
|
24706 |
|
24707 | ;(function (root, factory) {
|
24708 | if (true) {
|
24709 | // CommonJS
|
24710 | module.exports = exports = factory(__webpack_require__(4));
|
24711 | }
|
24712 | else {}
|
24713 | }(this, function (CryptoJS) {
|
24714 |
|
24715 | (function (Math) {
|
24716 | // Shortcuts
|
24717 | var C = CryptoJS;
|
24718 | var C_lib = C.lib;
|
24719 | var WordArray = C_lib.WordArray;
|
24720 | var Hasher = C_lib.Hasher;
|
24721 | var C_algo = C.algo;
|
24722 |
|
24723 | // Constants table
|
24724 | var T = [];
|
24725 |
|
24726 | // Compute constants
|
24727 | (function () {
|
24728 | for (var i = 0; i < 64; i++) {
|
24729 | T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0;
|
24730 | }
|
24731 | }());
|
24732 |
|
24733 | /**
|
24734 | * MD5 hash algorithm.
|
24735 | */
|
24736 | var MD5 = C_algo.MD5 = Hasher.extend({
|
24737 | _doReset: function () {
|
24738 | this._hash = new WordArray.init([
|
24739 | 0x67452301, 0xefcdab89,
|
24740 | 0x98badcfe, 0x10325476
|
24741 | ]);
|
24742 | },
|
24743 |
|
24744 | _doProcessBlock: function (M, offset) {
|
24745 | // Swap endian
|
24746 | for (var i = 0; i < 16; i++) {
|
24747 | // Shortcuts
|
24748 | var offset_i = offset + i;
|
24749 | var M_offset_i = M[offset_i];
|
24750 |
|
24751 | M[offset_i] = (
|
24752 | (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
|
24753 | (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
|
24754 | );
|
24755 | }
|
24756 |
|
24757 | // Shortcuts
|
24758 | var H = this._hash.words;
|
24759 |
|
24760 | var M_offset_0 = M[offset + 0];
|
24761 | var M_offset_1 = M[offset + 1];
|
24762 | var M_offset_2 = M[offset + 2];
|
24763 | var M_offset_3 = M[offset + 3];
|
24764 | var M_offset_4 = M[offset + 4];
|
24765 | var M_offset_5 = M[offset + 5];
|
24766 | var M_offset_6 = M[offset + 6];
|
24767 | var M_offset_7 = M[offset + 7];
|
24768 | var M_offset_8 = M[offset + 8];
|
24769 | var M_offset_9 = M[offset + 9];
|
24770 | var M_offset_10 = M[offset + 10];
|
24771 | var M_offset_11 = M[offset + 11];
|
24772 | var M_offset_12 = M[offset + 12];
|
24773 | var M_offset_13 = M[offset + 13];
|
24774 | var M_offset_14 = M[offset + 14];
|
24775 | var M_offset_15 = M[offset + 15];
|
24776 |
|
24777 | // Working varialbes
|
24778 | var a = H[0];
|
24779 | var b = H[1];
|
24780 | var c = H[2];
|
24781 | var d = H[3];
|
24782 |
|
24783 | // Computation
|
24784 | a = FF(a, b, c, d, M_offset_0, 7, T[0]);
|
24785 | d = FF(d, a, b, c, M_offset_1, 12, T[1]);
|
24786 | c = FF(c, d, a, b, M_offset_2, 17, T[2]);
|
24787 | b = FF(b, c, d, a, M_offset_3, 22, T[3]);
|
24788 | a = FF(a, b, c, d, M_offset_4, 7, T[4]);
|
24789 | d = FF(d, a, b, c, M_offset_5, 12, T[5]);
|
24790 | c = FF(c, d, a, b, M_offset_6, 17, T[6]);
|
24791 | b = FF(b, c, d, a, M_offset_7, 22, T[7]);
|
24792 | a = FF(a, b, c, d, M_offset_8, 7, T[8]);
|
24793 | d = FF(d, a, b, c, M_offset_9, 12, T[9]);
|
24794 | c = FF(c, d, a, b, M_offset_10, 17, T[10]);
|
24795 | b = FF(b, c, d, a, M_offset_11, 22, T[11]);
|
24796 | a = FF(a, b, c, d, M_offset_12, 7, T[12]);
|
24797 | d = FF(d, a, b, c, M_offset_13, 12, T[13]);
|
24798 | c = FF(c, d, a, b, M_offset_14, 17, T[14]);
|
24799 | b = FF(b, c, d, a, M_offset_15, 22, T[15]);
|
24800 |
|
24801 | a = GG(a, b, c, d, M_offset_1, 5, T[16]);
|
24802 | d = GG(d, a, b, c, M_offset_6, 9, T[17]);
|
24803 | c = GG(c, d, a, b, M_offset_11, 14, T[18]);
|
24804 | b = GG(b, c, d, a, M_offset_0, 20, T[19]);
|
24805 | a = GG(a, b, c, d, M_offset_5, 5, T[20]);
|
24806 | d = GG(d, a, b, c, M_offset_10, 9, T[21]);
|
24807 | c = GG(c, d, a, b, M_offset_15, 14, T[22]);
|
24808 | b = GG(b, c, d, a, M_offset_4, 20, T[23]);
|
24809 | a = GG(a, b, c, d, M_offset_9, 5, T[24]);
|
24810 | d = GG(d, a, b, c, M_offset_14, 9, T[25]);
|
24811 | c = GG(c, d, a, b, M_offset_3, 14, T[26]);
|
24812 | b = GG(b, c, d, a, M_offset_8, 20, T[27]);
|
24813 | a = GG(a, b, c, d, M_offset_13, 5, T[28]);
|
24814 | d = GG(d, a, b, c, M_offset_2, 9, T[29]);
|
24815 | c = GG(c, d, a, b, M_offset_7, 14, T[30]);
|
24816 | b = GG(b, c, d, a, M_offset_12, 20, T[31]);
|
24817 |
|
24818 | a = HH(a, b, c, d, M_offset_5, 4, T[32]);
|
24819 | d = HH(d, a, b, c, M_offset_8, 11, T[33]);
|
24820 | c = HH(c, d, a, b, M_offset_11, 16, T[34]);
|
24821 | b = HH(b, c, d, a, M_offset_14, 23, T[35]);
|
24822 | a = HH(a, b, c, d, M_offset_1, 4, T[36]);
|
24823 | d = HH(d, a, b, c, M_offset_4, 11, T[37]);
|
24824 | c = HH(c, d, a, b, M_offset_7, 16, T[38]);
|
24825 | b = HH(b, c, d, a, M_offset_10, 23, T[39]);
|
24826 | a = HH(a, b, c, d, M_offset_13, 4, T[40]);
|
24827 | d = HH(d, a, b, c, M_offset_0, 11, T[41]);
|
24828 | c = HH(c, d, a, b, M_offset_3, 16, T[42]);
|
24829 | b = HH(b, c, d, a, M_offset_6, 23, T[43]);
|
24830 | a = HH(a, b, c, d, M_offset_9, 4, T[44]);
|
24831 | d = HH(d, a, b, c, M_offset_12, 11, T[45]);
|
24832 | c = HH(c, d, a, b, M_offset_15, 16, T[46]);
|
24833 | b = HH(b, c, d, a, M_offset_2, 23, T[47]);
|
24834 |
|
24835 | a = II(a, b, c, d, M_offset_0, 6, T[48]);
|
24836 | d = II(d, a, b, c, M_offset_7, 10, T[49]);
|
24837 | c = II(c, d, a, b, M_offset_14, 15, T[50]);
|
24838 | b = II(b, c, d, a, M_offset_5, 21, T[51]);
|
24839 | a = II(a, b, c, d, M_offset_12, 6, T[52]);
|
24840 | d = II(d, a, b, c, M_offset_3, 10, T[53]);
|
24841 | c = II(c, d, a, b, M_offset_10, 15, T[54]);
|
24842 | b = II(b, c, d, a, M_offset_1, 21, T[55]);
|
24843 | a = II(a, b, c, d, M_offset_8, 6, T[56]);
|
24844 | d = II(d, a, b, c, M_offset_15, 10, T[57]);
|
24845 | c = II(c, d, a, b, M_offset_6, 15, T[58]);
|
24846 | b = II(b, c, d, a, M_offset_13, 21, T[59]);
|
24847 | a = II(a, b, c, d, M_offset_4, 6, T[60]);
|
24848 | d = II(d, a, b, c, M_offset_11, 10, T[61]);
|
24849 | c = II(c, d, a, b, M_offset_2, 15, T[62]);
|
24850 | b = II(b, c, d, a, M_offset_9, 21, T[63]);
|
24851 |
|
24852 | // Intermediate hash value
|
24853 | H[0] = (H[0] + a) | 0;
|
24854 | H[1] = (H[1] + b) | 0;
|
24855 | H[2] = (H[2] + c) | 0;
|
24856 | H[3] = (H[3] + d) | 0;
|
24857 | },
|
24858 |
|
24859 | _doFinalize: function () {
|
24860 | // Shortcuts
|
24861 | var data = this._data;
|
24862 | var dataWords = data.words;
|
24863 |
|
24864 | var nBitsTotal = this._nDataBytes * 8;
|
24865 | var nBitsLeft = data.sigBytes * 8;
|
24866 |
|
24867 | // Add padding
|
24868 | dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
|
24869 |
|
24870 | var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000);
|
24871 | var nBitsTotalL = nBitsTotal;
|
24872 | dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = (
|
24873 | (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) |
|
24874 | (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00)
|
24875 | );
|
24876 | dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
|
24877 | (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) |
|
24878 | (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00)
|
24879 | );
|
24880 |
|
24881 | data.sigBytes = (dataWords.length + 1) * 4;
|
24882 |
|
24883 | // Hash final blocks
|
24884 | this._process();
|
24885 |
|
24886 | // Shortcuts
|
24887 | var hash = this._hash;
|
24888 | var H = hash.words;
|
24889 |
|
24890 | // Swap endian
|
24891 | for (var i = 0; i < 4; i++) {
|
24892 | // Shortcut
|
24893 | var H_i = H[i];
|
24894 |
|
24895 | H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
|
24896 | (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00);
|
24897 | }
|
24898 |
|
24899 | // Return final computed hash
|
24900 | return hash;
|
24901 | },
|
24902 |
|
24903 | clone: function () {
|
24904 | var clone = Hasher.clone.call(this);
|
24905 | clone._hash = this._hash.clone();
|
24906 |
|
24907 | return clone;
|
24908 | }
|
24909 | });
|
24910 |
|
24911 | function FF(a, b, c, d, x, s, t) {
|
24912 | var n = a + ((b & c) | (~b & d)) + x + t;
|
24913 | return ((n << s) | (n >>> (32 - s))) + b;
|
24914 | }
|
24915 |
|
24916 | function GG(a, b, c, d, x, s, t) {
|
24917 | var n = a + ((b & d) | (c & ~d)) + x + t;
|
24918 | return ((n << s) | (n >>> (32 - s))) + b;
|
24919 | }
|
24920 |
|
24921 | function HH(a, b, c, d, x, s, t) {
|
24922 | var n = a + (b ^ c ^ d) + x + t;
|
24923 | return ((n << s) | (n >>> (32 - s))) + b;
|
24924 | }
|
24925 |
|
24926 | function II(a, b, c, d, x, s, t) {
|
24927 | var n = a + (c ^ (b | ~d)) + x + t;
|
24928 | return ((n << s) | (n >>> (32 - s))) + b;
|
24929 | }
|
24930 |
|
24931 | /**
|
24932 | * Shortcut function to the hasher's object interface.
|
24933 | *
|
24934 | * @param {WordArray|string} message The message to hash.
|
24935 | *
|
24936 | * @return {WordArray} The hash.
|
24937 | *
|
24938 | * @static
|
24939 | *
|
24940 | * @example
|
24941 | *
|
24942 | * var hash = CryptoJS.MD5('message');
|
24943 | * var hash = CryptoJS.MD5(wordArray);
|
24944 | */
|
24945 | C.MD5 = Hasher._createHelper(MD5);
|
24946 |
|
24947 | /**
|
24948 | * Shortcut function to the HMAC's object interface.
|
24949 | *
|
24950 | * @param {WordArray|string} message The message to hash.
|
24951 | * @param {WordArray|string} key The secret key.
|
24952 | *
|
24953 | * @return {WordArray} The HMAC.
|
24954 | *
|
24955 | * @static
|
24956 | *
|
24957 | * @example
|
24958 | *
|
24959 | * var hmac = CryptoJS.HmacMD5(message, key);
|
24960 | */
|
24961 | C.HmacMD5 = Hasher._createHmacHelper(MD5);
|
24962 | }(Math));
|
24963 |
|
24964 |
|
24965 | return CryptoJS.MD5;
|
24966 |
|
24967 | }));
|
24968 |
|
24969 | /***/ }),
|
24970 | /* 108 */
|
24971 | /***/ (function(module, exports, __webpack_require__) {
|
24972 |
|
24973 | ;(function (root, factory) {
|
24974 | if (true) {
|
24975 | // CommonJS
|
24976 | module.exports = exports = factory(__webpack_require__(4));
|
24977 | }
|
24978 | else {}
|
24979 | }(this, function (CryptoJS) {
|
24980 |
|
24981 | (function () {
|
24982 | // Shortcuts
|
24983 | var C = CryptoJS;
|
24984 | var C_lib = C.lib;
|
24985 | var WordArray = C_lib.WordArray;
|
24986 | var Hasher = C_lib.Hasher;
|
24987 | var C_algo = C.algo;
|
24988 |
|
24989 | // Reusable object
|
24990 | var W = [];
|
24991 |
|
24992 | /**
|
24993 | * SHA-1 hash algorithm.
|
24994 | */
|
24995 | var SHA1 = C_algo.SHA1 = Hasher.extend({
|
24996 | _doReset: function () {
|
24997 | this._hash = new WordArray.init([
|
24998 | 0x67452301, 0xefcdab89,
|
24999 | 0x98badcfe, 0x10325476,
|
25000 | 0xc3d2e1f0
|
25001 | ]);
|
25002 | },
|
25003 |
|
25004 | _doProcessBlock: function (M, offset) {
|
25005 | // Shortcut
|
25006 | var H = this._hash.words;
|
25007 |
|
25008 | // Working variables
|
25009 | var a = H[0];
|
25010 | var b = H[1];
|
25011 | var c = H[2];
|
25012 | var d = H[3];
|
25013 | var e = H[4];
|
25014 |
|
25015 | // Computation
|
25016 | for (var i = 0; i < 80; i++) {
|
25017 | if (i < 16) {
|
25018 | W[i] = M[offset + i] | 0;
|
25019 | } else {
|
25020 | var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
|
25021 | W[i] = (n << 1) | (n >>> 31);
|
25022 | }
|
25023 |
|
25024 | var t = ((a << 5) | (a >>> 27)) + e + W[i];
|
25025 | if (i < 20) {
|
25026 | t += ((b & c) | (~b & d)) + 0x5a827999;
|
25027 | } else if (i < 40) {
|
25028 | t += (b ^ c ^ d) + 0x6ed9eba1;
|
25029 | } else if (i < 60) {
|
25030 | t += ((b & c) | (b & d) | (c & d)) - 0x70e44324;
|
25031 | } else /* if (i < 80) */ {
|
25032 | t += (b ^ c ^ d) - 0x359d3e2a;
|
25033 | }
|
25034 |
|
25035 | e = d;
|
25036 | d = c;
|
25037 | c = (b << 30) | (b >>> 2);
|
25038 | b = a;
|
25039 | a = t;
|
25040 | }
|
25041 |
|
25042 | // Intermediate hash value
|
25043 | H[0] = (H[0] + a) | 0;
|
25044 | H[1] = (H[1] + b) | 0;
|
25045 | H[2] = (H[2] + c) | 0;
|
25046 | H[3] = (H[3] + d) | 0;
|
25047 | H[4] = (H[4] + e) | 0;
|
25048 | },
|
25049 |
|
25050 | _doFinalize: function () {
|
25051 | // Shortcuts
|
25052 | var data = this._data;
|
25053 | var dataWords = data.words;
|
25054 |
|
25055 | var nBitsTotal = this._nDataBytes * 8;
|
25056 | var nBitsLeft = data.sigBytes * 8;
|
25057 |
|
25058 | // Add padding
|
25059 | dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
|
25060 | dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
|
25061 | dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
|
25062 | data.sigBytes = dataWords.length * 4;
|
25063 |
|
25064 | // Hash final blocks
|
25065 | this._process();
|
25066 |
|
25067 | // Return final computed hash
|
25068 | return this._hash;
|
25069 | },
|
25070 |
|
25071 | clone: function () {
|
25072 | var clone = Hasher.clone.call(this);
|
25073 | clone._hash = this._hash.clone();
|
25074 |
|
25075 | return clone;
|
25076 | }
|
25077 | });
|
25078 |
|
25079 | /**
|
25080 | * Shortcut function to the hasher's object interface.
|
25081 | *
|
25082 | * @param {WordArray|string} message The message to hash.
|
25083 | *
|
25084 | * @return {WordArray} The hash.
|
25085 | *
|
25086 | * @static
|
25087 | *
|
25088 | * @example
|
25089 | *
|
25090 | * var hash = CryptoJS.SHA1('message');
|
25091 | * var hash = CryptoJS.SHA1(wordArray);
|
25092 | */
|
25093 | C.SHA1 = Hasher._createHelper(SHA1);
|
25094 |
|
25095 | /**
|
25096 | * Shortcut function to the HMAC's object interface.
|
25097 | *
|
25098 | * @param {WordArray|string} message The message to hash.
|
25099 | * @param {WordArray|string} key The secret key.
|
25100 | *
|
25101 | * @return {WordArray} The HMAC.
|
25102 | *
|
25103 | * @static
|
25104 | *
|
25105 | * @example
|
25106 | *
|
25107 | * var hmac = CryptoJS.HmacSHA1(message, key);
|
25108 | */
|
25109 | C.HmacSHA1 = Hasher._createHmacHelper(SHA1);
|
25110 | }());
|
25111 |
|
25112 |
|
25113 | return CryptoJS.SHA1;
|
25114 |
|
25115 | }));
|
25116 |
|
25117 | /***/ }),
|
25118 | /* 109 */
|
25119 | /***/ (function(module, exports, __webpack_require__) {
|
25120 |
|
25121 | ;(function (root, factory) {
|
25122 | if (true) {
|
25123 | // CommonJS
|
25124 | module.exports = exports = factory(__webpack_require__(4));
|
25125 | }
|
25126 | else {}
|
25127 | }(this, function (CryptoJS) {
|
25128 |
|
25129 | (function () {
|
25130 | // Shortcuts
|
25131 | var C = CryptoJS;
|
25132 | var C_lib = C.lib;
|
25133 | var Base = C_lib.Base;
|
25134 | var C_enc = C.enc;
|
25135 | var Utf8 = C_enc.Utf8;
|
25136 | var C_algo = C.algo;
|
25137 |
|
25138 | /**
|
25139 | * HMAC algorithm.
|
25140 | */
|
25141 | var HMAC = C_algo.HMAC = Base.extend({
|
25142 | /**
|
25143 | * Initializes a newly created HMAC.
|
25144 | *
|
25145 | * @param {Hasher} hasher The hash algorithm to use.
|
25146 | * @param {WordArray|string} key The secret key.
|
25147 | *
|
25148 | * @example
|
25149 | *
|
25150 | * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key);
|
25151 | */
|
25152 | init: function (hasher, key) {
|
25153 | // Init hasher
|
25154 | hasher = this._hasher = new hasher.init();
|
25155 |
|
25156 | // Convert string to WordArray, else assume WordArray already
|
25157 | if (typeof key == 'string') {
|
25158 | key = Utf8.parse(key);
|
25159 | }
|
25160 |
|
25161 | // Shortcuts
|
25162 | var hasherBlockSize = hasher.blockSize;
|
25163 | var hasherBlockSizeBytes = hasherBlockSize * 4;
|
25164 |
|
25165 | // Allow arbitrary length keys
|
25166 | if (key.sigBytes > hasherBlockSizeBytes) {
|
25167 | key = hasher.finalize(key);
|
25168 | }
|
25169 |
|
25170 | // Clamp excess bits
|
25171 | key.clamp();
|
25172 |
|
25173 | // Clone key for inner and outer pads
|
25174 | var oKey = this._oKey = key.clone();
|
25175 | var iKey = this._iKey = key.clone();
|
25176 |
|
25177 | // Shortcuts
|
25178 | var oKeyWords = oKey.words;
|
25179 | var iKeyWords = iKey.words;
|
25180 |
|
25181 | // XOR keys with pad constants
|
25182 | for (var i = 0; i < hasherBlockSize; i++) {
|
25183 | oKeyWords[i] ^= 0x5c5c5c5c;
|
25184 | iKeyWords[i] ^= 0x36363636;
|
25185 | }
|
25186 | oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes;
|
25187 |
|
25188 | // Set initial values
|
25189 | this.reset();
|
25190 | },
|
25191 |
|
25192 | /**
|
25193 | * Resets this HMAC to its initial state.
|
25194 | *
|
25195 | * @example
|
25196 | *
|
25197 | * hmacHasher.reset();
|
25198 | */
|
25199 | reset: function () {
|
25200 | // Shortcut
|
25201 | var hasher = this._hasher;
|
25202 |
|
25203 | // Reset
|
25204 | hasher.reset();
|
25205 | hasher.update(this._iKey);
|
25206 | },
|
25207 |
|
25208 | /**
|
25209 | * Updates this HMAC with a message.
|
25210 | *
|
25211 | * @param {WordArray|string} messageUpdate The message to append.
|
25212 | *
|
25213 | * @return {HMAC} This HMAC instance.
|
25214 | *
|
25215 | * @example
|
25216 | *
|
25217 | * hmacHasher.update('message');
|
25218 | * hmacHasher.update(wordArray);
|
25219 | */
|
25220 | update: function (messageUpdate) {
|
25221 | this._hasher.update(messageUpdate);
|
25222 |
|
25223 | // Chainable
|
25224 | return this;
|
25225 | },
|
25226 |
|
25227 | /**
|
25228 | * Finalizes the HMAC computation.
|
25229 | * Note that the finalize operation is effectively a destructive, read-once operation.
|
25230 | *
|
25231 | * @param {WordArray|string} messageUpdate (Optional) A final message update.
|
25232 | *
|
25233 | * @return {WordArray} The HMAC.
|
25234 | *
|
25235 | * @example
|
25236 | *
|
25237 | * var hmac = hmacHasher.finalize();
|
25238 | * var hmac = hmacHasher.finalize('message');
|
25239 | * var hmac = hmacHasher.finalize(wordArray);
|
25240 | */
|
25241 | finalize: function (messageUpdate) {
|
25242 | // Shortcut
|
25243 | var hasher = this._hasher;
|
25244 |
|
25245 | // Compute HMAC
|
25246 | var innerHash = hasher.finalize(messageUpdate);
|
25247 | hasher.reset();
|
25248 | var hmac = hasher.finalize(this._oKey.clone().concat(innerHash));
|
25249 |
|
25250 | return hmac;
|
25251 | }
|
25252 | });
|
25253 | }());
|
25254 |
|
25255 |
|
25256 | }));
|
25257 |
|
25258 | /***/ }),
|
25259 | /* 110 */
|
25260 | /***/ (function(module, exports, __webpack_require__) {
|
25261 |
|
25262 | "use strict";
|
25263 |
|
25264 | Object.defineProperty(exports, "__esModule", { value: true });
|
25265 | exports.default = {
|
25266 | MainNet: {
|
25267 | Name: "MainNet",
|
25268 | ProtocolConfiguration: {
|
25269 | Magic: 7630401,
|
25270 | AddressVersion: 23,
|
25271 | StandbyValidators: [
|
25272 | "03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c",
|
25273 | "02df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e895093",
|
25274 | "03b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a",
|
25275 | "02ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba554",
|
25276 | "024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d",
|
25277 | "02aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e",
|
25278 | "02486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a70"
|
25279 | ],
|
25280 | SeedList: [
|
25281 | "seed1.neo.org:10333",
|
25282 | "seed2.neo.org:10333",
|
25283 | "seed3.neo.org:10333",
|
25284 | "seed4.neo.org:10333",
|
25285 | "seed5.neo.org:10333"
|
25286 | ],
|
25287 | SystemFee: {
|
25288 | EnrollmentTransaction: 1000,
|
25289 | IssueTransaction: 500,
|
25290 | PublishTransaction: 500,
|
25291 | RegisterTransaction: 10000
|
25292 | }
|
25293 | },
|
25294 | ExtraConfiguration: {
|
25295 | neonDB: "http://api.wallet.cityofzion.io",
|
25296 | neoscan: "https://api.neoscan.io/api/main_net"
|
25297 | }
|
25298 | },
|
25299 | TestNet: {
|
25300 | Name: "TestNet",
|
25301 | ProtocolConfiguration: {
|
25302 | Magic: 1953787457,
|
25303 | AddressVersion: 23,
|
25304 | StandbyValidators: [
|
25305 | "0327da12b5c40200e9f65569476bbff2218da4f32548ff43b6387ec1416a231ee8",
|
25306 | "026ce35b29147ad09e4afe4ec4a7319095f08198fa8babbe3c56e970b143528d22",
|
25307 | "0209e7fd41dfb5c2f8dc72eb30358ac100ea8c72da18847befe06eade68cebfcb9",
|
25308 | "039dafd8571a641058ccc832c5e2111ea39b09c0bde36050914384f7a48bce9bf9",
|
25309 | "038dddc06ce687677a53d54f096d2591ba2302068cf123c1f2d75c2dddc5425579",
|
25310 | "02d02b1873a0863cd042cc717da31cea0d7cf9db32b74d4c72c01b0011503e2e22",
|
25311 | "034ff5ceeac41acf22cd5ed2da17a6df4dd8358fcb2bfb1a43208ad0feaab2746b"
|
25312 | ],
|
25313 | SeedList: [
|
25314 | "seed1.neo.org:20333",
|
25315 | "seed2.neo.org:20333",
|
25316 | "seed3.neo.org:20333",
|
25317 | "seed4.neo.org:20333",
|
25318 | "seed5.neo.org:20333"
|
25319 | ],
|
25320 | SystemFee: {
|
25321 | EnrollmentTransaction: 10,
|
25322 | IssueTransaction: 5,
|
25323 | PublishTransaction: 5,
|
25324 | RegisterTransaction: 100
|
25325 | }
|
25326 | },
|
25327 | ExtraConfiguration: {
|
25328 | neonDB: "http://testnet-api.wallet.cityofzion.io",
|
25329 | neoscan: "https://neoscan-testnet.io/api/test_net"
|
25330 | }
|
25331 | },
|
25332 | CozNet: {
|
25333 | Name: "CozNet",
|
25334 | ProtocolConfiguration: {
|
25335 | Magic: 1010102,
|
25336 | AddressVersion: 23,
|
25337 | StandbyValidators: [
|
25338 | "032d9e51c7d48b0f5cc63d63deb89767685832cf69eb7113900290f217ae0504ee",
|
25339 | "022a5b7ccf03166a95e1750f0c350c734c34fe7aac66622eecdb5a529d2e69b1df",
|
25340 | "03c478d43271c297696ee3ab5a7946ee60287015c7dca6cba867819c7f271bc4ea",
|
25341 | "0393ef777d01fb60eef1da3474b975c6a393b464bcfe588e2ad7dbc4dbdfa2c244"
|
25342 | ],
|
25343 | SeedList: [
|
25344 | "188.68.34.29:10330",
|
25345 | "188.68.34.29:10332",
|
25346 | "188.68.34.29:10334",
|
25347 | "188.68.34.29:10336"
|
25348 | ],
|
25349 | SystemFee: {
|
25350 | EnrollmentTransaction: 1000,
|
25351 | IssueTransaction: 500,
|
25352 | PublishTransaction: 500,
|
25353 | RegisterTransaction: 10000
|
25354 | }
|
25355 | },
|
25356 | ExtraConfiguration: {
|
25357 | neoscan: "https://coz.neoscan-testnet.io/api/main_net"
|
25358 | }
|
25359 | }
|
25360 | };
|
25361 |
|
25362 |
|
25363 | /***/ }),
|
25364 | /* 111 */
|
25365 | /***/ (function(module, __webpack_exports__, __webpack_require__) {
|
25366 |
|
25367 | "use strict";
|
25368 | __webpack_require__.r(__webpack_exports__);
|
25369 | var neoCli_namespaceObject = {};
|
25370 | __webpack_require__.r(neoCli_namespaceObject);
|
25371 | __webpack_require__.d(neoCli_namespaceObject, "instance", function() { return neoCli_class; });
|
25372 | __webpack_require__.d(neoCli_namespaceObject, "getRPCEndpoint", function() { return getRPCEndpoint; });
|
25373 | __webpack_require__.d(neoCli_namespaceObject, "getBalance", function() { return getBalance; });
|
25374 | __webpack_require__.d(neoCli_namespaceObject, "getClaims", function() { return getClaims; });
|
25375 | __webpack_require__.d(neoCli_namespaceObject, "getMaxClaimAmount", function() { return getMaxClaimAmount; });
|
25376 | var neonDB_namespaceObject = {};
|
25377 | __webpack_require__.r(neonDB_namespaceObject);
|
25378 | __webpack_require__.d(neonDB_namespaceObject, "instance", function() { return neonDB_class; });
|
25379 | __webpack_require__.d(neonDB_namespaceObject, "getRPCEndpoint", function() { return core_getRPCEndpoint; });
|
25380 | __webpack_require__.d(neonDB_namespaceObject, "getBalance", function() { return core_getBalance; });
|
25381 | __webpack_require__.d(neonDB_namespaceObject, "getClaims", function() { return core_getClaims; });
|
25382 | __webpack_require__.d(neonDB_namespaceObject, "getMaxClaimAmount", function() { return core_getMaxClaimAmount; });
|
25383 | __webpack_require__.d(neonDB_namespaceObject, "getTransactionHistory", function() { return getTransactionHistory; });
|
25384 | __webpack_require__.d(neonDB_namespaceObject, "getHeight", function() { return getHeight; });
|
25385 | var neoscan_namespaceObject = {};
|
25386 | __webpack_require__.r(neoscan_namespaceObject);
|
25387 | __webpack_require__.d(neoscan_namespaceObject, "instance", function() { return neoscan_class; });
|
25388 | __webpack_require__.d(neoscan_namespaceObject, "getRPCEndpoint", function() { return neoscan_core_getRPCEndpoint; });
|
25389 | __webpack_require__.d(neoscan_namespaceObject, "getBalance", function() { return neoscan_core_getBalance; });
|
25390 | __webpack_require__.d(neoscan_namespaceObject, "getClaims", function() { return neoscan_core_getClaims; });
|
25391 | __webpack_require__.d(neoscan_namespaceObject, "getMaxClaimAmount", function() { return neoscan_core_getMaxClaimAmount; });
|
25392 | __webpack_require__.d(neoscan_namespaceObject, "getHeight", function() { return core_getHeight; });
|
25393 | __webpack_require__.d(neoscan_namespaceObject, "getTransactionHistory", function() { return core_getTransactionHistory; });
|
25394 | var plugin_namespaceObject = {};
|
25395 | __webpack_require__.r(plugin_namespaceObject);
|
25396 | __webpack_require__.d(plugin_namespaceObject, "neoCli", function() { return neoCli_namespaceObject; });
|
25397 | __webpack_require__.d(plugin_namespaceObject, "neoscan", function() { return neoscan_namespaceObject; });
|
25398 | __webpack_require__.d(plugin_namespaceObject, "neonDB", function() { return neonDB_namespaceObject; });
|
25399 | __webpack_require__.d(plugin_namespaceObject, "checkProperty", function() { return checkProperty; });
|
25400 | __webpack_require__.d(plugin_namespaceObject, "modifyTransactionForEmptyTransaction", function() { return modifyTransactionForEmptyTransaction; });
|
25401 | __webpack_require__.d(plugin_namespaceObject, "extractDump", function() { return extractDump; });
|
25402 | __webpack_require__.d(plugin_namespaceObject, "getVerificationSignatureForSmartContract", function() { return getVerificationSignatureForSmartContract; });
|
25403 | __webpack_require__.d(plugin_namespaceObject, "createClaimTx", function() { return createClaimTx; });
|
25404 | __webpack_require__.d(plugin_namespaceObject, "createContractTx", function() { return createContractTx; });
|
25405 | __webpack_require__.d(plugin_namespaceObject, "createInvocationTx", function() { return createInvocationTx; });
|
25406 | __webpack_require__.d(plugin_namespaceObject, "createStateTx", function() { return createStateTx; });
|
25407 | __webpack_require__.d(plugin_namespaceObject, "fillUrl", function() { return fillUrl; });
|
25408 | __webpack_require__.d(plugin_namespaceObject, "fillBalance", function() { return fillBalance; });
|
25409 | __webpack_require__.d(plugin_namespaceObject, "fillSigningFunction", function() { return fillSigningFunction; });
|
25410 | __webpack_require__.d(plugin_namespaceObject, "fillClaims", function() { return fillClaims; });
|
25411 | __webpack_require__.d(plugin_namespaceObject, "addAttributeForMintToken", function() { return addAttributeForMintToken; });
|
25412 | __webpack_require__.d(plugin_namespaceObject, "addSignatureForMintToken", function() { return addSignatureForMintToken; });
|
25413 | __webpack_require__.d(plugin_namespaceObject, "sendTx", function() { return sendTx; });
|
25414 | __webpack_require__.d(plugin_namespaceObject, "applyTxToBalance", function() { return applyTxToBalance; });
|
25415 | __webpack_require__.d(plugin_namespaceObject, "signTx", function() { return signTx; });
|
25416 | __webpack_require__.d(plugin_namespaceObject, "signWithPrivateKey", function() { return signWithPrivateKey; });
|
25417 | __webpack_require__.d(plugin_namespaceObject, "addAttributeIfExecutingAsSmartContract", function() { return addAttributeIfExecutingAsSmartContract; });
|
25418 | __webpack_require__.d(plugin_namespaceObject, "addSignatureIfExecutingAsSmartContract", function() { return addSignatureIfExecutingAsSmartContract; });
|
25419 | __webpack_require__.d(plugin_namespaceObject, "sendAsset", function() { return sendAsset; });
|
25420 | __webpack_require__.d(plugin_namespaceObject, "claimGas", function() { return claimGas; });
|
25421 | __webpack_require__.d(plugin_namespaceObject, "doInvoke", function() { return doInvoke; });
|
25422 | __webpack_require__.d(plugin_namespaceObject, "setupVote", function() { return setupVote; });
|
25423 | __webpack_require__.d(plugin_namespaceObject, "makeIntent", function() { return makeIntent; });
|
25424 |
|
25425 | // EXTERNAL MODULE: ../neon-core/lib/index.js + 62 modules
|
25426 | var lib = __webpack_require__(0);
|
25427 |
|
25428 | // EXTERNAL MODULE: /home/circleci/repo/node_modules/axios/index.js
|
25429 | var axios = __webpack_require__(1);
|
25430 | var axios_default = /*#__PURE__*/__webpack_require__.n(axios);
|
25431 |
|
25432 | // CONCATENATED MODULE: ../neon-api/lib/provider/neoCli/core.js
|
25433 | var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
25434 | return new (P || (P = Promise))(function (resolve, reject) {
|
25435 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
25436 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
25437 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
25438 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
25439 | });
|
25440 | };
|
25441 |
|
25442 |
|
25443 | const log = lib["logging"].default("api");
|
25444 | const BASE_REQ = lib["CONST"].DEFAULT_REQ;
|
25445 | function throwRpcError(err) {
|
25446 | throw new Error(`Encounter error code ${err.code}: ${err.message}`);
|
25447 | }
|
25448 | function getRPCEndpoint(url) {
|
25449 | return url;
|
25450 | }
|
25451 | function convertNeoCliTx(tx) {
|
25452 | return { index: tx.n, txid: tx.txid, value: tx.value };
|
25453 | }
|
25454 | function convertNeoCliClaimable(c) {
|
25455 | return {
|
25456 | claim: c.unclaimed,
|
25457 | txid: c.txid,
|
25458 | index: c.n,
|
25459 | value: c.value,
|
25460 | start: c.start_height,
|
25461 | end: c.end_height
|
25462 | };
|
25463 | }
|
25464 | /**
|
25465 | * Get balances of NEO and GAS for an address
|
25466 | * @param url - URL of a neonDB service.
|
25467 | * @param address - Address to check.
|
25468 | * @return Balance of address
|
25469 | */
|
25470 | function getBalance(url, address) {
|
25471 | return __awaiter(this, void 0, void 0, function* () {
|
25472 | const response = yield axios_default.a.post(url, Object.assign({}, BASE_REQ, { method: "getunspents", params: [address] }));
|
25473 | const data = response.data;
|
25474 | if (data.error) {
|
25475 | throwRpcError(data.error);
|
25476 | }
|
25477 | const bal = new lib["wallet"].Balance({
|
25478 | net: url,
|
25479 | address: data.result.address
|
25480 | });
|
25481 | for (const assetBalance of data.result.balance) {
|
25482 | if (assetBalance.amount === 0) {
|
25483 | continue;
|
25484 | }
|
25485 | if (assetBalance.unspent.length > 0) {
|
25486 | bal.addAsset(assetBalance.asset_symbol, {
|
25487 | unspent: assetBalance.unspent.map(convertNeoCliTx)
|
25488 | });
|
25489 | }
|
25490 | else {
|
25491 | bal.addToken(assetBalance.asset_symbol, assetBalance.amount);
|
25492 | }
|
25493 | }
|
25494 | log.info(`Retrieved Balance for ${address} from neonDB ${url}`);
|
25495 | return bal;
|
25496 | });
|
25497 | }
|
25498 | function getClaims(url, address) {
|
25499 | return __awaiter(this, void 0, void 0, function* () {
|
25500 | const response = yield axios_default.a.post(url, Object.assign({}, BASE_REQ, { method: "getclaimable", params: [address] }));
|
25501 | const data = response.data;
|
25502 | if (data.error) {
|
25503 | throwRpcError(data.error);
|
25504 | }
|
25505 | return new lib["wallet"].Claims({
|
25506 | net: url,
|
25507 | address: data.result.address,
|
25508 | claims: data.result.claimable.map(convertNeoCliClaimable)
|
25509 | });
|
25510 | });
|
25511 | }
|
25512 | function getMaxClaimAmount(url, address) {
|
25513 | return __awaiter(this, void 0, void 0, function* () {
|
25514 | const response = yield axios_default.a.post(url, Object.assign({}, BASE_REQ, { method: "getunclaimed", params: [address] }));
|
25515 | const data = response.data;
|
25516 | if (data.error) {
|
25517 | throwRpcError(data.error);
|
25518 | }
|
25519 | return new lib["u"].Fixed8(data.result.unclaimed).div(100000000);
|
25520 | });
|
25521 | }
|
25522 | //# sourceMappingURL=core.js.map
|
25523 | // CONCATENATED MODULE: ../neon-api/lib/provider/neoCli/class.js
|
25524 |
|
25525 |
|
25526 | const class_log = lib["logging"].default("api");
|
25527 | class class_NeoCli {
|
25528 | get name() {
|
25529 | return `NeoCli[${this.url}]`;
|
25530 | }
|
25531 | constructor(url) {
|
25532 | this.url = url;
|
25533 | this.rpc = new lib["rpc"].RPCClient(url);
|
25534 | class_log.info(`Created NeoCli Provider: ${this.url}`);
|
25535 | }
|
25536 | getRPCEndpoint(noCache) {
|
25537 | return Promise.resolve(this.url);
|
25538 | }
|
25539 | getBalance(address) {
|
25540 | return getBalance(this.url, address);
|
25541 | }
|
25542 | getClaims(address) {
|
25543 | return getClaims(this.url, address);
|
25544 | }
|
25545 | getMaxClaimAmount(address) {
|
25546 | return getMaxClaimAmount(this.url, address);
|
25547 | }
|
25548 | getHeight() {
|
25549 | return this.rpc.getBlockCount();
|
25550 | }
|
25551 | getTransactionHistory(address) {
|
25552 | throw new Error("Method not implemented.");
|
25553 | }
|
25554 | }
|
25555 | /* harmony default export */ var neoCli_class = (class_NeoCli);
|
25556 | //# sourceMappingURL=class.js.map
|
25557 | // CONCATENATED MODULE: ../neon-api/lib/provider/neoCli/index.js
|
25558 |
|
25559 |
|
25560 | //# sourceMappingURL=index.js.map
|
25561 | // CONCATENATED MODULE: ../neon-api/lib/settings.js
|
25562 | const settings = {
|
25563 | httpsOnly: false
|
25564 | };
|
25565 | function set(newSettings) {
|
25566 | Object.keys(settings).forEach(key => {
|
25567 | if (newSettings.hasOwnProperty(key)) {
|
25568 | settings[key] = !!newSettings[key];
|
25569 | }
|
25570 | });
|
25571 | }
|
25572 | /* harmony default export */ var lib_settings = (settings);
|
25573 | //# sourceMappingURL=settings.js.map
|
25574 | // CONCATENATED MODULE: ../neon-api/lib/provider/common.js
|
25575 | var common_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
25576 | return new (P || (P = Promise))(function (resolve, reject) {
|
25577 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
25578 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
25579 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
25580 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
25581 | });
|
25582 | };
|
25583 |
|
25584 | function filterHttpsOnly(nodes) {
|
25585 | return nodes.filter(n => n.url.includes("https://"));
|
25586 | }
|
25587 | function raceToSuccess(promises) {
|
25588 | return common_awaiter(this, void 0, void 0, function* () {
|
25589 | try {
|
25590 | const errors = yield Promise.all(promises.map(p => p.then(val => Promise.reject(val), err => err)));
|
25591 | return yield Promise.reject(errors);
|
25592 | }
|
25593 | catch (success) {
|
25594 | return success;
|
25595 | }
|
25596 | });
|
25597 | }
|
25598 | function getBestUrl(rpcs) {
|
25599 | return common_awaiter(this, void 0, void 0, function* () {
|
25600 | const clients = rpcs.map(r => new lib["rpc"].RPCClient(r.url));
|
25601 | return yield raceToSuccess(clients.map(c => c.ping().then(_ => c.net)));
|
25602 | });
|
25603 | }
|
25604 | function findGoodNodesFromHeight(nodes, tolerance = 1) {
|
25605 | if (nodes.length === 0) {
|
25606 | throw new Error("No eligible nodes found!");
|
25607 | }
|
25608 | const sortedNodes = nodes.slice().sort((n1, n2) => n2.height - n1.height);
|
25609 | const bestHeight = sortedNodes[0].height;
|
25610 | const threshold = bestHeight - tolerance;
|
25611 | return sortedNodes.filter(n => n.height >= threshold);
|
25612 | }
|
25613 | //# sourceMappingURL=common.js.map
|
25614 | // CONCATENATED MODULE: ../neon-api/lib/provider/neonDB/core.js
|
25615 | var core_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
25616 | return new (P || (P = Promise))(function (resolve, reject) {
|
25617 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
25618 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
25619 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
25620 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
25621 | });
|
25622 | };
|
25623 |
|
25624 |
|
25625 |
|
25626 |
|
25627 | const core_log = lib["logging"].default("api");
|
25628 | /**
|
25629 | * Returns an appropriate RPC endpoint retrieved from a neonDB endpoint.
|
25630 | * @param url - URL of a neonDB service.
|
25631 | * @returns URL of a good RPC endpoint.
|
25632 | */
|
25633 | function core_getRPCEndpoint(url) {
|
25634 | return core_awaiter(this, void 0, void 0, function* () {
|
25635 | const response = yield axios_default.a.get(url + "/v2/network/nodes");
|
25636 | const data = response.data.nodes;
|
25637 | let nodes = data
|
25638 | .filter(d => d.status)
|
25639 | .map(d => ({ height: d.block_height, url: d.url }));
|
25640 | if (settings.httpsOnly) {
|
25641 | nodes = filterHttpsOnly(nodes);
|
25642 | }
|
25643 | const goodNodes = findGoodNodesFromHeight(nodes);
|
25644 | const bestRPC = yield getBestUrl(goodNodes);
|
25645 | return bestRPC;
|
25646 | });
|
25647 | }
|
25648 | /**
|
25649 | * Get balances of NEO and GAS for an address
|
25650 | * @param url - URL of a neonDB service.
|
25651 | * @param address - Address to check.
|
25652 | * @return Balance of address
|
25653 | */
|
25654 | function core_getBalance(url, address) {
|
25655 | return core_awaiter(this, void 0, void 0, function* () {
|
25656 | const response = yield axios_default.a.get(url + "/v2/address/balance/" + address);
|
25657 | const data = response.data;
|
25658 | const bal = new lib["wallet"].Balance({ net: url, address });
|
25659 | if (data.NEO.balance > 0) {
|
25660 | bal.addAsset("NEO", data.NEO);
|
25661 | }
|
25662 | if (data.GAS.balance > 0) {
|
25663 | bal.addAsset("GAS", data.GAS);
|
25664 | }
|
25665 | core_log.info(`Retrieved Balance for ${address} from neonDB ${url}`);
|
25666 | return bal;
|
25667 | });
|
25668 | }
|
25669 | /**
|
25670 | * Get amounts of available (spent) and unavailable claims.
|
25671 | * @param url - URL of a neonDB service.
|
25672 | * @param address - Address to check.
|
25673 | * @return An object with available and unavailable GAS amounts.
|
25674 | */
|
25675 | function core_getClaims(url, address) {
|
25676 | return core_awaiter(this, void 0, void 0, function* () {
|
25677 | const response = yield axios_default.a.get(url + "/v2/address/claims/" + address);
|
25678 | const data = response.data;
|
25679 | const claims = data.claims.map(c => {
|
25680 | return {
|
25681 | claim: new lib["u"].Fixed8(c.claim || 0).div(100000000),
|
25682 | index: c.index,
|
25683 | txid: c.txid,
|
25684 | start: c.start || 0,
|
25685 | end: c.end || 0,
|
25686 | value: c.value
|
25687 | };
|
25688 | });
|
25689 | core_log.info(`Retrieved Claims for ${address} from neonDB ${url}`);
|
25690 | return new lib["wallet"].Claims({
|
25691 | net: url,
|
25692 | address,
|
25693 | claims
|
25694 | });
|
25695 | });
|
25696 | }
|
25697 | /**
|
25698 | * Gets the maximum amount of gas claimable after spending all NEO.
|
25699 | * @param url - URL of a neonDB service.
|
25700 | * @param address - Address to check.
|
25701 | * @return An object with available and unavailable GAS amounts.
|
25702 | */
|
25703 | function core_getMaxClaimAmount(url, address) {
|
25704 | return core_awaiter(this, void 0, void 0, function* () {
|
25705 | const response = yield axios_default.a.get(url + "/v2/address/claims/" + address);
|
25706 | const data = response.data;
|
25707 | core_log.info(`Retrieved maximum amount of gas claimable after spending all NEO for ${address} from neonDB ${url}`);
|
25708 | return new lib["u"].Fixed8(data.total_claim + data.total_unspent_claim).div(100000000);
|
25709 | });
|
25710 | }
|
25711 | /**
|
25712 | * Get transaction history for an account
|
25713 | * @param url - URL of a neonDB service.
|
25714 | * @param address - Address to check.
|
25715 | * @return a list of PastTransaction
|
25716 | */
|
25717 | function getTransactionHistory(url, address) {
|
25718 | return core_awaiter(this, void 0, void 0, function* () {
|
25719 | const response = yield axios_default.a.get(url + "/v2/address/history/" + address);
|
25720 | const data = response.data;
|
25721 | core_log.info(`Retrieved History for ${address} from neonDB ${url}`);
|
25722 | return data.history.map(rawTx => {
|
25723 | return {
|
25724 | change: {
|
25725 | NEO: new lib["u"].Fixed8(rawTx.NEO || 0),
|
25726 | GAS: new lib["u"].Fixed8(rawTx.GAS || 0)
|
25727 | },
|
25728 | blockHeight: rawTx.block_index,
|
25729 | txid: rawTx.txid
|
25730 | };
|
25731 | });
|
25732 | });
|
25733 | }
|
25734 | /**
|
25735 | * Get the current height of the light wallet DB
|
25736 | * @param url - URL of a neonDB service.
|
25737 | * @return Current height.
|
25738 | */
|
25739 | function getHeight(url) {
|
25740 | return core_awaiter(this, void 0, void 0, function* () {
|
25741 | const response = yield axios_default.a.get(url + "/v2/block/height");
|
25742 | return parseInt(response.data.block_height, 10);
|
25743 | });
|
25744 | }
|
25745 | //# sourceMappingURL=core.js.map
|
25746 | // CONCATENATED MODULE: ../neon-api/lib/provider/neonDB/class.js
|
25747 | var class_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
25748 | return new (P || (P = Promise))(function (resolve, reject) {
|
25749 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
25750 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
25751 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
25752 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
25753 | });
|
25754 | };
|
25755 |
|
25756 |
|
25757 | const neonDB_class_log = lib["logging"].default("api");
|
25758 | class class_NeonDB {
|
25759 | constructor(url) {
|
25760 | this.rpc = null;
|
25761 | this.cacheExpiry = null;
|
25762 | if (lib["settings"].networks[url] && lib["settings"].networks[url].extra.neonDB) {
|
25763 | this.url = lib["settings"].networks[url].extra.neonDB;
|
25764 | }
|
25765 | else {
|
25766 | this.url = url;
|
25767 | }
|
25768 | neonDB_class_log.info(`Created NeonDB Provider: ${this.url}`);
|
25769 | }
|
25770 | get name() {
|
25771 | return `NeonDB[${this.url}]`;
|
25772 | }
|
25773 | getRPCEndpoint(noCache = false) {
|
25774 | return class_awaiter(this, void 0, void 0, function* () {
|
25775 | if (!noCache &&
|
25776 | this.rpc &&
|
25777 | this.cacheExpiry &&
|
25778 | this.cacheExpiry < new Date()) {
|
25779 | const ping = yield this.rpc.ping();
|
25780 | if (ping <= 1000) {
|
25781 | return this.rpc.net;
|
25782 | }
|
25783 | }
|
25784 | const rpcAddress = yield core_getRPCEndpoint(this.url);
|
25785 | this.rpc = new lib["rpc"].RPCClient(rpcAddress);
|
25786 | this.cacheExpiry = new Date(new Date().getTime() + 5 * 60000);
|
25787 | return this.rpc.net;
|
25788 | });
|
25789 | }
|
25790 | getBalance(address) {
|
25791 | return core_getBalance(this.url, address);
|
25792 | }
|
25793 | getClaims(address) {
|
25794 | return core_getClaims(this.url, address);
|
25795 | }
|
25796 | getMaxClaimAmount(address) {
|
25797 | return core_getMaxClaimAmount(this.url, address);
|
25798 | }
|
25799 | getHeight() {
|
25800 | return getHeight(this.url);
|
25801 | }
|
25802 | getTransactionHistory(address) {
|
25803 | return getTransactionHistory(this.url, address);
|
25804 | }
|
25805 | }
|
25806 | /* harmony default export */ var neonDB_class = (class_NeonDB);
|
25807 | //# sourceMappingURL=class.js.map
|
25808 | // CONCATENATED MODULE: ../neon-api/lib/provider/neonDB/index.js
|
25809 |
|
25810 |
|
25811 | //# sourceMappingURL=index.js.map
|
25812 | // CONCATENATED MODULE: ../neon-api/lib/provider/neoscan/core.js
|
25813 | var neoscan_core_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
25814 | return new (P || (P = Promise))(function (resolve, reject) {
|
25815 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
25816 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
25817 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
25818 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
25819 | });
|
25820 | };
|
25821 |
|
25822 |
|
25823 |
|
25824 |
|
25825 | const neoscan_core_log = lib["logging"].default("api");
|
25826 | function parseUnspent(unspentArr) {
|
25827 | return unspentArr.map(coin => {
|
25828 | return {
|
25829 | index: coin.n,
|
25830 | txid: coin.txid,
|
25831 | value: coin.value
|
25832 | };
|
25833 | });
|
25834 | }
|
25835 | function parseClaims(claimArr) {
|
25836 | return claimArr.map(c => {
|
25837 | return {
|
25838 | start: c.start_height,
|
25839 | end: c.end_height,
|
25840 | index: c.n,
|
25841 | claim: c.unclaimed,
|
25842 | txid: c.txid,
|
25843 | value: c.value
|
25844 | };
|
25845 | });
|
25846 | }
|
25847 | function getChange(vin, vout, assetId) {
|
25848 | const totalOut = vin
|
25849 | .filter(i => i.asset === assetId)
|
25850 | .reduce((p, c) => p.add(c.value), new lib["u"].Fixed8(0));
|
25851 | const totalIn = vout
|
25852 | .filter(i => i.asset === assetId)
|
25853 | .reduce((p, c) => p.add(c.value), new lib["u"].Fixed8(0));
|
25854 | return totalIn.minus(totalOut);
|
25855 | }
|
25856 | function parseTxHistory(rawTxs, address) {
|
25857 | return rawTxs.map(tx => {
|
25858 | const vin = tx.vin
|
25859 | .filter(i => i.address_hash === address)
|
25860 | .map(i => ({ asset: i.asset, value: i.value }));
|
25861 | const vout = tx.vouts
|
25862 | .filter(o => o.address_hash === address)
|
25863 | .map(i => ({ asset: i.asset, value: i.value }));
|
25864 | const change = {
|
25865 | NEO: getChange(vin, vout, lib["CONST"].ASSET_ID.NEO),
|
25866 | GAS: getChange(vin, vout, lib["CONST"].ASSET_ID.GAS)
|
25867 | };
|
25868 | return {
|
25869 | txid: tx.txid,
|
25870 | blockHeight: tx.block_height,
|
25871 | change
|
25872 | };
|
25873 | });
|
25874 | }
|
25875 | /**
|
25876 | * Returns an appropriate RPC endpoint retrieved from a NeoScan endpoint.
|
25877 | * @param url - URL of a neoscan service.
|
25878 | * @returns URL of a good RPC endpoint.
|
25879 | */
|
25880 | function neoscan_core_getRPCEndpoint(url) {
|
25881 | return neoscan_core_awaiter(this, void 0, void 0, function* () {
|
25882 | const response = yield axios_default.a.get(url + "/v1/get_all_nodes");
|
25883 | let nodes = response.data;
|
25884 | if (settings.httpsOnly) {
|
25885 | nodes = filterHttpsOnly(nodes);
|
25886 | }
|
25887 | const goodNodes = findGoodNodesFromHeight(nodes);
|
25888 | const bestRPC = yield getBestUrl(goodNodes);
|
25889 | return bestRPC;
|
25890 | });
|
25891 | }
|
25892 | /**
|
25893 | * Gets balance for an address. Returns an empty Balance if endpoint returns not found.
|
25894 | * @param url - URL of a neoscan service.
|
25895 | * @param address Address to check.
|
25896 | * @return Balance of address retrieved from endpoint.
|
25897 | */
|
25898 | function neoscan_core_getBalance(url, address) {
|
25899 | return neoscan_core_awaiter(this, void 0, void 0, function* () {
|
25900 | const response = yield axios_default.a.get(url + "/v1/get_balance/" + address);
|
25901 | const data = response.data;
|
25902 | if (data.address === "not found" && data.balance === null) {
|
25903 | return new lib["wallet"].Balance({ net: url, address });
|
25904 | }
|
25905 | const bal = new lib["wallet"].Balance({
|
25906 | net: url,
|
25907 | address: data.address
|
25908 | });
|
25909 | const neoscanBalances = data.balance;
|
25910 | for (const b of neoscanBalances) {
|
25911 | if (b.amount > 0 && b.unspent.length > 0) {
|
25912 | bal.addAsset(b.asset, {
|
25913 | unspent: parseUnspent(b.unspent)
|
25914 | });
|
25915 | }
|
25916 | else {
|
25917 | bal.addToken(b.asset, b.amount);
|
25918 | }
|
25919 | }
|
25920 | neoscan_core_log.info(`Retrieved Balance for ${address} from neoscan ${url}`);
|
25921 | return bal;
|
25922 | });
|
25923 | }
|
25924 | /**
|
25925 | * Get claimable amounts for an address. Returns an empty Claims if endpoint returns not found.
|
25926 | * @param url - URL of a neoscan service.
|
25927 | * @param address - Address to check.
|
25928 | * @return Claims retrieved from endpoint.
|
25929 | */
|
25930 | function neoscan_core_getClaims(url, address) {
|
25931 | return neoscan_core_awaiter(this, void 0, void 0, function* () {
|
25932 | const response = yield axios_default.a.get(url + "/v1/get_claimable/" + address);
|
25933 | const data = response.data;
|
25934 | if (data.address === "not found" && data.claimable === null) {
|
25935 | return new lib["wallet"].Claims({ address: data.address });
|
25936 | }
|
25937 | const claims = parseClaims(data.claimable);
|
25938 | neoscan_core_log.info(`Retrieved Claims for ${address} from neoscan ${url}`);
|
25939 | return new lib["wallet"].Claims({
|
25940 | net: url,
|
25941 | address: data.address,
|
25942 | claims
|
25943 | });
|
25944 | });
|
25945 | }
|
25946 | /**
|
25947 | * Gets the maximum amount of gas claimable after spending all NEO.
|
25948 | * @param url - URL of a neoscan service.
|
25949 | * @param address Address to check.
|
25950 | * @return
|
25951 | */
|
25952 | function neoscan_core_getMaxClaimAmount(url, address) {
|
25953 | return neoscan_core_awaiter(this, void 0, void 0, function* () {
|
25954 | const response = yield axios_default.a.get(url + "/v1/get_unclaimed/" + address);
|
25955 | const data = response.data;
|
25956 | neoscan_core_log.info(`Retrieved maximum amount of gas claimable after spending all NEO for ${address} from neoscan ${url}`);
|
25957 | return new lib["u"].Fixed8(data.unclaimed || 0);
|
25958 | });
|
25959 | }
|
25960 | /**
|
25961 | * Get the current height of the light wallet DB
|
25962 | * @param url - URL of a neoscan service.
|
25963 | * @return Current height as reported by provider
|
25964 | */
|
25965 | function core_getHeight(url) {
|
25966 | return neoscan_core_awaiter(this, void 0, void 0, function* () {
|
25967 | const response = yield axios_default.a.get(url + "/v1/get_height");
|
25968 | const data = response.data;
|
25969 | return data.height;
|
25970 | });
|
25971 | }
|
25972 | /**
|
25973 | * Get transaction history for an account
|
25974 | * @param {string} net - 'MainNet' or 'TestNet'.
|
25975 | * @param {string} address - Address to check.
|
25976 | * @return {Promise<PastTransaction[]>} A listof PastTransactionPastTransaction[]
|
25977 | */
|
25978 | function core_getTransactionHistory(url, address) {
|
25979 | return neoscan_core_awaiter(this, void 0, void 0, function* () {
|
25980 | const response = yield axios_default.a.get(url + "/v1/get_last_transactions_by_address/" + address);
|
25981 | const data = response.data;
|
25982 | neoscan_core_log.info(`Retrieved History for ${address} from neoscan ${url}`);
|
25983 | return parseTxHistory(response.data, address);
|
25984 | });
|
25985 | }
|
25986 | //# sourceMappingURL=core.js.map
|
25987 | // CONCATENATED MODULE: ../neon-api/lib/provider/neoscan/class.js
|
25988 | var neoscan_class_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
25989 | return new (P || (P = Promise))(function (resolve, reject) {
|
25990 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
25991 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
25992 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
25993 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
25994 | });
|
25995 | };
|
25996 |
|
25997 |
|
25998 | const neoscan_class_log = lib["logging"].default("api");
|
25999 | class class_Neoscan {
|
26000 | constructor(url) {
|
26001 | this.rpc = null;
|
26002 | this.cacheExpiry = null;
|
26003 | if (lib["settings"].networks[url] && lib["settings"].networks[url].extra.neoscan) {
|
26004 | this.url = lib["settings"].networks[url].extra.neoscan;
|
26005 | }
|
26006 | else {
|
26007 | this.url = url;
|
26008 | }
|
26009 | neoscan_class_log.info(`Created Neoscan Provider: ${this.url}`);
|
26010 | }
|
26011 | get name() {
|
26012 | return `Neoscan[${this.url}]`;
|
26013 | }
|
26014 | getRPCEndpoint() {
|
26015 | return neoscan_class_awaiter(this, void 0, void 0, function* () {
|
26016 | if (this.rpc && this.cacheExpiry && this.cacheExpiry < new Date()) {
|
26017 | const ping = yield this.rpc.ping();
|
26018 | if (ping <= 1000) {
|
26019 | return this.rpc.net;
|
26020 | }
|
26021 | }
|
26022 | const rpcAddress = yield neoscan_core_getRPCEndpoint(this.url);
|
26023 | this.rpc = new lib["rpc"].RPCClient(rpcAddress);
|
26024 | this.cacheExpiry = new Date(new Date().getTime() + 5 * 60000);
|
26025 | return this.rpc.net;
|
26026 | });
|
26027 | }
|
26028 | getBalance(address) {
|
26029 | return neoscan_core_getBalance(this.url, address);
|
26030 | }
|
26031 | getClaims(address) {
|
26032 | return neoscan_core_getClaims(this.url, address);
|
26033 | }
|
26034 | getMaxClaimAmount(address) {
|
26035 | return neoscan_core_getMaxClaimAmount(this.url, address);
|
26036 | }
|
26037 | getHeight() {
|
26038 | return core_getHeight(this.url);
|
26039 | }
|
26040 | getTransactionHistory(address) {
|
26041 | return core_getTransactionHistory(this.url, address);
|
26042 | }
|
26043 | }
|
26044 | /* harmony default export */ var neoscan_class = (class_Neoscan);
|
26045 | //# sourceMappingURL=class.js.map
|
26046 | // CONCATENATED MODULE: ../neon-api/lib/provider/neoscan/index.js
|
26047 |
|
26048 |
|
26049 | //# sourceMappingURL=index.js.map
|
26050 | // CONCATENATED MODULE: ../neon-api/lib/funcs/common.js
|
26051 | var funcs_common_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
26052 | return new (P || (P = Promise))(function (resolve, reject) {
|
26053 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
26054 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
26055 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
26056 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
26057 | });
|
26058 | };
|
26059 |
|
26060 | /**
|
26061 | * Check that properties are defined in obj.
|
26062 | * @param obj - Object to check.
|
26063 | * @param props - List of properties to check.
|
26064 | */
|
26065 | function checkProperty(obj, ...props) {
|
26066 | for (const prop of props) {
|
26067 | if (!obj.hasOwnProperty(prop) ||
|
26068 | obj[prop] === null ||
|
26069 | obj[prop] === undefined) {
|
26070 | throw new ReferenceError(`Property not found: ${prop}`);
|
26071 | }
|
26072 | }
|
26073 | }
|
26074 | /**
|
26075 | * Adds the necessary attributes for validating an empty transaction.
|
26076 | * @param config
|
26077 | * @return
|
26078 | */
|
26079 | function modifyTransactionForEmptyTransaction(config) {
|
26080 | return funcs_common_awaiter(this, void 0, void 0, function* () {
|
26081 | if (config.tx.inputs.length === 0 && config.tx.outputs.length === 0) {
|
26082 | config.tx.addAttribute(lib["tx"].TxAttrUsage.Script, lib["u"].reverseHex(lib["wallet"].getScriptHashFromAddress(config.account.address)));
|
26083 | // This adds some random bits to the transaction to prevent any hash collision.
|
26084 | config.tx.addRemark(Date.now().toString() + lib["u"].ab2hexstring(lib["u"].generateRandomArray(4)));
|
26085 | }
|
26086 | return config;
|
26087 | });
|
26088 | }
|
26089 | const sensitiveFields = ["privateKey"];
|
26090 | /**
|
26091 | * Extracts fields for logging purposes. Removes any sensitive fields.
|
26092 | * @param config Configuration object
|
26093 | * @return object safe for logging
|
26094 | */
|
26095 | function extractDump(config) {
|
26096 | const dump = Object.assign({}, config);
|
26097 | for (const key of Object.keys(config)) {
|
26098 | if (sensitiveFields.indexOf(key) >= 0) {
|
26099 | delete dump[key];
|
26100 | }
|
26101 | }
|
26102 | return dump;
|
26103 | }
|
26104 | /**
|
26105 | * Returns a signature that can trigger verification for smart contract.
|
26106 | * Must be combined with a Script attribute for full effect.
|
26107 | * This signature requires some ordering within the array.
|
26108 | * @param url RPC url
|
26109 | * @param smartContractScriptHash The scripthash of the smart contract that you want to trigger verification for.
|
26110 | * @return A signature object that can be attached to a Transaction.
|
26111 | */
|
26112 | function getVerificationSignatureForSmartContract(url, smartContractScriptHash) {
|
26113 | return funcs_common_awaiter(this, void 0, void 0, function* () {
|
26114 | const contractState = yield lib["rpc"].Query.getContractState(smartContractScriptHash).execute(url);
|
26115 | const { parameters } = contractState.result;
|
26116 | const witness = new lib["tx"].Witness({
|
26117 | invocationScript: "00".repeat(parameters.length),
|
26118 | verificationScript: ""
|
26119 | });
|
26120 | witness.scriptHash = smartContractScriptHash;
|
26121 | return witness;
|
26122 | });
|
26123 | }
|
26124 | //# sourceMappingURL=common.js.map
|
26125 | // CONCATENATED MODULE: ../neon-api/lib/funcs/create.js
|
26126 | var create_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
26127 | return new (P || (P = Promise))(function (resolve, reject) {
|
26128 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
26129 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
26130 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
26131 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
26132 | });
|
26133 | };
|
26134 |
|
26135 |
|
26136 | function createClaimTx(config) {
|
26137 | return create_awaiter(this, void 0, void 0, function* () {
|
26138 | checkProperty(config, "claims");
|
26139 | config.tx = new lib["tx"].ClaimTransaction(config.override);
|
26140 | config.tx.addClaims(config.claims);
|
26141 | return config;
|
26142 | });
|
26143 | }
|
26144 | function createContractTx(config) {
|
26145 | return create_awaiter(this, void 0, void 0, function* () {
|
26146 | checkProperty(config, "balance", "intents");
|
26147 | config.tx = new lib["tx"].ContractTransaction(Object.assign({ outputs: config.intents }, config.override));
|
26148 | config.tx.calculate(config.balance, undefined, config.fees);
|
26149 | return config;
|
26150 | });
|
26151 | }
|
26152 | function createInvocationTx(config) {
|
26153 | return create_awaiter(this, void 0, void 0, function* () {
|
26154 | checkProperty(config, "script");
|
26155 | const processedScript = typeof config.script === "object"
|
26156 | ? lib["sc"].createScript(config.script)
|
26157 | : config.script;
|
26158 | config.tx = new lib["tx"].InvocationTransaction(Object.assign({
|
26159 | outputs: config.intents || [],
|
26160 | script: processedScript,
|
26161 | gas: config.gas || 0
|
26162 | }, config.override));
|
26163 | config.tx.calculate(config.balance || new lib["wallet"].Balance(), undefined, config.fees);
|
26164 | return config;
|
26165 | });
|
26166 | }
|
26167 | function createStateTx(config) {
|
26168 | return create_awaiter(this, void 0, void 0, function* () {
|
26169 | const descriptors = [
|
26170 | new lib["tx"].StateDescriptor({
|
26171 | type: lib["tx"].StateType.Account,
|
26172 | key: lib["u"].reverseHex(config.account.scriptHash),
|
26173 | field: "Votes",
|
26174 | value: lib["u"].int2hex(config.candidateKeys.length) + config.candidateKeys.join("")
|
26175 | })
|
26176 | ];
|
26177 | config.tx = new lib["tx"].StateTransaction({ descriptors });
|
26178 | return config;
|
26179 | });
|
26180 | }
|
26181 | //# sourceMappingURL=create.js.map
|
26182 | // CONCATENATED MODULE: ../neon-api/lib/funcs/sign.js
|
26183 | var sign_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
26184 | return new (P || (P = Promise))(function (resolve, reject) {
|
26185 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
26186 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
26187 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
26188 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
26189 | });
|
26190 | };
|
26191 |
|
26192 |
|
26193 | function addSignature(transaction, signature) {
|
26194 | transaction.scripts.push(lib["tx"].Witness.deserialize(signature));
|
26195 | }
|
26196 | /**
|
26197 | * Signs a transaction within the config object.
|
26198 | * @param config - Configuration object.
|
26199 | * @return Configuration object.
|
26200 | */
|
26201 | function signTx(config) {
|
26202 | return sign_awaiter(this, void 0, void 0, function* () {
|
26203 | checkProperty(config, "signingFunction", "tx");
|
26204 | const signatures = yield config.signingFunction(config.tx.serialize(false), config.account.publicKey);
|
26205 | if (signatures instanceof Array) {
|
26206 | signatures.forEach(sig => {
|
26207 | addSignature(config.tx, sig);
|
26208 | });
|
26209 | }
|
26210 | else {
|
26211 | addSignature(config.tx, signatures);
|
26212 | }
|
26213 | return config;
|
26214 | });
|
26215 | }
|
26216 | function signWithPrivateKey(privateKey) {
|
26217 | const pubKey = new lib["wallet"].Account(privateKey).publicKey;
|
26218 | return (txString, publicKey) => sign_awaiter(this, void 0, void 0, function* () {
|
26219 | const sig = lib["wallet"].sign(txString, privateKey);
|
26220 | const witness = lib["tx"].Witness.fromSignature(sig, publicKey || pubKey);
|
26221 | return witness.serialize();
|
26222 | });
|
26223 | }
|
26224 | //# sourceMappingURL=sign.js.map
|
26225 | // CONCATENATED MODULE: ../neon-api/lib/funcs/fill.js
|
26226 | var fill_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
26227 | return new (P || (P = Promise))(function (resolve, reject) {
|
26228 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
26229 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
26230 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
26231 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
26232 | });
|
26233 | };
|
26234 |
|
26235 |
|
26236 | /**
|
26237 | * Retrieves RPC endpoint URL of best available node
|
26238 | * @param config
|
26239 | * @return Configuration object with url field.
|
26240 | */
|
26241 | function fillUrl(config) {
|
26242 | return fill_awaiter(this, void 0, void 0, function* () {
|
26243 | if (config.url) {
|
26244 | return config;
|
26245 | }
|
26246 | config.url = yield config.api.getRPCEndpoint();
|
26247 | return config;
|
26248 | });
|
26249 | }
|
26250 | /**
|
26251 | * Retrieves Balance if no balance has been attached
|
26252 | * @param config
|
26253 | * @return Configuration object.
|
26254 | */
|
26255 | function fillBalance(config) {
|
26256 | return fill_awaiter(this, void 0, void 0, function* () {
|
26257 | if (!(config.balance instanceof lib["wallet"].Balance)) {
|
26258 | config.balance = yield config.api.getBalance(config.account.address);
|
26259 | }
|
26260 | return config;
|
26261 | });
|
26262 | }
|
26263 | /**
|
26264 | * Fills the signingFunction if no signingFunction provided.
|
26265 | * The signingFunction filled is a privateKey signing function using the private key from the account field.
|
26266 | * Throws an error if unable to find signingFunction and account.
|
26267 | * @param config
|
26268 | * @return Configuration object.
|
26269 | */
|
26270 | function fillSigningFunction(config) {
|
26271 | return fill_awaiter(this, void 0, void 0, function* () {
|
26272 | if (!config.signingFunction) {
|
26273 | if (config.account) {
|
26274 | config.signingFunction = signWithPrivateKey(config.account.privateKey);
|
26275 | }
|
26276 | else {
|
26277 | throw new Error("No account found!");
|
26278 | }
|
26279 | }
|
26280 | return config;
|
26281 | });
|
26282 | }
|
26283 | /**
|
26284 | * Retrieves Claims if no claims has been attached.
|
26285 | * @param config
|
26286 | * @return Configuration object.
|
26287 | */
|
26288 | function fillClaims(config) {
|
26289 | return fill_awaiter(this, void 0, void 0, function* () {
|
26290 | if (!(config.claims instanceof lib["wallet"].Claims)) {
|
26291 | config.claims = yield config.api.getClaims(config.account.address);
|
26292 | }
|
26293 | if (!config.claims.claims || config.claims.claims.length === 0) {
|
26294 | throw new Error(`No Claims found`);
|
26295 | }
|
26296 | return config;
|
26297 | });
|
26298 | }
|
26299 | //# sourceMappingURL=fill.js.map
|
26300 | // CONCATENATED MODULE: ../neon-api/lib/funcs/mint.js
|
26301 | var mint_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
26302 | return new (P || (P = Promise))(function (resolve, reject) {
|
26303 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
26304 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
26305 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
26306 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
26307 | });
|
26308 | };
|
26309 |
|
26310 |
|
26311 | /**
|
26312 | * Adds attributes to the override object for mintTokens invocations.
|
26313 | * @param {object} config - Configuration object.
|
26314 | * @return {Promise<object>} Configuration object.
|
26315 | */
|
26316 | function addAttributeForMintToken(config) {
|
26317 | return mint_awaiter(this, void 0, void 0, function* () {
|
26318 | if (typeof config.script === "object" &&
|
26319 | config.script.operation === "mintTokens" &&
|
26320 | config.script.scriptHash) {
|
26321 | config.tx.addAttribute(lib["tx"].TxAttrUsage.Script, lib["u"].reverseHex(config.script.scriptHash));
|
26322 | }
|
26323 | return config;
|
26324 | });
|
26325 | }
|
26326 | /**
|
26327 | * Adds the contractState to mintTokens invocations.
|
26328 | * @param {object} config - Configuration object.
|
26329 | * @return {Promise<object>} Configuration object.
|
26330 | */
|
26331 | function addSignatureForMintToken(config) {
|
26332 | return mint_awaiter(this, void 0, void 0, function* () {
|
26333 | if (typeof config.script === "object" &&
|
26334 | config.script.operation === "mintTokens" &&
|
26335 | config.script.scriptHash) {
|
26336 | const witness = yield getVerificationSignatureForSmartContract(config.url, config.script.scriptHash);
|
26337 | config.tx.addWitness(witness);
|
26338 | }
|
26339 | return config;
|
26340 | });
|
26341 | }
|
26342 | //# sourceMappingURL=mint.js.map
|
26343 | // CONCATENATED MODULE: ../neon-api/lib/funcs/send.js
|
26344 | var send_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
26345 | return new (P || (P = Promise))(function (resolve, reject) {
|
26346 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
26347 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
26348 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
26349 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
26350 | });
|
26351 | };
|
26352 |
|
26353 |
|
26354 | const send_log = lib["logging"].default("api");
|
26355 | /**
|
26356 | * Sends a transaction off within the config object.
|
26357 | * @param {object} config - Configuration object.
|
26358 | * @return {Promise<object>} Configuration object + response
|
26359 | */
|
26360 | function sendTx(config) {
|
26361 | return send_awaiter(this, void 0, void 0, function* () {
|
26362 | checkProperty(config, "tx", "url");
|
26363 | const response = yield lib["rpc"].Query.sendRawTransaction(config.tx).execute(config.url);
|
26364 | if (response.result === true) {
|
26365 | response.txid = config.tx.hash;
|
26366 | }
|
26367 | else {
|
26368 | send_log.error(`Transaction failed for ${config.account.address}: ${config.tx.serialize()}`);
|
26369 | }
|
26370 | return Object.assign(config, { response });
|
26371 | });
|
26372 | }
|
26373 | function applyTxToBalance(config) {
|
26374 | return send_awaiter(this, void 0, void 0, function* () {
|
26375 | if (config.response && config.response.result && config.balance) {
|
26376 | config.balance.applyTx(config.tx, false);
|
26377 | }
|
26378 | return config;
|
26379 | });
|
26380 | }
|
26381 | //# sourceMappingURL=send.js.map
|
26382 | // CONCATENATED MODULE: ../neon-api/lib/funcs/smartcontract.js
|
26383 | var smartcontract_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
26384 | return new (P || (P = Promise))(function (resolve, reject) {
|
26385 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
26386 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
26387 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
26388 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
26389 | });
|
26390 | };
|
26391 |
|
26392 |
|
26393 | /**
|
26394 | * Adds attributes to the override object for mintTokens invocations.
|
26395 | * @param config - Configuration object.
|
26396 | * @return Configuration object.
|
26397 | */
|
26398 | function addAttributeIfExecutingAsSmartContract(config) {
|
26399 | return smartcontract_awaiter(this, void 0, void 0, function* () {
|
26400 | if (!config.sendingFromSmartContract) {
|
26401 | return config;
|
26402 | }
|
26403 | config.tx.addAttribute(lib["tx"].TxAttrUsage.Script, lib["u"].reverseHex(config.sendingFromSmartContract));
|
26404 | return config;
|
26405 | });
|
26406 | }
|
26407 | /**
|
26408 | * Adds the contractState to invocations sending from the contract's balance.
|
26409 | * @param config - Configuration object.
|
26410 | * @return Configuration object.
|
26411 | */
|
26412 | function addSignatureIfExecutingAsSmartContract(config) {
|
26413 | return smartcontract_awaiter(this, void 0, void 0, function* () {
|
26414 | if (!config.sendingFromSmartContract) {
|
26415 | return config;
|
26416 | }
|
26417 | const witness = yield getVerificationSignatureForSmartContract(config.url, config.sendingFromSmartContract);
|
26418 | config.tx.addWitness(witness);
|
26419 | return config;
|
26420 | });
|
26421 | }
|
26422 | //# sourceMappingURL=smartcontract.js.map
|
26423 | // CONCATENATED MODULE: ../neon-api/lib/funcs/main.js
|
26424 | var main_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
26425 | return new (P || (P = Promise))(function (resolve, reject) {
|
26426 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
26427 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
26428 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
26429 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
26430 | });
|
26431 | };
|
26432 |
|
26433 |
|
26434 |
|
26435 |
|
26436 |
|
26437 |
|
26438 |
|
26439 |
|
26440 | const main_log = lib["logging"].default("api");
|
26441 | /**
|
26442 | * The core API methods are series of methods defined to aid conducting core functionality while making it easy to modify any parts of it.
|
26443 | * The core functionality are sendAsset, claimGas and doInvoke.
|
26444 | * These methods are designed to be modular in nature and intended for developers to create their own custom methods.
|
26445 | * The methods revolve around a configuration object in which everything is placed. Each method will take in the configuration object, check for its required fields and perform its operations, adding its results to the configuration object and returning it.
|
26446 | * For example, the getBalanceFrom function requires net and address fields and appends the url and balance fields to the object.
|
26447 | */
|
26448 | /**
|
26449 | * Function to construct and execute a ContractTransaction.
|
26450 | * @param config Configuration object.
|
26451 | * @return Configuration object.
|
26452 | */
|
26453 | function sendAsset(config) {
|
26454 | return main_awaiter(this, void 0, void 0, function* () {
|
26455 | return fillSigningFunction(config)
|
26456 | .then(fillUrl)
|
26457 | .then(fillBalance)
|
26458 | .then(createContractTx)
|
26459 | .then(addAttributeIfExecutingAsSmartContract)
|
26460 | .then(signTx)
|
26461 | .then(addSignatureIfExecutingAsSmartContract)
|
26462 | .then(sendTx)
|
26463 | .then(applyTxToBalance)
|
26464 | .catch((err) => {
|
26465 | const dump = extractDump(config);
|
26466 | main_log.error(`sendAsset failed with: ${err.message}. Dumping config`, dump);
|
26467 | throw err;
|
26468 | });
|
26469 | });
|
26470 | }
|
26471 | /**
|
26472 | * Perform a ClaimTransaction for all available GAS based on API
|
26473 | * @param config Configuration object.
|
26474 | * @return Configuration object.
|
26475 | */
|
26476 | function claimGas(config) {
|
26477 | return main_awaiter(this, void 0, void 0, function* () {
|
26478 | return fillSigningFunction(config)
|
26479 | .then(fillUrl)
|
26480 | .then(fillClaims)
|
26481 | .then(createClaimTx)
|
26482 | .then(addAttributeIfExecutingAsSmartContract)
|
26483 | .then(signTx)
|
26484 | .then(addSignatureIfExecutingAsSmartContract)
|
26485 | .then(sendTx)
|
26486 | .catch((err) => {
|
26487 | const dump = extractDump(config);
|
26488 | main_log.error(`claimGas failed with: ${err.message}. Dumping config`, dump);
|
26489 | throw err;
|
26490 | });
|
26491 | });
|
26492 | }
|
26493 | /**
|
26494 | * Perform a InvocationTransaction based on config given.
|
26495 | * @param config Configuration object.
|
26496 | * @return Configuration object.
|
26497 | */
|
26498 | function doInvoke(config) {
|
26499 | return main_awaiter(this, void 0, void 0, function* () {
|
26500 | return fillSigningFunction(config)
|
26501 | .then(fillUrl)
|
26502 | .then(fillBalance)
|
26503 | .then(createInvocationTx)
|
26504 | .then(addAttributeIfExecutingAsSmartContract)
|
26505 | .then(addAttributeForMintToken)
|
26506 | .then(modifyTransactionForEmptyTransaction)
|
26507 | .then(signTx)
|
26508 | .then(addSignatureIfExecutingAsSmartContract)
|
26509 | .then(addSignatureForMintToken)
|
26510 | .then(sendTx)
|
26511 | .then(applyTxToBalance)
|
26512 | .catch((err) => {
|
26513 | const dump = extractDump(config);
|
26514 | main_log.error(`doinvoke failed with: ${err.message}. Dumping config`, dump);
|
26515 | throw err;
|
26516 | });
|
26517 | });
|
26518 | }
|
26519 | /**
|
26520 | * Perform a StateTransaction based on config given.
|
26521 | * @param config Configuration object.
|
26522 | * @return modified configuration object.
|
26523 | */
|
26524 | function setupVote(config) {
|
26525 | return main_awaiter(this, void 0, void 0, function* () {
|
26526 | return fillSigningFunction(config)
|
26527 | .then(fillUrl)
|
26528 | .then(fillBalance)
|
26529 | .then(createStateTx)
|
26530 | .then(addAttributeIfExecutingAsSmartContract)
|
26531 | .then(modifyTransactionForEmptyTransaction)
|
26532 | .then(signTx)
|
26533 | .then(addSignatureIfExecutingAsSmartContract)
|
26534 | .then(sendTx)
|
26535 | .then(applyTxToBalance)
|
26536 | .catch((err) => {
|
26537 | const dump = extractDump(config);
|
26538 | main_log.error(`setupVote failed with: ${err.message}. Dumping config`, dump);
|
26539 | throw err;
|
26540 | });
|
26541 | });
|
26542 | }
|
26543 | function makeIntent(assetAmts, address) {
|
26544 | const acct = new lib["wallet"].Account(address);
|
26545 | return Object.keys(assetAmts).map(key => {
|
26546 | return new lib["tx"].TransactionOutput({
|
26547 | assetId: lib["CONST"].ASSET_ID[key],
|
26548 | value: assetAmts[key],
|
26549 | scriptHash: acct.scriptHash
|
26550 | });
|
26551 | });
|
26552 | }
|
26553 | //# sourceMappingURL=main.js.map
|
26554 | // CONCATENATED MODULE: ../neon-api/lib/funcs/index.js
|
26555 |
|
26556 |
|
26557 |
|
26558 |
|
26559 |
|
26560 |
|
26561 |
|
26562 |
|
26563 | //# sourceMappingURL=index.js.map
|
26564 | // CONCATENATED MODULE: ../neon-api/lib/plugin.js
|
26565 |
|
26566 |
|
26567 |
|
26568 |
|
26569 |
|
26570 | //# sourceMappingURL=plugin.js.map
|
26571 | // CONCATENATED MODULE: ../neon-api/lib/index.js
|
26572 | /* concated harmony reexport neoCli */__webpack_require__.d(__webpack_exports__, "neoCli", function() { return neoCli_namespaceObject; });
|
26573 | /* concated harmony reexport neoscan */__webpack_require__.d(__webpack_exports__, "neoscan", function() { return neoscan_namespaceObject; });
|
26574 | /* concated harmony reexport neonDB */__webpack_require__.d(__webpack_exports__, "neonDB", function() { return neonDB_namespaceObject; });
|
26575 | /* concated harmony reexport checkProperty */__webpack_require__.d(__webpack_exports__, "checkProperty", function() { return checkProperty; });
|
26576 | /* concated harmony reexport modifyTransactionForEmptyTransaction */__webpack_require__.d(__webpack_exports__, "modifyTransactionForEmptyTransaction", function() { return modifyTransactionForEmptyTransaction; });
|
26577 | /* concated harmony reexport extractDump */__webpack_require__.d(__webpack_exports__, "extractDump", function() { return extractDump; });
|
26578 | /* concated harmony reexport getVerificationSignatureForSmartContract */__webpack_require__.d(__webpack_exports__, "getVerificationSignatureForSmartContract", function() { return getVerificationSignatureForSmartContract; });
|
26579 | /* concated harmony reexport createClaimTx */__webpack_require__.d(__webpack_exports__, "createClaimTx", function() { return createClaimTx; });
|
26580 | /* concated harmony reexport createContractTx */__webpack_require__.d(__webpack_exports__, "createContractTx", function() { return createContractTx; });
|
26581 | /* concated harmony reexport createInvocationTx */__webpack_require__.d(__webpack_exports__, "createInvocationTx", function() { return createInvocationTx; });
|
26582 | /* concated harmony reexport createStateTx */__webpack_require__.d(__webpack_exports__, "createStateTx", function() { return createStateTx; });
|
26583 | /* concated harmony reexport fillUrl */__webpack_require__.d(__webpack_exports__, "fillUrl", function() { return fillUrl; });
|
26584 | /* concated harmony reexport fillBalance */__webpack_require__.d(__webpack_exports__, "fillBalance", function() { return fillBalance; });
|
26585 | /* concated harmony reexport fillSigningFunction */__webpack_require__.d(__webpack_exports__, "fillSigningFunction", function() { return fillSigningFunction; });
|
26586 | /* concated harmony reexport fillClaims */__webpack_require__.d(__webpack_exports__, "fillClaims", function() { return fillClaims; });
|
26587 | /* concated harmony reexport addAttributeForMintToken */__webpack_require__.d(__webpack_exports__, "addAttributeForMintToken", function() { return addAttributeForMintToken; });
|
26588 | /* concated harmony reexport addSignatureForMintToken */__webpack_require__.d(__webpack_exports__, "addSignatureForMintToken", function() { return addSignatureForMintToken; });
|
26589 | /* concated harmony reexport sendTx */__webpack_require__.d(__webpack_exports__, "sendTx", function() { return sendTx; });
|
26590 | /* concated harmony reexport applyTxToBalance */__webpack_require__.d(__webpack_exports__, "applyTxToBalance", function() { return applyTxToBalance; });
|
26591 | /* concated harmony reexport signTx */__webpack_require__.d(__webpack_exports__, "signTx", function() { return signTx; });
|
26592 | /* concated harmony reexport signWithPrivateKey */__webpack_require__.d(__webpack_exports__, "signWithPrivateKey", function() { return signWithPrivateKey; });
|
26593 | /* concated harmony reexport addAttributeIfExecutingAsSmartContract */__webpack_require__.d(__webpack_exports__, "addAttributeIfExecutingAsSmartContract", function() { return addAttributeIfExecutingAsSmartContract; });
|
26594 | /* concated harmony reexport addSignatureIfExecutingAsSmartContract */__webpack_require__.d(__webpack_exports__, "addSignatureIfExecutingAsSmartContract", function() { return addSignatureIfExecutingAsSmartContract; });
|
26595 | /* concated harmony reexport sendAsset */__webpack_require__.d(__webpack_exports__, "sendAsset", function() { return sendAsset; });
|
26596 | /* concated harmony reexport claimGas */__webpack_require__.d(__webpack_exports__, "claimGas", function() { return claimGas; });
|
26597 | /* concated harmony reexport doInvoke */__webpack_require__.d(__webpack_exports__, "doInvoke", function() { return doInvoke; });
|
26598 | /* concated harmony reexport setupVote */__webpack_require__.d(__webpack_exports__, "setupVote", function() { return setupVote; });
|
26599 | /* concated harmony reexport makeIntent */__webpack_require__.d(__webpack_exports__, "makeIntent", function() { return makeIntent; });
|
26600 |
|
26601 |
|
26602 | function assignSettings(baseSettings, newSettings) {
|
26603 | for (const key in newSettings) {
|
26604 | if (!(key in baseSettings)) {
|
26605 | Object.defineProperty(baseSettings, key, {
|
26606 | get() {
|
26607 | return newSettings[key];
|
26608 | },
|
26609 | set(val) {
|
26610 | newSettings[key] = val;
|
26611 | }
|
26612 | });
|
26613 | }
|
26614 | }
|
26615 | }
|
26616 | function bundle(neonCore) {
|
26617 | assignSettings(neonCore.settings, lib_settings);
|
26618 | return Object.assign({}, neonCore, { api: plugin_namespaceObject });
|
26619 | }
|
26620 | /* harmony default export */ var neon_api_lib = __webpack_exports__["default"] = (bundle);
|
26621 |
|
26622 | //# sourceMappingURL=index.js.map
|
26623 |
|
26624 | /***/ }),
|
26625 | /* 112 */
|
26626 | /***/ (function(module, __webpack_exports__, __webpack_require__) {
|
26627 |
|
26628 | "use strict";
|
26629 | __webpack_require__.r(__webpack_exports__);
|
26630 | var abi_namespaceObject = {};
|
26631 | __webpack_require__.r(abi_namespaceObject);
|
26632 | __webpack_require__.d(abi_namespaceObject, "name", function() { return abi_name; });
|
26633 | __webpack_require__.d(abi_namespaceObject, "symbol", function() { return abi_symbol; });
|
26634 | __webpack_require__.d(abi_namespaceObject, "decimals", function() { return abi_decimals; });
|
26635 | __webpack_require__.d(abi_namespaceObject, "totalSupply", function() { return abi_totalSupply; });
|
26636 | __webpack_require__.d(abi_namespaceObject, "balanceOf", function() { return balanceOf; });
|
26637 | __webpack_require__.d(abi_namespaceObject, "transfer", function() { return transfer; });
|
26638 | var plugin_namespaceObject = {};
|
26639 | __webpack_require__.r(plugin_namespaceObject);
|
26640 | __webpack_require__.d(plugin_namespaceObject, "abi", function() { return abi_namespaceObject; });
|
26641 | __webpack_require__.d(plugin_namespaceObject, "getToken", function() { return getToken; });
|
26642 | __webpack_require__.d(plugin_namespaceObject, "getTokens", function() { return getTokens; });
|
26643 | __webpack_require__.d(plugin_namespaceObject, "getTokenBalance", function() { return getTokenBalance; });
|
26644 | __webpack_require__.d(plugin_namespaceObject, "getTokenBalances", function() { return getTokenBalances; });
|
26645 |
|
26646 | // EXTERNAL MODULE: ../neon-core/lib/index.js + 62 modules
|
26647 | var lib = __webpack_require__(0);
|
26648 |
|
26649 | // CONCATENATED MODULE: ../neon-nep5/lib/abi.js
|
26650 |
|
26651 | function addressToScriptHash(address) {
|
26652 | return lib["u"].reverseHex(lib["wallet"].getScriptHashFromAddress(address));
|
26653 | }
|
26654 | /**
|
26655 | * Returns a function that applies a APPCALL for name to a ScriptBuilder.
|
26656 | * @example
|
26657 | * var generator = name(contractScriptHash);
|
26658 | * var script = generator().str;
|
26659 | */
|
26660 | function abi_name(scriptHash) {
|
26661 | return (sb = new lib["sc"].ScriptBuilder()) => {
|
26662 | return sb.emitAppCall(scriptHash, "name");
|
26663 | };
|
26664 | }
|
26665 | /**
|
26666 | * Returns a function that applies a APPCALL for symbol to a ScriptBuilder.
|
26667 | * @example
|
26668 | * var generator = symbol(contractScriptHash);
|
26669 | * var script = generator().str;
|
26670 | */
|
26671 | function abi_symbol(scriptHash) {
|
26672 | return (sb = new lib["sc"].ScriptBuilder()) => {
|
26673 | return sb.emitAppCall(scriptHash, "symbol");
|
26674 | };
|
26675 | }
|
26676 | /**
|
26677 | * Returns a function that applies a APPCALL for decimals to a ScriptBuilder.
|
26678 | * @example
|
26679 | * var generator = decimals(contractScriptHash);
|
26680 | * var script = generator().str;
|
26681 | */
|
26682 | function abi_decimals(scriptHash) {
|
26683 | return (sb = new lib["sc"].ScriptBuilder()) => {
|
26684 | return sb.emitAppCall(scriptHash, "decimals");
|
26685 | };
|
26686 | }
|
26687 | /**
|
26688 | * Returns a function that applies a APPCALL for totalSupply to a ScriptBuilder.
|
26689 | * @example
|
26690 | * var generator = totalSupply(contractScriptHash);
|
26691 | * var script = generator().str;
|
26692 | */
|
26693 | function abi_totalSupply(scriptHash) {
|
26694 | return (sb = new lib["sc"].ScriptBuilder()) => {
|
26695 | return sb.emitAppCall(scriptHash, "totalSupply");
|
26696 | };
|
26697 | }
|
26698 | /**
|
26699 | * Returns a function that applies a APPCALL for balanceOf to a ScriptBuilder.
|
26700 | * @example
|
26701 | * var generator = balanceOf(contractScriptHash, address);
|
26702 | * var script = generator().str;
|
26703 | */
|
26704 | function balanceOf(scriptHash, addr) {
|
26705 | return (sb = new lib["sc"].ScriptBuilder()) => {
|
26706 | const addressHash = addressToScriptHash(addr);
|
26707 | return sb.emitAppCall(scriptHash, "balanceOf", [addressHash]);
|
26708 | };
|
26709 | }
|
26710 | /**
|
26711 | * Returns a function that applies a APPCALL for balanceOf to a ScriptBuilder.
|
26712 | * amt is multipled by 100,000,000. The minimum number that can be provided is thus 0.00000001.
|
26713 | * @example
|
26714 | * var generator = transfer(contractScriptHash, sendingAddress, receivingAddress, amt);
|
26715 | * var script = generator().str;
|
26716 | */
|
26717 | function transfer(scriptHash, fromAddr, toAddr, amt) {
|
26718 | return (sb = new lib["sc"].ScriptBuilder()) => {
|
26719 | const fromHash = addressToScriptHash(fromAddr);
|
26720 | const toHash = addressToScriptHash(toAddr);
|
26721 | const adjustedAmt = new lib["u"].Fixed8(amt).toRawNumber();
|
26722 | return sb.emitAppCall(scriptHash, "transfer", [
|
26723 | fromHash,
|
26724 | toHash,
|
26725 | lib["sc"].ContractParam.integer(adjustedAmt.toString())
|
26726 | ]);
|
26727 | };
|
26728 | }
|
26729 | //# sourceMappingURL=abi.js.map
|
26730 | // CONCATENATED MODULE: ../neon-nep5/lib/main.js
|
26731 | var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
26732 | return new (P || (P = Promise))(function (resolve, reject) {
|
26733 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
26734 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
26735 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
26736 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
26737 | });
|
26738 | };
|
26739 |
|
26740 |
|
26741 | const log = lib["logging"].default("nep5");
|
26742 | const parseTokenInfo = lib["rpc"].buildParser(lib["rpc"].StringParser, lib["rpc"].StringParser, lib["rpc"].IntegerParser, lib["rpc"].Fixed8Parser);
|
26743 | const parseTokenInfoAndBalance = lib["rpc"].buildParser(lib["rpc"].StringParser, lib["rpc"].StringParser, lib["rpc"].IntegerParser, lib["rpc"].Fixed8Parser, lib["rpc"].Fixed8Parser);
|
26744 | /**
|
26745 | * Get the balance of a single token for a single address.
|
26746 | * @param url Url of the NEO node to query.
|
26747 | * @param scriptHash ScriptHash of the NEP5 contract.
|
26748 | * @param address the Address to query for the balance.
|
26749 | */
|
26750 | function getTokenBalance(url, scriptHash, address) {
|
26751 | return __awaiter(this, void 0, void 0, function* () {
|
26752 | const sb = new lib["sc"].ScriptBuilder();
|
26753 | abi_decimals(scriptHash)(sb);
|
26754 | balanceOf(scriptHash, address)(sb);
|
26755 | const script = sb.str;
|
26756 | try {
|
26757 | const res = yield lib["rpc"].Query.invokeScript(script).execute(url);
|
26758 | const decimals = lib["rpc"].IntegerParser(res.result.stack[0]);
|
26759 | return lib["rpc"]
|
26760 | .Fixed8Parser(res.result.stack[1])
|
26761 | .mul(Math.pow(10, 8 - decimals));
|
26762 | }
|
26763 | catch (err) {
|
26764 | log.error(`getTokenBalance failed with : ${err.message}`);
|
26765 | throw err;
|
26766 | }
|
26767 | });
|
26768 | }
|
26769 | /**
|
26770 | * Get token balances for an address.
|
26771 | * @param url URL of the NEO node to query.
|
26772 | * @param scriptHashArray Array of contract scriptHashes.
|
26773 | * @param address Address to query for balance of tokens.
|
26774 | */
|
26775 | function getTokenBalances(url, scriptHashArray, address) {
|
26776 | return __awaiter(this, void 0, void 0, function* () {
|
26777 | const addrScriptHash = lib["u"].reverseHex(lib["wallet"].getScriptHashFromAddress(address));
|
26778 | const sb = new lib["sc"].ScriptBuilder();
|
26779 | scriptHashArray.forEach(scriptHash => {
|
26780 | sb.emitAppCall(scriptHash, "symbol")
|
26781 | .emitAppCall(scriptHash, "decimals")
|
26782 | .emitAppCall(scriptHash, "balanceOf", [addrScriptHash]);
|
26783 | });
|
26784 | const res = yield lib["rpc"].Query.invokeScript(sb.str).execute(url);
|
26785 | const tokenList = {};
|
26786 | if (!res ||
|
26787 | !res.result ||
|
26788 | !res.result.stack ||
|
26789 | res.result.stack.length !== 3 * scriptHashArray.length) {
|
26790 | throw new Error("Stack returned was invalid");
|
26791 | }
|
26792 | try {
|
26793 | for (let i = 0; i < res.result.stack.length; i += 3) {
|
26794 | try {
|
26795 | const symbol = lib["rpc"].StringParser(res.result.stack[i]);
|
26796 | const decimals = lib["rpc"].IntegerParser(res.result.stack[i + 1]);
|
26797 | tokenList[symbol] = lib["rpc"]
|
26798 | .Fixed8Parser(res.result.stack[i + 2])
|
26799 | .mul(Math.pow(10, 8 - decimals));
|
26800 | }
|
26801 | catch (e) {
|
26802 | log.error(`single call in getTokenBalances failed with : ${e.message}`);
|
26803 | throw e;
|
26804 | }
|
26805 | }
|
26806 | return tokenList;
|
26807 | }
|
26808 | catch (err) {
|
26809 | log.error(`getTokenBalances failed with : ${err.message}`);
|
26810 | throw err;
|
26811 | }
|
26812 | });
|
26813 | }
|
26814 | /**
|
26815 | * Retrieves the complete information about a token.
|
26816 | * @param url RPC Node url to query.
|
26817 | * @param scriptHash ScriptHash of the NEP5 contract.
|
26818 | * @param address Optional address to query the balance for. If provided, the returned object will include the balance property.
|
26819 | */
|
26820 | function getToken(url, scriptHash, address) {
|
26821 | return __awaiter(this, void 0, void 0, function* () {
|
26822 | const parser = address ? parseTokenInfoAndBalance : parseTokenInfo;
|
26823 | const sb = new lib["sc"].ScriptBuilder();
|
26824 | abi_name(scriptHash)(sb);
|
26825 | abi_symbol(scriptHash)(sb);
|
26826 | abi_decimals(scriptHash)(sb);
|
26827 | abi_totalSupply(scriptHash)(sb);
|
26828 | if (address) {
|
26829 | balanceOf(scriptHash, address)(sb);
|
26830 | }
|
26831 | const script = sb.str;
|
26832 | try {
|
26833 | const res = yield lib["rpc"].Query.invokeScript(script)
|
26834 | .parseWith(parser)
|
26835 | .execute(url);
|
26836 | const result = {
|
26837 | name: res[0],
|
26838 | symbol: res[1],
|
26839 | decimals: res[2],
|
26840 | totalSupply: res[3].div(Math.pow(10, 8 - res[2])).toNumber()
|
26841 | };
|
26842 | if (address) {
|
26843 | result.balance = res[4].div(Math.pow(10, 8 - res[2]));
|
26844 | }
|
26845 | return result;
|
26846 | }
|
26847 | catch (err) {
|
26848 | log.error(`getToken failed with : ${err.message}`);
|
26849 | throw err;
|
26850 | }
|
26851 | });
|
26852 | }
|
26853 | /**
|
26854 | * Retrieves the complete information about a list of tokens.
|
26855 | * @param url RPC Node url to query.
|
26856 | * @param scriptHashArray Array of NEP5 contract scriptHashes.
|
26857 | * @param address Optional address to query the balance for. If provided, the returned object will include the balance property.
|
26858 | */
|
26859 | function getTokens(url, scriptHashArray, address) {
|
26860 | return __awaiter(this, void 0, void 0, function* () {
|
26861 | try {
|
26862 | const sb = new lib["sc"].ScriptBuilder();
|
26863 | scriptHashArray.forEach(scriptHash => {
|
26864 | if (address) {
|
26865 | const addrScriptHash = lib["u"].reverseHex(lib["wallet"].getScriptHashFromAddress(address));
|
26866 | sb.emitAppCall(scriptHash, "name")
|
26867 | .emitAppCall(scriptHash, "symbol")
|
26868 | .emitAppCall(scriptHash, "decimals")
|
26869 | .emitAppCall(scriptHash, "totalSupply")
|
26870 | .emitAppCall(scriptHash, "balanceOf", [addrScriptHash]);
|
26871 | }
|
26872 | else {
|
26873 | sb.emitAppCall(scriptHash, "name")
|
26874 | .emitAppCall(scriptHash, "symbol")
|
26875 | .emitAppCall(scriptHash, "decimals")
|
26876 | .emitAppCall(scriptHash, "totalSupply");
|
26877 | }
|
26878 | });
|
26879 | const res = yield lib["rpc"].Query.invokeScript(sb.str).execute(url);
|
26880 | const result = [];
|
26881 | const step = address ? 5 : 4;
|
26882 | for (let i = 0; i < res.result.stack.length; i += step) {
|
26883 | const name = lib["rpc"].StringParser(res.result.stack[i]);
|
26884 | const symbol = lib["rpc"].StringParser(res.result.stack[i + 1]);
|
26885 | const decimals = lib["rpc"].IntegerParser(res.result.stack[i + 2]);
|
26886 | const totalSupply = lib["rpc"]
|
26887 | .Fixed8Parser(res.result.stack[i + 3])
|
26888 | .dividedBy(Math.pow(10, decimals - lib["rpc"].IntegerParser(res.result.stack[i + 2])))
|
26889 | .toNumber();
|
26890 | const balance = address
|
26891 | ? lib["rpc"]
|
26892 | .Fixed8Parser(res.result.stack[i + 4])
|
26893 | .dividedBy(Math.pow(10, decimals - lib["rpc"].IntegerParser(res.result.stack[i + 2])))
|
26894 | : undefined;
|
26895 | const obj = {
|
26896 | name,
|
26897 | symbol,
|
26898 | decimals,
|
26899 | totalSupply,
|
26900 | balance
|
26901 | };
|
26902 | if (!obj.balance) {
|
26903 | delete obj.balance;
|
26904 | }
|
26905 | result.push(obj);
|
26906 | }
|
26907 | return result;
|
26908 | }
|
26909 | catch (err) {
|
26910 | log.error(`getTokens failed with : ${err.message}`);
|
26911 | throw err;
|
26912 | }
|
26913 | });
|
26914 | }
|
26915 | //# sourceMappingURL=main.js.map
|
26916 | // CONCATENATED MODULE: ../neon-nep5/lib/plugin.js
|
26917 |
|
26918 |
|
26919 |
|
26920 | //# sourceMappingURL=plugin.js.map
|
26921 | // CONCATENATED MODULE: ../neon-nep5/lib/index.js
|
26922 | /* concated harmony reexport abi */__webpack_require__.d(__webpack_exports__, "abi", function() { return abi_namespaceObject; });
|
26923 | /* concated harmony reexport getToken */__webpack_require__.d(__webpack_exports__, "getToken", function() { return getToken; });
|
26924 | /* concated harmony reexport getTokens */__webpack_require__.d(__webpack_exports__, "getTokens", function() { return getTokens; });
|
26925 | /* concated harmony reexport getTokenBalance */__webpack_require__.d(__webpack_exports__, "getTokenBalance", function() { return getTokenBalance; });
|
26926 | /* concated harmony reexport getTokenBalances */__webpack_require__.d(__webpack_exports__, "getTokenBalances", function() { return getTokenBalances; });
|
26927 |
|
26928 | function bundle(neonCore) {
|
26929 | return Object.assign({}, neonCore, { nep5: plugin_namespaceObject });
|
26930 | }
|
26931 | /* harmony default export */ var neon_nep5_lib = __webpack_exports__["default"] = (bundle);
|
26932 |
|
26933 | //# sourceMappingURL=index.js.map
|
26934 |
|
26935 | /***/ })
|
26936 | /******/ ]);
|
26937 | //# sourceMappingURL=index.js.map |
\ | No newline at end of file |