Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4fbea5a8f8 | ||
|
|
6a5805234f | ||
|
|
de6728487e | ||
|
|
f5a838f1cc | ||
|
|
af5f9653d6 | ||
|
|
d6e55c2e33 | ||
|
|
a80285cc83 | ||
|
|
d08705329a | ||
|
|
5679fe7a49 | ||
|
|
c95f5882a9 | ||
|
|
b5514743fb | ||
|
|
cd2042f9ce |
12
README.md
12
README.md
@ -1,10 +1,12 @@
|
||||
**Deprecation Warning**: It is recommended that the TypeScript interface of [libsignal-client](https://github.com/signalapp/libsignal-client) be used for all new applications. This library is no longer used by us or maintained.
|
||||
|
||||
# libsignal-protocol-javascript
|
||||
|
||||
[](https://travis-ci.org/WhisperSystems/libsignal-protocol-javascript)
|
||||
[](https://travis-ci.org/signalapp/libsignal-protocol-javascript)
|
||||
|
||||
|
||||
Signal Protocol implementation for the browser based on
|
||||
[libsignal-protocol-java](https://github.com/WhisperSystems/libsignal-protocol-java).
|
||||
[libsignal-protocol-java](https://github.com/signalapp/libsignal-protocol-java).
|
||||
|
||||
```
|
||||
/dist # Distributables
|
||||
@ -115,7 +117,7 @@ var store = new MySignalProtocolStore();
|
||||
var address = new libsignal.SignalProtocolAddress(recipientId, deviceId);
|
||||
|
||||
// Instantiate a SessionBuilder for a remote recipientId + deviceId tuple.
|
||||
SessionBuilder sessionBuilder = new libsignal.SessionBuilder(store, address);
|
||||
var sessionBuilder = new libsignal.SessionBuilder(store, address);
|
||||
|
||||
// Process a prekey fetched from the server. Returns a promise that resolves
|
||||
// once a session is created and saved in the store, or rejects if the
|
||||
@ -184,7 +186,7 @@ sessionCipher.decryptWhisperMessage(ciphertext).then(function(plaintext) {
|
||||
|
||||
## Building
|
||||
|
||||
To compile curve25519 from C souce files in `/native`, install
|
||||
To compile curve25519 from C source files in `/native`, install
|
||||
[emscripten](https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html).
|
||||
|
||||
```
|
||||
@ -193,6 +195,6 @@ grunt compile
|
||||
|
||||
## License
|
||||
|
||||
Copyright 2015-2016 Open Whisper Systems
|
||||
Copyright 2015-2018 Open Whisper Systems
|
||||
|
||||
Licensed under the GPLv3: http://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
@ -47,21 +47,18 @@
|
||||
/**
|
||||
* The low 32 bits as a signed value.
|
||||
* @type {number}
|
||||
* @expose
|
||||
*/
|
||||
this.low = low | 0;
|
||||
|
||||
/**
|
||||
* The high 32 bits as a signed value.
|
||||
* @type {number}
|
||||
* @expose
|
||||
*/
|
||||
this.high = high | 0;
|
||||
|
||||
/**
|
||||
* Whether unsigned or not.
|
||||
* @type {boolean}
|
||||
* @expose
|
||||
*/
|
||||
this.unsigned = !!unsigned;
|
||||
}
|
||||
@ -87,10 +84,9 @@
|
||||
* An indicator used to reliably determine if an object is a Long or not.
|
||||
* @type {boolean}
|
||||
* @const
|
||||
* @expose
|
||||
* @private
|
||||
*/
|
||||
Long.__isLong__;
|
||||
Long.prototype.__isLong__;
|
||||
|
||||
Object.defineProperty(Long.prototype, "__isLong__", {
|
||||
value: true,
|
||||
@ -113,7 +109,6 @@
|
||||
* @function
|
||||
* @param {*} obj Object
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
Long.isLong = isLong;
|
||||
|
||||
@ -170,7 +165,6 @@
|
||||
* @param {number} value The 32 bit integer in question
|
||||
* @param {boolean=} unsigned Whether unsigned or not, defaults to `false` for signed
|
||||
* @returns {!Long} The corresponding Long value
|
||||
* @expose
|
||||
*/
|
||||
Long.fromInt = fromInt;
|
||||
|
||||
@ -205,7 +199,6 @@
|
||||
* @param {number} value The number in question
|
||||
* @param {boolean=} unsigned Whether unsigned or not, defaults to `false` for signed
|
||||
* @returns {!Long} The corresponding Long value
|
||||
* @expose
|
||||
*/
|
||||
Long.fromNumber = fromNumber;
|
||||
|
||||
@ -228,7 +221,6 @@
|
||||
* @param {number} highBits The high 32 bits
|
||||
* @param {boolean=} unsigned Whether unsigned or not, defaults to `false` for signed
|
||||
* @returns {!Long} The corresponding Long value
|
||||
* @expose
|
||||
*/
|
||||
Long.fromBits = fromBits;
|
||||
|
||||
@ -298,7 +290,6 @@
|
||||
* @param {(boolean|number)=} unsigned Whether unsigned or not, defaults to `false` for signed
|
||||
* @param {number=} radix The radix in which the text is written (2-36), defaults to 10
|
||||
* @returns {!Long} The corresponding Long value
|
||||
* @expose
|
||||
*/
|
||||
Long.fromString = fromString;
|
||||
|
||||
@ -324,7 +315,6 @@
|
||||
* @function
|
||||
* @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val Value
|
||||
* @returns {!Long}
|
||||
* @expose
|
||||
*/
|
||||
Long.fromValue = fromValue;
|
||||
|
||||
@ -382,7 +372,6 @@
|
||||
/**
|
||||
* Signed zero.
|
||||
* @type {!Long}
|
||||
* @expose
|
||||
*/
|
||||
Long.ZERO = ZERO;
|
||||
|
||||
@ -395,7 +384,6 @@
|
||||
/**
|
||||
* Unsigned zero.
|
||||
* @type {!Long}
|
||||
* @expose
|
||||
*/
|
||||
Long.UZERO = UZERO;
|
||||
|
||||
@ -408,7 +396,6 @@
|
||||
/**
|
||||
* Signed one.
|
||||
* @type {!Long}
|
||||
* @expose
|
||||
*/
|
||||
Long.ONE = ONE;
|
||||
|
||||
@ -421,7 +408,6 @@
|
||||
/**
|
||||
* Unsigned one.
|
||||
* @type {!Long}
|
||||
* @expose
|
||||
*/
|
||||
Long.UONE = UONE;
|
||||
|
||||
@ -434,7 +420,6 @@
|
||||
/**
|
||||
* Signed negative one.
|
||||
* @type {!Long}
|
||||
* @expose
|
||||
*/
|
||||
Long.NEG_ONE = NEG_ONE;
|
||||
|
||||
@ -447,7 +432,6 @@
|
||||
/**
|
||||
* Maximum signed value.
|
||||
* @type {!Long}
|
||||
* @expose
|
||||
*/
|
||||
Long.MAX_VALUE = MAX_VALUE;
|
||||
|
||||
@ -460,7 +444,6 @@
|
||||
/**
|
||||
* Maximum unsigned value.
|
||||
* @type {!Long}
|
||||
* @expose
|
||||
*/
|
||||
Long.MAX_UNSIGNED_VALUE = MAX_UNSIGNED_VALUE;
|
||||
|
||||
@ -473,7 +456,6 @@
|
||||
/**
|
||||
* Minimum signed value.
|
||||
* @type {!Long}
|
||||
* @expose
|
||||
*/
|
||||
Long.MIN_VALUE = MIN_VALUE;
|
||||
|
||||
@ -486,7 +468,6 @@
|
||||
/**
|
||||
* Converts the Long to a 32 bit integer, assuming it is a 32 bit integer.
|
||||
* @returns {number}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.toInt = function toInt() {
|
||||
return this.unsigned ? this.low >>> 0 : this.low;
|
||||
@ -495,7 +476,6 @@
|
||||
/**
|
||||
* Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa).
|
||||
* @returns {number}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.toNumber = function toNumber() {
|
||||
if (this.unsigned)
|
||||
@ -509,7 +489,6 @@
|
||||
* @returns {string}
|
||||
* @override
|
||||
* @throws {RangeError} If `radix` is out of range
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.toString = function toString(radix) {
|
||||
radix = radix || 10;
|
||||
@ -552,7 +531,6 @@
|
||||
/**
|
||||
* Gets the high 32 bits as a signed integer.
|
||||
* @returns {number} Signed high bits
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.getHighBits = function getHighBits() {
|
||||
return this.high;
|
||||
@ -561,7 +539,6 @@
|
||||
/**
|
||||
* Gets the high 32 bits as an unsigned integer.
|
||||
* @returns {number} Unsigned high bits
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.getHighBitsUnsigned = function getHighBitsUnsigned() {
|
||||
return this.high >>> 0;
|
||||
@ -570,7 +547,6 @@
|
||||
/**
|
||||
* Gets the low 32 bits as a signed integer.
|
||||
* @returns {number} Signed low bits
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.getLowBits = function getLowBits() {
|
||||
return this.low;
|
||||
@ -579,7 +555,6 @@
|
||||
/**
|
||||
* Gets the low 32 bits as an unsigned integer.
|
||||
* @returns {number} Unsigned low bits
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.getLowBitsUnsigned = function getLowBitsUnsigned() {
|
||||
return this.low >>> 0;
|
||||
@ -588,7 +563,6 @@
|
||||
/**
|
||||
* Gets the number of bits needed to represent the absolute value of this Long.
|
||||
* @returns {number}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.getNumBitsAbs = function getNumBitsAbs() {
|
||||
if (this.isNegative()) // Unsigned Longs are never negative
|
||||
@ -603,7 +577,6 @@
|
||||
/**
|
||||
* Tests if this Long's value equals zero.
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.isZero = function isZero() {
|
||||
return this.high === 0 && this.low === 0;
|
||||
@ -612,7 +585,6 @@
|
||||
/**
|
||||
* Tests if this Long's value is negative.
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.isNegative = function isNegative() {
|
||||
return !this.unsigned && this.high < 0;
|
||||
@ -621,7 +593,6 @@
|
||||
/**
|
||||
* Tests if this Long's value is positive.
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.isPositive = function isPositive() {
|
||||
return this.unsigned || this.high >= 0;
|
||||
@ -630,7 +601,6 @@
|
||||
/**
|
||||
* Tests if this Long's value is odd.
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.isOdd = function isOdd() {
|
||||
return (this.low & 1) === 1;
|
||||
@ -639,7 +609,6 @@
|
||||
/**
|
||||
* Tests if this Long's value is even.
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.isEven = function isEven() {
|
||||
return (this.low & 1) === 0;
|
||||
@ -649,7 +618,6 @@
|
||||
* Tests if this Long's value equals the specified's.
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.equals = function equals(other) {
|
||||
if (!isLong(other))
|
||||
@ -664,7 +632,6 @@
|
||||
* @function
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.eq = LongPrototype.equals;
|
||||
|
||||
@ -672,7 +639,6 @@
|
||||
* Tests if this Long's value differs from the specified's.
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.notEquals = function notEquals(other) {
|
||||
return !this.eq(/* validates */ other);
|
||||
@ -683,7 +649,6 @@
|
||||
* @function
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.neq = LongPrototype.notEquals;
|
||||
|
||||
@ -691,7 +656,6 @@
|
||||
* Tests if this Long's value is less than the specified's.
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.lessThan = function lessThan(other) {
|
||||
return this.comp(/* validates */ other) < 0;
|
||||
@ -702,7 +666,6 @@
|
||||
* @function
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.lt = LongPrototype.lessThan;
|
||||
|
||||
@ -710,7 +673,6 @@
|
||||
* Tests if this Long's value is less than or equal the specified's.
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) {
|
||||
return this.comp(/* validates */ other) <= 0;
|
||||
@ -721,7 +683,6 @@
|
||||
* @function
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.lte = LongPrototype.lessThanOrEqual;
|
||||
|
||||
@ -729,7 +690,6 @@
|
||||
* Tests if this Long's value is greater than the specified's.
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.greaterThan = function greaterThan(other) {
|
||||
return this.comp(/* validates */ other) > 0;
|
||||
@ -740,7 +700,6 @@
|
||||
* @function
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.gt = LongPrototype.greaterThan;
|
||||
|
||||
@ -748,7 +707,6 @@
|
||||
* Tests if this Long's value is greater than or equal the specified's.
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) {
|
||||
return this.comp(/* validates */ other) >= 0;
|
||||
@ -759,7 +717,6 @@
|
||||
* @function
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.gte = LongPrototype.greaterThanOrEqual;
|
||||
|
||||
@ -768,7 +725,6 @@
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {number} 0 if they are the same, 1 if the this is greater and -1
|
||||
* if the given one is greater
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.compare = function compare(other) {
|
||||
if (!isLong(other))
|
||||
@ -794,14 +750,12 @@
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {number} 0 if they are the same, 1 if the this is greater and -1
|
||||
* if the given one is greater
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.comp = LongPrototype.compare;
|
||||
|
||||
/**
|
||||
* Negates this Long's value.
|
||||
* @returns {!Long} Negated Long
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.negate = function negate() {
|
||||
if (!this.unsigned && this.eq(MIN_VALUE))
|
||||
@ -813,7 +767,6 @@
|
||||
* Negates this Long's value. This is an alias of {@link Long#negate}.
|
||||
* @function
|
||||
* @returns {!Long} Negated Long
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.neg = LongPrototype.negate;
|
||||
|
||||
@ -821,7 +774,6 @@
|
||||
* Returns the sum of this and the specified Long.
|
||||
* @param {!Long|number|string} addend Addend
|
||||
* @returns {!Long} Sum
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.add = function add(addend) {
|
||||
if (!isLong(addend))
|
||||
@ -858,7 +810,6 @@
|
||||
* Returns the difference of this and the specified Long.
|
||||
* @param {!Long|number|string} subtrahend Subtrahend
|
||||
* @returns {!Long} Difference
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.subtract = function subtract(subtrahend) {
|
||||
if (!isLong(subtrahend))
|
||||
@ -871,7 +822,6 @@
|
||||
* @function
|
||||
* @param {!Long|number|string} subtrahend Subtrahend
|
||||
* @returns {!Long} Difference
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.sub = LongPrototype.subtract;
|
||||
|
||||
@ -879,7 +829,6 @@
|
||||
* Returns the product of this and the specified Long.
|
||||
* @param {!Long|number|string} multiplier Multiplier
|
||||
* @returns {!Long} Product
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.multiply = function multiply(multiplier) {
|
||||
if (this.isZero())
|
||||
@ -947,7 +896,6 @@
|
||||
* @function
|
||||
* @param {!Long|number|string} multiplier Multiplier
|
||||
* @returns {!Long} Product
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.mul = LongPrototype.multiply;
|
||||
|
||||
@ -956,7 +904,6 @@
|
||||
* unsigned if this Long is unsigned.
|
||||
* @param {!Long|number|string} divisor Divisor
|
||||
* @returns {!Long} Quotient
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.divide = function divide(divisor) {
|
||||
if (!isLong(divisor))
|
||||
@ -967,6 +914,8 @@
|
||||
return this.unsigned ? UZERO : ZERO;
|
||||
var approx, rem, res;
|
||||
if (!this.unsigned) {
|
||||
// This section is only relevant for signed longs and is derived from the
|
||||
// closure library as a whole.
|
||||
if (this.eq(MIN_VALUE)) {
|
||||
if (divisor.eq(ONE) || divisor.eq(NEG_ONE))
|
||||
return MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE
|
||||
@ -992,19 +941,18 @@
|
||||
return this.neg().div(divisor).neg();
|
||||
} else if (divisor.isNegative())
|
||||
return this.div(divisor.neg()).neg();
|
||||
} else if (!divisor.unsigned)
|
||||
divisor = divisor.toUnsigned();
|
||||
|
||||
// The algorithm below has not been made for unsigned longs. It's therefore
|
||||
// required to take special care of the MSB prior to running it.
|
||||
if (this.unsigned) {
|
||||
res = ZERO;
|
||||
} else {
|
||||
// The algorithm below has not been made for unsigned longs. It's therefore
|
||||
// required to take special care of the MSB prior to running it.
|
||||
if (!divisor.unsigned)
|
||||
divisor = divisor.toUnsigned();
|
||||
if (divisor.gt(this))
|
||||
return UZERO;
|
||||
if (divisor.gt(this.shru(1))) // 15 >>> 1 = 7 ; with divisor = 8 ; true
|
||||
return UONE;
|
||||
res = UZERO;
|
||||
} else
|
||||
res = ZERO;
|
||||
}
|
||||
|
||||
// Repeat the following until the remainder is less than other: find a
|
||||
// floating-point that approximates remainder / other *from below*, add this
|
||||
@ -1048,7 +996,6 @@
|
||||
* @function
|
||||
* @param {!Long|number|string} divisor Divisor
|
||||
* @returns {!Long} Quotient
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.div = LongPrototype.divide;
|
||||
|
||||
@ -1056,7 +1003,6 @@
|
||||
* Returns this Long modulo the specified.
|
||||
* @param {!Long|number|string} divisor Divisor
|
||||
* @returns {!Long} Remainder
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.modulo = function modulo(divisor) {
|
||||
if (!isLong(divisor))
|
||||
@ -1069,14 +1015,12 @@
|
||||
* @function
|
||||
* @param {!Long|number|string} divisor Divisor
|
||||
* @returns {!Long} Remainder
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.mod = LongPrototype.modulo;
|
||||
|
||||
/**
|
||||
* Returns the bitwise NOT of this Long.
|
||||
* @returns {!Long}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.not = function not() {
|
||||
return fromBits(~this.low, ~this.high, this.unsigned);
|
||||
@ -1086,7 +1030,6 @@
|
||||
* Returns the bitwise AND of this Long and the specified.
|
||||
* @param {!Long|number|string} other Other Long
|
||||
* @returns {!Long}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.and = function and(other) {
|
||||
if (!isLong(other))
|
||||
@ -1098,7 +1041,6 @@
|
||||
* Returns the bitwise OR of this Long and the specified.
|
||||
* @param {!Long|number|string} other Other Long
|
||||
* @returns {!Long}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.or = function or(other) {
|
||||
if (!isLong(other))
|
||||
@ -1110,7 +1052,6 @@
|
||||
* Returns the bitwise XOR of this Long and the given one.
|
||||
* @param {!Long|number|string} other Other Long
|
||||
* @returns {!Long}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.xor = function xor(other) {
|
||||
if (!isLong(other))
|
||||
@ -1122,7 +1063,6 @@
|
||||
* Returns this Long with bits shifted to the left by the given amount.
|
||||
* @param {number|!Long} numBits Number of bits
|
||||
* @returns {!Long} Shifted Long
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.shiftLeft = function shiftLeft(numBits) {
|
||||
if (isLong(numBits))
|
||||
@ -1140,7 +1080,6 @@
|
||||
* @function
|
||||
* @param {number|!Long} numBits Number of bits
|
||||
* @returns {!Long} Shifted Long
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.shl = LongPrototype.shiftLeft;
|
||||
|
||||
@ -1148,7 +1087,6 @@
|
||||
* Returns this Long with bits arithmetically shifted to the right by the given amount.
|
||||
* @param {number|!Long} numBits Number of bits
|
||||
* @returns {!Long} Shifted Long
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.shiftRight = function shiftRight(numBits) {
|
||||
if (isLong(numBits))
|
||||
@ -1166,7 +1104,6 @@
|
||||
* @function
|
||||
* @param {number|!Long} numBits Number of bits
|
||||
* @returns {!Long} Shifted Long
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.shr = LongPrototype.shiftRight;
|
||||
|
||||
@ -1174,7 +1111,6 @@
|
||||
* Returns this Long with bits logically shifted to the right by the given amount.
|
||||
* @param {number|!Long} numBits Number of bits
|
||||
* @returns {!Long} Shifted Long
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.shiftRightUnsigned = function shiftRightUnsigned(numBits) {
|
||||
if (isLong(numBits))
|
||||
@ -1199,14 +1135,12 @@
|
||||
* @function
|
||||
* @param {number|!Long} numBits Number of bits
|
||||
* @returns {!Long} Shifted Long
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.shru = LongPrototype.shiftRightUnsigned;
|
||||
|
||||
/**
|
||||
* Converts this Long to signed.
|
||||
* @returns {!Long} Signed long
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.toSigned = function toSigned() {
|
||||
if (!this.unsigned)
|
||||
@ -1217,7 +1151,6 @@
|
||||
/**
|
||||
* Converts this Long to unsigned.
|
||||
* @returns {!Long} Unsigned long
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.toUnsigned = function toUnsigned() {
|
||||
if (this.unsigned)
|
||||
@ -1225,6 +1158,53 @@
|
||||
return fromBits(this.low, this.high, true);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts this Long to its byte representation.
|
||||
* @param {boolean=} le Whether little or big endian, defaults to big endian
|
||||
* @returns {!Array.<number>} Byte representation
|
||||
*/
|
||||
LongPrototype.toBytes = function(le) {
|
||||
return le ? this.toBytesLE() : this.toBytesBE();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts this Long to its little endian byte representation.
|
||||
* @returns {!Array.<number>} Little endian byte representation
|
||||
*/
|
||||
LongPrototype.toBytesLE = function() {
|
||||
var hi = this.high,
|
||||
lo = this.low;
|
||||
return [
|
||||
lo & 0xff,
|
||||
(lo >>> 8) & 0xff,
|
||||
(lo >>> 16) & 0xff,
|
||||
(lo >>> 24) & 0xff,
|
||||
hi & 0xff,
|
||||
(hi >>> 8) & 0xff,
|
||||
(hi >>> 16) & 0xff,
|
||||
(hi >>> 24) & 0xff
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts this Long to its big endian byte representation.
|
||||
* @returns {!Array.<number>} Big endian byte representation
|
||||
*/
|
||||
LongPrototype.toBytesBE = function() {
|
||||
var hi = this.high,
|
||||
lo = this.low;
|
||||
return [
|
||||
(hi >>> 24) & 0xff,
|
||||
(hi >>> 16) & 0xff,
|
||||
(hi >>> 8) & 0xff,
|
||||
hi & 0xff,
|
||||
(lo >>> 24) & 0xff,
|
||||
(lo >>> 16) & 0xff,
|
||||
(lo >>> 8) & 0xff,
|
||||
lo & 0xff
|
||||
];
|
||||
}
|
||||
|
||||
return Long;
|
||||
});
|
||||
|
||||
|
||||
179
dist/libsignal-protocol.js
vendored
179
dist/libsignal-protocol.js
vendored
@ -25399,21 +25399,18 @@ Curve25519Worker.prototype = {
|
||||
/**
|
||||
* The low 32 bits as a signed value.
|
||||
* @type {number}
|
||||
* @expose
|
||||
*/
|
||||
this.low = low | 0;
|
||||
|
||||
/**
|
||||
* The high 32 bits as a signed value.
|
||||
* @type {number}
|
||||
* @expose
|
||||
*/
|
||||
this.high = high | 0;
|
||||
|
||||
/**
|
||||
* Whether unsigned or not.
|
||||
* @type {boolean}
|
||||
* @expose
|
||||
*/
|
||||
this.unsigned = !!unsigned;
|
||||
}
|
||||
@ -25439,10 +25436,9 @@ Curve25519Worker.prototype = {
|
||||
* An indicator used to reliably determine if an object is a Long or not.
|
||||
* @type {boolean}
|
||||
* @const
|
||||
* @expose
|
||||
* @private
|
||||
*/
|
||||
Long.__isLong__;
|
||||
Long.prototype.__isLong__;
|
||||
|
||||
Object.defineProperty(Long.prototype, "__isLong__", {
|
||||
value: true,
|
||||
@ -25465,7 +25461,6 @@ Curve25519Worker.prototype = {
|
||||
* @function
|
||||
* @param {*} obj Object
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
Long.isLong = isLong;
|
||||
|
||||
@ -25522,7 +25517,6 @@ Curve25519Worker.prototype = {
|
||||
* @param {number} value The 32 bit integer in question
|
||||
* @param {boolean=} unsigned Whether unsigned or not, defaults to `false` for signed
|
||||
* @returns {!Long} The corresponding Long value
|
||||
* @expose
|
||||
*/
|
||||
Long.fromInt = fromInt;
|
||||
|
||||
@ -25557,7 +25551,6 @@ Curve25519Worker.prototype = {
|
||||
* @param {number} value The number in question
|
||||
* @param {boolean=} unsigned Whether unsigned or not, defaults to `false` for signed
|
||||
* @returns {!Long} The corresponding Long value
|
||||
* @expose
|
||||
*/
|
||||
Long.fromNumber = fromNumber;
|
||||
|
||||
@ -25580,7 +25573,6 @@ Curve25519Worker.prototype = {
|
||||
* @param {number} highBits The high 32 bits
|
||||
* @param {boolean=} unsigned Whether unsigned or not, defaults to `false` for signed
|
||||
* @returns {!Long} The corresponding Long value
|
||||
* @expose
|
||||
*/
|
||||
Long.fromBits = fromBits;
|
||||
|
||||
@ -25650,7 +25642,6 @@ Curve25519Worker.prototype = {
|
||||
* @param {(boolean|number)=} unsigned Whether unsigned or not, defaults to `false` for signed
|
||||
* @param {number=} radix The radix in which the text is written (2-36), defaults to 10
|
||||
* @returns {!Long} The corresponding Long value
|
||||
* @expose
|
||||
*/
|
||||
Long.fromString = fromString;
|
||||
|
||||
@ -25676,7 +25667,6 @@ Curve25519Worker.prototype = {
|
||||
* @function
|
||||
* @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val Value
|
||||
* @returns {!Long}
|
||||
* @expose
|
||||
*/
|
||||
Long.fromValue = fromValue;
|
||||
|
||||
@ -25734,7 +25724,6 @@ Curve25519Worker.prototype = {
|
||||
/**
|
||||
* Signed zero.
|
||||
* @type {!Long}
|
||||
* @expose
|
||||
*/
|
||||
Long.ZERO = ZERO;
|
||||
|
||||
@ -25747,7 +25736,6 @@ Curve25519Worker.prototype = {
|
||||
/**
|
||||
* Unsigned zero.
|
||||
* @type {!Long}
|
||||
* @expose
|
||||
*/
|
||||
Long.UZERO = UZERO;
|
||||
|
||||
@ -25760,7 +25748,6 @@ Curve25519Worker.prototype = {
|
||||
/**
|
||||
* Signed one.
|
||||
* @type {!Long}
|
||||
* @expose
|
||||
*/
|
||||
Long.ONE = ONE;
|
||||
|
||||
@ -25773,7 +25760,6 @@ Curve25519Worker.prototype = {
|
||||
/**
|
||||
* Unsigned one.
|
||||
* @type {!Long}
|
||||
* @expose
|
||||
*/
|
||||
Long.UONE = UONE;
|
||||
|
||||
@ -25786,7 +25772,6 @@ Curve25519Worker.prototype = {
|
||||
/**
|
||||
* Signed negative one.
|
||||
* @type {!Long}
|
||||
* @expose
|
||||
*/
|
||||
Long.NEG_ONE = NEG_ONE;
|
||||
|
||||
@ -25799,7 +25784,6 @@ Curve25519Worker.prototype = {
|
||||
/**
|
||||
* Maximum signed value.
|
||||
* @type {!Long}
|
||||
* @expose
|
||||
*/
|
||||
Long.MAX_VALUE = MAX_VALUE;
|
||||
|
||||
@ -25812,7 +25796,6 @@ Curve25519Worker.prototype = {
|
||||
/**
|
||||
* Maximum unsigned value.
|
||||
* @type {!Long}
|
||||
* @expose
|
||||
*/
|
||||
Long.MAX_UNSIGNED_VALUE = MAX_UNSIGNED_VALUE;
|
||||
|
||||
@ -25825,7 +25808,6 @@ Curve25519Worker.prototype = {
|
||||
/**
|
||||
* Minimum signed value.
|
||||
* @type {!Long}
|
||||
* @expose
|
||||
*/
|
||||
Long.MIN_VALUE = MIN_VALUE;
|
||||
|
||||
@ -25838,7 +25820,6 @@ Curve25519Worker.prototype = {
|
||||
/**
|
||||
* Converts the Long to a 32 bit integer, assuming it is a 32 bit integer.
|
||||
* @returns {number}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.toInt = function toInt() {
|
||||
return this.unsigned ? this.low >>> 0 : this.low;
|
||||
@ -25847,7 +25828,6 @@ Curve25519Worker.prototype = {
|
||||
/**
|
||||
* Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa).
|
||||
* @returns {number}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.toNumber = function toNumber() {
|
||||
if (this.unsigned)
|
||||
@ -25861,7 +25841,6 @@ Curve25519Worker.prototype = {
|
||||
* @returns {string}
|
||||
* @override
|
||||
* @throws {RangeError} If `radix` is out of range
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.toString = function toString(radix) {
|
||||
radix = radix || 10;
|
||||
@ -25904,7 +25883,6 @@ Curve25519Worker.prototype = {
|
||||
/**
|
||||
* Gets the high 32 bits as a signed integer.
|
||||
* @returns {number} Signed high bits
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.getHighBits = function getHighBits() {
|
||||
return this.high;
|
||||
@ -25913,7 +25891,6 @@ Curve25519Worker.prototype = {
|
||||
/**
|
||||
* Gets the high 32 bits as an unsigned integer.
|
||||
* @returns {number} Unsigned high bits
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.getHighBitsUnsigned = function getHighBitsUnsigned() {
|
||||
return this.high >>> 0;
|
||||
@ -25922,7 +25899,6 @@ Curve25519Worker.prototype = {
|
||||
/**
|
||||
* Gets the low 32 bits as a signed integer.
|
||||
* @returns {number} Signed low bits
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.getLowBits = function getLowBits() {
|
||||
return this.low;
|
||||
@ -25931,7 +25907,6 @@ Curve25519Worker.prototype = {
|
||||
/**
|
||||
* Gets the low 32 bits as an unsigned integer.
|
||||
* @returns {number} Unsigned low bits
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.getLowBitsUnsigned = function getLowBitsUnsigned() {
|
||||
return this.low >>> 0;
|
||||
@ -25940,7 +25915,6 @@ Curve25519Worker.prototype = {
|
||||
/**
|
||||
* Gets the number of bits needed to represent the absolute value of this Long.
|
||||
* @returns {number}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.getNumBitsAbs = function getNumBitsAbs() {
|
||||
if (this.isNegative()) // Unsigned Longs are never negative
|
||||
@ -25955,7 +25929,6 @@ Curve25519Worker.prototype = {
|
||||
/**
|
||||
* Tests if this Long's value equals zero.
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.isZero = function isZero() {
|
||||
return this.high === 0 && this.low === 0;
|
||||
@ -25964,7 +25937,6 @@ Curve25519Worker.prototype = {
|
||||
/**
|
||||
* Tests if this Long's value is negative.
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.isNegative = function isNegative() {
|
||||
return !this.unsigned && this.high < 0;
|
||||
@ -25973,7 +25945,6 @@ Curve25519Worker.prototype = {
|
||||
/**
|
||||
* Tests if this Long's value is positive.
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.isPositive = function isPositive() {
|
||||
return this.unsigned || this.high >= 0;
|
||||
@ -25982,7 +25953,6 @@ Curve25519Worker.prototype = {
|
||||
/**
|
||||
* Tests if this Long's value is odd.
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.isOdd = function isOdd() {
|
||||
return (this.low & 1) === 1;
|
||||
@ -25991,7 +25961,6 @@ Curve25519Worker.prototype = {
|
||||
/**
|
||||
* Tests if this Long's value is even.
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.isEven = function isEven() {
|
||||
return (this.low & 1) === 0;
|
||||
@ -26001,7 +25970,6 @@ Curve25519Worker.prototype = {
|
||||
* Tests if this Long's value equals the specified's.
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.equals = function equals(other) {
|
||||
if (!isLong(other))
|
||||
@ -26016,7 +25984,6 @@ Curve25519Worker.prototype = {
|
||||
* @function
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.eq = LongPrototype.equals;
|
||||
|
||||
@ -26024,7 +25991,6 @@ Curve25519Worker.prototype = {
|
||||
* Tests if this Long's value differs from the specified's.
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.notEquals = function notEquals(other) {
|
||||
return !this.eq(/* validates */ other);
|
||||
@ -26035,7 +26001,6 @@ Curve25519Worker.prototype = {
|
||||
* @function
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.neq = LongPrototype.notEquals;
|
||||
|
||||
@ -26043,7 +26008,6 @@ Curve25519Worker.prototype = {
|
||||
* Tests if this Long's value is less than the specified's.
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.lessThan = function lessThan(other) {
|
||||
return this.comp(/* validates */ other) < 0;
|
||||
@ -26054,7 +26018,6 @@ Curve25519Worker.prototype = {
|
||||
* @function
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.lt = LongPrototype.lessThan;
|
||||
|
||||
@ -26062,7 +26025,6 @@ Curve25519Worker.prototype = {
|
||||
* Tests if this Long's value is less than or equal the specified's.
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) {
|
||||
return this.comp(/* validates */ other) <= 0;
|
||||
@ -26073,7 +26035,6 @@ Curve25519Worker.prototype = {
|
||||
* @function
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.lte = LongPrototype.lessThanOrEqual;
|
||||
|
||||
@ -26081,7 +26042,6 @@ Curve25519Worker.prototype = {
|
||||
* Tests if this Long's value is greater than the specified's.
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.greaterThan = function greaterThan(other) {
|
||||
return this.comp(/* validates */ other) > 0;
|
||||
@ -26092,7 +26052,6 @@ Curve25519Worker.prototype = {
|
||||
* @function
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.gt = LongPrototype.greaterThan;
|
||||
|
||||
@ -26100,7 +26059,6 @@ Curve25519Worker.prototype = {
|
||||
* Tests if this Long's value is greater than or equal the specified's.
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) {
|
||||
return this.comp(/* validates */ other) >= 0;
|
||||
@ -26111,7 +26069,6 @@ Curve25519Worker.prototype = {
|
||||
* @function
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {boolean}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.gte = LongPrototype.greaterThanOrEqual;
|
||||
|
||||
@ -26120,7 +26077,6 @@ Curve25519Worker.prototype = {
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {number} 0 if they are the same, 1 if the this is greater and -1
|
||||
* if the given one is greater
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.compare = function compare(other) {
|
||||
if (!isLong(other))
|
||||
@ -26146,14 +26102,12 @@ Curve25519Worker.prototype = {
|
||||
* @param {!Long|number|string} other Other value
|
||||
* @returns {number} 0 if they are the same, 1 if the this is greater and -1
|
||||
* if the given one is greater
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.comp = LongPrototype.compare;
|
||||
|
||||
/**
|
||||
* Negates this Long's value.
|
||||
* @returns {!Long} Negated Long
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.negate = function negate() {
|
||||
if (!this.unsigned && this.eq(MIN_VALUE))
|
||||
@ -26165,7 +26119,6 @@ Curve25519Worker.prototype = {
|
||||
* Negates this Long's value. This is an alias of {@link Long#negate}.
|
||||
* @function
|
||||
* @returns {!Long} Negated Long
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.neg = LongPrototype.negate;
|
||||
|
||||
@ -26173,7 +26126,6 @@ Curve25519Worker.prototype = {
|
||||
* Returns the sum of this and the specified Long.
|
||||
* @param {!Long|number|string} addend Addend
|
||||
* @returns {!Long} Sum
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.add = function add(addend) {
|
||||
if (!isLong(addend))
|
||||
@ -26210,7 +26162,6 @@ Curve25519Worker.prototype = {
|
||||
* Returns the difference of this and the specified Long.
|
||||
* @param {!Long|number|string} subtrahend Subtrahend
|
||||
* @returns {!Long} Difference
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.subtract = function subtract(subtrahend) {
|
||||
if (!isLong(subtrahend))
|
||||
@ -26223,7 +26174,6 @@ Curve25519Worker.prototype = {
|
||||
* @function
|
||||
* @param {!Long|number|string} subtrahend Subtrahend
|
||||
* @returns {!Long} Difference
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.sub = LongPrototype.subtract;
|
||||
|
||||
@ -26231,7 +26181,6 @@ Curve25519Worker.prototype = {
|
||||
* Returns the product of this and the specified Long.
|
||||
* @param {!Long|number|string} multiplier Multiplier
|
||||
* @returns {!Long} Product
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.multiply = function multiply(multiplier) {
|
||||
if (this.isZero())
|
||||
@ -26299,7 +26248,6 @@ Curve25519Worker.prototype = {
|
||||
* @function
|
||||
* @param {!Long|number|string} multiplier Multiplier
|
||||
* @returns {!Long} Product
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.mul = LongPrototype.multiply;
|
||||
|
||||
@ -26308,7 +26256,6 @@ Curve25519Worker.prototype = {
|
||||
* unsigned if this Long is unsigned.
|
||||
* @param {!Long|number|string} divisor Divisor
|
||||
* @returns {!Long} Quotient
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.divide = function divide(divisor) {
|
||||
if (!isLong(divisor))
|
||||
@ -26319,6 +26266,8 @@ Curve25519Worker.prototype = {
|
||||
return this.unsigned ? UZERO : ZERO;
|
||||
var approx, rem, res;
|
||||
if (!this.unsigned) {
|
||||
// This section is only relevant for signed longs and is derived from the
|
||||
// closure library as a whole.
|
||||
if (this.eq(MIN_VALUE)) {
|
||||
if (divisor.eq(ONE) || divisor.eq(NEG_ONE))
|
||||
return MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE
|
||||
@ -26344,19 +26293,18 @@ Curve25519Worker.prototype = {
|
||||
return this.neg().div(divisor).neg();
|
||||
} else if (divisor.isNegative())
|
||||
return this.div(divisor.neg()).neg();
|
||||
} else if (!divisor.unsigned)
|
||||
divisor = divisor.toUnsigned();
|
||||
|
||||
// The algorithm below has not been made for unsigned longs. It's therefore
|
||||
// required to take special care of the MSB prior to running it.
|
||||
if (this.unsigned) {
|
||||
res = ZERO;
|
||||
} else {
|
||||
// The algorithm below has not been made for unsigned longs. It's therefore
|
||||
// required to take special care of the MSB prior to running it.
|
||||
if (!divisor.unsigned)
|
||||
divisor = divisor.toUnsigned();
|
||||
if (divisor.gt(this))
|
||||
return UZERO;
|
||||
if (divisor.gt(this.shru(1))) // 15 >>> 1 = 7 ; with divisor = 8 ; true
|
||||
return UONE;
|
||||
res = UZERO;
|
||||
} else
|
||||
res = ZERO;
|
||||
}
|
||||
|
||||
// Repeat the following until the remainder is less than other: find a
|
||||
// floating-point that approximates remainder / other *from below*, add this
|
||||
@ -26400,7 +26348,6 @@ Curve25519Worker.prototype = {
|
||||
* @function
|
||||
* @param {!Long|number|string} divisor Divisor
|
||||
* @returns {!Long} Quotient
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.div = LongPrototype.divide;
|
||||
|
||||
@ -26408,7 +26355,6 @@ Curve25519Worker.prototype = {
|
||||
* Returns this Long modulo the specified.
|
||||
* @param {!Long|number|string} divisor Divisor
|
||||
* @returns {!Long} Remainder
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.modulo = function modulo(divisor) {
|
||||
if (!isLong(divisor))
|
||||
@ -26421,14 +26367,12 @@ Curve25519Worker.prototype = {
|
||||
* @function
|
||||
* @param {!Long|number|string} divisor Divisor
|
||||
* @returns {!Long} Remainder
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.mod = LongPrototype.modulo;
|
||||
|
||||
/**
|
||||
* Returns the bitwise NOT of this Long.
|
||||
* @returns {!Long}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.not = function not() {
|
||||
return fromBits(~this.low, ~this.high, this.unsigned);
|
||||
@ -26438,7 +26382,6 @@ Curve25519Worker.prototype = {
|
||||
* Returns the bitwise AND of this Long and the specified.
|
||||
* @param {!Long|number|string} other Other Long
|
||||
* @returns {!Long}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.and = function and(other) {
|
||||
if (!isLong(other))
|
||||
@ -26450,7 +26393,6 @@ Curve25519Worker.prototype = {
|
||||
* Returns the bitwise OR of this Long and the specified.
|
||||
* @param {!Long|number|string} other Other Long
|
||||
* @returns {!Long}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.or = function or(other) {
|
||||
if (!isLong(other))
|
||||
@ -26462,7 +26404,6 @@ Curve25519Worker.prototype = {
|
||||
* Returns the bitwise XOR of this Long and the given one.
|
||||
* @param {!Long|number|string} other Other Long
|
||||
* @returns {!Long}
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.xor = function xor(other) {
|
||||
if (!isLong(other))
|
||||
@ -26474,7 +26415,6 @@ Curve25519Worker.prototype = {
|
||||
* Returns this Long with bits shifted to the left by the given amount.
|
||||
* @param {number|!Long} numBits Number of bits
|
||||
* @returns {!Long} Shifted Long
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.shiftLeft = function shiftLeft(numBits) {
|
||||
if (isLong(numBits))
|
||||
@ -26492,7 +26432,6 @@ Curve25519Worker.prototype = {
|
||||
* @function
|
||||
* @param {number|!Long} numBits Number of bits
|
||||
* @returns {!Long} Shifted Long
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.shl = LongPrototype.shiftLeft;
|
||||
|
||||
@ -26500,7 +26439,6 @@ Curve25519Worker.prototype = {
|
||||
* Returns this Long with bits arithmetically shifted to the right by the given amount.
|
||||
* @param {number|!Long} numBits Number of bits
|
||||
* @returns {!Long} Shifted Long
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.shiftRight = function shiftRight(numBits) {
|
||||
if (isLong(numBits))
|
||||
@ -26518,7 +26456,6 @@ Curve25519Worker.prototype = {
|
||||
* @function
|
||||
* @param {number|!Long} numBits Number of bits
|
||||
* @returns {!Long} Shifted Long
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.shr = LongPrototype.shiftRight;
|
||||
|
||||
@ -26526,7 +26463,6 @@ Curve25519Worker.prototype = {
|
||||
* Returns this Long with bits logically shifted to the right by the given amount.
|
||||
* @param {number|!Long} numBits Number of bits
|
||||
* @returns {!Long} Shifted Long
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.shiftRightUnsigned = function shiftRightUnsigned(numBits) {
|
||||
if (isLong(numBits))
|
||||
@ -26551,14 +26487,12 @@ Curve25519Worker.prototype = {
|
||||
* @function
|
||||
* @param {number|!Long} numBits Number of bits
|
||||
* @returns {!Long} Shifted Long
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.shru = LongPrototype.shiftRightUnsigned;
|
||||
|
||||
/**
|
||||
* Converts this Long to signed.
|
||||
* @returns {!Long} Signed long
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.toSigned = function toSigned() {
|
||||
if (!this.unsigned)
|
||||
@ -26569,7 +26503,6 @@ Curve25519Worker.prototype = {
|
||||
/**
|
||||
* Converts this Long to unsigned.
|
||||
* @returns {!Long} Unsigned long
|
||||
* @expose
|
||||
*/
|
||||
LongPrototype.toUnsigned = function toUnsigned() {
|
||||
if (this.unsigned)
|
||||
@ -26577,6 +26510,53 @@ Curve25519Worker.prototype = {
|
||||
return fromBits(this.low, this.high, true);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts this Long to its byte representation.
|
||||
* @param {boolean=} le Whether little or big endian, defaults to big endian
|
||||
* @returns {!Array.<number>} Byte representation
|
||||
*/
|
||||
LongPrototype.toBytes = function(le) {
|
||||
return le ? this.toBytesLE() : this.toBytesBE();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts this Long to its little endian byte representation.
|
||||
* @returns {!Array.<number>} Little endian byte representation
|
||||
*/
|
||||
LongPrototype.toBytesLE = function() {
|
||||
var hi = this.high,
|
||||
lo = this.low;
|
||||
return [
|
||||
lo & 0xff,
|
||||
(lo >>> 8) & 0xff,
|
||||
(lo >>> 16) & 0xff,
|
||||
(lo >>> 24) & 0xff,
|
||||
hi & 0xff,
|
||||
(hi >>> 8) & 0xff,
|
||||
(hi >>> 16) & 0xff,
|
||||
(hi >>> 24) & 0xff
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts this Long to its big endian byte representation.
|
||||
* @returns {!Array.<number>} Big endian byte representation
|
||||
*/
|
||||
LongPrototype.toBytesBE = function() {
|
||||
var hi = this.high,
|
||||
lo = this.low;
|
||||
return [
|
||||
(hi >>> 24) & 0xff,
|
||||
(hi >>> 16) & 0xff,
|
||||
(hi >>> 8) & 0xff,
|
||||
hi & 0xff,
|
||||
(lo >>> 24) & 0xff,
|
||||
(lo >>> 16) & 0xff,
|
||||
(lo >>> 8) & 0xff,
|
||||
lo & 0xff
|
||||
];
|
||||
}
|
||||
|
||||
return Long;
|
||||
});
|
||||
|
||||
@ -35311,8 +35291,6 @@ var Internal = Internal || {};
|
||||
result = result | (a[i] ^ b[i]);
|
||||
}
|
||||
if (result !== 0) {
|
||||
console.log('Our MAC ', dcodeIO.ByteBuffer.wrap(calculated_mac).toHex());
|
||||
console.log('Their MAC', dcodeIO.ByteBuffer.wrap(mac).toHex());
|
||||
throw new Error("Bad MAC");
|
||||
}
|
||||
});
|
||||
@ -35762,6 +35740,10 @@ Internal.SessionRecord = function() {
|
||||
delete sessions[util.toString(oldestBaseKey)];
|
||||
}
|
||||
},
|
||||
deleteAllSessions: function() {
|
||||
// Used primarily in session reset scenarios, where we really delete sessions
|
||||
this.sessions = {};
|
||||
}
|
||||
};
|
||||
|
||||
return SessionRecord;
|
||||
@ -36032,14 +36014,7 @@ libsignal.SessionBuilder = function (storage, remoteAddress) {
|
||||
this.processV3 = builder.processV3.bind(builder);
|
||||
};
|
||||
|
||||
function SessionCipher(storage, remoteAddress, options) {
|
||||
options = options || {};
|
||||
|
||||
if (typeof options.messageKeysLimit === 'undefined') {
|
||||
options.messageKeysLimit = 1000;
|
||||
}
|
||||
|
||||
this.messageKeysLimit = options.messageKeysLimit;
|
||||
function SessionCipher(storage, remoteAddress) {
|
||||
this.remoteAddress = remoteAddress;
|
||||
this.storage = storage;
|
||||
}
|
||||
@ -36257,7 +36232,7 @@ SessionCipher.prototype = {
|
||||
}.bind(this));
|
||||
},
|
||||
doDecryptWhisperMessage: function(messageBytes, session) {
|
||||
if (!messageBytes instanceof ArrayBuffer) {
|
||||
if (!(messageBytes instanceof ArrayBuffer)) {
|
||||
throw new Error("Expected messageBytes to be an ArrayBuffer");
|
||||
}
|
||||
var version = (new Uint8Array(messageBytes))[0];
|
||||
@ -36312,15 +36287,14 @@ SessionCipher.prototype = {
|
||||
});
|
||||
},
|
||||
fillMessageKeys: function(chain, counter) {
|
||||
if (this.messageKeysLimit && Object.keys(chain.messageKeys).length >= this.messageKeysLimit) {
|
||||
console.log("Too many message keys for chain");
|
||||
return Promise.resolve(); // Stalker, much?
|
||||
}
|
||||
|
||||
if (chain.chainKey.counter >= counter) {
|
||||
return Promise.resolve(); // Already calculated
|
||||
}
|
||||
|
||||
if (counter - chain.chainKey.counter > 2000) {
|
||||
throw new Error('Over 2000 messages into the future!');
|
||||
}
|
||||
|
||||
if (chain.chainKey.key === undefined) {
|
||||
throw new Error("Got invalid request to extend chain after it was already closed");
|
||||
}
|
||||
@ -36432,11 +36406,25 @@ SessionCipher.prototype = {
|
||||
return this.storage.storeSession(address, record.serialize());
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
},
|
||||
deleteAllSessionsForDevice: function() {
|
||||
// Used in session reset scenarios, where we really need to delete
|
||||
var address = this.remoteAddress.toString();
|
||||
return Internal.SessionLock.queueJobForNumber(address, function() {
|
||||
return this.getRecord(address).then(function(record) {
|
||||
if (record === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
record.deleteAllSessions();
|
||||
return this.storage.storeSession(address, record.serialize());
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
}
|
||||
};
|
||||
|
||||
libsignal.SessionCipher = function(storage, remoteAddress, options) {
|
||||
var cipher = new SessionCipher(storage, remoteAddress, options);
|
||||
libsignal.SessionCipher = function(storage, remoteAddress) {
|
||||
var cipher = new SessionCipher(storage, remoteAddress);
|
||||
|
||||
// returns a Promise that resolves to a ciphertext object
|
||||
this.encrypt = cipher.encrypt.bind(cipher);
|
||||
@ -36451,6 +36439,7 @@ libsignal.SessionCipher = function(storage, remoteAddress, options) {
|
||||
this.getRemoteRegistrationId = cipher.getRemoteRegistrationId.bind(cipher);
|
||||
this.hasOpenSession = cipher.hasOpenSession.bind(cipher);
|
||||
this.closeOpenSessionForDevice = cipher.closeOpenSessionForDevice.bind(cipher);
|
||||
this.deleteAllSessionsForDevice = cipher.deleteAllSessionsForDevice.bind(cipher);
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "libsignal-protocol",
|
||||
"repository": "https://github.com/WhisperSystems/libsignal-protocol-javascript.git",
|
||||
"version": "1.2.0",
|
||||
"version": "1.3.0",
|
||||
"license": "GPL-3.0",
|
||||
"dependencies": {
|
||||
"long": "^3.1.0",
|
||||
|
||||
@ -1,11 +1,4 @@
|
||||
function SessionCipher(storage, remoteAddress, options) {
|
||||
options = options || {};
|
||||
|
||||
if (typeof options.messageKeysLimit === 'undefined') {
|
||||
options.messageKeysLimit = 1000;
|
||||
}
|
||||
|
||||
this.messageKeysLimit = options.messageKeysLimit;
|
||||
function SessionCipher(storage, remoteAddress) {
|
||||
this.remoteAddress = remoteAddress;
|
||||
this.storage = storage;
|
||||
}
|
||||
@ -278,15 +271,14 @@ SessionCipher.prototype = {
|
||||
});
|
||||
},
|
||||
fillMessageKeys: function(chain, counter) {
|
||||
if (this.messageKeysLimit && Object.keys(chain.messageKeys).length >= this.messageKeysLimit) {
|
||||
console.log("Too many message keys for chain");
|
||||
return Promise.resolve(); // Stalker, much?
|
||||
}
|
||||
|
||||
if (chain.chainKey.counter >= counter) {
|
||||
return Promise.resolve(); // Already calculated
|
||||
}
|
||||
|
||||
if (counter - chain.chainKey.counter > 2000) {
|
||||
throw new Error('Over 2000 messages into the future!');
|
||||
}
|
||||
|
||||
if (chain.chainKey.key === undefined) {
|
||||
throw new Error("Got invalid request to extend chain after it was already closed");
|
||||
}
|
||||
@ -415,8 +407,8 @@ SessionCipher.prototype = {
|
||||
}
|
||||
};
|
||||
|
||||
libsignal.SessionCipher = function(storage, remoteAddress, options) {
|
||||
var cipher = new SessionCipher(storage, remoteAddress, options);
|
||||
libsignal.SessionCipher = function(storage, remoteAddress) {
|
||||
var cipher = new SessionCipher(storage, remoteAddress);
|
||||
|
||||
// returns a Promise that resolves to a ciphertext object
|
||||
this.encrypt = cipher.encrypt.bind(cipher);
|
||||
|
||||
@ -101,8 +101,6 @@ var Internal = Internal || {};
|
||||
result = result | (a[i] ^ b[i]);
|
||||
}
|
||||
if (result !== 0) {
|
||||
console.log('Our MAC ', dcodeIO.ByteBuffer.wrap(calculated_mac).toHex());
|
||||
console.log('Their MAC', dcodeIO.ByteBuffer.wrap(mac).toHex());
|
||||
throw new Error("Bad MAC");
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user