linter
This commit is contained in:
parent
07f25566ca
commit
f36bb7a04e
@ -9,4 +9,5 @@ module.exports = {
|
|||||||
'plugin:@typescript-eslint/eslint-recommended',
|
'plugin:@typescript-eslint/eslint-recommended',
|
||||||
'plugin:@typescript-eslint/recommended',
|
'plugin:@typescript-eslint/recommended',
|
||||||
],
|
],
|
||||||
|
rules: {},
|
||||||
};
|
};
|
||||||
|
@ -44,7 +44,7 @@ export {
|
|||||||
} from "../crypto/workers/nodeThreadWorker";
|
} from "../crypto/workers/nodeThreadWorker";
|
||||||
|
|
||||||
export class AndroidHttpLib implements HttpRequestLibrary {
|
export class AndroidHttpLib implements HttpRequestLibrary {
|
||||||
useNfcTunnel: boolean = false;
|
useNfcTunnel = false;
|
||||||
|
|
||||||
private nodeHttpLib: HttpRequestLibrary = new NodeHttpLib();
|
private nodeHttpLib: HttpRequestLibrary = new NodeHttpLib();
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ function ts64(x: Uint8Array, i: number, h: number, l: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function vn(x: Uint8Array, xi: number, y: Uint8Array, yi: number, n: number) {
|
function vn(x: Uint8Array, xi: number, y: Uint8Array, yi: number, n: number) {
|
||||||
var i,
|
let i,
|
||||||
d = 0;
|
d = 0;
|
||||||
for (i = 0; i < n; i++) d |= x[xi + i] ^ y[yi + i];
|
for (i = 0; i < n; i++) d |= x[xi + i] ^ y[yi + i];
|
||||||
return (1 & ((d - 1) >>> 8)) - 1;
|
return (1 & ((d - 1) >>> 8)) - 1;
|
||||||
@ -153,7 +153,7 @@ function crypto_verify_32(
|
|||||||
|
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
function core_salsa20(o: Uint8Array, p: Uint8Array, k: Uint8Array, c: Uint8Array) {
|
function core_salsa20(o: Uint8Array, p: Uint8Array, k: Uint8Array, c: Uint8Array) {
|
||||||
var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24,
|
const j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24,
|
||||||
j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24,
|
j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24,
|
||||||
j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24,
|
j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24,
|
||||||
j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24,
|
j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24,
|
||||||
@ -170,11 +170,11 @@ function core_salsa20(o: Uint8Array, p: Uint8Array, k: Uint8Array, c: Uint8Array
|
|||||||
j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24,
|
j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24,
|
||||||
j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24;
|
j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24;
|
||||||
|
|
||||||
var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7,
|
let x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7,
|
||||||
x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14,
|
x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14,
|
||||||
x15 = j15, u;
|
x15 = j15, u;
|
||||||
|
|
||||||
for (var i = 0; i < 20; i += 2) {
|
for (let i = 0; i < 20; i += 2) {
|
||||||
u = x0 + x12 | 0;
|
u = x0 + x12 | 0;
|
||||||
x4 ^= u<<7 | u>>>(32-7);
|
x4 ^= u<<7 | u>>>(32-7);
|
||||||
u = x4 + x0 | 0;
|
u = x4 + x0 | 0;
|
||||||
@ -351,7 +351,7 @@ function core_hsalsa20(
|
|||||||
k: Uint8Array,
|
k: Uint8Array,
|
||||||
c: Uint8Array,
|
c: Uint8Array,
|
||||||
) {
|
) {
|
||||||
var j0 =
|
const j0 =
|
||||||
(c[0] & 0xff) |
|
(c[0] & 0xff) |
|
||||||
((c[1] & 0xff) << 8) |
|
((c[1] & 0xff) << 8) |
|
||||||
((c[2] & 0xff) << 16) |
|
((c[2] & 0xff) << 16) |
|
||||||
@ -432,7 +432,7 @@ function core_hsalsa20(
|
|||||||
((c[14] & 0xff) << 16) |
|
((c[14] & 0xff) << 16) |
|
||||||
((c[15] & 0xff) << 24);
|
((c[15] & 0xff) << 24);
|
||||||
|
|
||||||
var x0 = j0,
|
let x0 = j0,
|
||||||
x1 = j1,
|
x1 = j1,
|
||||||
x2 = j2,
|
x2 = j2,
|
||||||
x3 = j3,
|
x3 = j3,
|
||||||
@ -450,7 +450,7 @@ function core_hsalsa20(
|
|||||||
x15 = j15,
|
x15 = j15,
|
||||||
u;
|
u;
|
||||||
|
|
||||||
for (var i = 0; i < 20; i += 2) {
|
for (let i = 0; i < 20; i += 2) {
|
||||||
u = (x0 + x12) | 0;
|
u = (x0 + x12) | 0;
|
||||||
x4 ^= (u << 7) | (u >>> (32 - 7));
|
x4 ^= (u << 7) | (u >>> (32 - 7));
|
||||||
u = (x4 + x0) | 0;
|
u = (x4 + x0) | 0;
|
||||||
@ -583,7 +583,7 @@ function crypto_core_hsalsa20(
|
|||||||
core_hsalsa20(out, inp, k, c);
|
core_hsalsa20(out, inp, k, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
var sigma = new Uint8Array([
|
const sigma = new Uint8Array([
|
||||||
101,
|
101,
|
||||||
120,
|
120,
|
||||||
112,
|
112,
|
||||||
@ -612,9 +612,9 @@ function crypto_stream_salsa20_xor(
|
|||||||
n: Uint8Array,
|
n: Uint8Array,
|
||||||
k: Uint8Array,
|
k: Uint8Array,
|
||||||
) {
|
) {
|
||||||
var z = new Uint8Array(16),
|
const z = new Uint8Array(16),
|
||||||
x = new Uint8Array(64);
|
x = new Uint8Array(64);
|
||||||
var u, i;
|
let u, i;
|
||||||
for (i = 0; i < 16; i++) z[i] = 0;
|
for (i = 0; i < 16; i++) z[i] = 0;
|
||||||
for (i = 0; i < 8; i++) z[i] = n[i];
|
for (i = 0; i < 8; i++) z[i] = n[i];
|
||||||
while (b >= 64) {
|
while (b >= 64) {
|
||||||
@ -644,9 +644,9 @@ function crypto_stream_salsa20(
|
|||||||
n: Uint8Array,
|
n: Uint8Array,
|
||||||
k: Uint8Array,
|
k: Uint8Array,
|
||||||
) {
|
) {
|
||||||
var z = new Uint8Array(16),
|
const z = new Uint8Array(16),
|
||||||
x = new Uint8Array(64);
|
x = new Uint8Array(64);
|
||||||
var u, i;
|
let u, i;
|
||||||
for (i = 0; i < 16; i++) z[i] = 0;
|
for (i = 0; i < 16; i++) z[i] = 0;
|
||||||
for (i = 0; i < 8; i++) z[i] = n[i];
|
for (i = 0; i < 8; i++) z[i] = n[i];
|
||||||
while (b >= 64) {
|
while (b >= 64) {
|
||||||
@ -675,10 +675,10 @@ function crypto_stream(
|
|||||||
n: Uint8Array,
|
n: Uint8Array,
|
||||||
k: Uint8Array,
|
k: Uint8Array,
|
||||||
) {
|
) {
|
||||||
var s = new Uint8Array(32);
|
const s = new Uint8Array(32);
|
||||||
crypto_core_hsalsa20(s, n, k, sigma);
|
crypto_core_hsalsa20(s, n, k, sigma);
|
||||||
var sn = new Uint8Array(8);
|
const sn = new Uint8Array(8);
|
||||||
for (var i = 0; i < 8; i++) sn[i] = n[i + 16];
|
for (let i = 0; i < 8; i++) sn[i] = n[i + 16];
|
||||||
return crypto_stream_salsa20(c, cpos, d, sn, s);
|
return crypto_stream_salsa20(c, cpos, d, sn, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -691,10 +691,10 @@ function crypto_stream_xor(
|
|||||||
n: Uint8Array,
|
n: Uint8Array,
|
||||||
k: Uint8Array,
|
k: Uint8Array,
|
||||||
) {
|
) {
|
||||||
var s = new Uint8Array(32);
|
const s = new Uint8Array(32);
|
||||||
crypto_core_hsalsa20(s, n, k, sigma);
|
crypto_core_hsalsa20(s, n, k, sigma);
|
||||||
var sn = new Uint8Array(8);
|
const sn = new Uint8Array(8);
|
||||||
for (var i = 0; i < 8; i++) sn[i] = n[i + 16];
|
for (let i = 0; i < 8; i++) sn[i] = n[i + 16];
|
||||||
return crypto_stream_salsa20_xor(c, cpos, m, mpos, d, sn, s);
|
return crypto_stream_salsa20_xor(c, cpos, m, mpos, d, sn, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -712,7 +712,7 @@ class poly1305 {
|
|||||||
fin = 0;
|
fin = 0;
|
||||||
|
|
||||||
constructor(key: Uint8Array) {
|
constructor(key: Uint8Array) {
|
||||||
var t0, t1, t2, t3, t4, t5, t6, t7;
|
let t0, t1, t2, t3, t4, t5, t6, t7;
|
||||||
|
|
||||||
t0 = (key[0] & 0xff) | ((key[1] & 0xff) << 8);
|
t0 = (key[0] & 0xff) | ((key[1] & 0xff) << 8);
|
||||||
this.r[0] = t0 & 0x1fff;
|
this.r[0] = t0 & 0x1fff;
|
||||||
@ -744,11 +744,11 @@ class poly1305 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
blocks(m: Uint8Array, mpos: number, bytes: number) {
|
blocks(m: Uint8Array, mpos: number, bytes: number) {
|
||||||
var hibit = this.fin ? 0 : 1 << 11;
|
const hibit = this.fin ? 0 : 1 << 11;
|
||||||
var t0, t1, t2, t3, t4, t5, t6, t7, c;
|
let t0, t1, t2, t3, t4, t5, t6, t7, c;
|
||||||
var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9;
|
let d0, d1, d2, d3, d4, d5, d6, d7, d8, d9;
|
||||||
|
|
||||||
var h0 = this.h[0],
|
let h0 = this.h[0],
|
||||||
h1 = this.h[1],
|
h1 = this.h[1],
|
||||||
h2 = this.h[2],
|
h2 = this.h[2],
|
||||||
h3 = this.h[3],
|
h3 = this.h[3],
|
||||||
@ -759,7 +759,7 @@ class poly1305 {
|
|||||||
h8 = this.h[8],
|
h8 = this.h[8],
|
||||||
h9 = this.h[9];
|
h9 = this.h[9];
|
||||||
|
|
||||||
var r0 = this.r[0],
|
const r0 = this.r[0],
|
||||||
r1 = this.r[1],
|
r1 = this.r[1],
|
||||||
r2 = this.r[2],
|
r2 = this.r[2],
|
||||||
r3 = this.r[3],
|
r3 = this.r[3],
|
||||||
@ -985,8 +985,8 @@ class poly1305 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
finish(mac: Uint8Array, macpos: number) {
|
finish(mac: Uint8Array, macpos: number) {
|
||||||
var g = new Uint16Array(10);
|
const g = new Uint16Array(10);
|
||||||
var c, mask, f, i;
|
let c, mask, f, i;
|
||||||
|
|
||||||
if (this.leftover) {
|
if (this.leftover) {
|
||||||
i = this.leftover;
|
i = this.leftover;
|
||||||
@ -1062,7 +1062,7 @@ class poly1305 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
update(m: Uint8Array, mpos: number, bytes: number) {
|
update(m: Uint8Array, mpos: number, bytes: number) {
|
||||||
var i, want;
|
let i, want;
|
||||||
|
|
||||||
if (this.leftover) {
|
if (this.leftover) {
|
||||||
want = 16 - this.leftover;
|
want = 16 - this.leftover;
|
||||||
@ -1098,7 +1098,7 @@ function crypto_onetimeauth(
|
|||||||
n: number,
|
n: number,
|
||||||
k: Uint8Array,
|
k: Uint8Array,
|
||||||
) {
|
) {
|
||||||
var s = new poly1305(k);
|
const s = new poly1305(k);
|
||||||
s.update(m, mpos, n);
|
s.update(m, mpos, n);
|
||||||
s.finish(out, outpos);
|
s.finish(out, outpos);
|
||||||
return 0;
|
return 0;
|
||||||
@ -1112,7 +1112,7 @@ function crypto_onetimeauth_verify(
|
|||||||
n: number,
|
n: number,
|
||||||
k: Uint8Array,
|
k: Uint8Array,
|
||||||
) {
|
) {
|
||||||
var x = new Uint8Array(16);
|
const x = new Uint8Array(16);
|
||||||
crypto_onetimeauth(x, 0, m, mpos, n, k);
|
crypto_onetimeauth(x, 0, m, mpos, n, k);
|
||||||
return crypto_verify_16(h, hpos, x, 0);
|
return crypto_verify_16(h, hpos, x, 0);
|
||||||
}
|
}
|
||||||
@ -1124,7 +1124,7 @@ function crypto_secretbox(
|
|||||||
n: Uint8Array,
|
n: Uint8Array,
|
||||||
k: Uint8Array,
|
k: Uint8Array,
|
||||||
) {
|
) {
|
||||||
var i;
|
let i;
|
||||||
if (d < 32) return -1;
|
if (d < 32) return -1;
|
||||||
crypto_stream_xor(c, 0, m, 0, d, n, k);
|
crypto_stream_xor(c, 0, m, 0, d, n, k);
|
||||||
crypto_onetimeauth(c, 16, c, 32, d - 32, c);
|
crypto_onetimeauth(c, 16, c, 32, d - 32, c);
|
||||||
@ -1139,8 +1139,8 @@ function crypto_secretbox_open(
|
|||||||
n: Uint8Array,
|
n: Uint8Array,
|
||||||
k: Uint8Array,
|
k: Uint8Array,
|
||||||
) {
|
) {
|
||||||
var i;
|
let i;
|
||||||
var x = new Uint8Array(32);
|
const x = new Uint8Array(32);
|
||||||
if (d < 32) return -1;
|
if (d < 32) return -1;
|
||||||
crypto_stream(x, 0, 32, n, k);
|
crypto_stream(x, 0, 32, n, k);
|
||||||
if (crypto_onetimeauth_verify(c, 16, c, 32, d - 32, x) !== 0) return -1;
|
if (crypto_onetimeauth_verify(c, 16, c, 32, d - 32, x) !== 0) return -1;
|
||||||
@ -1150,12 +1150,12 @@ function crypto_secretbox_open(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function set25519(r: Float64Array, a: Float64Array) {
|
function set25519(r: Float64Array, a: Float64Array) {
|
||||||
var i;
|
let i;
|
||||||
for (i = 0; i < 16; i++) r[i] = a[i] | 0;
|
for (i = 0; i < 16; i++) r[i] = a[i] | 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function car25519(o: Float64Array) {
|
function car25519(o: Float64Array) {
|
||||||
var i,
|
let i,
|
||||||
v,
|
v,
|
||||||
c = 1;
|
c = 1;
|
||||||
for (i = 0; i < 16; i++) {
|
for (i = 0; i < 16; i++) {
|
||||||
@ -1167,9 +1167,9 @@ function car25519(o: Float64Array) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sel25519(p: Float64Array, q: Float64Array, b: number) {
|
function sel25519(p: Float64Array, q: Float64Array, b: number) {
|
||||||
var t,
|
let t,
|
||||||
c = ~(b - 1);
|
c = ~(b - 1);
|
||||||
for (var i = 0; i < 16; i++) {
|
for (let i = 0; i < 16; i++) {
|
||||||
t = c & (p[i] ^ q[i]);
|
t = c & (p[i] ^ q[i]);
|
||||||
p[i] ^= t;
|
p[i] ^= t;
|
||||||
q[i] ^= t;
|
q[i] ^= t;
|
||||||
@ -1177,8 +1177,8 @@ function sel25519(p: Float64Array, q: Float64Array, b: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function pack25519(o: Uint8Array, n: Float64Array) {
|
function pack25519(o: Uint8Array, n: Float64Array) {
|
||||||
var i, j, b;
|
let i, j, b;
|
||||||
var m = gf(),
|
const m = gf(),
|
||||||
t = gf();
|
t = gf();
|
||||||
for (i = 0; i < 16; i++) t[i] = n[i];
|
for (i = 0; i < 16; i++) t[i] = n[i];
|
||||||
car25519(t);
|
car25519(t);
|
||||||
@ -1202,7 +1202,7 @@ function pack25519(o: Uint8Array, n: Float64Array) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function neq25519(a: Float64Array, b: Float64Array) {
|
function neq25519(a: Float64Array, b: Float64Array) {
|
||||||
var c = new Uint8Array(32),
|
const c = new Uint8Array(32),
|
||||||
d = new Uint8Array(32);
|
d = new Uint8Array(32);
|
||||||
pack25519(c, a);
|
pack25519(c, a);
|
||||||
pack25519(d, b);
|
pack25519(d, b);
|
||||||
@ -1210,27 +1210,27 @@ function neq25519(a: Float64Array, b: Float64Array) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function par25519(a: Float64Array) {
|
function par25519(a: Float64Array) {
|
||||||
var d = new Uint8Array(32);
|
const d = new Uint8Array(32);
|
||||||
pack25519(d, a);
|
pack25519(d, a);
|
||||||
return d[0] & 1;
|
return d[0] & 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
function unpack25519(o: Float64Array, n: Uint8Array) {
|
function unpack25519(o: Float64Array, n: Uint8Array) {
|
||||||
var i;
|
let i;
|
||||||
for (i = 0; i < 16; i++) o[i] = n[2 * i] + (n[2 * i + 1] << 8);
|
for (i = 0; i < 16; i++) o[i] = n[2 * i] + (n[2 * i + 1] << 8);
|
||||||
o[15] &= 0x7fff;
|
o[15] &= 0x7fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
function A(o: Float64Array, a: Float64Array, b: Float64Array) {
|
function A(o: Float64Array, a: Float64Array, b: Float64Array) {
|
||||||
for (var i = 0; i < 16; i++) o[i] = a[i] + b[i];
|
for (let i = 0; i < 16; i++) o[i] = a[i] + b[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
function Z(o: Float64Array, a: Float64Array, b: Float64Array) {
|
function Z(o: Float64Array, a: Float64Array, b: Float64Array) {
|
||||||
for (var i = 0; i < 16; i++) o[i] = a[i] - b[i];
|
for (let i = 0; i < 16; i++) o[i] = a[i] - b[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
function M(o: Float64Array, a: Float64Array, b: Float64Array) {
|
function M(o: Float64Array, a: Float64Array, b: Float64Array) {
|
||||||
var v,
|
let v,
|
||||||
c,
|
c,
|
||||||
t0 = 0,
|
t0 = 0,
|
||||||
t1 = 0,
|
t1 = 0,
|
||||||
@ -1697,8 +1697,8 @@ function S(o: Float64Array, a: Float64Array) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function inv25519(o: Float64Array, i: Float64Array) {
|
function inv25519(o: Float64Array, i: Float64Array) {
|
||||||
var c = gf();
|
const c = gf();
|
||||||
var a;
|
let a;
|
||||||
for (a = 0; a < 16; a++) c[a] = i[a];
|
for (a = 0; a < 16; a++) c[a] = i[a];
|
||||||
for (a = 253; a >= 0; a--) {
|
for (a = 253; a >= 0; a--) {
|
||||||
S(c, c);
|
S(c, c);
|
||||||
@ -1708,8 +1708,8 @@ function inv25519(o: Float64Array, i: Float64Array) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function pow2523(o: Float64Array, i: Float64Array) {
|
function pow2523(o: Float64Array, i: Float64Array) {
|
||||||
var c = gf();
|
const c = gf();
|
||||||
var a;
|
let a;
|
||||||
for (a = 0; a < 16; a++) c[a] = i[a];
|
for (a = 0; a < 16; a++) c[a] = i[a];
|
||||||
for (a = 250; a >= 0; a--) {
|
for (a = 250; a >= 0; a--) {
|
||||||
S(c, c);
|
S(c, c);
|
||||||
@ -1719,11 +1719,11 @@ function pow2523(o: Float64Array, i: Float64Array) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function crypto_scalarmult(q: Uint8Array, n: Uint8Array, p: Uint8Array) {
|
function crypto_scalarmult(q: Uint8Array, n: Uint8Array, p: Uint8Array) {
|
||||||
var z = new Uint8Array(32);
|
const z = new Uint8Array(32);
|
||||||
var x = new Float64Array(80),
|
let x = new Float64Array(80),
|
||||||
r,
|
r,
|
||||||
i;
|
i;
|
||||||
var a = gf(),
|
const a = gf(),
|
||||||
b = gf(),
|
b = gf(),
|
||||||
c = gf(),
|
c = gf(),
|
||||||
d = gf(),
|
d = gf(),
|
||||||
@ -1769,8 +1769,8 @@ function crypto_scalarmult(q: Uint8Array, n: Uint8Array, p: Uint8Array) {
|
|||||||
x[i + 48] = b[i];
|
x[i + 48] = b[i];
|
||||||
x[i + 64] = d[i];
|
x[i + 64] = d[i];
|
||||||
}
|
}
|
||||||
var x32 = x.subarray(32);
|
const x32 = x.subarray(32);
|
||||||
var x16 = x.subarray(16);
|
const x16 = x.subarray(16);
|
||||||
inv25519(x32, x32);
|
inv25519(x32, x32);
|
||||||
M(x16, x16, x32);
|
M(x16, x16, x32);
|
||||||
pack25519(q, x16);
|
pack25519(q, x16);
|
||||||
@ -1787,13 +1787,13 @@ function crypto_box_keypair(y: Uint8Array, x: Uint8Array) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function crypto_box_beforenm(k: Uint8Array, y: Uint8Array, x: Uint8Array) {
|
function crypto_box_beforenm(k: Uint8Array, y: Uint8Array, x: Uint8Array) {
|
||||||
var s = new Uint8Array(32);
|
const s = new Uint8Array(32);
|
||||||
crypto_scalarmult(s, x, y);
|
crypto_scalarmult(s, x, y);
|
||||||
return crypto_core_hsalsa20(k, _0, s, sigma);
|
return crypto_core_hsalsa20(k, _0, s, sigma);
|
||||||
}
|
}
|
||||||
|
|
||||||
var crypto_box_afternm = crypto_secretbox;
|
const crypto_box_afternm = crypto_secretbox;
|
||||||
var crypto_box_open_afternm = crypto_secretbox_open;
|
const crypto_box_open_afternm = crypto_secretbox_open;
|
||||||
|
|
||||||
function crypto_box(
|
function crypto_box(
|
||||||
c: Uint8Array,
|
c: Uint8Array,
|
||||||
@ -1803,7 +1803,7 @@ function crypto_box(
|
|||||||
y: Uint8Array,
|
y: Uint8Array,
|
||||||
x: Uint8Array,
|
x: Uint8Array,
|
||||||
) {
|
) {
|
||||||
var k = new Uint8Array(32);
|
const k = new Uint8Array(32);
|
||||||
crypto_box_beforenm(k, y, x);
|
crypto_box_beforenm(k, y, x);
|
||||||
return crypto_box_afternm(c, m, d, n, k);
|
return crypto_box_afternm(c, m, d, n, k);
|
||||||
}
|
}
|
||||||
@ -1816,13 +1816,13 @@ function crypto_box_open(
|
|||||||
y: Uint8Array,
|
y: Uint8Array,
|
||||||
x: Uint8Array,
|
x: Uint8Array,
|
||||||
) {
|
) {
|
||||||
var k = new Uint8Array(32);
|
const k = new Uint8Array(32);
|
||||||
crypto_box_beforenm(k, y, x);
|
crypto_box_beforenm(k, y, x);
|
||||||
return crypto_box_open_afternm(m, c, d, n, k);
|
return crypto_box_open_afternm(m, c, d, n, k);
|
||||||
}
|
}
|
||||||
|
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
var K = [
|
const K = [
|
||||||
0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
|
0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
|
||||||
0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
|
0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
|
||||||
0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
|
0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
|
||||||
@ -1871,7 +1871,7 @@ function crypto_hashblocks_hl(
|
|||||||
m: Uint8Array,
|
m: Uint8Array,
|
||||||
n: number,
|
n: number,
|
||||||
) {
|
) {
|
||||||
var wh = new Int32Array(16),
|
let wh = new Int32Array(16),
|
||||||
wl = new Int32Array(16),
|
wl = new Int32Array(16),
|
||||||
bh0,
|
bh0,
|
||||||
bh1,
|
bh1,
|
||||||
@ -1900,7 +1900,7 @@ function crypto_hashblocks_hl(
|
|||||||
c,
|
c,
|
||||||
d;
|
d;
|
||||||
|
|
||||||
var ah0 = hh[0],
|
let ah0 = hh[0],
|
||||||
ah1 = hh[1],
|
ah1 = hh[1],
|
||||||
ah2 = hh[2],
|
ah2 = hh[2],
|
||||||
ah3 = hh[3],
|
ah3 = hh[3],
|
||||||
@ -1917,7 +1917,7 @@ function crypto_hashblocks_hl(
|
|||||||
al6 = hl[6],
|
al6 = hl[6],
|
||||||
al7 = hl[7];
|
al7 = hl[7];
|
||||||
|
|
||||||
var pos = 0;
|
let pos = 0;
|
||||||
while (n >= 128) {
|
while (n >= 128) {
|
||||||
for (i = 0; i < 16; i++) {
|
for (i = 0; i < 16; i++) {
|
||||||
j = 8 * i + pos;
|
j = 8 * i + pos;
|
||||||
@ -2342,7 +2342,7 @@ function crypto_hash(out: Uint8Array, m: Uint8Array, n: number) {
|
|||||||
const hh = new Int32Array(8);
|
const hh = new Int32Array(8);
|
||||||
const hl = new Int32Array(8);
|
const hl = new Int32Array(8);
|
||||||
const x = new Uint8Array(256);
|
const x = new Uint8Array(256);
|
||||||
let b = n;
|
const b = n;
|
||||||
|
|
||||||
hh[0] = 0x6a09e667;
|
hh[0] = 0x6a09e667;
|
||||||
hh[1] = 0xbb67ae85;
|
hh[1] = 0xbb67ae85;
|
||||||
@ -2436,7 +2436,7 @@ export class HashState {
|
|||||||
const out = new Uint8Array(64);
|
const out = new Uint8Array(64);
|
||||||
let n = this.p;
|
let n = this.p;
|
||||||
const x = new Uint8Array(256);
|
const x = new Uint8Array(256);
|
||||||
let b = this.total;
|
const b = this.total;
|
||||||
for (let i = 0; i < n; i++) x[i] = this.next[i];
|
for (let i = 0; i < n; i++) x[i] = this.next[i];
|
||||||
x[n] = 128;
|
x[n] = 128;
|
||||||
|
|
||||||
@ -2451,7 +2451,7 @@ export class HashState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function add(p: Float64Array[], q: Float64Array[]) {
|
function add(p: Float64Array[], q: Float64Array[]) {
|
||||||
var a = gf(),
|
const a = gf(),
|
||||||
b = gf(),
|
b = gf(),
|
||||||
c = gf(),
|
c = gf(),
|
||||||
d = gf(),
|
d = gf(),
|
||||||
@ -2483,14 +2483,14 @@ function add(p: Float64Array[], q: Float64Array[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function cswap(p: Float64Array[], q: Float64Array[], b: number) {
|
function cswap(p: Float64Array[], q: Float64Array[], b: number) {
|
||||||
var i;
|
let i;
|
||||||
for (i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
sel25519(p[i], q[i], b);
|
sel25519(p[i], q[i], b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function pack(r: Uint8Array, p: Float64Array[]) {
|
function pack(r: Uint8Array, p: Float64Array[]) {
|
||||||
var tx = gf(),
|
const tx = gf(),
|
||||||
ty = gf(),
|
ty = gf(),
|
||||||
zi = gf();
|
zi = gf();
|
||||||
inv25519(zi, p[2]);
|
inv25519(zi, p[2]);
|
||||||
@ -2501,7 +2501,7 @@ function pack(r: Uint8Array, p: Float64Array[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function scalarmult(p: Float64Array[], q: Float64Array[], s: Uint8Array) {
|
function scalarmult(p: Float64Array[], q: Float64Array[], s: Uint8Array) {
|
||||||
var b, i;
|
let b, i;
|
||||||
set25519(p[0], gf0);
|
set25519(p[0], gf0);
|
||||||
set25519(p[1], gf1);
|
set25519(p[1], gf1);
|
||||||
set25519(p[2], gf1);
|
set25519(p[2], gf1);
|
||||||
@ -2545,7 +2545,7 @@ function crypto_sign_keypair(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var L = new Float64Array([
|
const L = new Float64Array([
|
||||||
0xed,
|
0xed,
|
||||||
0xd3,
|
0xd3,
|
||||||
0xf5,
|
0xf5,
|
||||||
@ -2581,7 +2581,7 @@ var L = new Float64Array([
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
function modL(r: Uint8Array, x: Float64Array) {
|
function modL(r: Uint8Array, x: Float64Array) {
|
||||||
var carry, i, j, k;
|
let carry, i, j, k;
|
||||||
for (i = 63; i >= 32; --i) {
|
for (i = 63; i >= 32; --i) {
|
||||||
carry = 0;
|
carry = 0;
|
||||||
for (j = i - 32, k = i - 12; j < k; ++j) {
|
for (j = i - 32, k = i - 12; j < k; ++j) {
|
||||||
@ -2614,20 +2614,20 @@ function reduce(r: Uint8Array) {
|
|||||||
|
|
||||||
// Note: difference from C - smlen returned, not passed as argument.
|
// Note: difference from C - smlen returned, not passed as argument.
|
||||||
function crypto_sign(sm: Uint8Array, m: Uint8Array, n: number, sk: Uint8Array) {
|
function crypto_sign(sm: Uint8Array, m: Uint8Array, n: number, sk: Uint8Array) {
|
||||||
var d = new Uint8Array(64),
|
const d = new Uint8Array(64),
|
||||||
h = new Uint8Array(64),
|
h = new Uint8Array(64),
|
||||||
r = new Uint8Array(64);
|
r = new Uint8Array(64);
|
||||||
var i,
|
let i,
|
||||||
j,
|
j,
|
||||||
x = new Float64Array(64);
|
x = new Float64Array(64);
|
||||||
var p = [gf(), gf(), gf(), gf()];
|
const p = [gf(), gf(), gf(), gf()];
|
||||||
|
|
||||||
crypto_hash(d, sk, 32);
|
crypto_hash(d, sk, 32);
|
||||||
d[0] &= 248;
|
d[0] &= 248;
|
||||||
d[31] &= 127;
|
d[31] &= 127;
|
||||||
d[31] |= 64;
|
d[31] |= 64;
|
||||||
|
|
||||||
var smlen = n + 64;
|
const smlen = n + 64;
|
||||||
for (i = 0; i < n; i++) sm[64 + i] = m[i];
|
for (i = 0; i < n; i++) sm[64 + i] = m[i];
|
||||||
for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i];
|
for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i];
|
||||||
|
|
||||||
@ -2700,10 +2700,10 @@ function crypto_sign_open(
|
|||||||
n: number,
|
n: number,
|
||||||
pk: Uint8Array,
|
pk: Uint8Array,
|
||||||
) {
|
) {
|
||||||
var i, mlen;
|
let i, mlen;
|
||||||
var t = new Uint8Array(32),
|
const t = new Uint8Array(32),
|
||||||
h = new Uint8Array(64);
|
h = new Uint8Array(64);
|
||||||
var p = [gf(), gf(), gf(), gf()],
|
const p = [gf(), gf(), gf(), gf()],
|
||||||
q = [gf(), gf(), gf(), gf()];
|
q = [gf(), gf(), gf(), gf()];
|
||||||
|
|
||||||
mlen = -1;
|
mlen = -1;
|
||||||
@ -2732,7 +2732,7 @@ function crypto_sign_open(
|
|||||||
return mlen;
|
return mlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
var crypto_secretbox_KEYBYTES = 32,
|
const crypto_secretbox_KEYBYTES = 32,
|
||||||
crypto_secretbox_NONCEBYTES = 24,
|
crypto_secretbox_NONCEBYTES = 24,
|
||||||
crypto_secretbox_ZEROBYTES = 32,
|
crypto_secretbox_ZEROBYTES = 32,
|
||||||
crypto_secretbox_BOXZEROBYTES = 16,
|
crypto_secretbox_BOXZEROBYTES = 16,
|
||||||
@ -2809,18 +2809,18 @@ function checkBoxLengths(pk: Uint8Array, sk: Uint8Array) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function checkArrayTypes(...args: Uint8Array[]) {
|
function checkArrayTypes(...args: Uint8Array[]) {
|
||||||
for (var i = 0; i < args.length; i++) {
|
for (let i = 0; i < args.length; i++) {
|
||||||
if (!(args[i] instanceof Uint8Array))
|
if (!(args[i] instanceof Uint8Array))
|
||||||
throw new TypeError("unexpected type, use Uint8Array");
|
throw new TypeError("unexpected type, use Uint8Array");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function cleanup(arr: Uint8Array) {
|
function cleanup(arr: Uint8Array) {
|
||||||
for (var i = 0; i < arr.length; i++) arr[i] = 0;
|
for (let i = 0; i < arr.length; i++) arr[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function randomBytes(n: number) {
|
export function randomBytes(n: number) {
|
||||||
var b = new Uint8Array(n);
|
const b = new Uint8Array(n);
|
||||||
randombytes(b, n);
|
randombytes(b, n);
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
@ -2828,9 +2828,9 @@ export function randomBytes(n: number) {
|
|||||||
export function secretbox(msg: Uint8Array, nonce: Uint8Array, key: Uint8Array) {
|
export function secretbox(msg: Uint8Array, nonce: Uint8Array, key: Uint8Array) {
|
||||||
checkArrayTypes(msg, nonce, key);
|
checkArrayTypes(msg, nonce, key);
|
||||||
checkLengths(key, nonce);
|
checkLengths(key, nonce);
|
||||||
var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length);
|
const m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length);
|
||||||
var c = new Uint8Array(m.length);
|
const c = new Uint8Array(m.length);
|
||||||
for (var i = 0; i < msg.length; i++)
|
for (let i = 0; i < msg.length; i++)
|
||||||
m[i + crypto_secretbox_ZEROBYTES] = msg[i];
|
m[i + crypto_secretbox_ZEROBYTES] = msg[i];
|
||||||
crypto_secretbox(c, m, m.length, nonce, key);
|
crypto_secretbox(c, m, m.length, nonce, key);
|
||||||
return c.subarray(crypto_secretbox_BOXZEROBYTES);
|
return c.subarray(crypto_secretbox_BOXZEROBYTES);
|
||||||
@ -2843,9 +2843,9 @@ export function secretbox_open(
|
|||||||
) {
|
) {
|
||||||
checkArrayTypes(box, nonce, key);
|
checkArrayTypes(box, nonce, key);
|
||||||
checkLengths(key, nonce);
|
checkLengths(key, nonce);
|
||||||
var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length);
|
const c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length);
|
||||||
var m = new Uint8Array(c.length);
|
const m = new Uint8Array(c.length);
|
||||||
for (var i = 0; i < box.length; i++)
|
for (let i = 0; i < box.length; i++)
|
||||||
c[i + crypto_secretbox_BOXZEROBYTES] = box[i];
|
c[i + crypto_secretbox_BOXZEROBYTES] = box[i];
|
||||||
if (c.length < 32) return null;
|
if (c.length < 32) return null;
|
||||||
if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null;
|
if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null;
|
||||||
@ -2860,7 +2860,7 @@ export function scalarMult(n: Uint8Array, p: Uint8Array) {
|
|||||||
checkArrayTypes(n, p);
|
checkArrayTypes(n, p);
|
||||||
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error("bad n size");
|
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error("bad n size");
|
||||||
if (p.length !== crypto_scalarmult_BYTES) throw new Error("bad p size");
|
if (p.length !== crypto_scalarmult_BYTES) throw new Error("bad p size");
|
||||||
var q = new Uint8Array(crypto_scalarmult_BYTES);
|
const q = new Uint8Array(crypto_scalarmult_BYTES);
|
||||||
crypto_scalarmult(q, n, p);
|
crypto_scalarmult(q, n, p);
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
@ -2868,7 +2868,7 @@ export function scalarMult(n: Uint8Array, p: Uint8Array) {
|
|||||||
export function scalarMult_base(n: Uint8Array) {
|
export function scalarMult_base(n: Uint8Array) {
|
||||||
checkArrayTypes(n);
|
checkArrayTypes(n);
|
||||||
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error("bad n size");
|
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error("bad n size");
|
||||||
var q = new Uint8Array(crypto_scalarmult_BYTES);
|
const q = new Uint8Array(crypto_scalarmult_BYTES);
|
||||||
crypto_scalarmult_base(q, n);
|
crypto_scalarmult_base(q, n);
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
@ -2882,14 +2882,14 @@ export function box(
|
|||||||
publicKey: Uint8Array,
|
publicKey: Uint8Array,
|
||||||
secretKey: Uint8Array,
|
secretKey: Uint8Array,
|
||||||
) {
|
) {
|
||||||
var k = box_before(publicKey, secretKey);
|
const k = box_before(publicKey, secretKey);
|
||||||
return secretbox(msg, nonce, k);
|
return secretbox(msg, nonce, k);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function box_before(publicKey: Uint8Array, secretKey: Uint8Array) {
|
export function box_before(publicKey: Uint8Array, secretKey: Uint8Array) {
|
||||||
checkArrayTypes(publicKey, secretKey);
|
checkArrayTypes(publicKey, secretKey);
|
||||||
checkBoxLengths(publicKey, secretKey);
|
checkBoxLengths(publicKey, secretKey);
|
||||||
var k = new Uint8Array(crypto_box_BEFORENMBYTES);
|
const k = new Uint8Array(crypto_box_BEFORENMBYTES);
|
||||||
crypto_box_beforenm(k, publicKey, secretKey);
|
crypto_box_beforenm(k, publicKey, secretKey);
|
||||||
return k;
|
return k;
|
||||||
}
|
}
|
||||||
@ -2902,15 +2902,15 @@ export function box_open(
|
|||||||
publicKey: Uint8Array,
|
publicKey: Uint8Array,
|
||||||
secretKey: Uint8Array,
|
secretKey: Uint8Array,
|
||||||
) {
|
) {
|
||||||
var k = box_before(publicKey, secretKey);
|
const k = box_before(publicKey, secretKey);
|
||||||
return secretbox_open(msg, nonce, k);
|
return secretbox_open(msg, nonce, k);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const box_open_after = secretbox_open;
|
export const box_open_after = secretbox_open;
|
||||||
|
|
||||||
export function box_keyPair() {
|
export function box_keyPair() {
|
||||||
var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
|
const pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
|
||||||
var sk = new Uint8Array(crypto_box_SECRETKEYBYTES);
|
const sk = new Uint8Array(crypto_box_SECRETKEYBYTES);
|
||||||
crypto_box_keypair(pk, sk);
|
crypto_box_keypair(pk, sk);
|
||||||
return { publicKey: pk, secretKey: sk };
|
return { publicKey: pk, secretKey: sk };
|
||||||
}
|
}
|
||||||
@ -2919,7 +2919,7 @@ export function box_keyPair_fromSecretKey(secretKey: Uint8Array) {
|
|||||||
checkArrayTypes(secretKey);
|
checkArrayTypes(secretKey);
|
||||||
if (secretKey.length !== crypto_box_SECRETKEYBYTES)
|
if (secretKey.length !== crypto_box_SECRETKEYBYTES)
|
||||||
throw new Error("bad secret key size");
|
throw new Error("bad secret key size");
|
||||||
var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
|
const pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
|
||||||
crypto_scalarmult_base(pk, secretKey);
|
crypto_scalarmult_base(pk, secretKey);
|
||||||
return { publicKey: pk, secretKey: new Uint8Array(secretKey) };
|
return { publicKey: pk, secretKey: new Uint8Array(secretKey) };
|
||||||
}
|
}
|
||||||
@ -2934,7 +2934,7 @@ export function sign(msg: Uint8Array, secretKey: Uint8Array) {
|
|||||||
checkArrayTypes(msg, secretKey);
|
checkArrayTypes(msg, secretKey);
|
||||||
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
|
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
|
||||||
throw new Error("bad secret key size");
|
throw new Error("bad secret key size");
|
||||||
var signedMsg = new Uint8Array(crypto_sign_BYTES + msg.length);
|
const signedMsg = new Uint8Array(crypto_sign_BYTES + msg.length);
|
||||||
crypto_sign(signedMsg, msg, msg.length, secretKey);
|
crypto_sign(signedMsg, msg, msg.length, secretKey);
|
||||||
return signedMsg;
|
return signedMsg;
|
||||||
}
|
}
|
||||||
@ -2943,18 +2943,18 @@ export function sign_open(signedMsg: Uint8Array, publicKey: Uint8Array) {
|
|||||||
checkArrayTypes(signedMsg, publicKey);
|
checkArrayTypes(signedMsg, publicKey);
|
||||||
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
|
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
|
||||||
throw new Error("bad public key size");
|
throw new Error("bad public key size");
|
||||||
var tmp = new Uint8Array(signedMsg.length);
|
const tmp = new Uint8Array(signedMsg.length);
|
||||||
var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey);
|
const mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey);
|
||||||
if (mlen < 0) return null;
|
if (mlen < 0) return null;
|
||||||
var m = new Uint8Array(mlen);
|
const m = new Uint8Array(mlen);
|
||||||
for (var i = 0; i < m.length; i++) m[i] = tmp[i];
|
for (let i = 0; i < m.length; i++) m[i] = tmp[i];
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sign_detached(msg: Uint8Array, secretKey: Uint8Array) {
|
export function sign_detached(msg: Uint8Array, secretKey: Uint8Array) {
|
||||||
var signedMsg = sign(msg, secretKey);
|
const signedMsg = sign(msg, secretKey);
|
||||||
var sig = new Uint8Array(crypto_sign_BYTES);
|
const sig = new Uint8Array(crypto_sign_BYTES);
|
||||||
for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i];
|
for (let i = 0; i < sig.length; i++) sig[i] = signedMsg[i];
|
||||||
return sig;
|
return sig;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2967,17 +2967,17 @@ export function sign_detached_verify(
|
|||||||
if (sig.length !== crypto_sign_BYTES) throw new Error("bad signature size");
|
if (sig.length !== crypto_sign_BYTES) throw new Error("bad signature size");
|
||||||
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
|
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
|
||||||
throw new Error("bad public key size");
|
throw new Error("bad public key size");
|
||||||
var sm = new Uint8Array(crypto_sign_BYTES + msg.length);
|
const sm = new Uint8Array(crypto_sign_BYTES + msg.length);
|
||||||
var m = new Uint8Array(crypto_sign_BYTES + msg.length);
|
const m = new Uint8Array(crypto_sign_BYTES + msg.length);
|
||||||
var i;
|
let i;
|
||||||
for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i];
|
for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i];
|
||||||
for (i = 0; i < msg.length; i++) sm[i + crypto_sign_BYTES] = msg[i];
|
for (i = 0; i < msg.length; i++) sm[i + crypto_sign_BYTES] = msg[i];
|
||||||
return crypto_sign_open(m, sm, sm.length, publicKey) >= 0;
|
return crypto_sign_open(m, sm, sm.length, publicKey) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sign_keyPair() {
|
export function sign_keyPair() {
|
||||||
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
const pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
||||||
var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
|
const sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
|
||||||
crypto_sign_keypair(pk, sk, false);
|
crypto_sign_keypair(pk, sk, false);
|
||||||
return { publicKey: pk, secretKey: sk };
|
return { publicKey: pk, secretKey: sk };
|
||||||
}
|
}
|
||||||
@ -3009,17 +3009,17 @@ export function sign_keyPair_fromSecretKey(secretKey: Uint8Array) {
|
|||||||
checkArrayTypes(secretKey);
|
checkArrayTypes(secretKey);
|
||||||
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
|
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
|
||||||
throw new Error("bad secret key size");
|
throw new Error("bad secret key size");
|
||||||
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
const pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
||||||
for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32 + i];
|
for (let i = 0; i < pk.length; i++) pk[i] = secretKey[32 + i];
|
||||||
return { publicKey: pk, secretKey: new Uint8Array(secretKey) };
|
return { publicKey: pk, secretKey: new Uint8Array(secretKey) };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sign_keyPair_fromSeed(seed: Uint8Array) {
|
export function sign_keyPair_fromSeed(seed: Uint8Array) {
|
||||||
checkArrayTypes(seed);
|
checkArrayTypes(seed);
|
||||||
if (seed.length !== crypto_sign_SEEDBYTES) throw new Error("bad seed size");
|
if (seed.length !== crypto_sign_SEEDBYTES) throw new Error("bad seed size");
|
||||||
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
const pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
||||||
var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
|
const sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
|
||||||
for (var i = 0; i < 32; i++) sk[i] = seed[i];
|
for (let i = 0; i < 32; i++) sk[i] = seed[i];
|
||||||
crypto_sign_keypair(pk, sk, true);
|
crypto_sign_keypair(pk, sk, true);
|
||||||
return { publicKey: pk, secretKey: sk };
|
return { publicKey: pk, secretKey: sk };
|
||||||
}
|
}
|
||||||
@ -3031,7 +3031,7 @@ export const sign_signatureLength = crypto_sign_BYTES;
|
|||||||
|
|
||||||
export function hash(msg: Uint8Array) {
|
export function hash(msg: Uint8Array) {
|
||||||
checkArrayTypes(msg);
|
checkArrayTypes(msg);
|
||||||
var h = new Uint8Array(crypto_hash_BYTES);
|
const h = new Uint8Array(crypto_hash_BYTES);
|
||||||
crypto_hash(h, msg, msg.length);
|
crypto_hash(h, msg, msg.length);
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
@ -3082,9 +3082,9 @@ export function sign_ed25519_pk_to_curve25519(
|
|||||||
typeof self !== "undefined" ? self.crypto || (self as any).msCrypto : null;
|
typeof self !== "undefined" ? self.crypto || (self as any).msCrypto : null;
|
||||||
if (cr && cr.getRandomValues) {
|
if (cr && cr.getRandomValues) {
|
||||||
// Browsers.
|
// Browsers.
|
||||||
var QUOTA = 65536;
|
const QUOTA = 65536;
|
||||||
setPRNG(function (x: Uint8Array, n: number) {
|
setPRNG(function (x: Uint8Array, n: number) {
|
||||||
var i,
|
let i,
|
||||||
v = new Uint8Array(n);
|
v = new Uint8Array(n);
|
||||||
for (i = 0; i < n; i += QUOTA) {
|
for (i = 0; i < n; i += QUOTA) {
|
||||||
cr.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
|
cr.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
|
||||||
@ -3097,7 +3097,7 @@ export function sign_ed25519_pk_to_curve25519(
|
|||||||
const cr = require("crypto");
|
const cr = require("crypto");
|
||||||
if (cr && cr.randomBytes) {
|
if (cr && cr.randomBytes) {
|
||||||
setPRNG(function (x: Uint8Array, n: number) {
|
setPRNG(function (x: Uint8Array, n: number) {
|
||||||
var i,
|
let i,
|
||||||
v = cr.randomBytes(n);
|
v = cr.randomBytes(n);
|
||||||
for (i = 0; i < n; i++) x[i] = v[i];
|
for (i = 0; i < n; i++) x[i] = v[i];
|
||||||
cleanup(v);
|
cleanup(v);
|
||||||
|
@ -11,8 +11,8 @@
|
|||||||
// Classes:
|
// Classes:
|
||||||
//
|
//
|
||||||
// new sha256.Hash()
|
// new sha256.Hash()
|
||||||
export const digestLength: number = 32;
|
export const digestLength = 32;
|
||||||
export const blockSize: number = 64;
|
export const blockSize = 64;
|
||||||
|
|
||||||
// SHA-256 constants
|
// SHA-256 constants
|
||||||
const K = new Uint32Array([
|
const K = new Uint32Array([
|
||||||
@ -188,10 +188,10 @@ export class HashSha256 {
|
|||||||
private state: Int32Array = new Int32Array(8); // hash state
|
private state: Int32Array = new Int32Array(8); // hash state
|
||||||
private temp: Int32Array = new Int32Array(64); // temporary state
|
private temp: Int32Array = new Int32Array(64); // temporary state
|
||||||
private buffer: Uint8Array = new Uint8Array(128); // buffer for data to hash
|
private buffer: Uint8Array = new Uint8Array(128); // buffer for data to hash
|
||||||
private bufferLength: number = 0; // number of bytes in buffer
|
private bufferLength = 0; // number of bytes in buffer
|
||||||
private bytesHashed: number = 0; // number of total bytes hashed
|
private bytesHashed = 0; // number of total bytes hashed
|
||||||
|
|
||||||
finished: boolean = false; // indicates whether the hash was finalized
|
finished = false; // indicates whether the hash was finalized
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.reset();
|
this.reset();
|
||||||
|
@ -40,7 +40,7 @@ function hexToBytes(hex: string) {
|
|||||||
|
|
||||||
function bytesToHex(bytes: Uint8Array): string {
|
function bytesToHex(bytes: Uint8Array): string {
|
||||||
for (var hex = [], i = 0; i < bytes.length; i++) {
|
for (var hex = [], i = 0; i < bytes.length; i++) {
|
||||||
var current = bytes[i] < 0 ? bytes[i] + 256 : bytes[i];
|
const current = bytes[i] < 0 ? bytes[i] + 256 : bytes[i];
|
||||||
hex.push((current >>> 4).toString(16));
|
hex.push((current >>> 4).toString(16));
|
||||||
hex.push((current & 0xf).toString(16));
|
hex.push((current & 0xf).toString(16));
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ export class BrowserCryptoWorkerFactory implements CryptoWorkerFactory {
|
|||||||
* for the execution of expensive operations.
|
* for the execution of expensive operations.
|
||||||
*/
|
*/
|
||||||
export class CryptoApi {
|
export class CryptoApi {
|
||||||
private nextRpcId: number = 1;
|
private nextRpcId = 1;
|
||||||
private workers: WorkerState[];
|
private workers: WorkerState[];
|
||||||
private workQueues: WorkItem[][];
|
private workQueues: WorkItem[][];
|
||||||
|
|
||||||
@ -142,12 +142,12 @@ export class CryptoApi {
|
|||||||
/**
|
/**
|
||||||
* Number of busy workers.
|
* Number of busy workers.
|
||||||
*/
|
*/
|
||||||
private numBusy: number = 0;
|
private numBusy = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Did we stop accepting new requests?
|
* Did we stop accepting new requests?
|
||||||
*/
|
*/
|
||||||
private stopped: boolean = false;
|
private stopped = false;
|
||||||
|
|
||||||
static enableTracing = false;
|
static enableTracing = false;
|
||||||
|
|
||||||
@ -155,7 +155,7 @@ export class CryptoApi {
|
|||||||
* Terminate all worker threads.
|
* Terminate all worker threads.
|
||||||
*/
|
*/
|
||||||
terminateWorkers() {
|
terminateWorkers() {
|
||||||
for (let worker of this.workers) {
|
for (const worker of this.workers) {
|
||||||
if (worker.w) {
|
if (worker.w) {
|
||||||
CryptoApi.enableTracing && console.log("terminating worker");
|
CryptoApi.enableTracing && console.log("terminating worker");
|
||||||
worker.w.terminate();
|
worker.w.terminate();
|
||||||
|
@ -123,13 +123,13 @@ class SignaturePurposeBuilder {
|
|||||||
|
|
||||||
build(): Uint8Array {
|
build(): Uint8Array {
|
||||||
let payloadLen = 0;
|
let payloadLen = 0;
|
||||||
for (let c of this.chunks) {
|
for (const c of this.chunks) {
|
||||||
payloadLen += c.byteLength;
|
payloadLen += c.byteLength;
|
||||||
}
|
}
|
||||||
const buf = new ArrayBuffer(4 + 4 + payloadLen);
|
const buf = new ArrayBuffer(4 + 4 + payloadLen);
|
||||||
const u8buf = new Uint8Array(buf);
|
const u8buf = new Uint8Array(buf);
|
||||||
let p = 8;
|
let p = 8;
|
||||||
for (let c of this.chunks) {
|
for (const c of this.chunks) {
|
||||||
u8buf.set(c, p);
|
u8buf.set(c, p);
|
||||||
p += c.byteLength;
|
p += c.byteLength;
|
||||||
}
|
}
|
||||||
@ -158,7 +158,7 @@ function checkSignKeyOkay(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class CryptoImplementation {
|
export class CryptoImplementation {
|
||||||
static enableTracing: boolean = false;
|
static enableTracing = false;
|
||||||
|
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
||||||
|
@ -23,8 +23,8 @@ import readline from "readline";
|
|||||||
|
|
||||||
class Converter<T> {}
|
class Converter<T> {}
|
||||||
|
|
||||||
export let INT = new Converter<number>();
|
export const INT = new Converter<number>();
|
||||||
export let STRING: Converter<string> = new Converter<string>();
|
export const STRING: Converter<string> = new Converter<string>();
|
||||||
|
|
||||||
export interface OptionArgs<T> {
|
export interface OptionArgs<T> {
|
||||||
help?: string;
|
help?: string;
|
||||||
@ -90,7 +90,7 @@ function splitOpt(opt: string): { key: string; value?: string } {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function formatListing(key: string, value?: string): string {
|
function formatListing(key: string, value?: string): string {
|
||||||
let res = " " + key;
|
const res = " " + key;
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -139,7 +139,7 @@ export class CommandGroup<GN extends keyof any, TG> {
|
|||||||
name: name as string,
|
name: name as string,
|
||||||
};
|
};
|
||||||
this.options.push(def);
|
this.options.push(def);
|
||||||
for (let flag of flagspec) {
|
for (const flag of flagspec) {
|
||||||
if (flag.startsWith("--")) {
|
if (flag.startsWith("--")) {
|
||||||
const flagname = flag.substring(2);
|
const flagname = flag.substring(2);
|
||||||
this.longOptions[flagname] = def;
|
this.longOptions[flagname] = def;
|
||||||
@ -168,7 +168,7 @@ export class CommandGroup<GN extends keyof any, TG> {
|
|||||||
name: name as string,
|
name: name as string,
|
||||||
};
|
};
|
||||||
this.options.push(def);
|
this.options.push(def);
|
||||||
for (let flag of flagspec) {
|
for (const flag of flagspec) {
|
||||||
if (flag.startsWith("--")) {
|
if (flag.startsWith("--")) {
|
||||||
const flagname = flag.substring(2);
|
const flagname = flag.substring(2);
|
||||||
this.longOptions[flagname] = def;
|
this.longOptions[flagname] = def;
|
||||||
@ -225,7 +225,7 @@ export class CommandGroup<GN extends keyof any, TG> {
|
|||||||
name: name as string,
|
name: name as string,
|
||||||
};
|
};
|
||||||
this.options.push(def);
|
this.options.push(def);
|
||||||
for (let flag of flagspec) {
|
for (const flag of flagspec) {
|
||||||
if (flag.startsWith("--")) {
|
if (flag.startsWith("--")) {
|
||||||
const flagname = flag.substring(2);
|
const flagname = flag.substring(2);
|
||||||
this.longOptions[flagname] = def;
|
this.longOptions[flagname] = def;
|
||||||
@ -271,7 +271,7 @@ export class CommandGroup<GN extends keyof any, TG> {
|
|||||||
|
|
||||||
printHelp(progName: string, parents: CommandGroup<any, any>[]) {
|
printHelp(progName: string, parents: CommandGroup<any, any>[]) {
|
||||||
let usageSpec = "";
|
let usageSpec = "";
|
||||||
for (let p of parents) {
|
for (const p of parents) {
|
||||||
usageSpec += (p.name ?? progName) + " ";
|
usageSpec += (p.name ?? progName) + " ";
|
||||||
if (p.arguments.length >= 1) {
|
if (p.arguments.length >= 1) {
|
||||||
usageSpec += "<ARGS...> ";
|
usageSpec += "<ARGS...> ";
|
||||||
@ -281,7 +281,7 @@ export class CommandGroup<GN extends keyof any, TG> {
|
|||||||
if (this.subcommands.length != 0) {
|
if (this.subcommands.length != 0) {
|
||||||
usageSpec += "COMMAND ";
|
usageSpec += "COMMAND ";
|
||||||
}
|
}
|
||||||
for (let a of this.arguments) {
|
for (const a of this.arguments) {
|
||||||
const argName = a.args.metavar ?? a.name;
|
const argName = a.args.metavar ?? a.name;
|
||||||
usageSpec += `<${argName}> `;
|
usageSpec += `<${argName}> `;
|
||||||
}
|
}
|
||||||
@ -294,7 +294,7 @@ export class CommandGroup<GN extends keyof any, TG> {
|
|||||||
if (this.options.length != 0) {
|
if (this.options.length != 0) {
|
||||||
console.log();
|
console.log();
|
||||||
console.log("Options:");
|
console.log("Options:");
|
||||||
for (let opt of this.options) {
|
for (const opt of this.options) {
|
||||||
let optSpec = opt.flagspec.join(", ");
|
let optSpec = opt.flagspec.join(", ");
|
||||||
if (!opt.isFlag) {
|
if (!opt.isFlag) {
|
||||||
optSpec = optSpec + "=VALUE";
|
optSpec = optSpec + "=VALUE";
|
||||||
@ -306,7 +306,7 @@ export class CommandGroup<GN extends keyof any, TG> {
|
|||||||
if (this.subcommands.length != 0) {
|
if (this.subcommands.length != 0) {
|
||||||
console.log();
|
console.log();
|
||||||
console.log("Commands:");
|
console.log("Commands:");
|
||||||
for (let subcmd of this.subcommands) {
|
for (const subcmd of this.subcommands) {
|
||||||
console.log(formatListing(subcmd.name, subcmd.args.help));
|
console.log(formatListing(subcmd.name, subcmd.args.help));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -444,7 +444,7 @@ export class CommandGroup<GN extends keyof any, TG> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let option of this.options) {
|
for (const option of this.options) {
|
||||||
if (option.isFlag == false && option.required == true) {
|
if (option.isFlag == false && option.required == true) {
|
||||||
if (!foundOptions[option.name]) {
|
if (!foundOptions[option.name]) {
|
||||||
if (option.args.default !== undefined) {
|
if (option.args.default !== undefined) {
|
||||||
@ -459,7 +459,7 @@ export class CommandGroup<GN extends keyof any, TG> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let option of this.options) {
|
for (const option of this.options) {
|
||||||
const ph = option.args.onPresentHandler;
|
const ph = option.args.onPresentHandler;
|
||||||
if (ph && foundOptions[option.name]) {
|
if (ph && foundOptions[option.name]) {
|
||||||
ph(myArgs[option.name]);
|
ph(myArgs[option.name]);
|
||||||
|
@ -138,9 +138,9 @@ export async function getDefaultNodeWallet(
|
|||||||
|
|
||||||
export async function withdrawTestBalance(
|
export async function withdrawTestBalance(
|
||||||
myWallet: Wallet,
|
myWallet: Wallet,
|
||||||
amount: string = "TESTKUDOS:10",
|
amount = "TESTKUDOS:10",
|
||||||
bankBaseUrl: string = "https://bank.test.taler.net/",
|
bankBaseUrl = "https://bank.test.taler.net/",
|
||||||
exchangeBaseUrl: string = "https://exchange.test.taler.net/",
|
exchangeBaseUrl = "https://exchange.test.taler.net/",
|
||||||
) {
|
) {
|
||||||
const reserveResponse = await myWallet.createReserve({
|
const reserveResponse = await myWallet.createReserve({
|
||||||
amount: amounts.parseOrThrow(amount),
|
amount: amounts.parseOrThrow(amount),
|
||||||
|
@ -43,7 +43,7 @@ async function makePayment(
|
|||||||
amount: string,
|
amount: string,
|
||||||
summary: string,
|
summary: string,
|
||||||
): Promise<{ orderId: string }> {
|
): Promise<{ orderId: string }> {
|
||||||
let orderResp = await merchant.createOrder(
|
const orderResp = await merchant.createOrder(
|
||||||
amount,
|
amount,
|
||||||
summary,
|
summary,
|
||||||
"taler://fulfillment-success/thx",
|
"taler://fulfillment-success/thx",
|
||||||
@ -60,7 +60,7 @@ async function makePayment(
|
|||||||
throw Error("no taler://pay/ URI in payment response");
|
throw Error("no taler://pay/ URI in payment response");
|
||||||
}
|
}
|
||||||
|
|
||||||
let preparePayResult = await wallet.preparePayForUri(talerPayUri);
|
const preparePayResult = await wallet.preparePayForUri(talerPayUri);
|
||||||
|
|
||||||
console.log("prepare pay result", preparePayResult);
|
console.log("prepare pay result", preparePayResult);
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ async function makePayment(
|
|||||||
throw Error("payment not possible");
|
throw Error("payment not possible");
|
||||||
}
|
}
|
||||||
|
|
||||||
let confirmPayResult = await wallet.confirmPay(
|
const confirmPayResult = await wallet.confirmPay(
|
||||||
preparePayResult.proposalId,
|
preparePayResult.proposalId,
|
||||||
undefined,
|
undefined,
|
||||||
);
|
);
|
||||||
@ -159,7 +159,7 @@ export async function runIntegrationTest(args: IntegrationTestArgs) {
|
|||||||
// Wait until the withdraw is done
|
// Wait until the withdraw is done
|
||||||
await myWallet.runUntilDone();
|
await myWallet.runUntilDone();
|
||||||
|
|
||||||
let { orderId: refundOrderId } = await makePayment(
|
const { orderId: refundOrderId } = await makePayment(
|
||||||
myWallet,
|
myWallet,
|
||||||
myMerchant,
|
myMerchant,
|
||||||
Amounts.stringify(spendAmountTwo),
|
Amounts.stringify(spendAmountTwo),
|
||||||
@ -299,7 +299,7 @@ export async function runIntegrationTestBasic(cfg: Configuration) {
|
|||||||
// Wait until the withdraw is done
|
// Wait until the withdraw is done
|
||||||
await myWallet.runUntilDone();
|
await myWallet.runUntilDone();
|
||||||
|
|
||||||
let { orderId: refundOrderId } = await makePayment(
|
const { orderId: refundOrderId } = await makePayment(
|
||||||
myWallet,
|
myWallet,
|
||||||
myMerchant,
|
myMerchant,
|
||||||
Amounts.stringify(spendAmountTwo),
|
Amounts.stringify(spendAmountTwo),
|
||||||
|
@ -593,7 +593,7 @@ testCli
|
|||||||
})
|
})
|
||||||
.action(async (args) => {
|
.action(async (args) => {
|
||||||
applyVerbose(args.wallet.verbose);
|
applyVerbose(args.wallet.verbose);
|
||||||
let cmdObj = args.integrationtestCmd;
|
const cmdObj = args.integrationtestCmd;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await runIntegrationTest({
|
await runIntegrationTest({
|
||||||
|
@ -14,4 +14,4 @@
|
|||||||
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export let strings: {[s: string]: any} = {};
|
export const strings: {[s: string]: any} = {};
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export let strings: { [s: string]: any } = {};
|
export const strings: { [s: string]: any } = {};
|
||||||
strings["de"] = {
|
strings["de"] = {
|
||||||
domain: "messages",
|
domain: "messages",
|
||||||
locale_data: {
|
locale_data: {
|
||||||
|
@ -198,7 +198,7 @@ async function updateExchangeWithKeys(
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
let recoupGroupId: string | undefined = undefined;
|
const recoupGroupId: string | undefined = undefined;
|
||||||
|
|
||||||
await ws.db.runWithWriteTransaction(
|
await ws.db.runWithWriteTransaction(
|
||||||
[Stores.exchanges, Stores.denominations, Stores.recoupGroups, Stores.coins],
|
[Stores.exchanges, Stores.denominations, Stores.recoupGroups, Stores.coins],
|
||||||
@ -459,7 +459,7 @@ async function updateExchangeWithWireInfo(
|
|||||||
export async function updateExchangeFromUrl(
|
export async function updateExchangeFromUrl(
|
||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
baseUrl: string,
|
baseUrl: string,
|
||||||
forceNow: boolean = false,
|
forceNow = false,
|
||||||
): Promise<ExchangeRecord> {
|
): Promise<ExchangeRecord> {
|
||||||
const onOpErr = (e: OperationError) => setExchangeError(ws, baseUrl, e);
|
const onOpErr = (e: OperationError) => setExchangeError(ws, baseUrl, e);
|
||||||
return await guardOperationException(
|
return await guardOperationException(
|
||||||
@ -476,7 +476,7 @@ export async function updateExchangeFromUrl(
|
|||||||
async function updateExchangeFromUrlImpl(
|
async function updateExchangeFromUrlImpl(
|
||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
baseUrl: string,
|
baseUrl: string,
|
||||||
forceNow: boolean = false,
|
forceNow = false,
|
||||||
): Promise<ExchangeRecord> {
|
): Promise<ExchangeRecord> {
|
||||||
const now = getTimestampNow();
|
const now = getTimestampNow();
|
||||||
baseUrl = canonicalizeBaseUrl(baseUrl);
|
baseUrl = canonicalizeBaseUrl(baseUrl);
|
||||||
@ -583,7 +583,7 @@ export async function getExchangePaytoUri(
|
|||||||
if (!exchangeWireInfo) {
|
if (!exchangeWireInfo) {
|
||||||
throw Error(`Exchange wire info for '${exchangeBaseUrl}' not found.`);
|
throw Error(`Exchange wire info for '${exchangeBaseUrl}' not found.`);
|
||||||
}
|
}
|
||||||
for (let account of exchangeWireInfo.accounts) {
|
for (const account of exchangeWireInfo.accounts) {
|
||||||
const res = parsePaytoUri(account.payto_uri);
|
const res = parsePaytoUri(account.payto_uri);
|
||||||
if (!res) {
|
if (!res) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -333,7 +333,7 @@ export async function getHistory(
|
|||||||
amountsRaw.push(c.currentAmount);
|
amountsRaw.push(c.currentAmount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let amountRefreshedRaw = Amounts.sum(amountsRaw).amount;
|
const amountRefreshedRaw = Amounts.sum(amountsRaw).amount;
|
||||||
let amountRefreshedEffective: AmountJson;
|
let amountRefreshedEffective: AmountJson;
|
||||||
if (amountsEffective.length == 0) {
|
if (amountsEffective.length == 0) {
|
||||||
amountRefreshedEffective = Amounts.getZero(
|
amountRefreshedEffective = Amounts.getZero(
|
||||||
|
@ -198,8 +198,8 @@ export function selectPayCoins(
|
|||||||
let totalFees = Amounts.getZero(currency);
|
let totalFees = Amounts.getZero(currency);
|
||||||
let amountPayRemaining = paymentAmount;
|
let amountPayRemaining = paymentAmount;
|
||||||
let amountDepositFeeLimitRemaining = depositFeeLimit;
|
let amountDepositFeeLimitRemaining = depositFeeLimit;
|
||||||
let customerWireFees = Amounts.getZero(currency);
|
const customerWireFees = Amounts.getZero(currency);
|
||||||
let customerDepositFees = Amounts.getZero(currency);
|
const customerDepositFees = Amounts.getZero(currency);
|
||||||
for (const aci of acis) {
|
for (const aci of acis) {
|
||||||
// Don't use this coin if depositing it is more expensive than
|
// Don't use this coin if depositing it is more expensive than
|
||||||
// the amount it would give the merchant.
|
// the amount it would give the merchant.
|
||||||
@ -283,7 +283,7 @@ async function getCoinsForPayment(
|
|||||||
const exchanges = await ws.db.iter(Stores.exchanges).toArray();
|
const exchanges = await ws.db.iter(Stores.exchanges).toArray();
|
||||||
|
|
||||||
for (const exchange of exchanges) {
|
for (const exchange of exchanges) {
|
||||||
let isOkay: boolean = false;
|
let isOkay = false;
|
||||||
const exchangeDetails = exchange.details;
|
const exchangeDetails = exchange.details;
|
||||||
if (!exchangeDetails) {
|
if (!exchangeDetails) {
|
||||||
continue;
|
continue;
|
||||||
@ -618,7 +618,7 @@ async function incrementPurchasePayRetry(
|
|||||||
export async function processDownloadProposal(
|
export async function processDownloadProposal(
|
||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
proposalId: string,
|
proposalId: string,
|
||||||
forceNow: boolean = false,
|
forceNow = false,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const onOpErr = (err: OperationError) =>
|
const onOpErr = (err: OperationError) =>
|
||||||
incrementProposalRetry(ws, proposalId, err);
|
incrementProposalRetry(ws, proposalId, err);
|
||||||
@ -1106,7 +1106,7 @@ export async function confirmPay(
|
|||||||
export async function processPurchasePay(
|
export async function processPurchasePay(
|
||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
proposalId: string,
|
proposalId: string,
|
||||||
forceNow: boolean = false,
|
forceNow = false,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const onOpErr = (e: OperationError) =>
|
const onOpErr = (e: OperationError) =>
|
||||||
incrementPurchasePayRetry(ws, proposalId, e);
|
incrementPurchasePayRetry(ws, proposalId, e);
|
||||||
|
@ -54,7 +54,7 @@ async function gatherExchangePending(
|
|||||||
tx: TransactionHandle,
|
tx: TransactionHandle,
|
||||||
now: Timestamp,
|
now: Timestamp,
|
||||||
resp: PendingOperationsResponse,
|
resp: PendingOperationsResponse,
|
||||||
onlyDue: boolean = false,
|
onlyDue = false,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (onlyDue) {
|
if (onlyDue) {
|
||||||
// FIXME: exchanges should also be updated regularly
|
// FIXME: exchanges should also be updated regularly
|
||||||
@ -146,7 +146,7 @@ async function gatherReservePending(
|
|||||||
tx: TransactionHandle,
|
tx: TransactionHandle,
|
||||||
now: Timestamp,
|
now: Timestamp,
|
||||||
resp: PendingOperationsResponse,
|
resp: PendingOperationsResponse,
|
||||||
onlyDue: boolean = false,
|
onlyDue = false,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
// FIXME: this should be optimized by using an index for "onlyDue==true".
|
// FIXME: this should be optimized by using an index for "onlyDue==true".
|
||||||
await tx.iter(Stores.reserves).forEach((reserve) => {
|
await tx.iter(Stores.reserves).forEach((reserve) => {
|
||||||
@ -215,7 +215,7 @@ async function gatherRefreshPending(
|
|||||||
tx: TransactionHandle,
|
tx: TransactionHandle,
|
||||||
now: Timestamp,
|
now: Timestamp,
|
||||||
resp: PendingOperationsResponse,
|
resp: PendingOperationsResponse,
|
||||||
onlyDue: boolean = false,
|
onlyDue = false,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await tx.iter(Stores.refreshGroups).forEach((r) => {
|
await tx.iter(Stores.refreshGroups).forEach((r) => {
|
||||||
if (r.timestampFinished) {
|
if (r.timestampFinished) {
|
||||||
@ -244,7 +244,7 @@ async function gatherWithdrawalPending(
|
|||||||
tx: TransactionHandle,
|
tx: TransactionHandle,
|
||||||
now: Timestamp,
|
now: Timestamp,
|
||||||
resp: PendingOperationsResponse,
|
resp: PendingOperationsResponse,
|
||||||
onlyDue: boolean = false,
|
onlyDue = false,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await tx.iter(Stores.withdrawalGroups).forEach((wsr) => {
|
await tx.iter(Stores.withdrawalGroups).forEach((wsr) => {
|
||||||
if (wsr.timestampFinish) {
|
if (wsr.timestampFinish) {
|
||||||
@ -279,7 +279,7 @@ async function gatherProposalPending(
|
|||||||
tx: TransactionHandle,
|
tx: TransactionHandle,
|
||||||
now: Timestamp,
|
now: Timestamp,
|
||||||
resp: PendingOperationsResponse,
|
resp: PendingOperationsResponse,
|
||||||
onlyDue: boolean = false,
|
onlyDue = false,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await tx.iter(Stores.proposals).forEach((proposal) => {
|
await tx.iter(Stores.proposals).forEach((proposal) => {
|
||||||
if (proposal.proposalStatus == ProposalStatus.PROPOSED) {
|
if (proposal.proposalStatus == ProposalStatus.PROPOSED) {
|
||||||
@ -320,7 +320,7 @@ async function gatherTipPending(
|
|||||||
tx: TransactionHandle,
|
tx: TransactionHandle,
|
||||||
now: Timestamp,
|
now: Timestamp,
|
||||||
resp: PendingOperationsResponse,
|
resp: PendingOperationsResponse,
|
||||||
onlyDue: boolean = false,
|
onlyDue = false,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await tx.iter(Stores.tips).forEach((tip) => {
|
await tx.iter(Stores.tips).forEach((tip) => {
|
||||||
if (tip.pickedUp) {
|
if (tip.pickedUp) {
|
||||||
@ -350,7 +350,7 @@ async function gatherPurchasePending(
|
|||||||
tx: TransactionHandle,
|
tx: TransactionHandle,
|
||||||
now: Timestamp,
|
now: Timestamp,
|
||||||
resp: PendingOperationsResponse,
|
resp: PendingOperationsResponse,
|
||||||
onlyDue: boolean = false,
|
onlyDue = false,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await tx.iter(Stores.purchases).forEach((pr) => {
|
await tx.iter(Stores.purchases).forEach((pr) => {
|
||||||
if (pr.paymentSubmitPending) {
|
if (pr.paymentSubmitPending) {
|
||||||
@ -413,7 +413,7 @@ async function gatherRecoupPending(
|
|||||||
tx: TransactionHandle,
|
tx: TransactionHandle,
|
||||||
now: Timestamp,
|
now: Timestamp,
|
||||||
resp: PendingOperationsResponse,
|
resp: PendingOperationsResponse,
|
||||||
onlyDue: boolean = false,
|
onlyDue = false,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await tx.iter(Stores.recoupGroups).forEach((rg) => {
|
await tx.iter(Stores.recoupGroups).forEach((rg) => {
|
||||||
if (rg.timestampFinished) {
|
if (rg.timestampFinished) {
|
||||||
|
@ -291,7 +291,7 @@ async function resetRecoupGroupRetry(
|
|||||||
export async function processRecoupGroup(
|
export async function processRecoupGroup(
|
||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
recoupGroupId: string,
|
recoupGroupId: string,
|
||||||
forceNow: boolean = false,
|
forceNow = false,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await ws.memoProcessRecoup.memo(recoupGroupId, async () => {
|
await ws.memoProcessRecoup.memo(recoupGroupId, async () => {
|
||||||
const onOpErr = (e: OperationError) =>
|
const onOpErr = (e: OperationError) =>
|
||||||
@ -306,7 +306,7 @@ export async function processRecoupGroup(
|
|||||||
async function processRecoupGroupImpl(
|
async function processRecoupGroupImpl(
|
||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
recoupGroupId: string,
|
recoupGroupId: string,
|
||||||
forceNow: boolean = false,
|
forceNow = false,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (forceNow) {
|
if (forceNow) {
|
||||||
await resetRecoupGroupRetry(ws, recoupGroupId);
|
await resetRecoupGroupRetry(ws, recoupGroupId);
|
||||||
@ -386,7 +386,7 @@ async function processRecoup(
|
|||||||
|
|
||||||
const coinPub = recoupGroup.coinPubs[coinIdx];
|
const coinPub = recoupGroup.coinPubs[coinIdx];
|
||||||
|
|
||||||
let coin = await ws.db.get(Stores.coins, coinPub);
|
const coin = await ws.db.get(Stores.coins, coinPub);
|
||||||
if (!coin) {
|
if (!coin) {
|
||||||
throw Error(`Coin ${coinPub} not found, can't request payback`);
|
throw Error(`Coin ${coinPub} not found, can't request payback`);
|
||||||
}
|
}
|
||||||
|
@ -446,7 +446,7 @@ async function refreshReveal(
|
|||||||
rg.timestampFinished = getTimestampNow();
|
rg.timestampFinished = getTimestampNow();
|
||||||
rg.retryInfo = initRetryInfo(false);
|
rg.retryInfo = initRetryInfo(false);
|
||||||
}
|
}
|
||||||
for (let coin of coins) {
|
for (const coin of coins) {
|
||||||
await tx.put(Stores.coins, coin);
|
await tx.put(Stores.coins, coin);
|
||||||
}
|
}
|
||||||
await tx.put(Stores.refreshGroups, rg);
|
await tx.put(Stores.refreshGroups, rg);
|
||||||
@ -482,7 +482,7 @@ async function incrementRefreshRetry(
|
|||||||
export async function processRefreshGroup(
|
export async function processRefreshGroup(
|
||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
refreshGroupId: string,
|
refreshGroupId: string,
|
||||||
forceNow: boolean = false,
|
forceNow = false,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await ws.memoProcessRefresh.memo(refreshGroupId, async () => {
|
await ws.memoProcessRefresh.memo(refreshGroupId, async () => {
|
||||||
const onOpErr = (e: OperationError) =>
|
const onOpErr = (e: OperationError) =>
|
||||||
|
@ -300,7 +300,7 @@ export async function applyRefund(
|
|||||||
export async function processPurchaseQueryRefund(
|
export async function processPurchaseQueryRefund(
|
||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
proposalId: string,
|
proposalId: string,
|
||||||
forceNow: boolean = false,
|
forceNow = false,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const onOpErr = (e: OperationError) =>
|
const onOpErr = (e: OperationError) =>
|
||||||
incrementPurchaseQueryRefundRetry(ws, proposalId, e);
|
incrementPurchaseQueryRefundRetry(ws, proposalId, e);
|
||||||
@ -366,7 +366,7 @@ async function processPurchaseQueryRefundImpl(
|
|||||||
export async function processPurchaseApplyRefund(
|
export async function processPurchaseApplyRefund(
|
||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
proposalId: string,
|
proposalId: string,
|
||||||
forceNow: boolean = false,
|
forceNow = false,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const onOpErr = (e: OperationError) =>
|
const onOpErr = (e: OperationError) =>
|
||||||
incrementPurchaseApplyRefundRetry(ws, proposalId, e);
|
incrementPurchaseApplyRefundRetry(ws, proposalId, e);
|
||||||
@ -460,7 +460,7 @@ async function processPurchaseApplyRefundImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Groups that failed/succeeded
|
// Groups that failed/succeeded
|
||||||
let groups: { [refundGroupId: string]: boolean } = {};
|
const groups: { [refundGroupId: string]: boolean } = {};
|
||||||
|
|
||||||
// Avoid duplicates
|
// Avoid duplicates
|
||||||
const refreshCoinsMap: { [coinPub: string]: CoinPublicKey } = {};
|
const refreshCoinsMap: { [coinPub: string]: CoinPublicKey } = {};
|
||||||
|
@ -248,7 +248,7 @@ export async function forceQueryReserve(
|
|||||||
export async function processReserve(
|
export async function processReserve(
|
||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
reservePub: string,
|
reservePub: string,
|
||||||
forceNow: boolean = false,
|
forceNow = false,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
return ws.memoProcessReserve.memo(reservePub, async () => {
|
return ws.memoProcessReserve.memo(reservePub, async () => {
|
||||||
const onOpError = (err: OperationError) =>
|
const onOpError = (err: OperationError) =>
|
||||||
@ -264,7 +264,7 @@ async function registerReserveWithBank(
|
|||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
reservePub: string,
|
reservePub: string,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
let reserve = await ws.db.get(Stores.reserves, reservePub);
|
const reserve = await ws.db.get(Stores.reserves, reservePub);
|
||||||
switch (reserve?.reserveStatus) {
|
switch (reserve?.reserveStatus) {
|
||||||
case ReserveRecordStatus.WAIT_CONFIRM_BANK:
|
case ReserveRecordStatus.WAIT_CONFIRM_BANK:
|
||||||
case ReserveRecordStatus.REGISTERING_BANK:
|
case ReserveRecordStatus.REGISTERING_BANK:
|
||||||
@ -317,7 +317,7 @@ async function processReserveBankStatusImpl(
|
|||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
reservePub: string,
|
reservePub: string,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
let reserve = await ws.db.get(Stores.reserves, reservePub);
|
const reserve = await ws.db.get(Stores.reserves, reservePub);
|
||||||
switch (reserve?.reserveStatus) {
|
switch (reserve?.reserveStatus) {
|
||||||
case ReserveRecordStatus.WAIT_CONFIRM_BANK:
|
case ReserveRecordStatus.WAIT_CONFIRM_BANK:
|
||||||
case ReserveRecordStatus.REGISTERING_BANK:
|
case ReserveRecordStatus.REGISTERING_BANK:
|
||||||
@ -534,7 +534,7 @@ async function updateReserve(
|
|||||||
async function processReserveImpl(
|
async function processReserveImpl(
|
||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
reservePub: string,
|
reservePub: string,
|
||||||
forceNow: boolean = false,
|
forceNow = false,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const reserve = await ws.db.get(Stores.reserves, reservePub);
|
const reserve = await ws.db.get(Stores.reserves, reservePub);
|
||||||
if (!reserve) {
|
if (!reserve) {
|
||||||
|
@ -66,7 +66,7 @@ export async function getTipStatus(
|
|||||||
|
|
||||||
console.log("status", tipPickupStatus);
|
console.log("status", tipPickupStatus);
|
||||||
|
|
||||||
let amount = Amounts.parseOrThrow(tipPickupStatus.amount);
|
const amount = Amounts.parseOrThrow(tipPickupStatus.amount);
|
||||||
|
|
||||||
let tipRecord = await ws.db.get(Stores.tips, [
|
let tipRecord = await ws.db.get(Stores.tips, [
|
||||||
res.merchantTipId,
|
res.merchantTipId,
|
||||||
@ -147,7 +147,7 @@ async function incrementTipRetry(
|
|||||||
export async function processTip(
|
export async function processTip(
|
||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
tipId: string,
|
tipId: string,
|
||||||
forceNow: boolean = false,
|
forceNow = false,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const onOpErr = (e: OperationError) => incrementTipRetry(ws, tipId, e);
|
const onOpErr = (e: OperationError) => incrementTipRetry(ws, tipId, e);
|
||||||
await guardOperationException(
|
await guardOperationException(
|
||||||
|
@ -394,7 +394,7 @@ async function incrementWithdrawalRetry(
|
|||||||
export async function processWithdrawGroup(
|
export async function processWithdrawGroup(
|
||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
withdrawalGroupId: string,
|
withdrawalGroupId: string,
|
||||||
forceNow: boolean = false,
|
forceNow = false,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const onOpErr = (e: OperationError) =>
|
const onOpErr = (e: OperationError) =>
|
||||||
incrementWithdrawalRetry(ws, withdrawalGroupId, e);
|
incrementWithdrawalRetry(ws, withdrawalGroupId, e);
|
||||||
@ -470,7 +470,7 @@ export async function getExchangeWithdrawalInfo(
|
|||||||
.reduce((a, b) => Amounts.add(a, b).amount);
|
.reduce((a, b) => Amounts.add(a, b).amount);
|
||||||
|
|
||||||
const exchangeWireAccounts: string[] = [];
|
const exchangeWireAccounts: string[] = [];
|
||||||
for (let account of exchangeWireInfo.accounts) {
|
for (const account of exchangeWireInfo.accounts) {
|
||||||
exchangeWireAccounts.push(account.payto_uri);
|
exchangeWireAccounts.push(account.payto_uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ export function updateRetryInfoTimeout(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function initRetryInfo(
|
export function initRetryInfo(
|
||||||
active: boolean = true,
|
active = true,
|
||||||
p: RetryPolicy = defaultRetryPolicy,
|
p: RetryPolicy = defaultRetryPolicy,
|
||||||
): RetryInfo {
|
): RetryInfo {
|
||||||
if (!active) {
|
if (!active) {
|
||||||
|
@ -260,7 +260,7 @@ export function parse(s: string): AmountJson | undefined {
|
|||||||
if (tail.length > fractionalLength + 1) {
|
if (tail.length > fractionalLength + 1) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
let value = Number.parseInt(res[2]);
|
const value = Number.parseInt(res[2]);
|
||||||
if (value > maxAmountValue) {
|
if (value > maxAmountValue) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
@ -123,8 +123,8 @@ interface CursorValueResult<T> {
|
|||||||
|
|
||||||
class ResultStream<T> {
|
class ResultStream<T> {
|
||||||
private currentPromise: Promise<void>;
|
private currentPromise: Promise<void>;
|
||||||
private gotCursorEnd: boolean = false;
|
private gotCursorEnd = false;
|
||||||
private awaitingResult: boolean = false;
|
private awaitingResult = false;
|
||||||
|
|
||||||
constructor(private req: IDBRequest) {
|
constructor(private req: IDBRequest) {
|
||||||
this.awaitingResult = true;
|
this.awaitingResult = true;
|
||||||
@ -304,7 +304,7 @@ function runWithTransaction<T>(
|
|||||||
const storeName = stores.map((x) => x.name);
|
const storeName = stores.map((x) => x.name);
|
||||||
const tx = db.transaction(storeName, mode);
|
const tx = db.transaction(storeName, mode);
|
||||||
let funResult: any = undefined;
|
let funResult: any = undefined;
|
||||||
let gotFunResult: boolean = false;
|
let gotFunResult = false;
|
||||||
tx.oncomplete = () => {
|
tx.oncomplete = () => {
|
||||||
// This is a fatal error: The transaction completed *before*
|
// This is a fatal error: The transaction completed *before*
|
||||||
// the transaction function returned. Likely, the transaction
|
// the transaction function returned. Likely, the transaction
|
||||||
|
@ -34,7 +34,7 @@ export interface Duration {
|
|||||||
readonly d_ms: number | "forever";
|
readonly d_ms: number | "forever";
|
||||||
}
|
}
|
||||||
|
|
||||||
let timeshift: number = 0;
|
let timeshift = 0;
|
||||||
|
|
||||||
export function setDangerousTimetravel(dt: number) {
|
export function setDangerousTimetravel(dt: number) {
|
||||||
timeshift = dt;
|
timeshift = dt;
|
||||||
|
@ -87,7 +87,7 @@ const nullTimerHandle = {
|
|||||||
* Group of timers that can be destroyed at once.
|
* Group of timers that can be destroyed at once.
|
||||||
*/
|
*/
|
||||||
export class TimerGroup {
|
export class TimerGroup {
|
||||||
private stopped: boolean = false;
|
private stopped = false;
|
||||||
|
|
||||||
private timerMap: { [index: number]: TimerHandle } = {};
|
private timerMap: { [index: number]: TimerHandle } = {};
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ export class Wallet {
|
|||||||
private ws: InternalWalletState;
|
private ws: InternalWalletState;
|
||||||
private timerGroup: TimerGroup = new TimerGroup();
|
private timerGroup: TimerGroup = new TimerGroup();
|
||||||
private latch = new AsyncCondition();
|
private latch = new AsyncCondition();
|
||||||
private stopped: boolean = false;
|
private stopped = false;
|
||||||
private memoRunRetryLoop = new AsyncOpMemoSingle<void>();
|
private memoRunRetryLoop = new AsyncOpMemoSingle<void>();
|
||||||
|
|
||||||
get db(): Database {
|
get db(): Database {
|
||||||
@ -175,7 +175,7 @@ export class Wallet {
|
|||||||
*/
|
*/
|
||||||
async processOnePendingOperation(
|
async processOnePendingOperation(
|
||||||
pending: PendingOperationInfo,
|
pending: PendingOperationInfo,
|
||||||
forceNow: boolean = false,
|
forceNow = false,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
console.log("running pending", pending);
|
console.log("running pending", pending);
|
||||||
switch (pending.type) {
|
switch (pending.type) {
|
||||||
@ -230,7 +230,7 @@ export class Wallet {
|
|||||||
/**
|
/**
|
||||||
* Process pending operations.
|
* Process pending operations.
|
||||||
*/
|
*/
|
||||||
public async runPending(forceNow: boolean = false): Promise<void> {
|
public async runPending(forceNow = false): Promise<void> {
|
||||||
const onlyDue = !forceNow;
|
const onlyDue = !forceNow;
|
||||||
const pendingOpsResponse = await this.getPendingOperations({ onlyDue });
|
const pendingOpsResponse = await this.getPendingOperations({ onlyDue });
|
||||||
for (const p of pendingOpsResponse.pendingOperations) {
|
for (const p of pendingOpsResponse.pendingOperations) {
|
||||||
@ -318,7 +318,7 @@ export class Wallet {
|
|||||||
private async runRetryLoopImpl(): Promise<void> {
|
private async runRetryLoopImpl(): Promise<void> {
|
||||||
while (!this.stopped) {
|
while (!this.stopped) {
|
||||||
console.log("running wallet retry loop iteration");
|
console.log("running wallet retry loop iteration");
|
||||||
let pending = await this.getPendingOperations({ onlyDue: true });
|
const pending = await this.getPendingOperations({ onlyDue: true });
|
||||||
console.log("pending ops", JSON.stringify(pending, undefined, 2));
|
console.log("pending ops", JSON.stringify(pending, undefined, 2));
|
||||||
if (pending.pendingOperations.length === 0) {
|
if (pending.pendingOperations.length === 0) {
|
||||||
const allPending = await this.getPendingOperations({ onlyDue: false });
|
const allPending = await this.getPendingOperations({ onlyDue: false });
|
||||||
@ -382,7 +382,7 @@ export class Wallet {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!applied) {
|
if (!applied) {
|
||||||
for (let c of builtinCurrencies) {
|
for (const c of builtinCurrencies) {
|
||||||
await tx.put(Stores.currencies, c);
|
await tx.put(Stores.currencies, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -489,7 +489,7 @@ export class Wallet {
|
|||||||
*/
|
*/
|
||||||
async updateExchangeFromUrl(
|
async updateExchangeFromUrl(
|
||||||
baseUrl: string,
|
baseUrl: string,
|
||||||
force: boolean = false,
|
force = false,
|
||||||
): Promise<ExchangeRecord> {
|
): Promise<ExchangeRecord> {
|
||||||
try {
|
try {
|
||||||
return updateExchangeFromUrl(this.ws, baseUrl, force);
|
return updateExchangeFromUrl(this.ws, baseUrl, force);
|
||||||
|
@ -38,25 +38,25 @@ export class ChromeBadge {
|
|||||||
* might still be running even if we're not busy anymore,
|
* might still be running even if we're not busy anymore,
|
||||||
* just to transition to the "normal" state in a animated way.
|
* just to transition to the "normal" state in a animated way.
|
||||||
*/
|
*/
|
||||||
private animationRunning: boolean = false;
|
private animationRunning = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the wallet still busy? Note that we do not stop the
|
* Is the wallet still busy? Note that we do not stop the
|
||||||
* animation immediately when the wallet goes idle, but
|
* animation immediately when the wallet goes idle, but
|
||||||
* instead slowly close the gap.
|
* instead slowly close the gap.
|
||||||
*/
|
*/
|
||||||
private isBusy: boolean = false;
|
private isBusy = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current rotation angle, ranges from 0 to rotationAngleMax.
|
* Current rotation angle, ranges from 0 to rotationAngleMax.
|
||||||
*/
|
*/
|
||||||
private rotationAngle: number = 0;
|
private rotationAngle = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* While animating, how wide is the current gap in the circle?
|
* While animating, how wide is the current gap in the circle?
|
||||||
* Ranges from 0 to openMax.
|
* Ranges from 0 to openMax.
|
||||||
*/
|
*/
|
||||||
private gapWidth: number = 0;
|
private gapWidth = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Should we show the notification dot?
|
* Should we show the notification dot?
|
||||||
|
@ -30,7 +30,7 @@ import * as React from "react";
|
|||||||
|
|
||||||
const jed = setupJed();
|
const jed = setupJed();
|
||||||
|
|
||||||
let enableTracing = false;
|
const enableTracing = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up jed library for internationalization,
|
* Set up jed library for internationalization,
|
||||||
|
@ -26,9 +26,9 @@
|
|||||||
*/
|
*/
|
||||||
import * as wxApi from "./wxApi";
|
import * as wxApi from "./wxApi";
|
||||||
|
|
||||||
declare var cloneInto: any;
|
declare let cloneInto: any;
|
||||||
|
|
||||||
let logVerbose: boolean = false;
|
let logVerbose = false;
|
||||||
try {
|
try {
|
||||||
logVerbose = !!localStorage.getItem("taler-log-verbose");
|
logVerbose = !!localStorage.getItem("taler-log-verbose");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -77,7 +77,7 @@ class BenchmarkRunner extends React.Component<any, BenchmarkRunnerState> {
|
|||||||
|
|
||||||
async run() {
|
async run() {
|
||||||
this.setState({ result: undefined, running: true });
|
this.setState({ result: undefined, running: true });
|
||||||
let result = await wxApi.benchmarkCrypto(this.state.repetitions);
|
const result = await wxApi.benchmarkCrypto(this.state.repetitions);
|
||||||
this.setState({ result, running: false });
|
this.setState({ result, running: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,8 +427,8 @@ function amountDiff(
|
|||||||
total: string | Amounts.AmountJson,
|
total: string | Amounts.AmountJson,
|
||||||
partial: string | Amounts.AmountJson,
|
partial: string | Amounts.AmountJson,
|
||||||
): Amounts.AmountJson | string {
|
): Amounts.AmountJson | string {
|
||||||
let a = typeof total === "string" ? Amounts.parse(total) : total;
|
const a = typeof total === "string" ? Amounts.parse(total) : total;
|
||||||
let b = typeof partial === "string" ? Amounts.parse(partial) : partial;
|
const b = typeof partial === "string" ? Amounts.parse(partial) : partial;
|
||||||
if (a && b) {
|
if (a && b) {
|
||||||
return Amounts.sub(a, b).amount;
|
return Amounts.sub(a, b).amount;
|
||||||
} else {
|
} else {
|
||||||
@ -437,7 +437,7 @@ function amountDiff(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parseSummary(summary: string) {
|
function parseSummary(summary: string) {
|
||||||
let parsed = summary.split(/: (.+)/);
|
const parsed = summary.split(/: (.+)/);
|
||||||
return {
|
return {
|
||||||
merchant: parsed[0],
|
merchant: parsed[0],
|
||||||
item: parsed[1],
|
item: parsed[1],
|
||||||
|
@ -61,7 +61,7 @@ export const AmountView = ({ amount }: { amount: AmountJson | string }) =>
|
|||||||
* Abbreviate a string to a given length, and show the full
|
* Abbreviate a string to a given length, and show the full
|
||||||
* string on hover as a tooltip.
|
* string on hover as a tooltip.
|
||||||
*/
|
*/
|
||||||
export function abbrev(s: string, n: number = 5) {
|
export function abbrev(s: string, n = 5) {
|
||||||
let sAbbrev = s;
|
let sAbbrev = s;
|
||||||
if (s.length > n) {
|
if (s.length > n) {
|
||||||
sAbbrev = s.slice(0, n) + "..";
|
sAbbrev = s.slice(0, n) + "..";
|
||||||
|
@ -384,7 +384,7 @@ let currentDatabase: IDBDatabase | undefined;
|
|||||||
*/
|
*/
|
||||||
let outdatedDbVersion: number | undefined;
|
let outdatedDbVersion: number | undefined;
|
||||||
|
|
||||||
let walletInit: OpenedPromise<void> = openPromise<void>();
|
const walletInit: OpenedPromise<void> = openPromise<void>();
|
||||||
|
|
||||||
async function reinitWallet() {
|
async function reinitWallet() {
|
||||||
if (currentWallet) {
|
if (currentWallet) {
|
||||||
@ -571,7 +571,7 @@ export async function wxMain() {
|
|||||||
}
|
}
|
||||||
if (details.statusCode === 402 || details.statusCode === 202) {
|
if (details.statusCode === 402 || details.statusCode === 202) {
|
||||||
console.log(`got 402/202 from ${details.url}`);
|
console.log(`got 402/202 from ${details.url}`);
|
||||||
for (let header of details.responseHeaders || []) {
|
for (const header of details.responseHeaders || []) {
|
||||||
if (header.name.toLowerCase() === "taler") {
|
if (header.name.toLowerCase() === "taler") {
|
||||||
const talerUri = header.value || "";
|
const talerUri = header.value || "";
|
||||||
const uriType = classifyTalerUri(talerUri);
|
const uriType = classifyTalerUri(talerUri);
|
||||||
|
Loading…
Reference in New Issue
Block a user