pusher 5.0.0 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/parse.js DELETED
@@ -1,4261 +0,0 @@
1
- module.exports = /******/ (function (modules) {
2
- // webpackBootstrap
3
- /******/ // The module cache
4
- /******/ var installedModules = {} // The require function
5
-
6
- /******/ /******/ function __webpack_require__(moduleId) {
7
- /******/ // Check if module is in cache
8
- /******/ if (installedModules[moduleId])
9
- /******/ return installedModules[moduleId].exports // Create a new module (and put it into the cache)
10
-
11
- /******/ /******/ var module = (installedModules[moduleId] = {
12
- /******/ exports: {},
13
- /******/ id: moduleId,
14
- /******/ loaded: false,
15
- /******/
16
- }) // Execute the module function
17
-
18
- /******/ /******/ modules[moduleId].call(
19
- module.exports,
20
- module,
21
- module.exports,
22
- __webpack_require__
23
- ) // Flag the module as loaded
24
-
25
- /******/ /******/ module.loaded = true // Return the exports of the module
26
-
27
- /******/ /******/ return module.exports
28
- /******/
29
- } // expose the modules object (__webpack_modules__)
30
-
31
- /******/ /******/ __webpack_require__.m = modules // expose the module cache
32
-
33
- /******/ /******/ __webpack_require__.c = installedModules // __webpack_public_path__
34
-
35
- /******/ /******/ __webpack_require__.p = "" // Load entry module and return exports
36
-
37
- /******/ /******/ return __webpack_require__(0)
38
- /******/
39
- })(
40
- /************************************************************************/
41
- /******/ [
42
- /* 0 */
43
- /***/ function (module, exports, __webpack_require__) {
44
- var crypto = __webpack_require__(1)
45
- var url = __webpack_require__(2)
46
-
47
- var auth = __webpack_require__(3)
48
- var errors = __webpack_require__(5)
49
- var events = __webpack_require__(6)
50
- var requests = __webpack_require__(9)
51
- var util = __webpack_require__(4)
52
-
53
- var PusherConfig = __webpack_require__(12)
54
- var Token = __webpack_require__(14)
55
- var WebHook = __webpack_require__(16)
56
- var NotificationClient = __webpack_require__(17)
57
-
58
- var validateChannel = function (channel) {
59
- if (
60
- typeof channel !== "string" ||
61
- channel === "" ||
62
- channel.match(/[^A-Za-z0-9_\-=@,.;]/)
63
- ) {
64
- throw new Error("Invalid channel name: '" + channel + "'")
65
- }
66
- if (channel.length > 200) {
67
- throw new Error("Channel name too long: '" + channel + "'")
68
- }
69
- }
70
-
71
- var validateSocketId = function (socketId) {
72
- if (
73
- typeof socketId !== "string" ||
74
- socketId === "" ||
75
- !socketId.match(/^\d+\.\d+$/)
76
- ) {
77
- throw new Error("Invalid socket id: '" + socketId + "'")
78
- }
79
- }
80
-
81
- /** Callback passed to all REST API methods.
82
- *
83
- * @callback requestCallback
84
- * @param {RequestError} error
85
- * @param request
86
- * @param response
87
- */
88
-
89
- /** Provides access to Pusher's REST API, WebHooks and authentication.
90
- *
91
- * @constructor
92
- * @param {Object} options
93
- * @param {String} [options.host="api.pusherapp.com"] API hostname
94
- * @param {String} [options.notification_host="api.pusherapp.com"] Notification API hostname
95
- * @param {Boolean} [options.useTLS=false] whether to use TLS
96
- * @param {Boolean} [options.encrypted=false] deprecated; renamed to `useTLS`
97
- * @param {Boolean} [options.notification_encrypted=false] whether to use TLS for notifications
98
- * @param {Integer} [options.port] port, default depends on the scheme
99
- * @param {Integer} options.appId application ID
100
- * @param {String} options.key application key
101
- * @param {String} options.secret application secret
102
- * @param {String} [options.proxy] HTTP proxy to channel requests through
103
- * @param {Integer} [options.timeout] request timeout in milliseconds
104
- * @param {Boolean} [options.keepAlive] whether requests should use keep-alive
105
- */
106
- function Pusher(options) {
107
- this.config = new PusherConfig(options)
108
- var notificationOptions = util.mergeObjects({}, options, {
109
- host: options.notificationHost,
110
- encrypted: options.notificationEncrypted,
111
- })
112
- this.notificationClient = new NotificationClient(notificationOptions)
113
- }
114
-
115
- /** Create a Pusher instance using a URL.
116
- *
117
- * URL should be in SCHEME://APP_KEY:SECRET_KEY@HOST:PORT/apps/APP_ID form.
118
- *
119
- * @param {String} pusherUrl URL containing endpoint and app details
120
- * @param {Object} [options] options, see the {@link Pusher} for details
121
- * @returns {Pusher} instance configured for the URL and options
122
- */
123
- Pusher.forURL = function (pusherUrl, options) {
124
- var apiUrl = url.parse(pusherUrl)
125
- var apiPath = apiUrl.pathname.split("/")
126
- var apiAuth = apiUrl.auth.split(":")
127
-
128
- return new Pusher(
129
- util.mergeObjects({}, options || {}, {
130
- scheme: apiUrl.protocol.replace(/:$/, ""),
131
- host: apiUrl.hostname,
132
- port: parseInt(apiUrl.port, 10) || undefined,
133
- appId: parseInt(apiPath[apiPath.length - 1], 10),
134
- key: apiAuth[0],
135
- secret: apiAuth[1],
136
- })
137
- )
138
- }
139
-
140
- /** Create a Pusher instance using a cluster name.
141
- *
142
- * @param {String} cluster cluster name
143
- * @param {Object} [options] options, see the {@link Pusher} for details
144
- * @returns {Pusher} instance configured for the cluster and options
145
- */
146
- Pusher.forCluster = function (cluster, options) {
147
- return new Pusher(
148
- util.mergeObjects({}, options || {}, {
149
- host: "api-" + cluster + ".pusher.com",
150
- })
151
- )
152
- }
153
-
154
- /** Returns a signature for given socket id, channel and socket data.
155
- *
156
- * @param {String} socketId socket id
157
- * @param {String} channel channel name
158
- * @param {Object} [data] additional socket data
159
- * @returns {String} authentication signature
160
- */
161
- Pusher.prototype.authenticate = function (socketId, channel, data) {
162
- validateSocketId(socketId)
163
- validateChannel(channel)
164
-
165
- return auth.getSocketSignature(
166
- this,
167
- this.config.token,
168
- channel,
169
- socketId,
170
- data
171
- )
172
- }
173
-
174
- /** Triggers an event.
175
- *
176
- * Channel names can contain only characters which are alphanumeric, '_' or '-'
177
- * and have to be at most 200 characters long.
178
- *
179
- * Event name can be at most 200 characters long.
180
- *
181
- * Calls back with three arguments - error, request and response. When request
182
- * completes with code < 400, error will be null. Otherwise, error will be
183
- * populated with response details.
184
- *
185
- * @param {String|String[]} channel list of at most 100 channels
186
- * @param {String} event event name
187
- * @param data event data, objects are JSON-encoded
188
- * @param {String} [socketId] id of a socket that should not receive the event
189
- * @param {requestCallback} [callback]
190
- * @see RequestError
191
- */
192
- Pusher.prototype.trigger = function (
193
- channels,
194
- event,
195
- data,
196
- socketId,
197
- callback
198
- ) {
199
- if (typeof socketId === "function") {
200
- callback = socketId
201
- socketId = undefined
202
- }
203
-
204
- if (socketId) {
205
- validateSocketId(socketId)
206
- }
207
- if (!(channels instanceof Array)) {
208
- // add single channel to array for multi trigger compatibility
209
- channels = [channels]
210
- }
211
- if (event.length > 200) {
212
- throw new Error("Too long event name: '" + event + "'")
213
- }
214
- if (channels.length > 100) {
215
- throw new Error("Can't trigger a message to more than 100 channels")
216
- }
217
- for (var i = 0; i < channels.length; i++) {
218
- validateChannel(channels[i])
219
- }
220
- events.trigger(this, channels, event, data, socketId, callback)
221
- }
222
-
223
- /* Triggers a batch of events
224
- *
225
- * @param {Event[]} An array of events, where Event is
226
- * {
227
- * name: string,
228
- * channel: string,
229
- * data: any JSON-encodable data
230
- * }
231
- */
232
- Pusher.prototype.triggerBatch = function (batch, callback) {
233
- events.triggerBatch(this, batch, callback)
234
- }
235
-
236
- Pusher.prototype.notify = function () {
237
- this.notificationClient.notify.apply(this.notificationClient, arguments)
238
- }
239
-
240
- /** Makes a POST request to Pusher, handles the authentication.
241
- *
242
- * Calls back with three arguments - error, request and response. When request
243
- * completes with code < 400, error will be null. Otherwise, error will be
244
- * populated with response details.
245
- *
246
- * @param {Object} options
247
- * @param {String} options.path request path
248
- * @param {Object} options.params query params
249
- * @param {String} options.body request body
250
- * @param {requestCallback} [callback]
251
- * @see RequestError
252
- */
253
- Pusher.prototype.post = function (options, callback) {
254
- requests.send(
255
- this.config,
256
- util.mergeObjects({}, options, { method: "POST" }),
257
- callback
258
- )
259
- }
260
-
261
- /** Makes a GET request to Pusher, handles the authentication.
262
- *
263
- * Calls back with three arguments - error, request and response. When request
264
- * completes with code < 400, error will be null. Otherwise, error will be
265
- * populated with response details.
266
- *
267
- * @param {Object} options
268
- * @param {String} options.path request path
269
- * @param {Object} options.params query params
270
- * @param {requestCallback} [callback]
271
- * @see RequestError
272
- */
273
- Pusher.prototype.get = function (options, callback) {
274
- requests.send(
275
- this.config,
276
- util.mergeObjects({}, options, { method: "GET" }),
277
- callback
278
- )
279
- }
280
-
281
- /** Creates a WebHook object for a given request.
282
- *
283
- * @param {Object} request
284
- * @param {Object} request.headers WebHook HTTP headers with lower-case keys
285
- * @param {String} request.rawBody raw WebHook body
286
- * @returns {WebHook}
287
- */
288
- Pusher.prototype.webhook = function (request) {
289
- return new WebHook(this.config.token, request)
290
- }
291
-
292
- /** Builds a signed query string that can be used in a request to Pusher.
293
- *
294
- * @param {Object} options
295
- * @param {String} options.method request method
296
- * @param {String} options.path request path
297
- * @param {Object} options.params query params
298
- * @param {String} options.body request body
299
- * @returns {String} signed query string
300
- */
301
- Pusher.prototype.createSignedQueryString = function (options) {
302
- return requests.createSignedQueryString(this.config.token, options)
303
- }
304
-
305
- Pusher.prototype.channelSharedSecret = function (channel) {
306
- return crypto
307
- .createHash("sha256")
308
- .update(channel + this.config.encryptionMasterKey)
309
- .digest()
310
- }
311
-
312
- /** Exported {@link Token} constructor. */
313
- Pusher.Token = Token
314
- /** Exported {@link RequestError} constructor. */
315
- Pusher.RequestError = errors.RequestError
316
- /** Exported {@link WebHookError} constructor. */
317
- Pusher.WebHookError = errors.WebHookError
318
-
319
- module.exports = Pusher
320
-
321
- /***/
322
- },
323
- /* 1 */
324
- /***/ function (module, exports) {
325
- module.exports = require("crypto")
326
-
327
- /***/
328
- },
329
- /* 2 */
330
- /***/ function (module, exports) {
331
- module.exports = require("url")
332
-
333
- /***/
334
- },
335
- /* 3 */
336
- /***/ function (module, exports, __webpack_require__) {
337
- var util = __webpack_require__(4)
338
-
339
- function getSocketSignature(pusher, token, channel, socketID, data) {
340
- var result = {}
341
-
342
- var signatureData = [socketID, channel]
343
- if (data) {
344
- var serializedData = JSON.stringify(data)
345
- signatureData.push(serializedData)
346
- result.channel_data = serializedData
347
- }
348
-
349
- result.auth = token.key + ":" + token.sign(signatureData.join(":"))
350
-
351
- if (util.isEncryptedChannel(channel)) {
352
- if (pusher.config.encryptionMasterKey === undefined) {
353
- throw new Error(
354
- "Cannot generate shared_secret because encryptionMasterKey is not set"
355
- )
356
- }
357
- result.shared_secret = Buffer(
358
- pusher.channelSharedSecret(channel)
359
- ).toString("base64")
360
- }
361
-
362
- return result
363
- }
364
-
365
- exports.getSocketSignature = getSocketSignature
366
-
367
- /***/
368
- },
369
- /* 4 */
370
- /***/ function (module, exports, __webpack_require__) {
371
- var crypto = __webpack_require__(1)
372
-
373
- function toOrderedArray(map) {
374
- return Object.keys(map)
375
- .map(function (key) {
376
- return [key, map[key]]
377
- })
378
- .sort(function (a, b) {
379
- if (a[0] < b[0]) {
380
- return -1
381
- }
382
- if (a[0] > b[0]) {
383
- return 1
384
- }
385
- return 0
386
- })
387
- .map(function (pair) {
388
- return pair[0] + "=" + pair[1]
389
- })
390
- }
391
-
392
- function mergeObjects(target) {
393
- for (var i = 1; i < arguments.length; i++) {
394
- var object = arguments[i]
395
- for (var key in object) {
396
- if (object.hasOwnProperty(key)) {
397
- target[key] = object[key]
398
- }
399
- }
400
- }
401
-
402
- return target
403
- }
404
-
405
- function getMD5(body) {
406
- return crypto.createHash("md5").update(body, "utf8").digest("hex")
407
- }
408
-
409
- function secureCompare(a, b) {
410
- if (a.length !== b.length) {
411
- return false
412
- }
413
- var result = 0
414
- for (var i in a) {
415
- result |= a.charCodeAt(i) ^ b.charCodeAt(i)
416
- }
417
- return result === 0
418
- }
419
-
420
- function isEncryptedChannel(channel) {
421
- return channel.startsWith("private-encrypted-")
422
- }
423
-
424
- exports.toOrderedArray = toOrderedArray
425
- exports.mergeObjects = mergeObjects
426
- exports.getMD5 = getMD5
427
- exports.secureCompare = secureCompare
428
- exports.isEncryptedChannel = isEncryptedChannel
429
-
430
- /***/
431
- },
432
- /* 5 */
433
- /***/ function (module, exports) {
434
- /** Contains information about an HTTP request error.
435
- *
436
- * @constructor
437
- * @extends Error
438
- * @param {String} message error message
439
- * @param {String} url request URL
440
- * @param [error] optional error cause
441
- * @param {Integer} [statusCode] response status code, if received
442
- * @param {String} [statusCode] response body, if received
443
- */
444
- function RequestError(message, url, error, statusCode, body) {
445
- this.name = "PusherRequestError"
446
- this.stack = new Error().stack
447
-
448
- /** @member {String} error message */
449
- this.message = message
450
- /** @member {String} request URL */
451
- this.url = url
452
- /** @member optional error cause */
453
- this.error = error
454
- /** @member {Integer} response status code, if received */
455
- this.statusCode = statusCode
456
- /** @member {String} response body, if received */
457
- this.body = body
458
- }
459
- RequestError.prototype = new Error()
460
-
461
- /** Contains information about a WebHook error.
462
- *
463
- * @constructor
464
- * @extends Error
465
- * @param {String} message error message
466
- * @param {String} contentType WebHook content type
467
- * @param {String} body WebHook body
468
- * @param {String} signature WebHook signature
469
- */
470
- function WebHookError(message, contentType, body, signature) {
471
- this.name = "PusherWebHookError"
472
- this.stack = new Error().stack
473
-
474
- /** @member {String} error message */
475
- this.message = message
476
- /** @member {String} WebHook content type */
477
- this.contentType = contentType
478
- /** @member {String} WebHook body */
479
- this.body = body
480
- /** @member {String} WebHook signature */
481
- this.signature = signature
482
- }
483
- WebHookError.prototype = new Error()
484
-
485
- exports.RequestError = RequestError
486
- exports.WebHookError = WebHookError
487
-
488
- /***/
489
- },
490
- /* 6 */
491
- /***/ function (module, exports, __webpack_require__) {
492
- var util = __webpack_require__(4)
493
- var nacl = __webpack_require__(7)
494
- var naclUtil = __webpack_require__(8)
495
-
496
- function encrypt(pusher, channel, data) {
497
- if (pusher.config.encryptionMasterKey === undefined) {
498
- throw new Error(
499
- "Set encryptionMasterKey before triggering events on encrypted channels"
500
- )
501
- }
502
-
503
- var nonceBytes = nacl.randomBytes(24)
504
-
505
- var ciphertextBytes = nacl.secretbox(
506
- naclUtil.decodeUTF8(JSON.stringify(data)),
507
- nonceBytes,
508
- pusher.channelSharedSecret(channel)
509
- )
510
-
511
- return JSON.stringify({
512
- nonce: naclUtil.encodeBase64(nonceBytes),
513
- ciphertext: naclUtil.encodeBase64(ciphertextBytes),
514
- })
515
- }
516
-
517
- exports.trigger = function (
518
- pusher,
519
- channels,
520
- eventName,
521
- data,
522
- socketId,
523
- callback
524
- ) {
525
- if (channels.length === 1 && util.isEncryptedChannel(channels[0])) {
526
- var channel = channels[0]
527
- var event = {
528
- name: eventName,
529
- data: encrypt(pusher, channel, data),
530
- channels: [channel],
531
- }
532
- if (socketId) {
533
- event.socket_id = socketId
534
- }
535
- pusher.post({ path: "/events", body: event }, callback)
536
- } else {
537
- for (var i = 0; i < channels.length; i++) {
538
- if (util.isEncryptedChannel(channels[i])) {
539
- // For rationale, see limitations of end-to-end encryption in the README
540
- throw new Error(
541
- "You cannot trigger to multiple channels when using encrypted channels"
542
- )
543
- }
544
- }
545
-
546
- var event = {
547
- name: eventName,
548
- data: ensureJSON(data),
549
- channels: channels,
550
- }
551
- if (socketId) {
552
- event.socket_id = socketId
553
- }
554
- pusher.post({ path: "/events", body: event }, callback)
555
- }
556
- }
557
-
558
- exports.triggerBatch = function (pusher, batch, callback) {
559
- for (var i = 0; i < batch.length; i++) {
560
- batch[i].data = util.isEncryptedChannel(batch[i].channel)
561
- ? encrypt(pusher, batch[i].channel, batch[i].data)
562
- : ensureJSON(batch[i].data)
563
- }
564
- pusher.post({ path: "/batch_events", body: { batch: batch } }, callback)
565
- }
566
-
567
- function ensureJSON(data) {
568
- return typeof data === "string" ? data : JSON.stringify(data)
569
- }
570
-
571
- /***/
572
- },
573
- /* 7 */
574
- /***/ function (module, exports, __webpack_require__) {
575
- ;(function (nacl) {
576
- "use strict"
577
-
578
- // Ported in 2014 by Dmitry Chestnykh and Devi Mandiri.
579
- // Public domain.
580
- //
581
- // Implementation derived from TweetNaCl version 20140427.
582
- // See for details: http://tweetnacl.cr.yp.to/
583
-
584
- var gf = function (init) {
585
- var i,
586
- r = new Float64Array(16)
587
- if (init) for (i = 0; i < init.length; i++) r[i] = init[i]
588
- return r
589
- }
590
-
591
- // Pluggable, initialized in high-level API below.
592
- var randombytes = function (/* x, n */) {
593
- throw new Error("no PRNG")
594
- }
595
-
596
- var _0 = new Uint8Array(16)
597
- var _9 = new Uint8Array(32)
598
- _9[0] = 9
599
-
600
- var gf0 = gf(),
601
- gf1 = gf([1]),
602
- _121665 = gf([0xdb41, 1]),
603
- D = gf([
604
- 0x78a3,
605
- 0x1359,
606
- 0x4dca,
607
- 0x75eb,
608
- 0xd8ab,
609
- 0x4141,
610
- 0x0a4d,
611
- 0x0070,
612
- 0xe898,
613
- 0x7779,
614
- 0x4079,
615
- 0x8cc7,
616
- 0xfe73,
617
- 0x2b6f,
618
- 0x6cee,
619
- 0x5203,
620
- ]),
621
- D2 = gf([
622
- 0xf159,
623
- 0x26b2,
624
- 0x9b94,
625
- 0xebd6,
626
- 0xb156,
627
- 0x8283,
628
- 0x149a,
629
- 0x00e0,
630
- 0xd130,
631
- 0xeef3,
632
- 0x80f2,
633
- 0x198e,
634
- 0xfce7,
635
- 0x56df,
636
- 0xd9dc,
637
- 0x2406,
638
- ]),
639
- X = gf([
640
- 0xd51a,
641
- 0x8f25,
642
- 0x2d60,
643
- 0xc956,
644
- 0xa7b2,
645
- 0x9525,
646
- 0xc760,
647
- 0x692c,
648
- 0xdc5c,
649
- 0xfdd6,
650
- 0xe231,
651
- 0xc0a4,
652
- 0x53fe,
653
- 0xcd6e,
654
- 0x36d3,
655
- 0x2169,
656
- ]),
657
- Y = gf([
658
- 0x6658,
659
- 0x6666,
660
- 0x6666,
661
- 0x6666,
662
- 0x6666,
663
- 0x6666,
664
- 0x6666,
665
- 0x6666,
666
- 0x6666,
667
- 0x6666,
668
- 0x6666,
669
- 0x6666,
670
- 0x6666,
671
- 0x6666,
672
- 0x6666,
673
- 0x6666,
674
- ]),
675
- I = gf([
676
- 0xa0b0,
677
- 0x4a0e,
678
- 0x1b27,
679
- 0xc4ee,
680
- 0xe478,
681
- 0xad2f,
682
- 0x1806,
683
- 0x2f43,
684
- 0xd7a7,
685
- 0x3dfb,
686
- 0x0099,
687
- 0x2b4d,
688
- 0xdf0b,
689
- 0x4fc1,
690
- 0x2480,
691
- 0x2b83,
692
- ])
693
-
694
- function ts64(x, i, h, l) {
695
- x[i] = (h >> 24) & 0xff
696
- x[i + 1] = (h >> 16) & 0xff
697
- x[i + 2] = (h >> 8) & 0xff
698
- x[i + 3] = h & 0xff
699
- x[i + 4] = (l >> 24) & 0xff
700
- x[i + 5] = (l >> 16) & 0xff
701
- x[i + 6] = (l >> 8) & 0xff
702
- x[i + 7] = l & 0xff
703
- }
704
-
705
- function vn(x, xi, y, yi, n) {
706
- var i,
707
- d = 0
708
- for (i = 0; i < n; i++) d |= x[xi + i] ^ y[yi + i]
709
- return (1 & ((d - 1) >>> 8)) - 1
710
- }
711
-
712
- function crypto_verify_16(x, xi, y, yi) {
713
- return vn(x, xi, y, yi, 16)
714
- }
715
-
716
- function crypto_verify_32(x, xi, y, yi) {
717
- return vn(x, xi, y, yi, 32)
718
- }
719
-
720
- function core_salsa20(o, p, k, c) {
721
- var j0 =
722
- (c[0] & 0xff) |
723
- ((c[1] & 0xff) << 8) |
724
- ((c[2] & 0xff) << 16) |
725
- ((c[3] & 0xff) << 24),
726
- j1 =
727
- (k[0] & 0xff) |
728
- ((k[1] & 0xff) << 8) |
729
- ((k[2] & 0xff) << 16) |
730
- ((k[3] & 0xff) << 24),
731
- j2 =
732
- (k[4] & 0xff) |
733
- ((k[5] & 0xff) << 8) |
734
- ((k[6] & 0xff) << 16) |
735
- ((k[7] & 0xff) << 24),
736
- j3 =
737
- (k[8] & 0xff) |
738
- ((k[9] & 0xff) << 8) |
739
- ((k[10] & 0xff) << 16) |
740
- ((k[11] & 0xff) << 24),
741
- j4 =
742
- (k[12] & 0xff) |
743
- ((k[13] & 0xff) << 8) |
744
- ((k[14] & 0xff) << 16) |
745
- ((k[15] & 0xff) << 24),
746
- j5 =
747
- (c[4] & 0xff) |
748
- ((c[5] & 0xff) << 8) |
749
- ((c[6] & 0xff) << 16) |
750
- ((c[7] & 0xff) << 24),
751
- j6 =
752
- (p[0] & 0xff) |
753
- ((p[1] & 0xff) << 8) |
754
- ((p[2] & 0xff) << 16) |
755
- ((p[3] & 0xff) << 24),
756
- j7 =
757
- (p[4] & 0xff) |
758
- ((p[5] & 0xff) << 8) |
759
- ((p[6] & 0xff) << 16) |
760
- ((p[7] & 0xff) << 24),
761
- j8 =
762
- (p[8] & 0xff) |
763
- ((p[9] & 0xff) << 8) |
764
- ((p[10] & 0xff) << 16) |
765
- ((p[11] & 0xff) << 24),
766
- j9 =
767
- (p[12] & 0xff) |
768
- ((p[13] & 0xff) << 8) |
769
- ((p[14] & 0xff) << 16) |
770
- ((p[15] & 0xff) << 24),
771
- j10 =
772
- (c[8] & 0xff) |
773
- ((c[9] & 0xff) << 8) |
774
- ((c[10] & 0xff) << 16) |
775
- ((c[11] & 0xff) << 24),
776
- j11 =
777
- (k[16] & 0xff) |
778
- ((k[17] & 0xff) << 8) |
779
- ((k[18] & 0xff) << 16) |
780
- ((k[19] & 0xff) << 24),
781
- j12 =
782
- (k[20] & 0xff) |
783
- ((k[21] & 0xff) << 8) |
784
- ((k[22] & 0xff) << 16) |
785
- ((k[23] & 0xff) << 24),
786
- j13 =
787
- (k[24] & 0xff) |
788
- ((k[25] & 0xff) << 8) |
789
- ((k[26] & 0xff) << 16) |
790
- ((k[27] & 0xff) << 24),
791
- j14 =
792
- (k[28] & 0xff) |
793
- ((k[29] & 0xff) << 8) |
794
- ((k[30] & 0xff) << 16) |
795
- ((k[31] & 0xff) << 24),
796
- j15 =
797
- (c[12] & 0xff) |
798
- ((c[13] & 0xff) << 8) |
799
- ((c[14] & 0xff) << 16) |
800
- ((c[15] & 0xff) << 24)
801
-
802
- var x0 = j0,
803
- x1 = j1,
804
- x2 = j2,
805
- x3 = j3,
806
- x4 = j4,
807
- x5 = j5,
808
- x6 = j6,
809
- x7 = j7,
810
- x8 = j8,
811
- x9 = j9,
812
- x10 = j10,
813
- x11 = j11,
814
- x12 = j12,
815
- x13 = j13,
816
- x14 = j14,
817
- x15 = j15,
818
- u
819
-
820
- for (var i = 0; i < 20; i += 2) {
821
- u = (x0 + x12) | 0
822
- x4 ^= (u << 7) | (u >>> (32 - 7))
823
- u = (x4 + x0) | 0
824
- x8 ^= (u << 9) | (u >>> (32 - 9))
825
- u = (x8 + x4) | 0
826
- x12 ^= (u << 13) | (u >>> (32 - 13))
827
- u = (x12 + x8) | 0
828
- x0 ^= (u << 18) | (u >>> (32 - 18))
829
-
830
- u = (x5 + x1) | 0
831
- x9 ^= (u << 7) | (u >>> (32 - 7))
832
- u = (x9 + x5) | 0
833
- x13 ^= (u << 9) | (u >>> (32 - 9))
834
- u = (x13 + x9) | 0
835
- x1 ^= (u << 13) | (u >>> (32 - 13))
836
- u = (x1 + x13) | 0
837
- x5 ^= (u << 18) | (u >>> (32 - 18))
838
-
839
- u = (x10 + x6) | 0
840
- x14 ^= (u << 7) | (u >>> (32 - 7))
841
- u = (x14 + x10) | 0
842
- x2 ^= (u << 9) | (u >>> (32 - 9))
843
- u = (x2 + x14) | 0
844
- x6 ^= (u << 13) | (u >>> (32 - 13))
845
- u = (x6 + x2) | 0
846
- x10 ^= (u << 18) | (u >>> (32 - 18))
847
-
848
- u = (x15 + x11) | 0
849
- x3 ^= (u << 7) | (u >>> (32 - 7))
850
- u = (x3 + x15) | 0
851
- x7 ^= (u << 9) | (u >>> (32 - 9))
852
- u = (x7 + x3) | 0
853
- x11 ^= (u << 13) | (u >>> (32 - 13))
854
- u = (x11 + x7) | 0
855
- x15 ^= (u << 18) | (u >>> (32 - 18))
856
-
857
- u = (x0 + x3) | 0
858
- x1 ^= (u << 7) | (u >>> (32 - 7))
859
- u = (x1 + x0) | 0
860
- x2 ^= (u << 9) | (u >>> (32 - 9))
861
- u = (x2 + x1) | 0
862
- x3 ^= (u << 13) | (u >>> (32 - 13))
863
- u = (x3 + x2) | 0
864
- x0 ^= (u << 18) | (u >>> (32 - 18))
865
-
866
- u = (x5 + x4) | 0
867
- x6 ^= (u << 7) | (u >>> (32 - 7))
868
- u = (x6 + x5) | 0
869
- x7 ^= (u << 9) | (u >>> (32 - 9))
870
- u = (x7 + x6) | 0
871
- x4 ^= (u << 13) | (u >>> (32 - 13))
872
- u = (x4 + x7) | 0
873
- x5 ^= (u << 18) | (u >>> (32 - 18))
874
-
875
- u = (x10 + x9) | 0
876
- x11 ^= (u << 7) | (u >>> (32 - 7))
877
- u = (x11 + x10) | 0
878
- x8 ^= (u << 9) | (u >>> (32 - 9))
879
- u = (x8 + x11) | 0
880
- x9 ^= (u << 13) | (u >>> (32 - 13))
881
- u = (x9 + x8) | 0
882
- x10 ^= (u << 18) | (u >>> (32 - 18))
883
-
884
- u = (x15 + x14) | 0
885
- x12 ^= (u << 7) | (u >>> (32 - 7))
886
- u = (x12 + x15) | 0
887
- x13 ^= (u << 9) | (u >>> (32 - 9))
888
- u = (x13 + x12) | 0
889
- x14 ^= (u << 13) | (u >>> (32 - 13))
890
- u = (x14 + x13) | 0
891
- x15 ^= (u << 18) | (u >>> (32 - 18))
892
- }
893
- x0 = (x0 + j0) | 0
894
- x1 = (x1 + j1) | 0
895
- x2 = (x2 + j2) | 0
896
- x3 = (x3 + j3) | 0
897
- x4 = (x4 + j4) | 0
898
- x5 = (x5 + j5) | 0
899
- x6 = (x6 + j6) | 0
900
- x7 = (x7 + j7) | 0
901
- x8 = (x8 + j8) | 0
902
- x9 = (x9 + j9) | 0
903
- x10 = (x10 + j10) | 0
904
- x11 = (x11 + j11) | 0
905
- x12 = (x12 + j12) | 0
906
- x13 = (x13 + j13) | 0
907
- x14 = (x14 + j14) | 0
908
- x15 = (x15 + j15) | 0
909
-
910
- o[0] = (x0 >>> 0) & 0xff
911
- o[1] = (x0 >>> 8) & 0xff
912
- o[2] = (x0 >>> 16) & 0xff
913
- o[3] = (x0 >>> 24) & 0xff
914
-
915
- o[4] = (x1 >>> 0) & 0xff
916
- o[5] = (x1 >>> 8) & 0xff
917
- o[6] = (x1 >>> 16) & 0xff
918
- o[7] = (x1 >>> 24) & 0xff
919
-
920
- o[8] = (x2 >>> 0) & 0xff
921
- o[9] = (x2 >>> 8) & 0xff
922
- o[10] = (x2 >>> 16) & 0xff
923
- o[11] = (x2 >>> 24) & 0xff
924
-
925
- o[12] = (x3 >>> 0) & 0xff
926
- o[13] = (x3 >>> 8) & 0xff
927
- o[14] = (x3 >>> 16) & 0xff
928
- o[15] = (x3 >>> 24) & 0xff
929
-
930
- o[16] = (x4 >>> 0) & 0xff
931
- o[17] = (x4 >>> 8) & 0xff
932
- o[18] = (x4 >>> 16) & 0xff
933
- o[19] = (x4 >>> 24) & 0xff
934
-
935
- o[20] = (x5 >>> 0) & 0xff
936
- o[21] = (x5 >>> 8) & 0xff
937
- o[22] = (x5 >>> 16) & 0xff
938
- o[23] = (x5 >>> 24) & 0xff
939
-
940
- o[24] = (x6 >>> 0) & 0xff
941
- o[25] = (x6 >>> 8) & 0xff
942
- o[26] = (x6 >>> 16) & 0xff
943
- o[27] = (x6 >>> 24) & 0xff
944
-
945
- o[28] = (x7 >>> 0) & 0xff
946
- o[29] = (x7 >>> 8) & 0xff
947
- o[30] = (x7 >>> 16) & 0xff
948
- o[31] = (x7 >>> 24) & 0xff
949
-
950
- o[32] = (x8 >>> 0) & 0xff
951
- o[33] = (x8 >>> 8) & 0xff
952
- o[34] = (x8 >>> 16) & 0xff
953
- o[35] = (x8 >>> 24) & 0xff
954
-
955
- o[36] = (x9 >>> 0) & 0xff
956
- o[37] = (x9 >>> 8) & 0xff
957
- o[38] = (x9 >>> 16) & 0xff
958
- o[39] = (x9 >>> 24) & 0xff
959
-
960
- o[40] = (x10 >>> 0) & 0xff
961
- o[41] = (x10 >>> 8) & 0xff
962
- o[42] = (x10 >>> 16) & 0xff
963
- o[43] = (x10 >>> 24) & 0xff
964
-
965
- o[44] = (x11 >>> 0) & 0xff
966
- o[45] = (x11 >>> 8) & 0xff
967
- o[46] = (x11 >>> 16) & 0xff
968
- o[47] = (x11 >>> 24) & 0xff
969
-
970
- o[48] = (x12 >>> 0) & 0xff
971
- o[49] = (x12 >>> 8) & 0xff
972
- o[50] = (x12 >>> 16) & 0xff
973
- o[51] = (x12 >>> 24) & 0xff
974
-
975
- o[52] = (x13 >>> 0) & 0xff
976
- o[53] = (x13 >>> 8) & 0xff
977
- o[54] = (x13 >>> 16) & 0xff
978
- o[55] = (x13 >>> 24) & 0xff
979
-
980
- o[56] = (x14 >>> 0) & 0xff
981
- o[57] = (x14 >>> 8) & 0xff
982
- o[58] = (x14 >>> 16) & 0xff
983
- o[59] = (x14 >>> 24) & 0xff
984
-
985
- o[60] = (x15 >>> 0) & 0xff
986
- o[61] = (x15 >>> 8) & 0xff
987
- o[62] = (x15 >>> 16) & 0xff
988
- o[63] = (x15 >>> 24) & 0xff
989
- }
990
-
991
- function core_hsalsa20(o, p, k, c) {
992
- var j0 =
993
- (c[0] & 0xff) |
994
- ((c[1] & 0xff) << 8) |
995
- ((c[2] & 0xff) << 16) |
996
- ((c[3] & 0xff) << 24),
997
- j1 =
998
- (k[0] & 0xff) |
999
- ((k[1] & 0xff) << 8) |
1000
- ((k[2] & 0xff) << 16) |
1001
- ((k[3] & 0xff) << 24),
1002
- j2 =
1003
- (k[4] & 0xff) |
1004
- ((k[5] & 0xff) << 8) |
1005
- ((k[6] & 0xff) << 16) |
1006
- ((k[7] & 0xff) << 24),
1007
- j3 =
1008
- (k[8] & 0xff) |
1009
- ((k[9] & 0xff) << 8) |
1010
- ((k[10] & 0xff) << 16) |
1011
- ((k[11] & 0xff) << 24),
1012
- j4 =
1013
- (k[12] & 0xff) |
1014
- ((k[13] & 0xff) << 8) |
1015
- ((k[14] & 0xff) << 16) |
1016
- ((k[15] & 0xff) << 24),
1017
- j5 =
1018
- (c[4] & 0xff) |
1019
- ((c[5] & 0xff) << 8) |
1020
- ((c[6] & 0xff) << 16) |
1021
- ((c[7] & 0xff) << 24),
1022
- j6 =
1023
- (p[0] & 0xff) |
1024
- ((p[1] & 0xff) << 8) |
1025
- ((p[2] & 0xff) << 16) |
1026
- ((p[3] & 0xff) << 24),
1027
- j7 =
1028
- (p[4] & 0xff) |
1029
- ((p[5] & 0xff) << 8) |
1030
- ((p[6] & 0xff) << 16) |
1031
- ((p[7] & 0xff) << 24),
1032
- j8 =
1033
- (p[8] & 0xff) |
1034
- ((p[9] & 0xff) << 8) |
1035
- ((p[10] & 0xff) << 16) |
1036
- ((p[11] & 0xff) << 24),
1037
- j9 =
1038
- (p[12] & 0xff) |
1039
- ((p[13] & 0xff) << 8) |
1040
- ((p[14] & 0xff) << 16) |
1041
- ((p[15] & 0xff) << 24),
1042
- j10 =
1043
- (c[8] & 0xff) |
1044
- ((c[9] & 0xff) << 8) |
1045
- ((c[10] & 0xff) << 16) |
1046
- ((c[11] & 0xff) << 24),
1047
- j11 =
1048
- (k[16] & 0xff) |
1049
- ((k[17] & 0xff) << 8) |
1050
- ((k[18] & 0xff) << 16) |
1051
- ((k[19] & 0xff) << 24),
1052
- j12 =
1053
- (k[20] & 0xff) |
1054
- ((k[21] & 0xff) << 8) |
1055
- ((k[22] & 0xff) << 16) |
1056
- ((k[23] & 0xff) << 24),
1057
- j13 =
1058
- (k[24] & 0xff) |
1059
- ((k[25] & 0xff) << 8) |
1060
- ((k[26] & 0xff) << 16) |
1061
- ((k[27] & 0xff) << 24),
1062
- j14 =
1063
- (k[28] & 0xff) |
1064
- ((k[29] & 0xff) << 8) |
1065
- ((k[30] & 0xff) << 16) |
1066
- ((k[31] & 0xff) << 24),
1067
- j15 =
1068
- (c[12] & 0xff) |
1069
- ((c[13] & 0xff) << 8) |
1070
- ((c[14] & 0xff) << 16) |
1071
- ((c[15] & 0xff) << 24)
1072
-
1073
- var x0 = j0,
1074
- x1 = j1,
1075
- x2 = j2,
1076
- x3 = j3,
1077
- x4 = j4,
1078
- x5 = j5,
1079
- x6 = j6,
1080
- x7 = j7,
1081
- x8 = j8,
1082
- x9 = j9,
1083
- x10 = j10,
1084
- x11 = j11,
1085
- x12 = j12,
1086
- x13 = j13,
1087
- x14 = j14,
1088
- x15 = j15,
1089
- u
1090
-
1091
- for (var i = 0; i < 20; i += 2) {
1092
- u = (x0 + x12) | 0
1093
- x4 ^= (u << 7) | (u >>> (32 - 7))
1094
- u = (x4 + x0) | 0
1095
- x8 ^= (u << 9) | (u >>> (32 - 9))
1096
- u = (x8 + x4) | 0
1097
- x12 ^= (u << 13) | (u >>> (32 - 13))
1098
- u = (x12 + x8) | 0
1099
- x0 ^= (u << 18) | (u >>> (32 - 18))
1100
-
1101
- u = (x5 + x1) | 0
1102
- x9 ^= (u << 7) | (u >>> (32 - 7))
1103
- u = (x9 + x5) | 0
1104
- x13 ^= (u << 9) | (u >>> (32 - 9))
1105
- u = (x13 + x9) | 0
1106
- x1 ^= (u << 13) | (u >>> (32 - 13))
1107
- u = (x1 + x13) | 0
1108
- x5 ^= (u << 18) | (u >>> (32 - 18))
1109
-
1110
- u = (x10 + x6) | 0
1111
- x14 ^= (u << 7) | (u >>> (32 - 7))
1112
- u = (x14 + x10) | 0
1113
- x2 ^= (u << 9) | (u >>> (32 - 9))
1114
- u = (x2 + x14) | 0
1115
- x6 ^= (u << 13) | (u >>> (32 - 13))
1116
- u = (x6 + x2) | 0
1117
- x10 ^= (u << 18) | (u >>> (32 - 18))
1118
-
1119
- u = (x15 + x11) | 0
1120
- x3 ^= (u << 7) | (u >>> (32 - 7))
1121
- u = (x3 + x15) | 0
1122
- x7 ^= (u << 9) | (u >>> (32 - 9))
1123
- u = (x7 + x3) | 0
1124
- x11 ^= (u << 13) | (u >>> (32 - 13))
1125
- u = (x11 + x7) | 0
1126
- x15 ^= (u << 18) | (u >>> (32 - 18))
1127
-
1128
- u = (x0 + x3) | 0
1129
- x1 ^= (u << 7) | (u >>> (32 - 7))
1130
- u = (x1 + x0) | 0
1131
- x2 ^= (u << 9) | (u >>> (32 - 9))
1132
- u = (x2 + x1) | 0
1133
- x3 ^= (u << 13) | (u >>> (32 - 13))
1134
- u = (x3 + x2) | 0
1135
- x0 ^= (u << 18) | (u >>> (32 - 18))
1136
-
1137
- u = (x5 + x4) | 0
1138
- x6 ^= (u << 7) | (u >>> (32 - 7))
1139
- u = (x6 + x5) | 0
1140
- x7 ^= (u << 9) | (u >>> (32 - 9))
1141
- u = (x7 + x6) | 0
1142
- x4 ^= (u << 13) | (u >>> (32 - 13))
1143
- u = (x4 + x7) | 0
1144
- x5 ^= (u << 18) | (u >>> (32 - 18))
1145
-
1146
- u = (x10 + x9) | 0
1147
- x11 ^= (u << 7) | (u >>> (32 - 7))
1148
- u = (x11 + x10) | 0
1149
- x8 ^= (u << 9) | (u >>> (32 - 9))
1150
- u = (x8 + x11) | 0
1151
- x9 ^= (u << 13) | (u >>> (32 - 13))
1152
- u = (x9 + x8) | 0
1153
- x10 ^= (u << 18) | (u >>> (32 - 18))
1154
-
1155
- u = (x15 + x14) | 0
1156
- x12 ^= (u << 7) | (u >>> (32 - 7))
1157
- u = (x12 + x15) | 0
1158
- x13 ^= (u << 9) | (u >>> (32 - 9))
1159
- u = (x13 + x12) | 0
1160
- x14 ^= (u << 13) | (u >>> (32 - 13))
1161
- u = (x14 + x13) | 0
1162
- x15 ^= (u << 18) | (u >>> (32 - 18))
1163
- }
1164
-
1165
- o[0] = (x0 >>> 0) & 0xff
1166
- o[1] = (x0 >>> 8) & 0xff
1167
- o[2] = (x0 >>> 16) & 0xff
1168
- o[3] = (x0 >>> 24) & 0xff
1169
-
1170
- o[4] = (x5 >>> 0) & 0xff
1171
- o[5] = (x5 >>> 8) & 0xff
1172
- o[6] = (x5 >>> 16) & 0xff
1173
- o[7] = (x5 >>> 24) & 0xff
1174
-
1175
- o[8] = (x10 >>> 0) & 0xff
1176
- o[9] = (x10 >>> 8) & 0xff
1177
- o[10] = (x10 >>> 16) & 0xff
1178
- o[11] = (x10 >>> 24) & 0xff
1179
-
1180
- o[12] = (x15 >>> 0) & 0xff
1181
- o[13] = (x15 >>> 8) & 0xff
1182
- o[14] = (x15 >>> 16) & 0xff
1183
- o[15] = (x15 >>> 24) & 0xff
1184
-
1185
- o[16] = (x6 >>> 0) & 0xff
1186
- o[17] = (x6 >>> 8) & 0xff
1187
- o[18] = (x6 >>> 16) & 0xff
1188
- o[19] = (x6 >>> 24) & 0xff
1189
-
1190
- o[20] = (x7 >>> 0) & 0xff
1191
- o[21] = (x7 >>> 8) & 0xff
1192
- o[22] = (x7 >>> 16) & 0xff
1193
- o[23] = (x7 >>> 24) & 0xff
1194
-
1195
- o[24] = (x8 >>> 0) & 0xff
1196
- o[25] = (x8 >>> 8) & 0xff
1197
- o[26] = (x8 >>> 16) & 0xff
1198
- o[27] = (x8 >>> 24) & 0xff
1199
-
1200
- o[28] = (x9 >>> 0) & 0xff
1201
- o[29] = (x9 >>> 8) & 0xff
1202
- o[30] = (x9 >>> 16) & 0xff
1203
- o[31] = (x9 >>> 24) & 0xff
1204
- }
1205
-
1206
- function crypto_core_salsa20(out, inp, k, c) {
1207
- core_salsa20(out, inp, k, c)
1208
- }
1209
-
1210
- function crypto_core_hsalsa20(out, inp, k, c) {
1211
- core_hsalsa20(out, inp, k, c)
1212
- }
1213
-
1214
- var sigma = new Uint8Array([
1215
- 101,
1216
- 120,
1217
- 112,
1218
- 97,
1219
- 110,
1220
- 100,
1221
- 32,
1222
- 51,
1223
- 50,
1224
- 45,
1225
- 98,
1226
- 121,
1227
- 116,
1228
- 101,
1229
- 32,
1230
- 107,
1231
- ])
1232
- // "expand 32-byte k"
1233
-
1234
- function crypto_stream_salsa20_xor(c, cpos, m, mpos, b, n, k) {
1235
- var z = new Uint8Array(16),
1236
- x = new Uint8Array(64)
1237
- var u, i
1238
- for (i = 0; i < 16; i++) z[i] = 0
1239
- for (i = 0; i < 8; i++) z[i] = n[i]
1240
- while (b >= 64) {
1241
- crypto_core_salsa20(x, z, k, sigma)
1242
- for (i = 0; i < 64; i++) c[cpos + i] = m[mpos + i] ^ x[i]
1243
- u = 1
1244
- for (i = 8; i < 16; i++) {
1245
- u = (u + (z[i] & 0xff)) | 0
1246
- z[i] = u & 0xff
1247
- u >>>= 8
1248
- }
1249
- b -= 64
1250
- cpos += 64
1251
- mpos += 64
1252
- }
1253
- if (b > 0) {
1254
- crypto_core_salsa20(x, z, k, sigma)
1255
- for (i = 0; i < b; i++) c[cpos + i] = m[mpos + i] ^ x[i]
1256
- }
1257
- return 0
1258
- }
1259
-
1260
- function crypto_stream_salsa20(c, cpos, b, n, k) {
1261
- var z = new Uint8Array(16),
1262
- x = new Uint8Array(64)
1263
- var u, i
1264
- for (i = 0; i < 16; i++) z[i] = 0
1265
- for (i = 0; i < 8; i++) z[i] = n[i]
1266
- while (b >= 64) {
1267
- crypto_core_salsa20(x, z, k, sigma)
1268
- for (i = 0; i < 64; i++) c[cpos + i] = x[i]
1269
- u = 1
1270
- for (i = 8; i < 16; i++) {
1271
- u = (u + (z[i] & 0xff)) | 0
1272
- z[i] = u & 0xff
1273
- u >>>= 8
1274
- }
1275
- b -= 64
1276
- cpos += 64
1277
- }
1278
- if (b > 0) {
1279
- crypto_core_salsa20(x, z, k, sigma)
1280
- for (i = 0; i < b; i++) c[cpos + i] = x[i]
1281
- }
1282
- return 0
1283
- }
1284
-
1285
- function crypto_stream(c, cpos, d, n, k) {
1286
- var s = new Uint8Array(32)
1287
- crypto_core_hsalsa20(s, n, k, sigma)
1288
- var sn = new Uint8Array(8)
1289
- for (var i = 0; i < 8; i++) sn[i] = n[i + 16]
1290
- return crypto_stream_salsa20(c, cpos, d, sn, s)
1291
- }
1292
-
1293
- function crypto_stream_xor(c, cpos, m, mpos, d, n, k) {
1294
- var s = new Uint8Array(32)
1295
- crypto_core_hsalsa20(s, n, k, sigma)
1296
- var sn = new Uint8Array(8)
1297
- for (var i = 0; i < 8; i++) sn[i] = n[i + 16]
1298
- return crypto_stream_salsa20_xor(c, cpos, m, mpos, d, sn, s)
1299
- }
1300
-
1301
- /*
1302
- * Port of Andrew Moon's Poly1305-donna-16. Public domain.
1303
- * https://github.com/floodyberry/poly1305-donna
1304
- */
1305
-
1306
- var poly1305 = function (key) {
1307
- this.buffer = new Uint8Array(16)
1308
- this.r = new Uint16Array(10)
1309
- this.h = new Uint16Array(10)
1310
- this.pad = new Uint16Array(8)
1311
- this.leftover = 0
1312
- this.fin = 0
1313
-
1314
- var t0, t1, t2, t3, t4, t5, t6, t7
1315
-
1316
- t0 = (key[0] & 0xff) | ((key[1] & 0xff) << 8)
1317
- this.r[0] = t0 & 0x1fff
1318
- t1 = (key[2] & 0xff) | ((key[3] & 0xff) << 8)
1319
- this.r[1] = ((t0 >>> 13) | (t1 << 3)) & 0x1fff
1320
- t2 = (key[4] & 0xff) | ((key[5] & 0xff) << 8)
1321
- this.r[2] = ((t1 >>> 10) | (t2 << 6)) & 0x1f03
1322
- t3 = (key[6] & 0xff) | ((key[7] & 0xff) << 8)
1323
- this.r[3] = ((t2 >>> 7) | (t3 << 9)) & 0x1fff
1324
- t4 = (key[8] & 0xff) | ((key[9] & 0xff) << 8)
1325
- this.r[4] = ((t3 >>> 4) | (t4 << 12)) & 0x00ff
1326
- this.r[5] = (t4 >>> 1) & 0x1ffe
1327
- t5 = (key[10] & 0xff) | ((key[11] & 0xff) << 8)
1328
- this.r[6] = ((t4 >>> 14) | (t5 << 2)) & 0x1fff
1329
- t6 = (key[12] & 0xff) | ((key[13] & 0xff) << 8)
1330
- this.r[7] = ((t5 >>> 11) | (t6 << 5)) & 0x1f81
1331
- t7 = (key[14] & 0xff) | ((key[15] & 0xff) << 8)
1332
- this.r[8] = ((t6 >>> 8) | (t7 << 8)) & 0x1fff
1333
- this.r[9] = (t7 >>> 5) & 0x007f
1334
-
1335
- this.pad[0] = (key[16] & 0xff) | ((key[17] & 0xff) << 8)
1336
- this.pad[1] = (key[18] & 0xff) | ((key[19] & 0xff) << 8)
1337
- this.pad[2] = (key[20] & 0xff) | ((key[21] & 0xff) << 8)
1338
- this.pad[3] = (key[22] & 0xff) | ((key[23] & 0xff) << 8)
1339
- this.pad[4] = (key[24] & 0xff) | ((key[25] & 0xff) << 8)
1340
- this.pad[5] = (key[26] & 0xff) | ((key[27] & 0xff) << 8)
1341
- this.pad[6] = (key[28] & 0xff) | ((key[29] & 0xff) << 8)
1342
- this.pad[7] = (key[30] & 0xff) | ((key[31] & 0xff) << 8)
1343
- }
1344
-
1345
- poly1305.prototype.blocks = function (m, mpos, bytes) {
1346
- var hibit = this.fin ? 0 : 1 << 11
1347
- var t0, t1, t2, t3, t4, t5, t6, t7, c
1348
- var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9
1349
-
1350
- var h0 = this.h[0],
1351
- h1 = this.h[1],
1352
- h2 = this.h[2],
1353
- h3 = this.h[3],
1354
- h4 = this.h[4],
1355
- h5 = this.h[5],
1356
- h6 = this.h[6],
1357
- h7 = this.h[7],
1358
- h8 = this.h[8],
1359
- h9 = this.h[9]
1360
-
1361
- var r0 = this.r[0],
1362
- r1 = this.r[1],
1363
- r2 = this.r[2],
1364
- r3 = this.r[3],
1365
- r4 = this.r[4],
1366
- r5 = this.r[5],
1367
- r6 = this.r[6],
1368
- r7 = this.r[7],
1369
- r8 = this.r[8],
1370
- r9 = this.r[9]
1371
-
1372
- while (bytes >= 16) {
1373
- t0 = (m[mpos + 0] & 0xff) | ((m[mpos + 1] & 0xff) << 8)
1374
- h0 += t0 & 0x1fff
1375
- t1 = (m[mpos + 2] & 0xff) | ((m[mpos + 3] & 0xff) << 8)
1376
- h1 += ((t0 >>> 13) | (t1 << 3)) & 0x1fff
1377
- t2 = (m[mpos + 4] & 0xff) | ((m[mpos + 5] & 0xff) << 8)
1378
- h2 += ((t1 >>> 10) | (t2 << 6)) & 0x1fff
1379
- t3 = (m[mpos + 6] & 0xff) | ((m[mpos + 7] & 0xff) << 8)
1380
- h3 += ((t2 >>> 7) | (t3 << 9)) & 0x1fff
1381
- t4 = (m[mpos + 8] & 0xff) | ((m[mpos + 9] & 0xff) << 8)
1382
- h4 += ((t3 >>> 4) | (t4 << 12)) & 0x1fff
1383
- h5 += (t4 >>> 1) & 0x1fff
1384
- t5 = (m[mpos + 10] & 0xff) | ((m[mpos + 11] & 0xff) << 8)
1385
- h6 += ((t4 >>> 14) | (t5 << 2)) & 0x1fff
1386
- t6 = (m[mpos + 12] & 0xff) | ((m[mpos + 13] & 0xff) << 8)
1387
- h7 += ((t5 >>> 11) | (t6 << 5)) & 0x1fff
1388
- t7 = (m[mpos + 14] & 0xff) | ((m[mpos + 15] & 0xff) << 8)
1389
- h8 += ((t6 >>> 8) | (t7 << 8)) & 0x1fff
1390
- h9 += (t7 >>> 5) | hibit
1391
-
1392
- c = 0
1393
-
1394
- d0 = c
1395
- d0 += h0 * r0
1396
- d0 += h1 * (5 * r9)
1397
- d0 += h2 * (5 * r8)
1398
- d0 += h3 * (5 * r7)
1399
- d0 += h4 * (5 * r6)
1400
- c = d0 >>> 13
1401
- d0 &= 0x1fff
1402
- d0 += h5 * (5 * r5)
1403
- d0 += h6 * (5 * r4)
1404
- d0 += h7 * (5 * r3)
1405
- d0 += h8 * (5 * r2)
1406
- d0 += h9 * (5 * r1)
1407
- c += d0 >>> 13
1408
- d0 &= 0x1fff
1409
-
1410
- d1 = c
1411
- d1 += h0 * r1
1412
- d1 += h1 * r0
1413
- d1 += h2 * (5 * r9)
1414
- d1 += h3 * (5 * r8)
1415
- d1 += h4 * (5 * r7)
1416
- c = d1 >>> 13
1417
- d1 &= 0x1fff
1418
- d1 += h5 * (5 * r6)
1419
- d1 += h6 * (5 * r5)
1420
- d1 += h7 * (5 * r4)
1421
- d1 += h8 * (5 * r3)
1422
- d1 += h9 * (5 * r2)
1423
- c += d1 >>> 13
1424
- d1 &= 0x1fff
1425
-
1426
- d2 = c
1427
- d2 += h0 * r2
1428
- d2 += h1 * r1
1429
- d2 += h2 * r0
1430
- d2 += h3 * (5 * r9)
1431
- d2 += h4 * (5 * r8)
1432
- c = d2 >>> 13
1433
- d2 &= 0x1fff
1434
- d2 += h5 * (5 * r7)
1435
- d2 += h6 * (5 * r6)
1436
- d2 += h7 * (5 * r5)
1437
- d2 += h8 * (5 * r4)
1438
- d2 += h9 * (5 * r3)
1439
- c += d2 >>> 13
1440
- d2 &= 0x1fff
1441
-
1442
- d3 = c
1443
- d3 += h0 * r3
1444
- d3 += h1 * r2
1445
- d3 += h2 * r1
1446
- d3 += h3 * r0
1447
- d3 += h4 * (5 * r9)
1448
- c = d3 >>> 13
1449
- d3 &= 0x1fff
1450
- d3 += h5 * (5 * r8)
1451
- d3 += h6 * (5 * r7)
1452
- d3 += h7 * (5 * r6)
1453
- d3 += h8 * (5 * r5)
1454
- d3 += h9 * (5 * r4)
1455
- c += d3 >>> 13
1456
- d3 &= 0x1fff
1457
-
1458
- d4 = c
1459
- d4 += h0 * r4
1460
- d4 += h1 * r3
1461
- d4 += h2 * r2
1462
- d4 += h3 * r1
1463
- d4 += h4 * r0
1464
- c = d4 >>> 13
1465
- d4 &= 0x1fff
1466
- d4 += h5 * (5 * r9)
1467
- d4 += h6 * (5 * r8)
1468
- d4 += h7 * (5 * r7)
1469
- d4 += h8 * (5 * r6)
1470
- d4 += h9 * (5 * r5)
1471
- c += d4 >>> 13
1472
- d4 &= 0x1fff
1473
-
1474
- d5 = c
1475
- d5 += h0 * r5
1476
- d5 += h1 * r4
1477
- d5 += h2 * r3
1478
- d5 += h3 * r2
1479
- d5 += h4 * r1
1480
- c = d5 >>> 13
1481
- d5 &= 0x1fff
1482
- d5 += h5 * r0
1483
- d5 += h6 * (5 * r9)
1484
- d5 += h7 * (5 * r8)
1485
- d5 += h8 * (5 * r7)
1486
- d5 += h9 * (5 * r6)
1487
- c += d5 >>> 13
1488
- d5 &= 0x1fff
1489
-
1490
- d6 = c
1491
- d6 += h0 * r6
1492
- d6 += h1 * r5
1493
- d6 += h2 * r4
1494
- d6 += h3 * r3
1495
- d6 += h4 * r2
1496
- c = d6 >>> 13
1497
- d6 &= 0x1fff
1498
- d6 += h5 * r1
1499
- d6 += h6 * r0
1500
- d6 += h7 * (5 * r9)
1501
- d6 += h8 * (5 * r8)
1502
- d6 += h9 * (5 * r7)
1503
- c += d6 >>> 13
1504
- d6 &= 0x1fff
1505
-
1506
- d7 = c
1507
- d7 += h0 * r7
1508
- d7 += h1 * r6
1509
- d7 += h2 * r5
1510
- d7 += h3 * r4
1511
- d7 += h4 * r3
1512
- c = d7 >>> 13
1513
- d7 &= 0x1fff
1514
- d7 += h5 * r2
1515
- d7 += h6 * r1
1516
- d7 += h7 * r0
1517
- d7 += h8 * (5 * r9)
1518
- d7 += h9 * (5 * r8)
1519
- c += d7 >>> 13
1520
- d7 &= 0x1fff
1521
-
1522
- d8 = c
1523
- d8 += h0 * r8
1524
- d8 += h1 * r7
1525
- d8 += h2 * r6
1526
- d8 += h3 * r5
1527
- d8 += h4 * r4
1528
- c = d8 >>> 13
1529
- d8 &= 0x1fff
1530
- d8 += h5 * r3
1531
- d8 += h6 * r2
1532
- d8 += h7 * r1
1533
- d8 += h8 * r0
1534
- d8 += h9 * (5 * r9)
1535
- c += d8 >>> 13
1536
- d8 &= 0x1fff
1537
-
1538
- d9 = c
1539
- d9 += h0 * r9
1540
- d9 += h1 * r8
1541
- d9 += h2 * r7
1542
- d9 += h3 * r6
1543
- d9 += h4 * r5
1544
- c = d9 >>> 13
1545
- d9 &= 0x1fff
1546
- d9 += h5 * r4
1547
- d9 += h6 * r3
1548
- d9 += h7 * r2
1549
- d9 += h8 * r1
1550
- d9 += h9 * r0
1551
- c += d9 >>> 13
1552
- d9 &= 0x1fff
1553
-
1554
- c = ((c << 2) + c) | 0
1555
- c = (c + d0) | 0
1556
- d0 = c & 0x1fff
1557
- c = c >>> 13
1558
- d1 += c
1559
-
1560
- h0 = d0
1561
- h1 = d1
1562
- h2 = d2
1563
- h3 = d3
1564
- h4 = d4
1565
- h5 = d5
1566
- h6 = d6
1567
- h7 = d7
1568
- h8 = d8
1569
- h9 = d9
1570
-
1571
- mpos += 16
1572
- bytes -= 16
1573
- }
1574
- this.h[0] = h0
1575
- this.h[1] = h1
1576
- this.h[2] = h2
1577
- this.h[3] = h3
1578
- this.h[4] = h4
1579
- this.h[5] = h5
1580
- this.h[6] = h6
1581
- this.h[7] = h7
1582
- this.h[8] = h8
1583
- this.h[9] = h9
1584
- }
1585
-
1586
- poly1305.prototype.finish = function (mac, macpos) {
1587
- var g = new Uint16Array(10)
1588
- var c, mask, f, i
1589
-
1590
- if (this.leftover) {
1591
- i = this.leftover
1592
- this.buffer[i++] = 1
1593
- for (; i < 16; i++) this.buffer[i] = 0
1594
- this.fin = 1
1595
- this.blocks(this.buffer, 0, 16)
1596
- }
1597
-
1598
- c = this.h[1] >>> 13
1599
- this.h[1] &= 0x1fff
1600
- for (i = 2; i < 10; i++) {
1601
- this.h[i] += c
1602
- c = this.h[i] >>> 13
1603
- this.h[i] &= 0x1fff
1604
- }
1605
- this.h[0] += c * 5
1606
- c = this.h[0] >>> 13
1607
- this.h[0] &= 0x1fff
1608
- this.h[1] += c
1609
- c = this.h[1] >>> 13
1610
- this.h[1] &= 0x1fff
1611
- this.h[2] += c
1612
-
1613
- g[0] = this.h[0] + 5
1614
- c = g[0] >>> 13
1615
- g[0] &= 0x1fff
1616
- for (i = 1; i < 10; i++) {
1617
- g[i] = this.h[i] + c
1618
- c = g[i] >>> 13
1619
- g[i] &= 0x1fff
1620
- }
1621
- g[9] -= 1 << 13
1622
-
1623
- mask = (c ^ 1) - 1
1624
- for (i = 0; i < 10; i++) g[i] &= mask
1625
- mask = ~mask
1626
- for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i]
1627
-
1628
- this.h[0] = (this.h[0] | (this.h[1] << 13)) & 0xffff
1629
- this.h[1] = ((this.h[1] >>> 3) | (this.h[2] << 10)) & 0xffff
1630
- this.h[2] = ((this.h[2] >>> 6) | (this.h[3] << 7)) & 0xffff
1631
- this.h[3] = ((this.h[3] >>> 9) | (this.h[4] << 4)) & 0xffff
1632
- this.h[4] =
1633
- ((this.h[4] >>> 12) | (this.h[5] << 1) | (this.h[6] << 14)) & 0xffff
1634
- this.h[5] = ((this.h[6] >>> 2) | (this.h[7] << 11)) & 0xffff
1635
- this.h[6] = ((this.h[7] >>> 5) | (this.h[8] << 8)) & 0xffff
1636
- this.h[7] = ((this.h[8] >>> 8) | (this.h[9] << 5)) & 0xffff
1637
-
1638
- f = this.h[0] + this.pad[0]
1639
- this.h[0] = f & 0xffff
1640
- for (i = 1; i < 8; i++) {
1641
- f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0
1642
- this.h[i] = f & 0xffff
1643
- }
1644
-
1645
- mac[macpos + 0] = (this.h[0] >>> 0) & 0xff
1646
- mac[macpos + 1] = (this.h[0] >>> 8) & 0xff
1647
- mac[macpos + 2] = (this.h[1] >>> 0) & 0xff
1648
- mac[macpos + 3] = (this.h[1] >>> 8) & 0xff
1649
- mac[macpos + 4] = (this.h[2] >>> 0) & 0xff
1650
- mac[macpos + 5] = (this.h[2] >>> 8) & 0xff
1651
- mac[macpos + 6] = (this.h[3] >>> 0) & 0xff
1652
- mac[macpos + 7] = (this.h[3] >>> 8) & 0xff
1653
- mac[macpos + 8] = (this.h[4] >>> 0) & 0xff
1654
- mac[macpos + 9] = (this.h[4] >>> 8) & 0xff
1655
- mac[macpos + 10] = (this.h[5] >>> 0) & 0xff
1656
- mac[macpos + 11] = (this.h[5] >>> 8) & 0xff
1657
- mac[macpos + 12] = (this.h[6] >>> 0) & 0xff
1658
- mac[macpos + 13] = (this.h[6] >>> 8) & 0xff
1659
- mac[macpos + 14] = (this.h[7] >>> 0) & 0xff
1660
- mac[macpos + 15] = (this.h[7] >>> 8) & 0xff
1661
- }
1662
-
1663
- poly1305.prototype.update = function (m, mpos, bytes) {
1664
- var i, want
1665
-
1666
- if (this.leftover) {
1667
- want = 16 - this.leftover
1668
- if (want > bytes) want = bytes
1669
- for (i = 0; i < want; i++)
1670
- this.buffer[this.leftover + i] = m[mpos + i]
1671
- bytes -= want
1672
- mpos += want
1673
- this.leftover += want
1674
- if (this.leftover < 16) return
1675
- this.blocks(this.buffer, 0, 16)
1676
- this.leftover = 0
1677
- }
1678
-
1679
- if (bytes >= 16) {
1680
- want = bytes - (bytes % 16)
1681
- this.blocks(m, mpos, want)
1682
- mpos += want
1683
- bytes -= want
1684
- }
1685
-
1686
- if (bytes) {
1687
- for (i = 0; i < bytes; i++)
1688
- this.buffer[this.leftover + i] = m[mpos + i]
1689
- this.leftover += bytes
1690
- }
1691
- }
1692
-
1693
- function crypto_onetimeauth(out, outpos, m, mpos, n, k) {
1694
- var s = new poly1305(k)
1695
- s.update(m, mpos, n)
1696
- s.finish(out, outpos)
1697
- return 0
1698
- }
1699
-
1700
- function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) {
1701
- var x = new Uint8Array(16)
1702
- crypto_onetimeauth(x, 0, m, mpos, n, k)
1703
- return crypto_verify_16(h, hpos, x, 0)
1704
- }
1705
-
1706
- function crypto_secretbox(c, m, d, n, k) {
1707
- var i
1708
- if (d < 32) return -1
1709
- crypto_stream_xor(c, 0, m, 0, d, n, k)
1710
- crypto_onetimeauth(c, 16, c, 32, d - 32, c)
1711
- for (i = 0; i < 16; i++) c[i] = 0
1712
- return 0
1713
- }
1714
-
1715
- function crypto_secretbox_open(m, c, d, n, k) {
1716
- var i
1717
- var x = new Uint8Array(32)
1718
- if (d < 32) return -1
1719
- crypto_stream(x, 0, 32, n, k)
1720
- if (crypto_onetimeauth_verify(c, 16, c, 32, d - 32, x) !== 0)
1721
- return -1
1722
- crypto_stream_xor(m, 0, c, 0, d, n, k)
1723
- for (i = 0; i < 32; i++) m[i] = 0
1724
- return 0
1725
- }
1726
-
1727
- function set25519(r, a) {
1728
- var i
1729
- for (i = 0; i < 16; i++) r[i] = a[i] | 0
1730
- }
1731
-
1732
- function car25519(o) {
1733
- var i,
1734
- v,
1735
- c = 1
1736
- for (i = 0; i < 16; i++) {
1737
- v = o[i] + c + 65535
1738
- c = Math.floor(v / 65536)
1739
- o[i] = v - c * 65536
1740
- }
1741
- o[0] += c - 1 + 37 * (c - 1)
1742
- }
1743
-
1744
- function sel25519(p, q, b) {
1745
- var t,
1746
- c = ~(b - 1)
1747
- for (var i = 0; i < 16; i++) {
1748
- t = c & (p[i] ^ q[i])
1749
- p[i] ^= t
1750
- q[i] ^= t
1751
- }
1752
- }
1753
-
1754
- function pack25519(o, n) {
1755
- var i, j, b
1756
- var m = gf(),
1757
- t = gf()
1758
- for (i = 0; i < 16; i++) t[i] = n[i]
1759
- car25519(t)
1760
- car25519(t)
1761
- car25519(t)
1762
- for (j = 0; j < 2; j++) {
1763
- m[0] = t[0] - 0xffed
1764
- for (i = 1; i < 15; i++) {
1765
- m[i] = t[i] - 0xffff - ((m[i - 1] >> 16) & 1)
1766
- m[i - 1] &= 0xffff
1767
- }
1768
- m[15] = t[15] - 0x7fff - ((m[14] >> 16) & 1)
1769
- b = (m[15] >> 16) & 1
1770
- m[14] &= 0xffff
1771
- sel25519(t, m, 1 - b)
1772
- }
1773
- for (i = 0; i < 16; i++) {
1774
- o[2 * i] = t[i] & 0xff
1775
- o[2 * i + 1] = t[i] >> 8
1776
- }
1777
- }
1778
-
1779
- function neq25519(a, b) {
1780
- var c = new Uint8Array(32),
1781
- d = new Uint8Array(32)
1782
- pack25519(c, a)
1783
- pack25519(d, b)
1784
- return crypto_verify_32(c, 0, d, 0)
1785
- }
1786
-
1787
- function par25519(a) {
1788
- var d = new Uint8Array(32)
1789
- pack25519(d, a)
1790
- return d[0] & 1
1791
- }
1792
-
1793
- function unpack25519(o, n) {
1794
- var i
1795
- for (i = 0; i < 16; i++) o[i] = n[2 * i] + (n[2 * i + 1] << 8)
1796
- o[15] &= 0x7fff
1797
- }
1798
-
1799
- function A(o, a, b) {
1800
- for (var i = 0; i < 16; i++) o[i] = a[i] + b[i]
1801
- }
1802
-
1803
- function Z(o, a, b) {
1804
- for (var i = 0; i < 16; i++) o[i] = a[i] - b[i]
1805
- }
1806
-
1807
- function M(o, a, b) {
1808
- var v,
1809
- c,
1810
- t0 = 0,
1811
- t1 = 0,
1812
- t2 = 0,
1813
- t3 = 0,
1814
- t4 = 0,
1815
- t5 = 0,
1816
- t6 = 0,
1817
- t7 = 0,
1818
- t8 = 0,
1819
- t9 = 0,
1820
- t10 = 0,
1821
- t11 = 0,
1822
- t12 = 0,
1823
- t13 = 0,
1824
- t14 = 0,
1825
- t15 = 0,
1826
- t16 = 0,
1827
- t17 = 0,
1828
- t18 = 0,
1829
- t19 = 0,
1830
- t20 = 0,
1831
- t21 = 0,
1832
- t22 = 0,
1833
- t23 = 0,
1834
- t24 = 0,
1835
- t25 = 0,
1836
- t26 = 0,
1837
- t27 = 0,
1838
- t28 = 0,
1839
- t29 = 0,
1840
- t30 = 0,
1841
- b0 = b[0],
1842
- b1 = b[1],
1843
- b2 = b[2],
1844
- b3 = b[3],
1845
- b4 = b[4],
1846
- b5 = b[5],
1847
- b6 = b[6],
1848
- b7 = b[7],
1849
- b8 = b[8],
1850
- b9 = b[9],
1851
- b10 = b[10],
1852
- b11 = b[11],
1853
- b12 = b[12],
1854
- b13 = b[13],
1855
- b14 = b[14],
1856
- b15 = b[15]
1857
-
1858
- v = a[0]
1859
- t0 += v * b0
1860
- t1 += v * b1
1861
- t2 += v * b2
1862
- t3 += v * b3
1863
- t4 += v * b4
1864
- t5 += v * b5
1865
- t6 += v * b6
1866
- t7 += v * b7
1867
- t8 += v * b8
1868
- t9 += v * b9
1869
- t10 += v * b10
1870
- t11 += v * b11
1871
- t12 += v * b12
1872
- t13 += v * b13
1873
- t14 += v * b14
1874
- t15 += v * b15
1875
- v = a[1]
1876
- t1 += v * b0
1877
- t2 += v * b1
1878
- t3 += v * b2
1879
- t4 += v * b3
1880
- t5 += v * b4
1881
- t6 += v * b5
1882
- t7 += v * b6
1883
- t8 += v * b7
1884
- t9 += v * b8
1885
- t10 += v * b9
1886
- t11 += v * b10
1887
- t12 += v * b11
1888
- t13 += v * b12
1889
- t14 += v * b13
1890
- t15 += v * b14
1891
- t16 += v * b15
1892
- v = a[2]
1893
- t2 += v * b0
1894
- t3 += v * b1
1895
- t4 += v * b2
1896
- t5 += v * b3
1897
- t6 += v * b4
1898
- t7 += v * b5
1899
- t8 += v * b6
1900
- t9 += v * b7
1901
- t10 += v * b8
1902
- t11 += v * b9
1903
- t12 += v * b10
1904
- t13 += v * b11
1905
- t14 += v * b12
1906
- t15 += v * b13
1907
- t16 += v * b14
1908
- t17 += v * b15
1909
- v = a[3]
1910
- t3 += v * b0
1911
- t4 += v * b1
1912
- t5 += v * b2
1913
- t6 += v * b3
1914
- t7 += v * b4
1915
- t8 += v * b5
1916
- t9 += v * b6
1917
- t10 += v * b7
1918
- t11 += v * b8
1919
- t12 += v * b9
1920
- t13 += v * b10
1921
- t14 += v * b11
1922
- t15 += v * b12
1923
- t16 += v * b13
1924
- t17 += v * b14
1925
- t18 += v * b15
1926
- v = a[4]
1927
- t4 += v * b0
1928
- t5 += v * b1
1929
- t6 += v * b2
1930
- t7 += v * b3
1931
- t8 += v * b4
1932
- t9 += v * b5
1933
- t10 += v * b6
1934
- t11 += v * b7
1935
- t12 += v * b8
1936
- t13 += v * b9
1937
- t14 += v * b10
1938
- t15 += v * b11
1939
- t16 += v * b12
1940
- t17 += v * b13
1941
- t18 += v * b14
1942
- t19 += v * b15
1943
- v = a[5]
1944
- t5 += v * b0
1945
- t6 += v * b1
1946
- t7 += v * b2
1947
- t8 += v * b3
1948
- t9 += v * b4
1949
- t10 += v * b5
1950
- t11 += v * b6
1951
- t12 += v * b7
1952
- t13 += v * b8
1953
- t14 += v * b9
1954
- t15 += v * b10
1955
- t16 += v * b11
1956
- t17 += v * b12
1957
- t18 += v * b13
1958
- t19 += v * b14
1959
- t20 += v * b15
1960
- v = a[6]
1961
- t6 += v * b0
1962
- t7 += v * b1
1963
- t8 += v * b2
1964
- t9 += v * b3
1965
- t10 += v * b4
1966
- t11 += v * b5
1967
- t12 += v * b6
1968
- t13 += v * b7
1969
- t14 += v * b8
1970
- t15 += v * b9
1971
- t16 += v * b10
1972
- t17 += v * b11
1973
- t18 += v * b12
1974
- t19 += v * b13
1975
- t20 += v * b14
1976
- t21 += v * b15
1977
- v = a[7]
1978
- t7 += v * b0
1979
- t8 += v * b1
1980
- t9 += v * b2
1981
- t10 += v * b3
1982
- t11 += v * b4
1983
- t12 += v * b5
1984
- t13 += v * b6
1985
- t14 += v * b7
1986
- t15 += v * b8
1987
- t16 += v * b9
1988
- t17 += v * b10
1989
- t18 += v * b11
1990
- t19 += v * b12
1991
- t20 += v * b13
1992
- t21 += v * b14
1993
- t22 += v * b15
1994
- v = a[8]
1995
- t8 += v * b0
1996
- t9 += v * b1
1997
- t10 += v * b2
1998
- t11 += v * b3
1999
- t12 += v * b4
2000
- t13 += v * b5
2001
- t14 += v * b6
2002
- t15 += v * b7
2003
- t16 += v * b8
2004
- t17 += v * b9
2005
- t18 += v * b10
2006
- t19 += v * b11
2007
- t20 += v * b12
2008
- t21 += v * b13
2009
- t22 += v * b14
2010
- t23 += v * b15
2011
- v = a[9]
2012
- t9 += v * b0
2013
- t10 += v * b1
2014
- t11 += v * b2
2015
- t12 += v * b3
2016
- t13 += v * b4
2017
- t14 += v * b5
2018
- t15 += v * b6
2019
- t16 += v * b7
2020
- t17 += v * b8
2021
- t18 += v * b9
2022
- t19 += v * b10
2023
- t20 += v * b11
2024
- t21 += v * b12
2025
- t22 += v * b13
2026
- t23 += v * b14
2027
- t24 += v * b15
2028
- v = a[10]
2029
- t10 += v * b0
2030
- t11 += v * b1
2031
- t12 += v * b2
2032
- t13 += v * b3
2033
- t14 += v * b4
2034
- t15 += v * b5
2035
- t16 += v * b6
2036
- t17 += v * b7
2037
- t18 += v * b8
2038
- t19 += v * b9
2039
- t20 += v * b10
2040
- t21 += v * b11
2041
- t22 += v * b12
2042
- t23 += v * b13
2043
- t24 += v * b14
2044
- t25 += v * b15
2045
- v = a[11]
2046
- t11 += v * b0
2047
- t12 += v * b1
2048
- t13 += v * b2
2049
- t14 += v * b3
2050
- t15 += v * b4
2051
- t16 += v * b5
2052
- t17 += v * b6
2053
- t18 += v * b7
2054
- t19 += v * b8
2055
- t20 += v * b9
2056
- t21 += v * b10
2057
- t22 += v * b11
2058
- t23 += v * b12
2059
- t24 += v * b13
2060
- t25 += v * b14
2061
- t26 += v * b15
2062
- v = a[12]
2063
- t12 += v * b0
2064
- t13 += v * b1
2065
- t14 += v * b2
2066
- t15 += v * b3
2067
- t16 += v * b4
2068
- t17 += v * b5
2069
- t18 += v * b6
2070
- t19 += v * b7
2071
- t20 += v * b8
2072
- t21 += v * b9
2073
- t22 += v * b10
2074
- t23 += v * b11
2075
- t24 += v * b12
2076
- t25 += v * b13
2077
- t26 += v * b14
2078
- t27 += v * b15
2079
- v = a[13]
2080
- t13 += v * b0
2081
- t14 += v * b1
2082
- t15 += v * b2
2083
- t16 += v * b3
2084
- t17 += v * b4
2085
- t18 += v * b5
2086
- t19 += v * b6
2087
- t20 += v * b7
2088
- t21 += v * b8
2089
- t22 += v * b9
2090
- t23 += v * b10
2091
- t24 += v * b11
2092
- t25 += v * b12
2093
- t26 += v * b13
2094
- t27 += v * b14
2095
- t28 += v * b15
2096
- v = a[14]
2097
- t14 += v * b0
2098
- t15 += v * b1
2099
- t16 += v * b2
2100
- t17 += v * b3
2101
- t18 += v * b4
2102
- t19 += v * b5
2103
- t20 += v * b6
2104
- t21 += v * b7
2105
- t22 += v * b8
2106
- t23 += v * b9
2107
- t24 += v * b10
2108
- t25 += v * b11
2109
- t26 += v * b12
2110
- t27 += v * b13
2111
- t28 += v * b14
2112
- t29 += v * b15
2113
- v = a[15]
2114
- t15 += v * b0
2115
- t16 += v * b1
2116
- t17 += v * b2
2117
- t18 += v * b3
2118
- t19 += v * b4
2119
- t20 += v * b5
2120
- t21 += v * b6
2121
- t22 += v * b7
2122
- t23 += v * b8
2123
- t24 += v * b9
2124
- t25 += v * b10
2125
- t26 += v * b11
2126
- t27 += v * b12
2127
- t28 += v * b13
2128
- t29 += v * b14
2129
- t30 += v * b15
2130
-
2131
- t0 += 38 * t16
2132
- t1 += 38 * t17
2133
- t2 += 38 * t18
2134
- t3 += 38 * t19
2135
- t4 += 38 * t20
2136
- t5 += 38 * t21
2137
- t6 += 38 * t22
2138
- t7 += 38 * t23
2139
- t8 += 38 * t24
2140
- t9 += 38 * t25
2141
- t10 += 38 * t26
2142
- t11 += 38 * t27
2143
- t12 += 38 * t28
2144
- t13 += 38 * t29
2145
- t14 += 38 * t30
2146
- // t15 left as is
2147
-
2148
- // first car
2149
- c = 1
2150
- v = t0 + c + 65535
2151
- c = Math.floor(v / 65536)
2152
- t0 = v - c * 65536
2153
- v = t1 + c + 65535
2154
- c = Math.floor(v / 65536)
2155
- t1 = v - c * 65536
2156
- v = t2 + c + 65535
2157
- c = Math.floor(v / 65536)
2158
- t2 = v - c * 65536
2159
- v = t3 + c + 65535
2160
- c = Math.floor(v / 65536)
2161
- t3 = v - c * 65536
2162
- v = t4 + c + 65535
2163
- c = Math.floor(v / 65536)
2164
- t4 = v - c * 65536
2165
- v = t5 + c + 65535
2166
- c = Math.floor(v / 65536)
2167
- t5 = v - c * 65536
2168
- v = t6 + c + 65535
2169
- c = Math.floor(v / 65536)
2170
- t6 = v - c * 65536
2171
- v = t7 + c + 65535
2172
- c = Math.floor(v / 65536)
2173
- t7 = v - c * 65536
2174
- v = t8 + c + 65535
2175
- c = Math.floor(v / 65536)
2176
- t8 = v - c * 65536
2177
- v = t9 + c + 65535
2178
- c = Math.floor(v / 65536)
2179
- t9 = v - c * 65536
2180
- v = t10 + c + 65535
2181
- c = Math.floor(v / 65536)
2182
- t10 = v - c * 65536
2183
- v = t11 + c + 65535
2184
- c = Math.floor(v / 65536)
2185
- t11 = v - c * 65536
2186
- v = t12 + c + 65535
2187
- c = Math.floor(v / 65536)
2188
- t12 = v - c * 65536
2189
- v = t13 + c + 65535
2190
- c = Math.floor(v / 65536)
2191
- t13 = v - c * 65536
2192
- v = t14 + c + 65535
2193
- c = Math.floor(v / 65536)
2194
- t14 = v - c * 65536
2195
- v = t15 + c + 65535
2196
- c = Math.floor(v / 65536)
2197
- t15 = v - c * 65536
2198
- t0 += c - 1 + 37 * (c - 1)
2199
-
2200
- // second car
2201
- c = 1
2202
- v = t0 + c + 65535
2203
- c = Math.floor(v / 65536)
2204
- t0 = v - c * 65536
2205
- v = t1 + c + 65535
2206
- c = Math.floor(v / 65536)
2207
- t1 = v - c * 65536
2208
- v = t2 + c + 65535
2209
- c = Math.floor(v / 65536)
2210
- t2 = v - c * 65536
2211
- v = t3 + c + 65535
2212
- c = Math.floor(v / 65536)
2213
- t3 = v - c * 65536
2214
- v = t4 + c + 65535
2215
- c = Math.floor(v / 65536)
2216
- t4 = v - c * 65536
2217
- v = t5 + c + 65535
2218
- c = Math.floor(v / 65536)
2219
- t5 = v - c * 65536
2220
- v = t6 + c + 65535
2221
- c = Math.floor(v / 65536)
2222
- t6 = v - c * 65536
2223
- v = t7 + c + 65535
2224
- c = Math.floor(v / 65536)
2225
- t7 = v - c * 65536
2226
- v = t8 + c + 65535
2227
- c = Math.floor(v / 65536)
2228
- t8 = v - c * 65536
2229
- v = t9 + c + 65535
2230
- c = Math.floor(v / 65536)
2231
- t9 = v - c * 65536
2232
- v = t10 + c + 65535
2233
- c = Math.floor(v / 65536)
2234
- t10 = v - c * 65536
2235
- v = t11 + c + 65535
2236
- c = Math.floor(v / 65536)
2237
- t11 = v - c * 65536
2238
- v = t12 + c + 65535
2239
- c = Math.floor(v / 65536)
2240
- t12 = v - c * 65536
2241
- v = t13 + c + 65535
2242
- c = Math.floor(v / 65536)
2243
- t13 = v - c * 65536
2244
- v = t14 + c + 65535
2245
- c = Math.floor(v / 65536)
2246
- t14 = v - c * 65536
2247
- v = t15 + c + 65535
2248
- c = Math.floor(v / 65536)
2249
- t15 = v - c * 65536
2250
- t0 += c - 1 + 37 * (c - 1)
2251
-
2252
- o[0] = t0
2253
- o[1] = t1
2254
- o[2] = t2
2255
- o[3] = t3
2256
- o[4] = t4
2257
- o[5] = t5
2258
- o[6] = t6
2259
- o[7] = t7
2260
- o[8] = t8
2261
- o[9] = t9
2262
- o[10] = t10
2263
- o[11] = t11
2264
- o[12] = t12
2265
- o[13] = t13
2266
- o[14] = t14
2267
- o[15] = t15
2268
- }
2269
-
2270
- function S(o, a) {
2271
- M(o, a, a)
2272
- }
2273
-
2274
- function inv25519(o, i) {
2275
- var c = gf()
2276
- var a
2277
- for (a = 0; a < 16; a++) c[a] = i[a]
2278
- for (a = 253; a >= 0; a--) {
2279
- S(c, c)
2280
- if (a !== 2 && a !== 4) M(c, c, i)
2281
- }
2282
- for (a = 0; a < 16; a++) o[a] = c[a]
2283
- }
2284
-
2285
- function pow2523(o, i) {
2286
- var c = gf()
2287
- var a
2288
- for (a = 0; a < 16; a++) c[a] = i[a]
2289
- for (a = 250; a >= 0; a--) {
2290
- S(c, c)
2291
- if (a !== 1) M(c, c, i)
2292
- }
2293
- for (a = 0; a < 16; a++) o[a] = c[a]
2294
- }
2295
-
2296
- function crypto_scalarmult(q, n, p) {
2297
- var z = new Uint8Array(32)
2298
- var x = new Float64Array(80),
2299
- r,
2300
- i
2301
- var a = gf(),
2302
- b = gf(),
2303
- c = gf(),
2304
- d = gf(),
2305
- e = gf(),
2306
- f = gf()
2307
- for (i = 0; i < 31; i++) z[i] = n[i]
2308
- z[31] = (n[31] & 127) | 64
2309
- z[0] &= 248
2310
- unpack25519(x, p)
2311
- for (i = 0; i < 16; i++) {
2312
- b[i] = x[i]
2313
- d[i] = a[i] = c[i] = 0
2314
- }
2315
- a[0] = d[0] = 1
2316
- for (i = 254; i >= 0; --i) {
2317
- r = (z[i >>> 3] >>> (i & 7)) & 1
2318
- sel25519(a, b, r)
2319
- sel25519(c, d, r)
2320
- A(e, a, c)
2321
- Z(a, a, c)
2322
- A(c, b, d)
2323
- Z(b, b, d)
2324
- S(d, e)
2325
- S(f, a)
2326
- M(a, c, a)
2327
- M(c, b, e)
2328
- A(e, a, c)
2329
- Z(a, a, c)
2330
- S(b, a)
2331
- Z(c, d, f)
2332
- M(a, c, _121665)
2333
- A(a, a, d)
2334
- M(c, c, a)
2335
- M(a, d, f)
2336
- M(d, b, x)
2337
- S(b, e)
2338
- sel25519(a, b, r)
2339
- sel25519(c, d, r)
2340
- }
2341
- for (i = 0; i < 16; i++) {
2342
- x[i + 16] = a[i]
2343
- x[i + 32] = c[i]
2344
- x[i + 48] = b[i]
2345
- x[i + 64] = d[i]
2346
- }
2347
- var x32 = x.subarray(32)
2348
- var x16 = x.subarray(16)
2349
- inv25519(x32, x32)
2350
- M(x16, x16, x32)
2351
- pack25519(q, x16)
2352
- return 0
2353
- }
2354
-
2355
- function crypto_scalarmult_base(q, n) {
2356
- return crypto_scalarmult(q, n, _9)
2357
- }
2358
-
2359
- function crypto_box_keypair(y, x) {
2360
- randombytes(x, 32)
2361
- return crypto_scalarmult_base(y, x)
2362
- }
2363
-
2364
- function crypto_box_beforenm(k, y, x) {
2365
- var s = new Uint8Array(32)
2366
- crypto_scalarmult(s, x, y)
2367
- return crypto_core_hsalsa20(k, _0, s, sigma)
2368
- }
2369
-
2370
- var crypto_box_afternm = crypto_secretbox
2371
- var crypto_box_open_afternm = crypto_secretbox_open
2372
-
2373
- function crypto_box(c, m, d, n, y, x) {
2374
- var k = new Uint8Array(32)
2375
- crypto_box_beforenm(k, y, x)
2376
- return crypto_box_afternm(c, m, d, n, k)
2377
- }
2378
-
2379
- function crypto_box_open(m, c, d, n, y, x) {
2380
- var k = new Uint8Array(32)
2381
- crypto_box_beforenm(k, y, x)
2382
- return crypto_box_open_afternm(m, c, d, n, k)
2383
- }
2384
-
2385
- var K = [
2386
- 0x428a2f98,
2387
- 0xd728ae22,
2388
- 0x71374491,
2389
- 0x23ef65cd,
2390
- 0xb5c0fbcf,
2391
- 0xec4d3b2f,
2392
- 0xe9b5dba5,
2393
- 0x8189dbbc,
2394
- 0x3956c25b,
2395
- 0xf348b538,
2396
- 0x59f111f1,
2397
- 0xb605d019,
2398
- 0x923f82a4,
2399
- 0xaf194f9b,
2400
- 0xab1c5ed5,
2401
- 0xda6d8118,
2402
- 0xd807aa98,
2403
- 0xa3030242,
2404
- 0x12835b01,
2405
- 0x45706fbe,
2406
- 0x243185be,
2407
- 0x4ee4b28c,
2408
- 0x550c7dc3,
2409
- 0xd5ffb4e2,
2410
- 0x72be5d74,
2411
- 0xf27b896f,
2412
- 0x80deb1fe,
2413
- 0x3b1696b1,
2414
- 0x9bdc06a7,
2415
- 0x25c71235,
2416
- 0xc19bf174,
2417
- 0xcf692694,
2418
- 0xe49b69c1,
2419
- 0x9ef14ad2,
2420
- 0xefbe4786,
2421
- 0x384f25e3,
2422
- 0x0fc19dc6,
2423
- 0x8b8cd5b5,
2424
- 0x240ca1cc,
2425
- 0x77ac9c65,
2426
- 0x2de92c6f,
2427
- 0x592b0275,
2428
- 0x4a7484aa,
2429
- 0x6ea6e483,
2430
- 0x5cb0a9dc,
2431
- 0xbd41fbd4,
2432
- 0x76f988da,
2433
- 0x831153b5,
2434
- 0x983e5152,
2435
- 0xee66dfab,
2436
- 0xa831c66d,
2437
- 0x2db43210,
2438
- 0xb00327c8,
2439
- 0x98fb213f,
2440
- 0xbf597fc7,
2441
- 0xbeef0ee4,
2442
- 0xc6e00bf3,
2443
- 0x3da88fc2,
2444
- 0xd5a79147,
2445
- 0x930aa725,
2446
- 0x06ca6351,
2447
- 0xe003826f,
2448
- 0x14292967,
2449
- 0x0a0e6e70,
2450
- 0x27b70a85,
2451
- 0x46d22ffc,
2452
- 0x2e1b2138,
2453
- 0x5c26c926,
2454
- 0x4d2c6dfc,
2455
- 0x5ac42aed,
2456
- 0x53380d13,
2457
- 0x9d95b3df,
2458
- 0x650a7354,
2459
- 0x8baf63de,
2460
- 0x766a0abb,
2461
- 0x3c77b2a8,
2462
- 0x81c2c92e,
2463
- 0x47edaee6,
2464
- 0x92722c85,
2465
- 0x1482353b,
2466
- 0xa2bfe8a1,
2467
- 0x4cf10364,
2468
- 0xa81a664b,
2469
- 0xbc423001,
2470
- 0xc24b8b70,
2471
- 0xd0f89791,
2472
- 0xc76c51a3,
2473
- 0x0654be30,
2474
- 0xd192e819,
2475
- 0xd6ef5218,
2476
- 0xd6990624,
2477
- 0x5565a910,
2478
- 0xf40e3585,
2479
- 0x5771202a,
2480
- 0x106aa070,
2481
- 0x32bbd1b8,
2482
- 0x19a4c116,
2483
- 0xb8d2d0c8,
2484
- 0x1e376c08,
2485
- 0x5141ab53,
2486
- 0x2748774c,
2487
- 0xdf8eeb99,
2488
- 0x34b0bcb5,
2489
- 0xe19b48a8,
2490
- 0x391c0cb3,
2491
- 0xc5c95a63,
2492
- 0x4ed8aa4a,
2493
- 0xe3418acb,
2494
- 0x5b9cca4f,
2495
- 0x7763e373,
2496
- 0x682e6ff3,
2497
- 0xd6b2b8a3,
2498
- 0x748f82ee,
2499
- 0x5defb2fc,
2500
- 0x78a5636f,
2501
- 0x43172f60,
2502
- 0x84c87814,
2503
- 0xa1f0ab72,
2504
- 0x8cc70208,
2505
- 0x1a6439ec,
2506
- 0x90befffa,
2507
- 0x23631e28,
2508
- 0xa4506ceb,
2509
- 0xde82bde9,
2510
- 0xbef9a3f7,
2511
- 0xb2c67915,
2512
- 0xc67178f2,
2513
- 0xe372532b,
2514
- 0xca273ece,
2515
- 0xea26619c,
2516
- 0xd186b8c7,
2517
- 0x21c0c207,
2518
- 0xeada7dd6,
2519
- 0xcde0eb1e,
2520
- 0xf57d4f7f,
2521
- 0xee6ed178,
2522
- 0x06f067aa,
2523
- 0x72176fba,
2524
- 0x0a637dc5,
2525
- 0xa2c898a6,
2526
- 0x113f9804,
2527
- 0xbef90dae,
2528
- 0x1b710b35,
2529
- 0x131c471b,
2530
- 0x28db77f5,
2531
- 0x23047d84,
2532
- 0x32caab7b,
2533
- 0x40c72493,
2534
- 0x3c9ebe0a,
2535
- 0x15c9bebc,
2536
- 0x431d67c4,
2537
- 0x9c100d4c,
2538
- 0x4cc5d4be,
2539
- 0xcb3e42b6,
2540
- 0x597f299c,
2541
- 0xfc657e2a,
2542
- 0x5fcb6fab,
2543
- 0x3ad6faec,
2544
- 0x6c44198c,
2545
- 0x4a475817,
2546
- ]
2547
-
2548
- function crypto_hashblocks_hl(hh, hl, m, n) {
2549
- var wh = new Int32Array(16),
2550
- wl = new Int32Array(16),
2551
- bh0,
2552
- bh1,
2553
- bh2,
2554
- bh3,
2555
- bh4,
2556
- bh5,
2557
- bh6,
2558
- bh7,
2559
- bl0,
2560
- bl1,
2561
- bl2,
2562
- bl3,
2563
- bl4,
2564
- bl5,
2565
- bl6,
2566
- bl7,
2567
- th,
2568
- tl,
2569
- i,
2570
- j,
2571
- h,
2572
- l,
2573
- a,
2574
- b,
2575
- c,
2576
- d
2577
-
2578
- var ah0 = hh[0],
2579
- ah1 = hh[1],
2580
- ah2 = hh[2],
2581
- ah3 = hh[3],
2582
- ah4 = hh[4],
2583
- ah5 = hh[5],
2584
- ah6 = hh[6],
2585
- ah7 = hh[7],
2586
- al0 = hl[0],
2587
- al1 = hl[1],
2588
- al2 = hl[2],
2589
- al3 = hl[3],
2590
- al4 = hl[4],
2591
- al5 = hl[5],
2592
- al6 = hl[6],
2593
- al7 = hl[7]
2594
-
2595
- var pos = 0
2596
- while (n >= 128) {
2597
- for (i = 0; i < 16; i++) {
2598
- j = 8 * i + pos
2599
- wh[i] =
2600
- (m[j + 0] << 24) | (m[j + 1] << 16) | (m[j + 2] << 8) | m[j + 3]
2601
- wl[i] =
2602
- (m[j + 4] << 24) | (m[j + 5] << 16) | (m[j + 6] << 8) | m[j + 7]
2603
- }
2604
- for (i = 0; i < 80; i++) {
2605
- bh0 = ah0
2606
- bh1 = ah1
2607
- bh2 = ah2
2608
- bh3 = ah3
2609
- bh4 = ah4
2610
- bh5 = ah5
2611
- bh6 = ah6
2612
- bh7 = ah7
2613
-
2614
- bl0 = al0
2615
- bl1 = al1
2616
- bl2 = al2
2617
- bl3 = al3
2618
- bl4 = al4
2619
- bl5 = al5
2620
- bl6 = al6
2621
- bl7 = al7
2622
-
2623
- // add
2624
- h = ah7
2625
- l = al7
2626
-
2627
- a = l & 0xffff
2628
- b = l >>> 16
2629
- c = h & 0xffff
2630
- d = h >>> 16
2631
-
2632
- // Sigma1
2633
- h =
2634
- ((ah4 >>> 14) | (al4 << (32 - 14))) ^
2635
- ((ah4 >>> 18) | (al4 << (32 - 18))) ^
2636
- ((al4 >>> (41 - 32)) | (ah4 << (32 - (41 - 32))))
2637
- l =
2638
- ((al4 >>> 14) | (ah4 << (32 - 14))) ^
2639
- ((al4 >>> 18) | (ah4 << (32 - 18))) ^
2640
- ((ah4 >>> (41 - 32)) | (al4 << (32 - (41 - 32))))
2641
-
2642
- a += l & 0xffff
2643
- b += l >>> 16
2644
- c += h & 0xffff
2645
- d += h >>> 16
2646
-
2647
- // Ch
2648
- h = (ah4 & ah5) ^ (~ah4 & ah6)
2649
- l = (al4 & al5) ^ (~al4 & al6)
2650
-
2651
- a += l & 0xffff
2652
- b += l >>> 16
2653
- c += h & 0xffff
2654
- d += h >>> 16
2655
-
2656
- // K
2657
- h = K[i * 2]
2658
- l = K[i * 2 + 1]
2659
-
2660
- a += l & 0xffff
2661
- b += l >>> 16
2662
- c += h & 0xffff
2663
- d += h >>> 16
2664
-
2665
- // w
2666
- h = wh[i % 16]
2667
- l = wl[i % 16]
2668
-
2669
- a += l & 0xffff
2670
- b += l >>> 16
2671
- c += h & 0xffff
2672
- d += h >>> 16
2673
-
2674
- b += a >>> 16
2675
- c += b >>> 16
2676
- d += c >>> 16
2677
-
2678
- th = (c & 0xffff) | (d << 16)
2679
- tl = (a & 0xffff) | (b << 16)
2680
-
2681
- // add
2682
- h = th
2683
- l = tl
2684
-
2685
- a = l & 0xffff
2686
- b = l >>> 16
2687
- c = h & 0xffff
2688
- d = h >>> 16
2689
-
2690
- // Sigma0
2691
- h =
2692
- ((ah0 >>> 28) | (al0 << (32 - 28))) ^
2693
- ((al0 >>> (34 - 32)) | (ah0 << (32 - (34 - 32)))) ^
2694
- ((al0 >>> (39 - 32)) | (ah0 << (32 - (39 - 32))))
2695
- l =
2696
- ((al0 >>> 28) | (ah0 << (32 - 28))) ^
2697
- ((ah0 >>> (34 - 32)) | (al0 << (32 - (34 - 32)))) ^
2698
- ((ah0 >>> (39 - 32)) | (al0 << (32 - (39 - 32))))
2699
-
2700
- a += l & 0xffff
2701
- b += l >>> 16
2702
- c += h & 0xffff
2703
- d += h >>> 16
2704
-
2705
- // Maj
2706
- h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2)
2707
- l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2)
2708
-
2709
- a += l & 0xffff
2710
- b += l >>> 16
2711
- c += h & 0xffff
2712
- d += h >>> 16
2713
-
2714
- b += a >>> 16
2715
- c += b >>> 16
2716
- d += c >>> 16
2717
-
2718
- bh7 = (c & 0xffff) | (d << 16)
2719
- bl7 = (a & 0xffff) | (b << 16)
2720
-
2721
- // add
2722
- h = bh3
2723
- l = bl3
2724
-
2725
- a = l & 0xffff
2726
- b = l >>> 16
2727
- c = h & 0xffff
2728
- d = h >>> 16
2729
-
2730
- h = th
2731
- l = tl
2732
-
2733
- a += l & 0xffff
2734
- b += l >>> 16
2735
- c += h & 0xffff
2736
- d += h >>> 16
2737
-
2738
- b += a >>> 16
2739
- c += b >>> 16
2740
- d += c >>> 16
2741
-
2742
- bh3 = (c & 0xffff) | (d << 16)
2743
- bl3 = (a & 0xffff) | (b << 16)
2744
-
2745
- ah1 = bh0
2746
- ah2 = bh1
2747
- ah3 = bh2
2748
- ah4 = bh3
2749
- ah5 = bh4
2750
- ah6 = bh5
2751
- ah7 = bh6
2752
- ah0 = bh7
2753
-
2754
- al1 = bl0
2755
- al2 = bl1
2756
- al3 = bl2
2757
- al4 = bl3
2758
- al5 = bl4
2759
- al6 = bl5
2760
- al7 = bl6
2761
- al0 = bl7
2762
-
2763
- if (i % 16 === 15) {
2764
- for (j = 0; j < 16; j++) {
2765
- // add
2766
- h = wh[j]
2767
- l = wl[j]
2768
-
2769
- a = l & 0xffff
2770
- b = l >>> 16
2771
- c = h & 0xffff
2772
- d = h >>> 16
2773
-
2774
- h = wh[(j + 9) % 16]
2775
- l = wl[(j + 9) % 16]
2776
-
2777
- a += l & 0xffff
2778
- b += l >>> 16
2779
- c += h & 0xffff
2780
- d += h >>> 16
2781
-
2782
- // sigma0
2783
- th = wh[(j + 1) % 16]
2784
- tl = wl[(j + 1) % 16]
2785
- h =
2786
- ((th >>> 1) | (tl << (32 - 1))) ^
2787
- ((th >>> 8) | (tl << (32 - 8))) ^
2788
- (th >>> 7)
2789
- l =
2790
- ((tl >>> 1) | (th << (32 - 1))) ^
2791
- ((tl >>> 8) | (th << (32 - 8))) ^
2792
- ((tl >>> 7) | (th << (32 - 7)))
2793
-
2794
- a += l & 0xffff
2795
- b += l >>> 16
2796
- c += h & 0xffff
2797
- d += h >>> 16
2798
-
2799
- // sigma1
2800
- th = wh[(j + 14) % 16]
2801
- tl = wl[(j + 14) % 16]
2802
- h =
2803
- ((th >>> 19) | (tl << (32 - 19))) ^
2804
- ((tl >>> (61 - 32)) | (th << (32 - (61 - 32)))) ^
2805
- (th >>> 6)
2806
- l =
2807
- ((tl >>> 19) | (th << (32 - 19))) ^
2808
- ((th >>> (61 - 32)) | (tl << (32 - (61 - 32)))) ^
2809
- ((tl >>> 6) | (th << (32 - 6)))
2810
-
2811
- a += l & 0xffff
2812
- b += l >>> 16
2813
- c += h & 0xffff
2814
- d += h >>> 16
2815
-
2816
- b += a >>> 16
2817
- c += b >>> 16
2818
- d += c >>> 16
2819
-
2820
- wh[j] = (c & 0xffff) | (d << 16)
2821
- wl[j] = (a & 0xffff) | (b << 16)
2822
- }
2823
- }
2824
- }
2825
-
2826
- // add
2827
- h = ah0
2828
- l = al0
2829
-
2830
- a = l & 0xffff
2831
- b = l >>> 16
2832
- c = h & 0xffff
2833
- d = h >>> 16
2834
-
2835
- h = hh[0]
2836
- l = hl[0]
2837
-
2838
- a += l & 0xffff
2839
- b += l >>> 16
2840
- c += h & 0xffff
2841
- d += h >>> 16
2842
-
2843
- b += a >>> 16
2844
- c += b >>> 16
2845
- d += c >>> 16
2846
-
2847
- hh[0] = ah0 = (c & 0xffff) | (d << 16)
2848
- hl[0] = al0 = (a & 0xffff) | (b << 16)
2849
-
2850
- h = ah1
2851
- l = al1
2852
-
2853
- a = l & 0xffff
2854
- b = l >>> 16
2855
- c = h & 0xffff
2856
- d = h >>> 16
2857
-
2858
- h = hh[1]
2859
- l = hl[1]
2860
-
2861
- a += l & 0xffff
2862
- b += l >>> 16
2863
- c += h & 0xffff
2864
- d += h >>> 16
2865
-
2866
- b += a >>> 16
2867
- c += b >>> 16
2868
- d += c >>> 16
2869
-
2870
- hh[1] = ah1 = (c & 0xffff) | (d << 16)
2871
- hl[1] = al1 = (a & 0xffff) | (b << 16)
2872
-
2873
- h = ah2
2874
- l = al2
2875
-
2876
- a = l & 0xffff
2877
- b = l >>> 16
2878
- c = h & 0xffff
2879
- d = h >>> 16
2880
-
2881
- h = hh[2]
2882
- l = hl[2]
2883
-
2884
- a += l & 0xffff
2885
- b += l >>> 16
2886
- c += h & 0xffff
2887
- d += h >>> 16
2888
-
2889
- b += a >>> 16
2890
- c += b >>> 16
2891
- d += c >>> 16
2892
-
2893
- hh[2] = ah2 = (c & 0xffff) | (d << 16)
2894
- hl[2] = al2 = (a & 0xffff) | (b << 16)
2895
-
2896
- h = ah3
2897
- l = al3
2898
-
2899
- a = l & 0xffff
2900
- b = l >>> 16
2901
- c = h & 0xffff
2902
- d = h >>> 16
2903
-
2904
- h = hh[3]
2905
- l = hl[3]
2906
-
2907
- a += l & 0xffff
2908
- b += l >>> 16
2909
- c += h & 0xffff
2910
- d += h >>> 16
2911
-
2912
- b += a >>> 16
2913
- c += b >>> 16
2914
- d += c >>> 16
2915
-
2916
- hh[3] = ah3 = (c & 0xffff) | (d << 16)
2917
- hl[3] = al3 = (a & 0xffff) | (b << 16)
2918
-
2919
- h = ah4
2920
- l = al4
2921
-
2922
- a = l & 0xffff
2923
- b = l >>> 16
2924
- c = h & 0xffff
2925
- d = h >>> 16
2926
-
2927
- h = hh[4]
2928
- l = hl[4]
2929
-
2930
- a += l & 0xffff
2931
- b += l >>> 16
2932
- c += h & 0xffff
2933
- d += h >>> 16
2934
-
2935
- b += a >>> 16
2936
- c += b >>> 16
2937
- d += c >>> 16
2938
-
2939
- hh[4] = ah4 = (c & 0xffff) | (d << 16)
2940
- hl[4] = al4 = (a & 0xffff) | (b << 16)
2941
-
2942
- h = ah5
2943
- l = al5
2944
-
2945
- a = l & 0xffff
2946
- b = l >>> 16
2947
- c = h & 0xffff
2948
- d = h >>> 16
2949
-
2950
- h = hh[5]
2951
- l = hl[5]
2952
-
2953
- a += l & 0xffff
2954
- b += l >>> 16
2955
- c += h & 0xffff
2956
- d += h >>> 16
2957
-
2958
- b += a >>> 16
2959
- c += b >>> 16
2960
- d += c >>> 16
2961
-
2962
- hh[5] = ah5 = (c & 0xffff) | (d << 16)
2963
- hl[5] = al5 = (a & 0xffff) | (b << 16)
2964
-
2965
- h = ah6
2966
- l = al6
2967
-
2968
- a = l & 0xffff
2969
- b = l >>> 16
2970
- c = h & 0xffff
2971
- d = h >>> 16
2972
-
2973
- h = hh[6]
2974
- l = hl[6]
2975
-
2976
- a += l & 0xffff
2977
- b += l >>> 16
2978
- c += h & 0xffff
2979
- d += h >>> 16
2980
-
2981
- b += a >>> 16
2982
- c += b >>> 16
2983
- d += c >>> 16
2984
-
2985
- hh[6] = ah6 = (c & 0xffff) | (d << 16)
2986
- hl[6] = al6 = (a & 0xffff) | (b << 16)
2987
-
2988
- h = ah7
2989
- l = al7
2990
-
2991
- a = l & 0xffff
2992
- b = l >>> 16
2993
- c = h & 0xffff
2994
- d = h >>> 16
2995
-
2996
- h = hh[7]
2997
- l = hl[7]
2998
-
2999
- a += l & 0xffff
3000
- b += l >>> 16
3001
- c += h & 0xffff
3002
- d += h >>> 16
3003
-
3004
- b += a >>> 16
3005
- c += b >>> 16
3006
- d += c >>> 16
3007
-
3008
- hh[7] = ah7 = (c & 0xffff) | (d << 16)
3009
- hl[7] = al7 = (a & 0xffff) | (b << 16)
3010
-
3011
- pos += 128
3012
- n -= 128
3013
- }
3014
-
3015
- return n
3016
- }
3017
-
3018
- function crypto_hash(out, m, n) {
3019
- var hh = new Int32Array(8),
3020
- hl = new Int32Array(8),
3021
- x = new Uint8Array(256),
3022
- i,
3023
- b = n
3024
-
3025
- hh[0] = 0x6a09e667
3026
- hh[1] = 0xbb67ae85
3027
- hh[2] = 0x3c6ef372
3028
- hh[3] = 0xa54ff53a
3029
- hh[4] = 0x510e527f
3030
- hh[5] = 0x9b05688c
3031
- hh[6] = 0x1f83d9ab
3032
- hh[7] = 0x5be0cd19
3033
-
3034
- hl[0] = 0xf3bcc908
3035
- hl[1] = 0x84caa73b
3036
- hl[2] = 0xfe94f82b
3037
- hl[3] = 0x5f1d36f1
3038
- hl[4] = 0xade682d1
3039
- hl[5] = 0x2b3e6c1f
3040
- hl[6] = 0xfb41bd6b
3041
- hl[7] = 0x137e2179
3042
-
3043
- crypto_hashblocks_hl(hh, hl, m, n)
3044
- n %= 128
3045
-
3046
- for (i = 0; i < n; i++) x[i] = m[b - n + i]
3047
- x[n] = 128
3048
-
3049
- n = 256 - 128 * (n < 112 ? 1 : 0)
3050
- x[n - 9] = 0
3051
- ts64(x, n - 8, (b / 0x20000000) | 0, b << 3)
3052
- crypto_hashblocks_hl(hh, hl, x, n)
3053
-
3054
- for (i = 0; i < 8; i++) ts64(out, 8 * i, hh[i], hl[i])
3055
-
3056
- return 0
3057
- }
3058
-
3059
- function add(p, q) {
3060
- var a = gf(),
3061
- b = gf(),
3062
- c = gf(),
3063
- d = gf(),
3064
- e = gf(),
3065
- f = gf(),
3066
- g = gf(),
3067
- h = gf(),
3068
- t = gf()
3069
-
3070
- Z(a, p[1], p[0])
3071
- Z(t, q[1], q[0])
3072
- M(a, a, t)
3073
- A(b, p[0], p[1])
3074
- A(t, q[0], q[1])
3075
- M(b, b, t)
3076
- M(c, p[3], q[3])
3077
- M(c, c, D2)
3078
- M(d, p[2], q[2])
3079
- A(d, d, d)
3080
- Z(e, b, a)
3081
- Z(f, d, c)
3082
- A(g, d, c)
3083
- A(h, b, a)
3084
-
3085
- M(p[0], e, f)
3086
- M(p[1], h, g)
3087
- M(p[2], g, f)
3088
- M(p[3], e, h)
3089
- }
3090
-
3091
- function cswap(p, q, b) {
3092
- var i
3093
- for (i = 0; i < 4; i++) {
3094
- sel25519(p[i], q[i], b)
3095
- }
3096
- }
3097
-
3098
- function pack(r, p) {
3099
- var tx = gf(),
3100
- ty = gf(),
3101
- zi = gf()
3102
- inv25519(zi, p[2])
3103
- M(tx, p[0], zi)
3104
- M(ty, p[1], zi)
3105
- pack25519(r, ty)
3106
- r[31] ^= par25519(tx) << 7
3107
- }
3108
-
3109
- function scalarmult(p, q, s) {
3110
- var b, i
3111
- set25519(p[0], gf0)
3112
- set25519(p[1], gf1)
3113
- set25519(p[2], gf1)
3114
- set25519(p[3], gf0)
3115
- for (i = 255; i >= 0; --i) {
3116
- b = (s[(i / 8) | 0] >> (i & 7)) & 1
3117
- cswap(p, q, b)
3118
- add(q, p)
3119
- add(p, p)
3120
- cswap(p, q, b)
3121
- }
3122
- }
3123
-
3124
- function scalarbase(p, s) {
3125
- var q = [gf(), gf(), gf(), gf()]
3126
- set25519(q[0], X)
3127
- set25519(q[1], Y)
3128
- set25519(q[2], gf1)
3129
- M(q[3], X, Y)
3130
- scalarmult(p, q, s)
3131
- }
3132
-
3133
- function crypto_sign_keypair(pk, sk, seeded) {
3134
- var d = new Uint8Array(64)
3135
- var p = [gf(), gf(), gf(), gf()]
3136
- var i
3137
-
3138
- if (!seeded) randombytes(sk, 32)
3139
- crypto_hash(d, sk, 32)
3140
- d[0] &= 248
3141
- d[31] &= 127
3142
- d[31] |= 64
3143
-
3144
- scalarbase(p, d)
3145
- pack(pk, p)
3146
-
3147
- for (i = 0; i < 32; i++) sk[i + 32] = pk[i]
3148
- return 0
3149
- }
3150
-
3151
- var L = new Float64Array([
3152
- 0xed,
3153
- 0xd3,
3154
- 0xf5,
3155
- 0x5c,
3156
- 0x1a,
3157
- 0x63,
3158
- 0x12,
3159
- 0x58,
3160
- 0xd6,
3161
- 0x9c,
3162
- 0xf7,
3163
- 0xa2,
3164
- 0xde,
3165
- 0xf9,
3166
- 0xde,
3167
- 0x14,
3168
- 0,
3169
- 0,
3170
- 0,
3171
- 0,
3172
- 0,
3173
- 0,
3174
- 0,
3175
- 0,
3176
- 0,
3177
- 0,
3178
- 0,
3179
- 0,
3180
- 0,
3181
- 0,
3182
- 0,
3183
- 0x10,
3184
- ])
3185
-
3186
- function modL(r, x) {
3187
- var carry, i, j, k
3188
- for (i = 63; i >= 32; --i) {
3189
- carry = 0
3190
- for (j = i - 32, k = i - 12; j < k; ++j) {
3191
- x[j] += carry - 16 * x[i] * L[j - (i - 32)]
3192
- carry = (x[j] + 128) >> 8
3193
- x[j] -= carry * 256
3194
- }
3195
- x[j] += carry
3196
- x[i] = 0
3197
- }
3198
- carry = 0
3199
- for (j = 0; j < 32; j++) {
3200
- x[j] += carry - (x[31] >> 4) * L[j]
3201
- carry = x[j] >> 8
3202
- x[j] &= 255
3203
- }
3204
- for (j = 0; j < 32; j++) x[j] -= carry * L[j]
3205
- for (i = 0; i < 32; i++) {
3206
- x[i + 1] += x[i] >> 8
3207
- r[i] = x[i] & 255
3208
- }
3209
- }
3210
-
3211
- function reduce(r) {
3212
- var x = new Float64Array(64),
3213
- i
3214
- for (i = 0; i < 64; i++) x[i] = r[i]
3215
- for (i = 0; i < 64; i++) r[i] = 0
3216
- modL(r, x)
3217
- }
3218
-
3219
- // Note: difference from C - smlen returned, not passed as argument.
3220
- function crypto_sign(sm, m, n, sk) {
3221
- var d = new Uint8Array(64),
3222
- h = new Uint8Array(64),
3223
- r = new Uint8Array(64)
3224
- var i,
3225
- j,
3226
- x = new Float64Array(64)
3227
- var p = [gf(), gf(), gf(), gf()]
3228
-
3229
- crypto_hash(d, sk, 32)
3230
- d[0] &= 248
3231
- d[31] &= 127
3232
- d[31] |= 64
3233
-
3234
- var smlen = n + 64
3235
- for (i = 0; i < n; i++) sm[64 + i] = m[i]
3236
- for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i]
3237
-
3238
- crypto_hash(r, sm.subarray(32), n + 32)
3239
- reduce(r)
3240
- scalarbase(p, r)
3241
- pack(sm, p)
3242
-
3243
- for (i = 32; i < 64; i++) sm[i] = sk[i]
3244
- crypto_hash(h, sm, n + 64)
3245
- reduce(h)
3246
-
3247
- for (i = 0; i < 64; i++) x[i] = 0
3248
- for (i = 0; i < 32; i++) x[i] = r[i]
3249
- for (i = 0; i < 32; i++) {
3250
- for (j = 0; j < 32; j++) {
3251
- x[i + j] += h[i] * d[j]
3252
- }
3253
- }
3254
-
3255
- modL(sm.subarray(32), x)
3256
- return smlen
3257
- }
3258
-
3259
- function unpackneg(r, p) {
3260
- var t = gf(),
3261
- chk = gf(),
3262
- num = gf(),
3263
- den = gf(),
3264
- den2 = gf(),
3265
- den4 = gf(),
3266
- den6 = gf()
3267
-
3268
- set25519(r[2], gf1)
3269
- unpack25519(r[1], p)
3270
- S(num, r[1])
3271
- M(den, num, D)
3272
- Z(num, num, r[2])
3273
- A(den, r[2], den)
3274
-
3275
- S(den2, den)
3276
- S(den4, den2)
3277
- M(den6, den4, den2)
3278
- M(t, den6, num)
3279
- M(t, t, den)
3280
-
3281
- pow2523(t, t)
3282
- M(t, t, num)
3283
- M(t, t, den)
3284
- M(t, t, den)
3285
- M(r[0], t, den)
3286
-
3287
- S(chk, r[0])
3288
- M(chk, chk, den)
3289
- if (neq25519(chk, num)) M(r[0], r[0], I)
3290
-
3291
- S(chk, r[0])
3292
- M(chk, chk, den)
3293
- if (neq25519(chk, num)) return -1
3294
-
3295
- if (par25519(r[0]) === p[31] >> 7) Z(r[0], gf0, r[0])
3296
-
3297
- M(r[3], r[0], r[1])
3298
- return 0
3299
- }
3300
-
3301
- function crypto_sign_open(m, sm, n, pk) {
3302
- var i, mlen
3303
- var t = new Uint8Array(32),
3304
- h = new Uint8Array(64)
3305
- var p = [gf(), gf(), gf(), gf()],
3306
- q = [gf(), gf(), gf(), gf()]
3307
-
3308
- mlen = -1
3309
- if (n < 64) return -1
3310
-
3311
- if (unpackneg(q, pk)) return -1
3312
-
3313
- for (i = 0; i < n; i++) m[i] = sm[i]
3314
- for (i = 0; i < 32; i++) m[i + 32] = pk[i]
3315
- crypto_hash(h, m, n)
3316
- reduce(h)
3317
- scalarmult(p, q, h)
3318
-
3319
- scalarbase(q, sm.subarray(32))
3320
- add(p, q)
3321
- pack(t, p)
3322
-
3323
- n -= 64
3324
- if (crypto_verify_32(sm, 0, t, 0)) {
3325
- for (i = 0; i < n; i++) m[i] = 0
3326
- return -1
3327
- }
3328
-
3329
- for (i = 0; i < n; i++) m[i] = sm[i + 64]
3330
- mlen = n
3331
- return mlen
3332
- }
3333
-
3334
- var crypto_secretbox_KEYBYTES = 32,
3335
- crypto_secretbox_NONCEBYTES = 24,
3336
- crypto_secretbox_ZEROBYTES = 32,
3337
- crypto_secretbox_BOXZEROBYTES = 16,
3338
- crypto_scalarmult_BYTES = 32,
3339
- crypto_scalarmult_SCALARBYTES = 32,
3340
- crypto_box_PUBLICKEYBYTES = 32,
3341
- crypto_box_SECRETKEYBYTES = 32,
3342
- crypto_box_BEFORENMBYTES = 32,
3343
- crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES,
3344
- crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES,
3345
- crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES,
3346
- crypto_sign_BYTES = 64,
3347
- crypto_sign_PUBLICKEYBYTES = 32,
3348
- crypto_sign_SECRETKEYBYTES = 64,
3349
- crypto_sign_SEEDBYTES = 32,
3350
- crypto_hash_BYTES = 64
3351
-
3352
- nacl.lowlevel = {
3353
- crypto_core_hsalsa20: crypto_core_hsalsa20,
3354
- crypto_stream_xor: crypto_stream_xor,
3355
- crypto_stream: crypto_stream,
3356
- crypto_stream_salsa20_xor: crypto_stream_salsa20_xor,
3357
- crypto_stream_salsa20: crypto_stream_salsa20,
3358
- crypto_onetimeauth: crypto_onetimeauth,
3359
- crypto_onetimeauth_verify: crypto_onetimeauth_verify,
3360
- crypto_verify_16: crypto_verify_16,
3361
- crypto_verify_32: crypto_verify_32,
3362
- crypto_secretbox: crypto_secretbox,
3363
- crypto_secretbox_open: crypto_secretbox_open,
3364
- crypto_scalarmult: crypto_scalarmult,
3365
- crypto_scalarmult_base: crypto_scalarmult_base,
3366
- crypto_box_beforenm: crypto_box_beforenm,
3367
- crypto_box_afternm: crypto_box_afternm,
3368
- crypto_box: crypto_box,
3369
- crypto_box_open: crypto_box_open,
3370
- crypto_box_keypair: crypto_box_keypair,
3371
- crypto_hash: crypto_hash,
3372
- crypto_sign: crypto_sign,
3373
- crypto_sign_keypair: crypto_sign_keypair,
3374
- crypto_sign_open: crypto_sign_open,
3375
-
3376
- crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES,
3377
- crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES,
3378
- crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES,
3379
- crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES,
3380
- crypto_scalarmult_BYTES: crypto_scalarmult_BYTES,
3381
- crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES,
3382
- crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES,
3383
- crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES,
3384
- crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES,
3385
- crypto_box_NONCEBYTES: crypto_box_NONCEBYTES,
3386
- crypto_box_ZEROBYTES: crypto_box_ZEROBYTES,
3387
- crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES,
3388
- crypto_sign_BYTES: crypto_sign_BYTES,
3389
- crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES,
3390
- crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES,
3391
- crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES,
3392
- crypto_hash_BYTES: crypto_hash_BYTES,
3393
- }
3394
-
3395
- /* High-level API */
3396
-
3397
- function checkLengths(k, n) {
3398
- if (k.length !== crypto_secretbox_KEYBYTES)
3399
- throw new Error("bad key size")
3400
- if (n.length !== crypto_secretbox_NONCEBYTES)
3401
- throw new Error("bad nonce size")
3402
- }
3403
-
3404
- function checkBoxLengths(pk, sk) {
3405
- if (pk.length !== crypto_box_PUBLICKEYBYTES)
3406
- throw new Error("bad public key size")
3407
- if (sk.length !== crypto_box_SECRETKEYBYTES)
3408
- throw new Error("bad secret key size")
3409
- }
3410
-
3411
- function checkArrayTypes() {
3412
- for (var i = 0; i < arguments.length; i++) {
3413
- if (!(arguments[i] instanceof Uint8Array))
3414
- throw new TypeError("unexpected type, use Uint8Array")
3415
- }
3416
- }
3417
-
3418
- function cleanup(arr) {
3419
- for (var i = 0; i < arr.length; i++) arr[i] = 0
3420
- }
3421
-
3422
- nacl.randomBytes = function (n) {
3423
- var b = new Uint8Array(n)
3424
- randombytes(b, n)
3425
- return b
3426
- }
3427
-
3428
- nacl.secretbox = function (msg, nonce, key) {
3429
- checkArrayTypes(msg, nonce, key)
3430
- checkLengths(key, nonce)
3431
- var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length)
3432
- var c = new Uint8Array(m.length)
3433
- for (var i = 0; i < msg.length; i++)
3434
- m[i + crypto_secretbox_ZEROBYTES] = msg[i]
3435
- crypto_secretbox(c, m, m.length, nonce, key)
3436
- return c.subarray(crypto_secretbox_BOXZEROBYTES)
3437
- }
3438
-
3439
- nacl.secretbox.open = function (box, nonce, key) {
3440
- checkArrayTypes(box, nonce, key)
3441
- checkLengths(key, nonce)
3442
- var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length)
3443
- var m = new Uint8Array(c.length)
3444
- for (var i = 0; i < box.length; i++)
3445
- c[i + crypto_secretbox_BOXZEROBYTES] = box[i]
3446
- if (c.length < 32) return null
3447
- if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0)
3448
- return null
3449
- return m.subarray(crypto_secretbox_ZEROBYTES)
3450
- }
3451
-
3452
- nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES
3453
- nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES
3454
- nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES
3455
-
3456
- nacl.scalarMult = function (n, p) {
3457
- checkArrayTypes(n, p)
3458
- if (n.length !== crypto_scalarmult_SCALARBYTES)
3459
- throw new Error("bad n size")
3460
- if (p.length !== crypto_scalarmult_BYTES)
3461
- throw new Error("bad p size")
3462
- var q = new Uint8Array(crypto_scalarmult_BYTES)
3463
- crypto_scalarmult(q, n, p)
3464
- return q
3465
- }
3466
-
3467
- nacl.scalarMult.base = function (n) {
3468
- checkArrayTypes(n)
3469
- if (n.length !== crypto_scalarmult_SCALARBYTES)
3470
- throw new Error("bad n size")
3471
- var q = new Uint8Array(crypto_scalarmult_BYTES)
3472
- crypto_scalarmult_base(q, n)
3473
- return q
3474
- }
3475
-
3476
- nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES
3477
- nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES
3478
-
3479
- nacl.box = function (msg, nonce, publicKey, secretKey) {
3480
- var k = nacl.box.before(publicKey, secretKey)
3481
- return nacl.secretbox(msg, nonce, k)
3482
- }
3483
-
3484
- nacl.box.before = function (publicKey, secretKey) {
3485
- checkArrayTypes(publicKey, secretKey)
3486
- checkBoxLengths(publicKey, secretKey)
3487
- var k = new Uint8Array(crypto_box_BEFORENMBYTES)
3488
- crypto_box_beforenm(k, publicKey, secretKey)
3489
- return k
3490
- }
3491
-
3492
- nacl.box.after = nacl.secretbox
3493
-
3494
- nacl.box.open = function (msg, nonce, publicKey, secretKey) {
3495
- var k = nacl.box.before(publicKey, secretKey)
3496
- return nacl.secretbox.open(msg, nonce, k)
3497
- }
3498
-
3499
- nacl.box.open.after = nacl.secretbox.open
3500
-
3501
- nacl.box.keyPair = function () {
3502
- var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES)
3503
- var sk = new Uint8Array(crypto_box_SECRETKEYBYTES)
3504
- crypto_box_keypair(pk, sk)
3505
- return { publicKey: pk, secretKey: sk }
3506
- }
3507
-
3508
- nacl.box.keyPair.fromSecretKey = function (secretKey) {
3509
- checkArrayTypes(secretKey)
3510
- if (secretKey.length !== crypto_box_SECRETKEYBYTES)
3511
- throw new Error("bad secret key size")
3512
- var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES)
3513
- crypto_scalarmult_base(pk, secretKey)
3514
- return { publicKey: pk, secretKey: new Uint8Array(secretKey) }
3515
- }
3516
-
3517
- nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES
3518
- nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES
3519
- nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES
3520
- nacl.box.nonceLength = crypto_box_NONCEBYTES
3521
- nacl.box.overheadLength = nacl.secretbox.overheadLength
3522
-
3523
- nacl.sign = function (msg, secretKey) {
3524
- checkArrayTypes(msg, secretKey)
3525
- if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
3526
- throw new Error("bad secret key size")
3527
- var signedMsg = new Uint8Array(crypto_sign_BYTES + msg.length)
3528
- crypto_sign(signedMsg, msg, msg.length, secretKey)
3529
- return signedMsg
3530
- }
3531
-
3532
- nacl.sign.open = function (signedMsg, publicKey) {
3533
- checkArrayTypes(signedMsg, publicKey)
3534
- if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
3535
- throw new Error("bad public key size")
3536
- var tmp = new Uint8Array(signedMsg.length)
3537
- var mlen = crypto_sign_open(
3538
- tmp,
3539
- signedMsg,
3540
- signedMsg.length,
3541
- publicKey
3542
- )
3543
- if (mlen < 0) return null
3544
- var m = new Uint8Array(mlen)
3545
- for (var i = 0; i < m.length; i++) m[i] = tmp[i]
3546
- return m
3547
- }
3548
-
3549
- nacl.sign.detached = function (msg, secretKey) {
3550
- var signedMsg = nacl.sign(msg, secretKey)
3551
- var sig = new Uint8Array(crypto_sign_BYTES)
3552
- for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i]
3553
- return sig
3554
- }
3555
-
3556
- nacl.sign.detached.verify = function (msg, sig, publicKey) {
3557
- checkArrayTypes(msg, sig, publicKey)
3558
- if (sig.length !== crypto_sign_BYTES)
3559
- throw new Error("bad signature size")
3560
- if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
3561
- throw new Error("bad public key size")
3562
- var sm = new Uint8Array(crypto_sign_BYTES + msg.length)
3563
- var m = new Uint8Array(crypto_sign_BYTES + msg.length)
3564
- var i
3565
- for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i]
3566
- for (i = 0; i < msg.length; i++) sm[i + crypto_sign_BYTES] = msg[i]
3567
- return crypto_sign_open(m, sm, sm.length, publicKey) >= 0
3568
- }
3569
-
3570
- nacl.sign.keyPair = function () {
3571
- var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES)
3572
- var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES)
3573
- crypto_sign_keypair(pk, sk)
3574
- return { publicKey: pk, secretKey: sk }
3575
- }
3576
-
3577
- nacl.sign.keyPair.fromSecretKey = function (secretKey) {
3578
- checkArrayTypes(secretKey)
3579
- if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
3580
- throw new Error("bad secret key size")
3581
- var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES)
3582
- for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32 + i]
3583
- return { publicKey: pk, secretKey: new Uint8Array(secretKey) }
3584
- }
3585
-
3586
- nacl.sign.keyPair.fromSeed = function (seed) {
3587
- checkArrayTypes(seed)
3588
- if (seed.length !== crypto_sign_SEEDBYTES)
3589
- throw new Error("bad seed size")
3590
- var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES)
3591
- var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES)
3592
- for (var i = 0; i < 32; i++) sk[i] = seed[i]
3593
- crypto_sign_keypair(pk, sk, true)
3594
- return { publicKey: pk, secretKey: sk }
3595
- }
3596
-
3597
- nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES
3598
- nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES
3599
- nacl.sign.seedLength = crypto_sign_SEEDBYTES
3600
- nacl.sign.signatureLength = crypto_sign_BYTES
3601
-
3602
- nacl.hash = function (msg) {
3603
- checkArrayTypes(msg)
3604
- var h = new Uint8Array(crypto_hash_BYTES)
3605
- crypto_hash(h, msg, msg.length)
3606
- return h
3607
- }
3608
-
3609
- nacl.hash.hashLength = crypto_hash_BYTES
3610
-
3611
- nacl.verify = function (x, y) {
3612
- checkArrayTypes(x, y)
3613
- // Zero length arguments are considered not equal.
3614
- if (x.length === 0 || y.length === 0) return false
3615
- if (x.length !== y.length) return false
3616
- return vn(x, 0, y, 0, x.length) === 0 ? true : false
3617
- }
3618
-
3619
- nacl.setPRNG = function (fn) {
3620
- randombytes = fn
3621
- }
3622
-
3623
- ;(function () {
3624
- // Initialize PRNG if environment provides CSPRNG.
3625
- // If not, methods calling randombytes will throw.
3626
- var crypto =
3627
- typeof self !== "undefined" ? self.crypto || self.msCrypto : null
3628
- if (crypto && crypto.getRandomValues) {
3629
- // Browsers.
3630
- var QUOTA = 65536
3631
- nacl.setPRNG(function (x, n) {
3632
- var i,
3633
- v = new Uint8Array(n)
3634
- for (i = 0; i < n; i += QUOTA) {
3635
- crypto.getRandomValues(
3636
- v.subarray(i, i + Math.min(n - i, QUOTA))
3637
- )
3638
- }
3639
- for (i = 0; i < n; i++) x[i] = v[i]
3640
- cleanup(v)
3641
- })
3642
- } else if (true) {
3643
- // Node.js.
3644
- crypto = __webpack_require__(1)
3645
- if (crypto && crypto.randomBytes) {
3646
- nacl.setPRNG(function (x, n) {
3647
- var i,
3648
- v = crypto.randomBytes(n)
3649
- for (i = 0; i < n; i++) x[i] = v[i]
3650
- cleanup(v)
3651
- })
3652
- }
3653
- }
3654
- })()
3655
- })(
3656
- typeof module !== "undefined" && module.exports
3657
- ? module.exports
3658
- : (self.nacl = self.nacl || {})
3659
- )
3660
-
3661
- /***/
3662
- },
3663
- /* 8 */
3664
- /***/ function (module, exports) {
3665
- // Written in 2014-2016 by Dmitry Chestnykh and Devi Mandiri.
3666
- // Public domain.
3667
- ;(function (root, f) {
3668
- "use strict"
3669
- if (typeof module !== "undefined" && module.exports)
3670
- module.exports = f()
3671
- else if (root.nacl) root.nacl.util = f()
3672
- else {
3673
- root.nacl = {}
3674
- root.nacl.util = f()
3675
- }
3676
- })(this, function () {
3677
- "use strict"
3678
-
3679
- var util = {}
3680
-
3681
- function validateBase64(s) {
3682
- if (
3683
- !/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(
3684
- s
3685
- )
3686
- ) {
3687
- throw new TypeError("invalid encoding")
3688
- }
3689
- }
3690
-
3691
- util.decodeUTF8 = function (s) {
3692
- if (typeof s !== "string") throw new TypeError("expected string")
3693
- var i,
3694
- d = unescape(encodeURIComponent(s)),
3695
- b = new Uint8Array(d.length)
3696
- for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i)
3697
- return b
3698
- }
3699
-
3700
- util.encodeUTF8 = function (arr) {
3701
- var i,
3702
- s = []
3703
- for (i = 0; i < arr.length; i++) s.push(String.fromCharCode(arr[i]))
3704
- return decodeURIComponent(escape(s.join("")))
3705
- }
3706
-
3707
- if (typeof atob === "undefined") {
3708
- // Node.js
3709
-
3710
- if (typeof Buffer.from !== "undefined") {
3711
- // Node v6 and later
3712
- util.encodeBase64 = function (arr) {
3713
- // v6 and later
3714
- return Buffer.from(arr).toString("base64")
3715
- }
3716
-
3717
- util.decodeBase64 = function (s) {
3718
- validateBase64(s)
3719
- return new Uint8Array(
3720
- Array.prototype.slice.call(Buffer.from(s, "base64"), 0)
3721
- )
3722
- }
3723
- } else {
3724
- // Node earlier than v6
3725
- util.encodeBase64 = function (arr) {
3726
- // v6 and later
3727
- return new Buffer(arr).toString("base64")
3728
- }
3729
-
3730
- util.decodeBase64 = function (s) {
3731
- validateBase64(s)
3732
- return new Uint8Array(
3733
- Array.prototype.slice.call(new Buffer(s, "base64"), 0)
3734
- )
3735
- }
3736
- }
3737
- } else {
3738
- // Browsers
3739
-
3740
- util.encodeBase64 = function (arr) {
3741
- var i,
3742
- s = [],
3743
- len = arr.length
3744
- for (i = 0; i < len; i++) s.push(String.fromCharCode(arr[i]))
3745
- return btoa(s.join(""))
3746
- }
3747
-
3748
- util.decodeBase64 = function (s) {
3749
- validateBase64(s)
3750
- var i,
3751
- d = atob(s),
3752
- b = new Uint8Array(d.length)
3753
- for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i)
3754
- return b
3755
- }
3756
- }
3757
-
3758
- return util
3759
- })
3760
-
3761
- /***/
3762
- },
3763
- /* 9 */
3764
- /***/ function (module, exports, __webpack_require__) {
3765
- var request = __webpack_require__(10)
3766
-
3767
- var errors = __webpack_require__(5)
3768
- var util = __webpack_require__(4)
3769
-
3770
- var pusherLibraryVersion = __webpack_require__(11)
3771
-
3772
- var RESERVED_QUERY_KEYS = {
3773
- auth_key: true,
3774
- auth_timestamp: true,
3775
- auth_version: true,
3776
- auth_signature: true,
3777
- body_md5: true,
3778
- }
3779
-
3780
- function send(config, options, callback) {
3781
- var handler = config.keepAlive ? request.forever() : request
3782
-
3783
- var path = config.prefixPath(options.path)
3784
- var body = options.body ? JSON.stringify(options.body) : undefined
3785
-
3786
- var queryString = createSignedQueryString(config.token, {
3787
- method: options.method,
3788
- path: path,
3789
- params: options.params,
3790
- body: body,
3791
- })
3792
-
3793
- var url = config.getBaseURL() + path + "?" + queryString
3794
-
3795
- var params = {
3796
- url: url,
3797
- proxy: config.proxy,
3798
- timeout: config.timeout,
3799
- headers: {
3800
- "x-pusher-library": "pusher-http-node " + pusherLibraryVersion,
3801
- },
3802
- }
3803
-
3804
- if (body) {
3805
- params.headers["content-type"] = "application/json"
3806
- params.body = body
3807
- }
3808
-
3809
- handler[options.method.toLowerCase()](params, function (
3810
- err,
3811
- res,
3812
- resBody
3813
- ) {
3814
- dispatchRequestResult(err, url, this.req, res, callback)
3815
- })
3816
- }
3817
-
3818
- function createSignedQueryString(token, request) {
3819
- var timestamp = (Date.now() / 1000) | 0
3820
-
3821
- var params = {
3822
- auth_key: token.key,
3823
- auth_timestamp: timestamp,
3824
- auth_version: "1.0",
3825
- }
3826
-
3827
- if (request.body) {
3828
- params.body_md5 = util.getMD5(request.body)
3829
- }
3830
-
3831
- if (request.params) {
3832
- for (var key in request.params) {
3833
- if (RESERVED_QUERY_KEYS[key] !== undefined) {
3834
- throw Error(
3835
- key + " is a required parameter and cannot be overidden"
3836
- )
3837
- }
3838
- params[key] = request.params[key]
3839
- }
3840
- }
3841
-
3842
- var method = request.method.toUpperCase()
3843
- var sortedKeyVal = util.toOrderedArray(params)
3844
- var queryString = sortedKeyVal.join("&")
3845
-
3846
- var signData = [method, request.path, queryString].join("\n")
3847
- queryString += "&auth_signature=" + token.sign(signData)
3848
-
3849
- return queryString
3850
- }
3851
-
3852
- function dispatchRequestResult(err, url, req, res, callback) {
3853
- if (typeof callback !== "function") {
3854
- return
3855
- }
3856
-
3857
- var error = null
3858
- if (err) {
3859
- error = new errors.RequestError(
3860
- "Request failed with an error",
3861
- url,
3862
- err,
3863
- res ? res.statusCode : null,
3864
- res ? res.body : null
3865
- )
3866
- } else if (res.statusCode >= 400) {
3867
- error = new errors.RequestError(
3868
- "Unexpected status code " + res.statusCode,
3869
- url,
3870
- err,
3871
- res ? res.statusCode : null,
3872
- res ? res.body : null
3873
- )
3874
- }
3875
- callback(error, req, res)
3876
- }
3877
-
3878
- exports.send = send
3879
- exports.createSignedQueryString = createSignedQueryString
3880
-
3881
- /***/
3882
- },
3883
- /* 10 */
3884
- /***/ function (module, exports) {
3885
- module.exports = ParseRequest = {
3886
- get: function (params, callback) {
3887
- this._request("GET", params, callback)
3888
- },
3889
-
3890
- post: function (params, callback) {
3891
- this._request("POST", params, callback)
3892
- },
3893
-
3894
- _request: function (method, params, callback) {
3895
- var request = {
3896
- method: method,
3897
- url: params.url,
3898
- headers: params.headers,
3899
- body: params.body,
3900
- }
3901
-
3902
- var success = function (res) {
3903
- var err = null
3904
- var res = new ParseResponse(res)
3905
- var body = res.body
3906
- callback(err, res, body)
3907
- }
3908
-
3909
- var error = function (res) {
3910
- var res = new ParseResponse(res)
3911
- var err = (body = res.body)
3912
- callback(err, res, body)
3913
- }
3914
-
3915
- Parse.Cloud.httpRequest(request).then(success, error)
3916
- },
3917
-
3918
- forever: function () {
3919
- console.log(
3920
- "This Parse extension does not support keep-alive." +
3921
- " Falling back to default..."
3922
- )
3923
- return this
3924
- },
3925
- }
3926
-
3927
- function ParseResponse(raw) {
3928
- this.statusCode = raw.status
3929
- this.body = raw.text
3930
- }
3931
-
3932
- /***/
3933
- },
3934
- /* 11 */
3935
- /***/ function (module, exports) {
3936
- module.exports = { version: "2.1.3" }
3937
-
3938
- /***/
3939
- },
3940
- /* 12 */
3941
- /***/ function (module, exports, __webpack_require__) {
3942
- var Config = __webpack_require__(13)
3943
- var util = __webpack_require__(4)
3944
-
3945
- function PusherConfig(options) {
3946
- Config.call(this, options)
3947
-
3948
- if (options.host) {
3949
- this.host = options.host
3950
- } else if (options.cluster) {
3951
- this.host = "api-" + options.cluster + ".pusher.com"
3952
- } else {
3953
- this.host = "api.pusherapp.com"
3954
- }
3955
- }
3956
-
3957
- util.mergeObjects(PusherConfig.prototype, Config.prototype)
3958
-
3959
- PusherConfig.prototype.prefixPath = function (subPath) {
3960
- return "/apps/" + this.appId + subPath
3961
- }
3962
-
3963
- module.exports = PusherConfig
3964
-
3965
- /***/
3966
- },
3967
- /* 13 */
3968
- /***/ function (module, exports, __webpack_require__) {
3969
- var Token = __webpack_require__(14)
3970
-
3971
- function Config(options) {
3972
- options = options || {}
3973
-
3974
- var useTLS = false
3975
- if (options.useTLS !== undefined && options.encrypted !== undefined) {
3976
- throw new Error(
3977
- "Cannot set both `useTLS` and `encrypted` configuration options"
3978
- )
3979
- } else if (options.useTLS !== undefined) {
3980
- useTLS = options.useTLS
3981
- } else if (options.encrypted !== undefined) {
3982
- // `encrypted` deprecated in favor of `useTLS`
3983
- console.warn("`encrypted` option is deprecated in favor of `useTLS`")
3984
- useTLS = options.encrypted
3985
- }
3986
- this.scheme = options.scheme || (useTLS ? "https" : "http")
3987
- this.port = options.port
3988
-
3989
- this.appId = options.appId
3990
- this.token = new Token(options.key, options.secret)
3991
-
3992
- this.proxy = options.proxy
3993
- this.timeout = options.timeout
3994
- this.keepAlive = options.keepAlive
3995
-
3996
- if (options.encryptionMasterKey !== undefined) {
3997
- if (typeof options.encryptionMasterKey !== "string") {
3998
- throw new Error("encryptionMasterKey must be a string")
3999
- }
4000
- if (options.encryptionMasterKey.length !== 32) {
4001
- throw new Error(
4002
- "encryptionMasterKey must be 32 characters long, but the string '" +
4003
- options.encryptionMasterKey +
4004
- "' is " +
4005
- options.encryptionMasterKey.length +
4006
- " characters long"
4007
- )
4008
- }
4009
- this.encryptionMasterKey = options.encryptionMasterKey
4010
- }
4011
- }
4012
-
4013
- Config.prototype.prefixPath = function (subPath) {
4014
- throw "NotImplementedError: #prefixPath should be implemented by subclasses"
4015
- }
4016
-
4017
- Config.prototype.getBaseURL = function (subPath, queryString) {
4018
- var port = this.port ? ":" + this.port : ""
4019
- return this.scheme + "://" + this.host + port
4020
- }
4021
-
4022
- module.exports = Config
4023
-
4024
- /***/
4025
- },
4026
- /* 14 */
4027
- /***/ function (module, exports, __webpack_require__) {
4028
- var crypto = __webpack_require__(1)
4029
- var Buffer = Buffer || __webpack_require__(15).Buffer
4030
- var util = __webpack_require__(4)
4031
-
4032
- /** Verifies and signs data against the key and secret.
4033
- *
4034
- * @constructor
4035
- * @param {String} key app key
4036
- * @param {String} secret app secret
4037
- */
4038
- function Token(key, secret) {
4039
- this.key = key
4040
- this.secret = secret
4041
- }
4042
-
4043
- /** Signs the string using the secret.
4044
- *
4045
- * @param {String} string
4046
- * @returns {String}
4047
- */
4048
- Token.prototype.sign = function (string) {
4049
- return crypto
4050
- .createHmac("sha256", this.secret)
4051
- .update(new Buffer(string, "utf-8"))
4052
- .digest("hex")
4053
- }
4054
-
4055
- /** Checks if the string has correct signature.
4056
- *
4057
- * @param {String} string
4058
- * @param {String} signature
4059
- * @returns {Boolean}
4060
- */
4061
- Token.prototype.verify = function (string, signature) {
4062
- return util.secureCompare(this.sign(string), signature)
4063
- }
4064
-
4065
- module.exports = Token
4066
-
4067
- /***/
4068
- },
4069
- /* 15 */
4070
- /***/ function (module, exports) {
4071
- module.exports = require("buffer")
4072
-
4073
- /***/
4074
- },
4075
- /* 16 */
4076
- /***/ function (module, exports, __webpack_require__) {
4077
- var errors = __webpack_require__(5)
4078
- var util = __webpack_require__(4)
4079
-
4080
- var Token = __webpack_require__(14)
4081
-
4082
- /** Provides validation and access methods for a WebHook.
4083
- *
4084
- * Before accessing WebHook data, check if it's valid. Otherwise, exceptions
4085
- * will be raised from access methods.
4086
- *
4087
- * @constructor
4088
- * @param {Token} primary token
4089
- * @param {Object} request
4090
- * @param {Object} request.headers WebHook HTTP headers with lower-case keys
4091
- * @param {String} request.rawBody raw WebHook body
4092
- */
4093
- function WebHook(token, request) {
4094
- this.token = token
4095
-
4096
- this.key = request.headers["x-pusher-key"]
4097
- this.signature = request.headers["x-pusher-signature"]
4098
- this.contentType = request.headers["content-type"]
4099
- this.body = request.rawBody
4100
-
4101
- if (this.isContentTypeValid()) {
4102
- try {
4103
- this.data = JSON.parse(this.body)
4104
- } catch (e) {}
4105
- }
4106
- }
4107
-
4108
- /** Checks whether the WebHook has valid body and signature.
4109
- *
4110
- * @param {Token|Token[]} list of additional tokens to be validated against
4111
- * @returns {Boolean}
4112
- */
4113
- WebHook.prototype.isValid = function (extraTokens) {
4114
- if (!this.isBodyValid()) {
4115
- return false
4116
- }
4117
-
4118
- extraTokens = extraTokens || []
4119
- if (!(extraTokens instanceof Array)) {
4120
- extraTokens = [extraTokens]
4121
- }
4122
-
4123
- var tokens = [this.token].concat(extraTokens)
4124
- for (var i in tokens) {
4125
- var token = tokens[i]
4126
- if (
4127
- this.key == token.key &&
4128
- token.verify(this.body, this.signature)
4129
- ) {
4130
- return true
4131
- }
4132
- }
4133
- return false
4134
- }
4135
-
4136
- /** Checks whether the WebHook content type is valid.
4137
- *
4138
- * For now, the only valid WebHooks have content type of application/json.
4139
- *
4140
- * @returns {Boolean}
4141
- */
4142
- WebHook.prototype.isContentTypeValid = function () {
4143
- return this.contentType === "application/json"
4144
- }
4145
-
4146
- /** Checks whether the WebHook content type and body is JSON.
4147
- *
4148
- * @returns {Boolean}
4149
- */
4150
- WebHook.prototype.isBodyValid = function () {
4151
- return this.data !== undefined
4152
- }
4153
-
4154
- /** Returns all WebHook data.
4155
- *
4156
- * @throws WebHookError when WebHook is invalid
4157
- * @returns {Object}
4158
- */
4159
- WebHook.prototype.getData = function () {
4160
- if (!this.isBodyValid()) {
4161
- throw new errors.WebHookError(
4162
- "Invalid WebHook body",
4163
- this.contentType,
4164
- this.body,
4165
- this.signature
4166
- )
4167
- }
4168
- return this.data
4169
- }
4170
-
4171
- /** Returns WebHook events array.
4172
- *
4173
- * @throws WebHookError when WebHook is invalid
4174
- * @returns {Object[]}
4175
- */
4176
- WebHook.prototype.getEvents = function () {
4177
- return this.getData().events
4178
- }
4179
-
4180
- /** Returns WebHook timestamp.
4181
- *
4182
- * @throws WebHookError when WebHook is invalid
4183
- * @returns {Date}
4184
- */
4185
- WebHook.prototype.getTime = function () {
4186
- return new Date(this.getData().time_ms)
4187
- }
4188
-
4189
- module.exports = WebHook
4190
-
4191
- /***/
4192
- },
4193
- /* 17 */
4194
- /***/ function (module, exports, __webpack_require__) {
4195
- var Config = __webpack_require__(13)
4196
- var requests = __webpack_require__(9)
4197
- var util = __webpack_require__(4)
4198
- var NotificationConfig = __webpack_require__(18)
4199
-
4200
- function NotificationClient(options) {
4201
- this.config = new NotificationConfig(options)
4202
- }
4203
-
4204
- NotificationClient.prototype.notify = function (
4205
- interests,
4206
- notification,
4207
- callback
4208
- ) {
4209
- if (!Array.isArray(interests)) {
4210
- throw new Error("Interests must be an array")
4211
- }
4212
-
4213
- if (interests.length == 0) {
4214
- throw new Error("Interests array must not be empty")
4215
- }
4216
-
4217
- var body = util.mergeObjects({ interests: interests }, notification)
4218
- requests.send(
4219
- this.config,
4220
- {
4221
- method: "POST",
4222
- body: body,
4223
- path: "/notifications",
4224
- },
4225
- callback
4226
- )
4227
- }
4228
-
4229
- module.exports = NotificationClient
4230
-
4231
- /***/
4232
- },
4233
- /* 18 */
4234
- /***/ function (module, exports, __webpack_require__) {
4235
- var Config = __webpack_require__(13)
4236
- var util = __webpack_require__(4)
4237
-
4238
- var DEFAULT_HOST = "nativepush-cluster1.pusher.com"
4239
- var API_PREFIX = "server_api"
4240
- var API_VERSION = "v1"
4241
-
4242
- function NotificationConfig(options) {
4243
- Config.call(this, options)
4244
- this.host = options.host || DEFAULT_HOST
4245
- }
4246
-
4247
- util.mergeObjects(NotificationConfig.prototype, Config.prototype)
4248
-
4249
- NotificationConfig.prototype.prefixPath = function (subPath) {
4250
- return (
4251
- "/" + API_PREFIX + "/" + API_VERSION + "/apps/" + this.appId + subPath
4252
- )
4253
- }
4254
-
4255
- module.exports = NotificationConfig
4256
-
4257
- /***/
4258
- },
4259
- /******/
4260
- ]
4261
- )