@zubari/sdk 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/TransactionService-CxwB1kpN.d.mts +205 -0
- package/dist/TransactionService-DdL6H6M-.d.ts +205 -0
- package/dist/{WalletManager-TiAdzqrn.d.ts → WalletManager-CYJNiww6.d.ts} +49 -132
- package/dist/{WalletManager-DJjdq89b.d.mts → WalletManager-Dmmcbtiw.d.mts} +49 -132
- package/dist/{index-BLuxEdLp.d.mts → index-DhluuR9H.d.mts} +1 -1
- package/dist/{index-BLuxEdLp.d.ts → index-DhluuR9H.d.ts} +1 -1
- package/dist/{index-DO3T2HVe.d.ts → index-OxzgPoRG.d.ts} +2 -2
- package/dist/{index-fXVD8_D0.d.mts → index-poGbMJzn.d.mts} +2 -2
- package/dist/index.d.mts +5 -6
- package/dist/index.d.ts +5 -6
- package/dist/index.js +3112 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3110 -3
- package/dist/index.mjs.map +1 -1
- package/dist/protocols/index.d.mts +1 -1
- package/dist/protocols/index.d.ts +1 -1
- package/dist/react/index.d.mts +4 -5
- package/dist/react/index.d.ts +4 -5
- package/dist/react/index.js +2704 -3
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +2704 -3
- package/dist/react/index.mjs.map +1 -1
- package/dist/services/index.d.mts +87 -3
- package/dist/services/index.d.ts +87 -3
- package/dist/services/index.js +3065 -2
- package/dist/services/index.js.map +1 -1
- package/dist/services/index.mjs +3062 -3
- package/dist/services/index.mjs.map +1 -1
- package/dist/wallet/index.d.mts +4 -5
- package/dist/wallet/index.d.ts +4 -5
- package/dist/wallet/index.js +2705 -2
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +2705 -2
- package/dist/wallet/index.mjs.map +1 -1
- package/package.json +6 -1
- package/dist/SwapService-C0G8IXW2.d.mts +0 -35
- package/dist/SwapService-DZD0OJI_.d.ts +0 -35
package/dist/services/index.js
CHANGED
|
@@ -1,5 +1,2468 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var ethers = require('ethers');
|
|
4
|
+
var bip39 = require('@scure/bip39');
|
|
5
|
+
var english = require('@scure/bip39/wordlists/english');
|
|
6
|
+
var bip32 = require('@scure/bip32');
|
|
7
|
+
var base = require('@scure/base');
|
|
8
|
+
var sha256 = require('@noble/hashes/sha256');
|
|
9
|
+
var ripemd160 = require('@noble/hashes/ripemd160');
|
|
10
|
+
|
|
11
|
+
var __create = Object.create;
|
|
12
|
+
var __defProp = Object.defineProperty;
|
|
13
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
14
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
15
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
16
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
17
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
18
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
19
|
+
}) : x)(function(x) {
|
|
20
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
21
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
22
|
+
});
|
|
23
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
24
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
25
|
+
};
|
|
26
|
+
var __export = (target, all) => {
|
|
27
|
+
for (var name in all)
|
|
28
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
29
|
+
};
|
|
30
|
+
var __copyProps = (to, from, except, desc) => {
|
|
31
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
32
|
+
for (let key of __getOwnPropNames(from))
|
|
33
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
34
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
35
|
+
}
|
|
36
|
+
return to;
|
|
37
|
+
};
|
|
38
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
39
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
40
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
41
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
42
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
43
|
+
!mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
44
|
+
mod
|
|
45
|
+
));
|
|
46
|
+
|
|
47
|
+
// ../../node_modules/tweetnacl/nacl-fast.js
|
|
48
|
+
var require_nacl_fast = __commonJS({
|
|
49
|
+
"../../node_modules/tweetnacl/nacl-fast.js"(exports$1, module) {
|
|
50
|
+
(function(nacl) {
|
|
51
|
+
var gf = function(init) {
|
|
52
|
+
var i, r = new Float64Array(16);
|
|
53
|
+
if (init) for (i = 0; i < init.length; i++) r[i] = init[i];
|
|
54
|
+
return r;
|
|
55
|
+
};
|
|
56
|
+
var randombytes = function() {
|
|
57
|
+
throw new Error("no PRNG");
|
|
58
|
+
};
|
|
59
|
+
var _0 = new Uint8Array(16);
|
|
60
|
+
var _9 = new Uint8Array(32);
|
|
61
|
+
_9[0] = 9;
|
|
62
|
+
var gf0 = gf(), gf1 = gf([1]), _121665 = gf([56129, 1]), D = gf([30883, 4953, 19914, 30187, 55467, 16705, 2637, 112, 59544, 30585, 16505, 36039, 65139, 11119, 27886, 20995]), D2 = gf([61785, 9906, 39828, 60374, 45398, 33411, 5274, 224, 53552, 61171, 33010, 6542, 64743, 22239, 55772, 9222]), X = gf([54554, 36645, 11616, 51542, 42930, 38181, 51040, 26924, 56412, 64982, 57905, 49316, 21502, 52590, 14035, 8553]), Y = gf([26200, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214]), I = gf([41136, 18958, 6951, 50414, 58488, 44335, 6150, 12099, 55207, 15867, 153, 11085, 57099, 20417, 9344, 11139]);
|
|
63
|
+
function ts64(x, i, h, l) {
|
|
64
|
+
x[i] = h >> 24 & 255;
|
|
65
|
+
x[i + 1] = h >> 16 & 255;
|
|
66
|
+
x[i + 2] = h >> 8 & 255;
|
|
67
|
+
x[i + 3] = h & 255;
|
|
68
|
+
x[i + 4] = l >> 24 & 255;
|
|
69
|
+
x[i + 5] = l >> 16 & 255;
|
|
70
|
+
x[i + 6] = l >> 8 & 255;
|
|
71
|
+
x[i + 7] = l & 255;
|
|
72
|
+
}
|
|
73
|
+
function vn(x, xi, y, yi, n) {
|
|
74
|
+
var i, d = 0;
|
|
75
|
+
for (i = 0; i < n; i++) d |= x[xi + i] ^ y[yi + i];
|
|
76
|
+
return (1 & d - 1 >>> 8) - 1;
|
|
77
|
+
}
|
|
78
|
+
function crypto_verify_16(x, xi, y, yi) {
|
|
79
|
+
return vn(x, xi, y, yi, 16);
|
|
80
|
+
}
|
|
81
|
+
function crypto_verify_32(x, xi, y, yi) {
|
|
82
|
+
return vn(x, xi, y, yi, 32);
|
|
83
|
+
}
|
|
84
|
+
function core_salsa20(o, p, k, c) {
|
|
85
|
+
var j0 = c[0] & 255 | (c[1] & 255) << 8 | (c[2] & 255) << 16 | (c[3] & 255) << 24, j1 = k[0] & 255 | (k[1] & 255) << 8 | (k[2] & 255) << 16 | (k[3] & 255) << 24, j2 = k[4] & 255 | (k[5] & 255) << 8 | (k[6] & 255) << 16 | (k[7] & 255) << 24, j3 = k[8] & 255 | (k[9] & 255) << 8 | (k[10] & 255) << 16 | (k[11] & 255) << 24, j4 = k[12] & 255 | (k[13] & 255) << 8 | (k[14] & 255) << 16 | (k[15] & 255) << 24, j5 = c[4] & 255 | (c[5] & 255) << 8 | (c[6] & 255) << 16 | (c[7] & 255) << 24, j6 = p[0] & 255 | (p[1] & 255) << 8 | (p[2] & 255) << 16 | (p[3] & 255) << 24, j7 = p[4] & 255 | (p[5] & 255) << 8 | (p[6] & 255) << 16 | (p[7] & 255) << 24, j8 = p[8] & 255 | (p[9] & 255) << 8 | (p[10] & 255) << 16 | (p[11] & 255) << 24, j9 = p[12] & 255 | (p[13] & 255) << 8 | (p[14] & 255) << 16 | (p[15] & 255) << 24, j10 = c[8] & 255 | (c[9] & 255) << 8 | (c[10] & 255) << 16 | (c[11] & 255) << 24, j11 = k[16] & 255 | (k[17] & 255) << 8 | (k[18] & 255) << 16 | (k[19] & 255) << 24, j12 = k[20] & 255 | (k[21] & 255) << 8 | (k[22] & 255) << 16 | (k[23] & 255) << 24, j13 = k[24] & 255 | (k[25] & 255) << 8 | (k[26] & 255) << 16 | (k[27] & 255) << 24, j14 = k[28] & 255 | (k[29] & 255) << 8 | (k[30] & 255) << 16 | (k[31] & 255) << 24, j15 = c[12] & 255 | (c[13] & 255) << 8 | (c[14] & 255) << 16 | (c[15] & 255) << 24;
|
|
86
|
+
var 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, x15 = j15, u;
|
|
87
|
+
for (var i = 0; i < 20; i += 2) {
|
|
88
|
+
u = x0 + x12 | 0;
|
|
89
|
+
x4 ^= u << 7 | u >>> 32 - 7;
|
|
90
|
+
u = x4 + x0 | 0;
|
|
91
|
+
x8 ^= u << 9 | u >>> 32 - 9;
|
|
92
|
+
u = x8 + x4 | 0;
|
|
93
|
+
x12 ^= u << 13 | u >>> 32 - 13;
|
|
94
|
+
u = x12 + x8 | 0;
|
|
95
|
+
x0 ^= u << 18 | u >>> 32 - 18;
|
|
96
|
+
u = x5 + x1 | 0;
|
|
97
|
+
x9 ^= u << 7 | u >>> 32 - 7;
|
|
98
|
+
u = x9 + x5 | 0;
|
|
99
|
+
x13 ^= u << 9 | u >>> 32 - 9;
|
|
100
|
+
u = x13 + x9 | 0;
|
|
101
|
+
x1 ^= u << 13 | u >>> 32 - 13;
|
|
102
|
+
u = x1 + x13 | 0;
|
|
103
|
+
x5 ^= u << 18 | u >>> 32 - 18;
|
|
104
|
+
u = x10 + x6 | 0;
|
|
105
|
+
x14 ^= u << 7 | u >>> 32 - 7;
|
|
106
|
+
u = x14 + x10 | 0;
|
|
107
|
+
x2 ^= u << 9 | u >>> 32 - 9;
|
|
108
|
+
u = x2 + x14 | 0;
|
|
109
|
+
x6 ^= u << 13 | u >>> 32 - 13;
|
|
110
|
+
u = x6 + x2 | 0;
|
|
111
|
+
x10 ^= u << 18 | u >>> 32 - 18;
|
|
112
|
+
u = x15 + x11 | 0;
|
|
113
|
+
x3 ^= u << 7 | u >>> 32 - 7;
|
|
114
|
+
u = x3 + x15 | 0;
|
|
115
|
+
x7 ^= u << 9 | u >>> 32 - 9;
|
|
116
|
+
u = x7 + x3 | 0;
|
|
117
|
+
x11 ^= u << 13 | u >>> 32 - 13;
|
|
118
|
+
u = x11 + x7 | 0;
|
|
119
|
+
x15 ^= u << 18 | u >>> 32 - 18;
|
|
120
|
+
u = x0 + x3 | 0;
|
|
121
|
+
x1 ^= u << 7 | u >>> 32 - 7;
|
|
122
|
+
u = x1 + x0 | 0;
|
|
123
|
+
x2 ^= u << 9 | u >>> 32 - 9;
|
|
124
|
+
u = x2 + x1 | 0;
|
|
125
|
+
x3 ^= u << 13 | u >>> 32 - 13;
|
|
126
|
+
u = x3 + x2 | 0;
|
|
127
|
+
x0 ^= u << 18 | u >>> 32 - 18;
|
|
128
|
+
u = x5 + x4 | 0;
|
|
129
|
+
x6 ^= u << 7 | u >>> 32 - 7;
|
|
130
|
+
u = x6 + x5 | 0;
|
|
131
|
+
x7 ^= u << 9 | u >>> 32 - 9;
|
|
132
|
+
u = x7 + x6 | 0;
|
|
133
|
+
x4 ^= u << 13 | u >>> 32 - 13;
|
|
134
|
+
u = x4 + x7 | 0;
|
|
135
|
+
x5 ^= u << 18 | u >>> 32 - 18;
|
|
136
|
+
u = x10 + x9 | 0;
|
|
137
|
+
x11 ^= u << 7 | u >>> 32 - 7;
|
|
138
|
+
u = x11 + x10 | 0;
|
|
139
|
+
x8 ^= u << 9 | u >>> 32 - 9;
|
|
140
|
+
u = x8 + x11 | 0;
|
|
141
|
+
x9 ^= u << 13 | u >>> 32 - 13;
|
|
142
|
+
u = x9 + x8 | 0;
|
|
143
|
+
x10 ^= u << 18 | u >>> 32 - 18;
|
|
144
|
+
u = x15 + x14 | 0;
|
|
145
|
+
x12 ^= u << 7 | u >>> 32 - 7;
|
|
146
|
+
u = x12 + x15 | 0;
|
|
147
|
+
x13 ^= u << 9 | u >>> 32 - 9;
|
|
148
|
+
u = x13 + x12 | 0;
|
|
149
|
+
x14 ^= u << 13 | u >>> 32 - 13;
|
|
150
|
+
u = x14 + x13 | 0;
|
|
151
|
+
x15 ^= u << 18 | u >>> 32 - 18;
|
|
152
|
+
}
|
|
153
|
+
x0 = x0 + j0 | 0;
|
|
154
|
+
x1 = x1 + j1 | 0;
|
|
155
|
+
x2 = x2 + j2 | 0;
|
|
156
|
+
x3 = x3 + j3 | 0;
|
|
157
|
+
x4 = x4 + j4 | 0;
|
|
158
|
+
x5 = x5 + j5 | 0;
|
|
159
|
+
x6 = x6 + j6 | 0;
|
|
160
|
+
x7 = x7 + j7 | 0;
|
|
161
|
+
x8 = x8 + j8 | 0;
|
|
162
|
+
x9 = x9 + j9 | 0;
|
|
163
|
+
x10 = x10 + j10 | 0;
|
|
164
|
+
x11 = x11 + j11 | 0;
|
|
165
|
+
x12 = x12 + j12 | 0;
|
|
166
|
+
x13 = x13 + j13 | 0;
|
|
167
|
+
x14 = x14 + j14 | 0;
|
|
168
|
+
x15 = x15 + j15 | 0;
|
|
169
|
+
o[0] = x0 >>> 0 & 255;
|
|
170
|
+
o[1] = x0 >>> 8 & 255;
|
|
171
|
+
o[2] = x0 >>> 16 & 255;
|
|
172
|
+
o[3] = x0 >>> 24 & 255;
|
|
173
|
+
o[4] = x1 >>> 0 & 255;
|
|
174
|
+
o[5] = x1 >>> 8 & 255;
|
|
175
|
+
o[6] = x1 >>> 16 & 255;
|
|
176
|
+
o[7] = x1 >>> 24 & 255;
|
|
177
|
+
o[8] = x2 >>> 0 & 255;
|
|
178
|
+
o[9] = x2 >>> 8 & 255;
|
|
179
|
+
o[10] = x2 >>> 16 & 255;
|
|
180
|
+
o[11] = x2 >>> 24 & 255;
|
|
181
|
+
o[12] = x3 >>> 0 & 255;
|
|
182
|
+
o[13] = x3 >>> 8 & 255;
|
|
183
|
+
o[14] = x3 >>> 16 & 255;
|
|
184
|
+
o[15] = x3 >>> 24 & 255;
|
|
185
|
+
o[16] = x4 >>> 0 & 255;
|
|
186
|
+
o[17] = x4 >>> 8 & 255;
|
|
187
|
+
o[18] = x4 >>> 16 & 255;
|
|
188
|
+
o[19] = x4 >>> 24 & 255;
|
|
189
|
+
o[20] = x5 >>> 0 & 255;
|
|
190
|
+
o[21] = x5 >>> 8 & 255;
|
|
191
|
+
o[22] = x5 >>> 16 & 255;
|
|
192
|
+
o[23] = x5 >>> 24 & 255;
|
|
193
|
+
o[24] = x6 >>> 0 & 255;
|
|
194
|
+
o[25] = x6 >>> 8 & 255;
|
|
195
|
+
o[26] = x6 >>> 16 & 255;
|
|
196
|
+
o[27] = x6 >>> 24 & 255;
|
|
197
|
+
o[28] = x7 >>> 0 & 255;
|
|
198
|
+
o[29] = x7 >>> 8 & 255;
|
|
199
|
+
o[30] = x7 >>> 16 & 255;
|
|
200
|
+
o[31] = x7 >>> 24 & 255;
|
|
201
|
+
o[32] = x8 >>> 0 & 255;
|
|
202
|
+
o[33] = x8 >>> 8 & 255;
|
|
203
|
+
o[34] = x8 >>> 16 & 255;
|
|
204
|
+
o[35] = x8 >>> 24 & 255;
|
|
205
|
+
o[36] = x9 >>> 0 & 255;
|
|
206
|
+
o[37] = x9 >>> 8 & 255;
|
|
207
|
+
o[38] = x9 >>> 16 & 255;
|
|
208
|
+
o[39] = x9 >>> 24 & 255;
|
|
209
|
+
o[40] = x10 >>> 0 & 255;
|
|
210
|
+
o[41] = x10 >>> 8 & 255;
|
|
211
|
+
o[42] = x10 >>> 16 & 255;
|
|
212
|
+
o[43] = x10 >>> 24 & 255;
|
|
213
|
+
o[44] = x11 >>> 0 & 255;
|
|
214
|
+
o[45] = x11 >>> 8 & 255;
|
|
215
|
+
o[46] = x11 >>> 16 & 255;
|
|
216
|
+
o[47] = x11 >>> 24 & 255;
|
|
217
|
+
o[48] = x12 >>> 0 & 255;
|
|
218
|
+
o[49] = x12 >>> 8 & 255;
|
|
219
|
+
o[50] = x12 >>> 16 & 255;
|
|
220
|
+
o[51] = x12 >>> 24 & 255;
|
|
221
|
+
o[52] = x13 >>> 0 & 255;
|
|
222
|
+
o[53] = x13 >>> 8 & 255;
|
|
223
|
+
o[54] = x13 >>> 16 & 255;
|
|
224
|
+
o[55] = x13 >>> 24 & 255;
|
|
225
|
+
o[56] = x14 >>> 0 & 255;
|
|
226
|
+
o[57] = x14 >>> 8 & 255;
|
|
227
|
+
o[58] = x14 >>> 16 & 255;
|
|
228
|
+
o[59] = x14 >>> 24 & 255;
|
|
229
|
+
o[60] = x15 >>> 0 & 255;
|
|
230
|
+
o[61] = x15 >>> 8 & 255;
|
|
231
|
+
o[62] = x15 >>> 16 & 255;
|
|
232
|
+
o[63] = x15 >>> 24 & 255;
|
|
233
|
+
}
|
|
234
|
+
function core_hsalsa20(o, p, k, c) {
|
|
235
|
+
var j0 = c[0] & 255 | (c[1] & 255) << 8 | (c[2] & 255) << 16 | (c[3] & 255) << 24, j1 = k[0] & 255 | (k[1] & 255) << 8 | (k[2] & 255) << 16 | (k[3] & 255) << 24, j2 = k[4] & 255 | (k[5] & 255) << 8 | (k[6] & 255) << 16 | (k[7] & 255) << 24, j3 = k[8] & 255 | (k[9] & 255) << 8 | (k[10] & 255) << 16 | (k[11] & 255) << 24, j4 = k[12] & 255 | (k[13] & 255) << 8 | (k[14] & 255) << 16 | (k[15] & 255) << 24, j5 = c[4] & 255 | (c[5] & 255) << 8 | (c[6] & 255) << 16 | (c[7] & 255) << 24, j6 = p[0] & 255 | (p[1] & 255) << 8 | (p[2] & 255) << 16 | (p[3] & 255) << 24, j7 = p[4] & 255 | (p[5] & 255) << 8 | (p[6] & 255) << 16 | (p[7] & 255) << 24, j8 = p[8] & 255 | (p[9] & 255) << 8 | (p[10] & 255) << 16 | (p[11] & 255) << 24, j9 = p[12] & 255 | (p[13] & 255) << 8 | (p[14] & 255) << 16 | (p[15] & 255) << 24, j10 = c[8] & 255 | (c[9] & 255) << 8 | (c[10] & 255) << 16 | (c[11] & 255) << 24, j11 = k[16] & 255 | (k[17] & 255) << 8 | (k[18] & 255) << 16 | (k[19] & 255) << 24, j12 = k[20] & 255 | (k[21] & 255) << 8 | (k[22] & 255) << 16 | (k[23] & 255) << 24, j13 = k[24] & 255 | (k[25] & 255) << 8 | (k[26] & 255) << 16 | (k[27] & 255) << 24, j14 = k[28] & 255 | (k[29] & 255) << 8 | (k[30] & 255) << 16 | (k[31] & 255) << 24, j15 = c[12] & 255 | (c[13] & 255) << 8 | (c[14] & 255) << 16 | (c[15] & 255) << 24;
|
|
236
|
+
var 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, x15 = j15, u;
|
|
237
|
+
for (var i = 0; i < 20; i += 2) {
|
|
238
|
+
u = x0 + x12 | 0;
|
|
239
|
+
x4 ^= u << 7 | u >>> 32 - 7;
|
|
240
|
+
u = x4 + x0 | 0;
|
|
241
|
+
x8 ^= u << 9 | u >>> 32 - 9;
|
|
242
|
+
u = x8 + x4 | 0;
|
|
243
|
+
x12 ^= u << 13 | u >>> 32 - 13;
|
|
244
|
+
u = x12 + x8 | 0;
|
|
245
|
+
x0 ^= u << 18 | u >>> 32 - 18;
|
|
246
|
+
u = x5 + x1 | 0;
|
|
247
|
+
x9 ^= u << 7 | u >>> 32 - 7;
|
|
248
|
+
u = x9 + x5 | 0;
|
|
249
|
+
x13 ^= u << 9 | u >>> 32 - 9;
|
|
250
|
+
u = x13 + x9 | 0;
|
|
251
|
+
x1 ^= u << 13 | u >>> 32 - 13;
|
|
252
|
+
u = x1 + x13 | 0;
|
|
253
|
+
x5 ^= u << 18 | u >>> 32 - 18;
|
|
254
|
+
u = x10 + x6 | 0;
|
|
255
|
+
x14 ^= u << 7 | u >>> 32 - 7;
|
|
256
|
+
u = x14 + x10 | 0;
|
|
257
|
+
x2 ^= u << 9 | u >>> 32 - 9;
|
|
258
|
+
u = x2 + x14 | 0;
|
|
259
|
+
x6 ^= u << 13 | u >>> 32 - 13;
|
|
260
|
+
u = x6 + x2 | 0;
|
|
261
|
+
x10 ^= u << 18 | u >>> 32 - 18;
|
|
262
|
+
u = x15 + x11 | 0;
|
|
263
|
+
x3 ^= u << 7 | u >>> 32 - 7;
|
|
264
|
+
u = x3 + x15 | 0;
|
|
265
|
+
x7 ^= u << 9 | u >>> 32 - 9;
|
|
266
|
+
u = x7 + x3 | 0;
|
|
267
|
+
x11 ^= u << 13 | u >>> 32 - 13;
|
|
268
|
+
u = x11 + x7 | 0;
|
|
269
|
+
x15 ^= u << 18 | u >>> 32 - 18;
|
|
270
|
+
u = x0 + x3 | 0;
|
|
271
|
+
x1 ^= u << 7 | u >>> 32 - 7;
|
|
272
|
+
u = x1 + x0 | 0;
|
|
273
|
+
x2 ^= u << 9 | u >>> 32 - 9;
|
|
274
|
+
u = x2 + x1 | 0;
|
|
275
|
+
x3 ^= u << 13 | u >>> 32 - 13;
|
|
276
|
+
u = x3 + x2 | 0;
|
|
277
|
+
x0 ^= u << 18 | u >>> 32 - 18;
|
|
278
|
+
u = x5 + x4 | 0;
|
|
279
|
+
x6 ^= u << 7 | u >>> 32 - 7;
|
|
280
|
+
u = x6 + x5 | 0;
|
|
281
|
+
x7 ^= u << 9 | u >>> 32 - 9;
|
|
282
|
+
u = x7 + x6 | 0;
|
|
283
|
+
x4 ^= u << 13 | u >>> 32 - 13;
|
|
284
|
+
u = x4 + x7 | 0;
|
|
285
|
+
x5 ^= u << 18 | u >>> 32 - 18;
|
|
286
|
+
u = x10 + x9 | 0;
|
|
287
|
+
x11 ^= u << 7 | u >>> 32 - 7;
|
|
288
|
+
u = x11 + x10 | 0;
|
|
289
|
+
x8 ^= u << 9 | u >>> 32 - 9;
|
|
290
|
+
u = x8 + x11 | 0;
|
|
291
|
+
x9 ^= u << 13 | u >>> 32 - 13;
|
|
292
|
+
u = x9 + x8 | 0;
|
|
293
|
+
x10 ^= u << 18 | u >>> 32 - 18;
|
|
294
|
+
u = x15 + x14 | 0;
|
|
295
|
+
x12 ^= u << 7 | u >>> 32 - 7;
|
|
296
|
+
u = x12 + x15 | 0;
|
|
297
|
+
x13 ^= u << 9 | u >>> 32 - 9;
|
|
298
|
+
u = x13 + x12 | 0;
|
|
299
|
+
x14 ^= u << 13 | u >>> 32 - 13;
|
|
300
|
+
u = x14 + x13 | 0;
|
|
301
|
+
x15 ^= u << 18 | u >>> 32 - 18;
|
|
302
|
+
}
|
|
303
|
+
o[0] = x0 >>> 0 & 255;
|
|
304
|
+
o[1] = x0 >>> 8 & 255;
|
|
305
|
+
o[2] = x0 >>> 16 & 255;
|
|
306
|
+
o[3] = x0 >>> 24 & 255;
|
|
307
|
+
o[4] = x5 >>> 0 & 255;
|
|
308
|
+
o[5] = x5 >>> 8 & 255;
|
|
309
|
+
o[6] = x5 >>> 16 & 255;
|
|
310
|
+
o[7] = x5 >>> 24 & 255;
|
|
311
|
+
o[8] = x10 >>> 0 & 255;
|
|
312
|
+
o[9] = x10 >>> 8 & 255;
|
|
313
|
+
o[10] = x10 >>> 16 & 255;
|
|
314
|
+
o[11] = x10 >>> 24 & 255;
|
|
315
|
+
o[12] = x15 >>> 0 & 255;
|
|
316
|
+
o[13] = x15 >>> 8 & 255;
|
|
317
|
+
o[14] = x15 >>> 16 & 255;
|
|
318
|
+
o[15] = x15 >>> 24 & 255;
|
|
319
|
+
o[16] = x6 >>> 0 & 255;
|
|
320
|
+
o[17] = x6 >>> 8 & 255;
|
|
321
|
+
o[18] = x6 >>> 16 & 255;
|
|
322
|
+
o[19] = x6 >>> 24 & 255;
|
|
323
|
+
o[20] = x7 >>> 0 & 255;
|
|
324
|
+
o[21] = x7 >>> 8 & 255;
|
|
325
|
+
o[22] = x7 >>> 16 & 255;
|
|
326
|
+
o[23] = x7 >>> 24 & 255;
|
|
327
|
+
o[24] = x8 >>> 0 & 255;
|
|
328
|
+
o[25] = x8 >>> 8 & 255;
|
|
329
|
+
o[26] = x8 >>> 16 & 255;
|
|
330
|
+
o[27] = x8 >>> 24 & 255;
|
|
331
|
+
o[28] = x9 >>> 0 & 255;
|
|
332
|
+
o[29] = x9 >>> 8 & 255;
|
|
333
|
+
o[30] = x9 >>> 16 & 255;
|
|
334
|
+
o[31] = x9 >>> 24 & 255;
|
|
335
|
+
}
|
|
336
|
+
function crypto_core_salsa20(out, inp, k, c) {
|
|
337
|
+
core_salsa20(out, inp, k, c);
|
|
338
|
+
}
|
|
339
|
+
function crypto_core_hsalsa20(out, inp, k, c) {
|
|
340
|
+
core_hsalsa20(out, inp, k, c);
|
|
341
|
+
}
|
|
342
|
+
var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]);
|
|
343
|
+
function crypto_stream_salsa20_xor(c, cpos, m, mpos, b, n, k) {
|
|
344
|
+
var z = new Uint8Array(16), x = new Uint8Array(64);
|
|
345
|
+
var u, i;
|
|
346
|
+
for (i = 0; i < 16; i++) z[i] = 0;
|
|
347
|
+
for (i = 0; i < 8; i++) z[i] = n[i];
|
|
348
|
+
while (b >= 64) {
|
|
349
|
+
crypto_core_salsa20(x, z, k, sigma);
|
|
350
|
+
for (i = 0; i < 64; i++) c[cpos + i] = m[mpos + i] ^ x[i];
|
|
351
|
+
u = 1;
|
|
352
|
+
for (i = 8; i < 16; i++) {
|
|
353
|
+
u = u + (z[i] & 255) | 0;
|
|
354
|
+
z[i] = u & 255;
|
|
355
|
+
u >>>= 8;
|
|
356
|
+
}
|
|
357
|
+
b -= 64;
|
|
358
|
+
cpos += 64;
|
|
359
|
+
mpos += 64;
|
|
360
|
+
}
|
|
361
|
+
if (b > 0) {
|
|
362
|
+
crypto_core_salsa20(x, z, k, sigma);
|
|
363
|
+
for (i = 0; i < b; i++) c[cpos + i] = m[mpos + i] ^ x[i];
|
|
364
|
+
}
|
|
365
|
+
return 0;
|
|
366
|
+
}
|
|
367
|
+
function crypto_stream_salsa20(c, cpos, b, n, k) {
|
|
368
|
+
var z = new Uint8Array(16), x = new Uint8Array(64);
|
|
369
|
+
var u, i;
|
|
370
|
+
for (i = 0; i < 16; i++) z[i] = 0;
|
|
371
|
+
for (i = 0; i < 8; i++) z[i] = n[i];
|
|
372
|
+
while (b >= 64) {
|
|
373
|
+
crypto_core_salsa20(x, z, k, sigma);
|
|
374
|
+
for (i = 0; i < 64; i++) c[cpos + i] = x[i];
|
|
375
|
+
u = 1;
|
|
376
|
+
for (i = 8; i < 16; i++) {
|
|
377
|
+
u = u + (z[i] & 255) | 0;
|
|
378
|
+
z[i] = u & 255;
|
|
379
|
+
u >>>= 8;
|
|
380
|
+
}
|
|
381
|
+
b -= 64;
|
|
382
|
+
cpos += 64;
|
|
383
|
+
}
|
|
384
|
+
if (b > 0) {
|
|
385
|
+
crypto_core_salsa20(x, z, k, sigma);
|
|
386
|
+
for (i = 0; i < b; i++) c[cpos + i] = x[i];
|
|
387
|
+
}
|
|
388
|
+
return 0;
|
|
389
|
+
}
|
|
390
|
+
function crypto_stream(c, cpos, d, n, k) {
|
|
391
|
+
var s = new Uint8Array(32);
|
|
392
|
+
crypto_core_hsalsa20(s, n, k, sigma);
|
|
393
|
+
var sn = new Uint8Array(8);
|
|
394
|
+
for (var i = 0; i < 8; i++) sn[i] = n[i + 16];
|
|
395
|
+
return crypto_stream_salsa20(c, cpos, d, sn, s);
|
|
396
|
+
}
|
|
397
|
+
function crypto_stream_xor(c, cpos, m, mpos, d, n, k) {
|
|
398
|
+
var s = new Uint8Array(32);
|
|
399
|
+
crypto_core_hsalsa20(s, n, k, sigma);
|
|
400
|
+
var sn = new Uint8Array(8);
|
|
401
|
+
for (var i = 0; i < 8; i++) sn[i] = n[i + 16];
|
|
402
|
+
return crypto_stream_salsa20_xor(c, cpos, m, mpos, d, sn, s);
|
|
403
|
+
}
|
|
404
|
+
var poly1305 = function(key) {
|
|
405
|
+
this.buffer = new Uint8Array(16);
|
|
406
|
+
this.r = new Uint16Array(10);
|
|
407
|
+
this.h = new Uint16Array(10);
|
|
408
|
+
this.pad = new Uint16Array(8);
|
|
409
|
+
this.leftover = 0;
|
|
410
|
+
this.fin = 0;
|
|
411
|
+
var t0, t1, t2, t3, t4, t5, t6, t7;
|
|
412
|
+
t0 = key[0] & 255 | (key[1] & 255) << 8;
|
|
413
|
+
this.r[0] = t0 & 8191;
|
|
414
|
+
t1 = key[2] & 255 | (key[3] & 255) << 8;
|
|
415
|
+
this.r[1] = (t0 >>> 13 | t1 << 3) & 8191;
|
|
416
|
+
t2 = key[4] & 255 | (key[5] & 255) << 8;
|
|
417
|
+
this.r[2] = (t1 >>> 10 | t2 << 6) & 7939;
|
|
418
|
+
t3 = key[6] & 255 | (key[7] & 255) << 8;
|
|
419
|
+
this.r[3] = (t2 >>> 7 | t3 << 9) & 8191;
|
|
420
|
+
t4 = key[8] & 255 | (key[9] & 255) << 8;
|
|
421
|
+
this.r[4] = (t3 >>> 4 | t4 << 12) & 255;
|
|
422
|
+
this.r[5] = t4 >>> 1 & 8190;
|
|
423
|
+
t5 = key[10] & 255 | (key[11] & 255) << 8;
|
|
424
|
+
this.r[6] = (t4 >>> 14 | t5 << 2) & 8191;
|
|
425
|
+
t6 = key[12] & 255 | (key[13] & 255) << 8;
|
|
426
|
+
this.r[7] = (t5 >>> 11 | t6 << 5) & 8065;
|
|
427
|
+
t7 = key[14] & 255 | (key[15] & 255) << 8;
|
|
428
|
+
this.r[8] = (t6 >>> 8 | t7 << 8) & 8191;
|
|
429
|
+
this.r[9] = t7 >>> 5 & 127;
|
|
430
|
+
this.pad[0] = key[16] & 255 | (key[17] & 255) << 8;
|
|
431
|
+
this.pad[1] = key[18] & 255 | (key[19] & 255) << 8;
|
|
432
|
+
this.pad[2] = key[20] & 255 | (key[21] & 255) << 8;
|
|
433
|
+
this.pad[3] = key[22] & 255 | (key[23] & 255) << 8;
|
|
434
|
+
this.pad[4] = key[24] & 255 | (key[25] & 255) << 8;
|
|
435
|
+
this.pad[5] = key[26] & 255 | (key[27] & 255) << 8;
|
|
436
|
+
this.pad[6] = key[28] & 255 | (key[29] & 255) << 8;
|
|
437
|
+
this.pad[7] = key[30] & 255 | (key[31] & 255) << 8;
|
|
438
|
+
};
|
|
439
|
+
poly1305.prototype.blocks = function(m, mpos, bytes) {
|
|
440
|
+
var hibit = this.fin ? 0 : 1 << 11;
|
|
441
|
+
var t0, t1, t2, t3, t4, t5, t6, t7, c;
|
|
442
|
+
var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9;
|
|
443
|
+
var h0 = this.h[0], h1 = this.h[1], h2 = this.h[2], h3 = this.h[3], h4 = this.h[4], h5 = this.h[5], h6 = this.h[6], h7 = this.h[7], h8 = this.h[8], h9 = this.h[9];
|
|
444
|
+
var r0 = this.r[0], r1 = this.r[1], r2 = this.r[2], r3 = this.r[3], r4 = this.r[4], r5 = this.r[5], r6 = this.r[6], r7 = this.r[7], r8 = this.r[8], r9 = this.r[9];
|
|
445
|
+
while (bytes >= 16) {
|
|
446
|
+
t0 = m[mpos + 0] & 255 | (m[mpos + 1] & 255) << 8;
|
|
447
|
+
h0 += t0 & 8191;
|
|
448
|
+
t1 = m[mpos + 2] & 255 | (m[mpos + 3] & 255) << 8;
|
|
449
|
+
h1 += (t0 >>> 13 | t1 << 3) & 8191;
|
|
450
|
+
t2 = m[mpos + 4] & 255 | (m[mpos + 5] & 255) << 8;
|
|
451
|
+
h2 += (t1 >>> 10 | t2 << 6) & 8191;
|
|
452
|
+
t3 = m[mpos + 6] & 255 | (m[mpos + 7] & 255) << 8;
|
|
453
|
+
h3 += (t2 >>> 7 | t3 << 9) & 8191;
|
|
454
|
+
t4 = m[mpos + 8] & 255 | (m[mpos + 9] & 255) << 8;
|
|
455
|
+
h4 += (t3 >>> 4 | t4 << 12) & 8191;
|
|
456
|
+
h5 += t4 >>> 1 & 8191;
|
|
457
|
+
t5 = m[mpos + 10] & 255 | (m[mpos + 11] & 255) << 8;
|
|
458
|
+
h6 += (t4 >>> 14 | t5 << 2) & 8191;
|
|
459
|
+
t6 = m[mpos + 12] & 255 | (m[mpos + 13] & 255) << 8;
|
|
460
|
+
h7 += (t5 >>> 11 | t6 << 5) & 8191;
|
|
461
|
+
t7 = m[mpos + 14] & 255 | (m[mpos + 15] & 255) << 8;
|
|
462
|
+
h8 += (t6 >>> 8 | t7 << 8) & 8191;
|
|
463
|
+
h9 += t7 >>> 5 | hibit;
|
|
464
|
+
c = 0;
|
|
465
|
+
d0 = c;
|
|
466
|
+
d0 += h0 * r0;
|
|
467
|
+
d0 += h1 * (5 * r9);
|
|
468
|
+
d0 += h2 * (5 * r8);
|
|
469
|
+
d0 += h3 * (5 * r7);
|
|
470
|
+
d0 += h4 * (5 * r6);
|
|
471
|
+
c = d0 >>> 13;
|
|
472
|
+
d0 &= 8191;
|
|
473
|
+
d0 += h5 * (5 * r5);
|
|
474
|
+
d0 += h6 * (5 * r4);
|
|
475
|
+
d0 += h7 * (5 * r3);
|
|
476
|
+
d0 += h8 * (5 * r2);
|
|
477
|
+
d0 += h9 * (5 * r1);
|
|
478
|
+
c += d0 >>> 13;
|
|
479
|
+
d0 &= 8191;
|
|
480
|
+
d1 = c;
|
|
481
|
+
d1 += h0 * r1;
|
|
482
|
+
d1 += h1 * r0;
|
|
483
|
+
d1 += h2 * (5 * r9);
|
|
484
|
+
d1 += h3 * (5 * r8);
|
|
485
|
+
d1 += h4 * (5 * r7);
|
|
486
|
+
c = d1 >>> 13;
|
|
487
|
+
d1 &= 8191;
|
|
488
|
+
d1 += h5 * (5 * r6);
|
|
489
|
+
d1 += h6 * (5 * r5);
|
|
490
|
+
d1 += h7 * (5 * r4);
|
|
491
|
+
d1 += h8 * (5 * r3);
|
|
492
|
+
d1 += h9 * (5 * r2);
|
|
493
|
+
c += d1 >>> 13;
|
|
494
|
+
d1 &= 8191;
|
|
495
|
+
d2 = c;
|
|
496
|
+
d2 += h0 * r2;
|
|
497
|
+
d2 += h1 * r1;
|
|
498
|
+
d2 += h2 * r0;
|
|
499
|
+
d2 += h3 * (5 * r9);
|
|
500
|
+
d2 += h4 * (5 * r8);
|
|
501
|
+
c = d2 >>> 13;
|
|
502
|
+
d2 &= 8191;
|
|
503
|
+
d2 += h5 * (5 * r7);
|
|
504
|
+
d2 += h6 * (5 * r6);
|
|
505
|
+
d2 += h7 * (5 * r5);
|
|
506
|
+
d2 += h8 * (5 * r4);
|
|
507
|
+
d2 += h9 * (5 * r3);
|
|
508
|
+
c += d2 >>> 13;
|
|
509
|
+
d2 &= 8191;
|
|
510
|
+
d3 = c;
|
|
511
|
+
d3 += h0 * r3;
|
|
512
|
+
d3 += h1 * r2;
|
|
513
|
+
d3 += h2 * r1;
|
|
514
|
+
d3 += h3 * r0;
|
|
515
|
+
d3 += h4 * (5 * r9);
|
|
516
|
+
c = d3 >>> 13;
|
|
517
|
+
d3 &= 8191;
|
|
518
|
+
d3 += h5 * (5 * r8);
|
|
519
|
+
d3 += h6 * (5 * r7);
|
|
520
|
+
d3 += h7 * (5 * r6);
|
|
521
|
+
d3 += h8 * (5 * r5);
|
|
522
|
+
d3 += h9 * (5 * r4);
|
|
523
|
+
c += d3 >>> 13;
|
|
524
|
+
d3 &= 8191;
|
|
525
|
+
d4 = c;
|
|
526
|
+
d4 += h0 * r4;
|
|
527
|
+
d4 += h1 * r3;
|
|
528
|
+
d4 += h2 * r2;
|
|
529
|
+
d4 += h3 * r1;
|
|
530
|
+
d4 += h4 * r0;
|
|
531
|
+
c = d4 >>> 13;
|
|
532
|
+
d4 &= 8191;
|
|
533
|
+
d4 += h5 * (5 * r9);
|
|
534
|
+
d4 += h6 * (5 * r8);
|
|
535
|
+
d4 += h7 * (5 * r7);
|
|
536
|
+
d4 += h8 * (5 * r6);
|
|
537
|
+
d4 += h9 * (5 * r5);
|
|
538
|
+
c += d4 >>> 13;
|
|
539
|
+
d4 &= 8191;
|
|
540
|
+
d5 = c;
|
|
541
|
+
d5 += h0 * r5;
|
|
542
|
+
d5 += h1 * r4;
|
|
543
|
+
d5 += h2 * r3;
|
|
544
|
+
d5 += h3 * r2;
|
|
545
|
+
d5 += h4 * r1;
|
|
546
|
+
c = d5 >>> 13;
|
|
547
|
+
d5 &= 8191;
|
|
548
|
+
d5 += h5 * r0;
|
|
549
|
+
d5 += h6 * (5 * r9);
|
|
550
|
+
d5 += h7 * (5 * r8);
|
|
551
|
+
d5 += h8 * (5 * r7);
|
|
552
|
+
d5 += h9 * (5 * r6);
|
|
553
|
+
c += d5 >>> 13;
|
|
554
|
+
d5 &= 8191;
|
|
555
|
+
d6 = c;
|
|
556
|
+
d6 += h0 * r6;
|
|
557
|
+
d6 += h1 * r5;
|
|
558
|
+
d6 += h2 * r4;
|
|
559
|
+
d6 += h3 * r3;
|
|
560
|
+
d6 += h4 * r2;
|
|
561
|
+
c = d6 >>> 13;
|
|
562
|
+
d6 &= 8191;
|
|
563
|
+
d6 += h5 * r1;
|
|
564
|
+
d6 += h6 * r0;
|
|
565
|
+
d6 += h7 * (5 * r9);
|
|
566
|
+
d6 += h8 * (5 * r8);
|
|
567
|
+
d6 += h9 * (5 * r7);
|
|
568
|
+
c += d6 >>> 13;
|
|
569
|
+
d6 &= 8191;
|
|
570
|
+
d7 = c;
|
|
571
|
+
d7 += h0 * r7;
|
|
572
|
+
d7 += h1 * r6;
|
|
573
|
+
d7 += h2 * r5;
|
|
574
|
+
d7 += h3 * r4;
|
|
575
|
+
d7 += h4 * r3;
|
|
576
|
+
c = d7 >>> 13;
|
|
577
|
+
d7 &= 8191;
|
|
578
|
+
d7 += h5 * r2;
|
|
579
|
+
d7 += h6 * r1;
|
|
580
|
+
d7 += h7 * r0;
|
|
581
|
+
d7 += h8 * (5 * r9);
|
|
582
|
+
d7 += h9 * (5 * r8);
|
|
583
|
+
c += d7 >>> 13;
|
|
584
|
+
d7 &= 8191;
|
|
585
|
+
d8 = c;
|
|
586
|
+
d8 += h0 * r8;
|
|
587
|
+
d8 += h1 * r7;
|
|
588
|
+
d8 += h2 * r6;
|
|
589
|
+
d8 += h3 * r5;
|
|
590
|
+
d8 += h4 * r4;
|
|
591
|
+
c = d8 >>> 13;
|
|
592
|
+
d8 &= 8191;
|
|
593
|
+
d8 += h5 * r3;
|
|
594
|
+
d8 += h6 * r2;
|
|
595
|
+
d8 += h7 * r1;
|
|
596
|
+
d8 += h8 * r0;
|
|
597
|
+
d8 += h9 * (5 * r9);
|
|
598
|
+
c += d8 >>> 13;
|
|
599
|
+
d8 &= 8191;
|
|
600
|
+
d9 = c;
|
|
601
|
+
d9 += h0 * r9;
|
|
602
|
+
d9 += h1 * r8;
|
|
603
|
+
d9 += h2 * r7;
|
|
604
|
+
d9 += h3 * r6;
|
|
605
|
+
d9 += h4 * r5;
|
|
606
|
+
c = d9 >>> 13;
|
|
607
|
+
d9 &= 8191;
|
|
608
|
+
d9 += h5 * r4;
|
|
609
|
+
d9 += h6 * r3;
|
|
610
|
+
d9 += h7 * r2;
|
|
611
|
+
d9 += h8 * r1;
|
|
612
|
+
d9 += h9 * r0;
|
|
613
|
+
c += d9 >>> 13;
|
|
614
|
+
d9 &= 8191;
|
|
615
|
+
c = (c << 2) + c | 0;
|
|
616
|
+
c = c + d0 | 0;
|
|
617
|
+
d0 = c & 8191;
|
|
618
|
+
c = c >>> 13;
|
|
619
|
+
d1 += c;
|
|
620
|
+
h0 = d0;
|
|
621
|
+
h1 = d1;
|
|
622
|
+
h2 = d2;
|
|
623
|
+
h3 = d3;
|
|
624
|
+
h4 = d4;
|
|
625
|
+
h5 = d5;
|
|
626
|
+
h6 = d6;
|
|
627
|
+
h7 = d7;
|
|
628
|
+
h8 = d8;
|
|
629
|
+
h9 = d9;
|
|
630
|
+
mpos += 16;
|
|
631
|
+
bytes -= 16;
|
|
632
|
+
}
|
|
633
|
+
this.h[0] = h0;
|
|
634
|
+
this.h[1] = h1;
|
|
635
|
+
this.h[2] = h2;
|
|
636
|
+
this.h[3] = h3;
|
|
637
|
+
this.h[4] = h4;
|
|
638
|
+
this.h[5] = h5;
|
|
639
|
+
this.h[6] = h6;
|
|
640
|
+
this.h[7] = h7;
|
|
641
|
+
this.h[8] = h8;
|
|
642
|
+
this.h[9] = h9;
|
|
643
|
+
};
|
|
644
|
+
poly1305.prototype.finish = function(mac, macpos) {
|
|
645
|
+
var g = new Uint16Array(10);
|
|
646
|
+
var c, mask, f, i;
|
|
647
|
+
if (this.leftover) {
|
|
648
|
+
i = this.leftover;
|
|
649
|
+
this.buffer[i++] = 1;
|
|
650
|
+
for (; i < 16; i++) this.buffer[i] = 0;
|
|
651
|
+
this.fin = 1;
|
|
652
|
+
this.blocks(this.buffer, 0, 16);
|
|
653
|
+
}
|
|
654
|
+
c = this.h[1] >>> 13;
|
|
655
|
+
this.h[1] &= 8191;
|
|
656
|
+
for (i = 2; i < 10; i++) {
|
|
657
|
+
this.h[i] += c;
|
|
658
|
+
c = this.h[i] >>> 13;
|
|
659
|
+
this.h[i] &= 8191;
|
|
660
|
+
}
|
|
661
|
+
this.h[0] += c * 5;
|
|
662
|
+
c = this.h[0] >>> 13;
|
|
663
|
+
this.h[0] &= 8191;
|
|
664
|
+
this.h[1] += c;
|
|
665
|
+
c = this.h[1] >>> 13;
|
|
666
|
+
this.h[1] &= 8191;
|
|
667
|
+
this.h[2] += c;
|
|
668
|
+
g[0] = this.h[0] + 5;
|
|
669
|
+
c = g[0] >>> 13;
|
|
670
|
+
g[0] &= 8191;
|
|
671
|
+
for (i = 1; i < 10; i++) {
|
|
672
|
+
g[i] = this.h[i] + c;
|
|
673
|
+
c = g[i] >>> 13;
|
|
674
|
+
g[i] &= 8191;
|
|
675
|
+
}
|
|
676
|
+
g[9] -= 1 << 13;
|
|
677
|
+
mask = (c ^ 1) - 1;
|
|
678
|
+
for (i = 0; i < 10; i++) g[i] &= mask;
|
|
679
|
+
mask = ~mask;
|
|
680
|
+
for (i = 0; i < 10; i++) this.h[i] = this.h[i] & mask | g[i];
|
|
681
|
+
this.h[0] = (this.h[0] | this.h[1] << 13) & 65535;
|
|
682
|
+
this.h[1] = (this.h[1] >>> 3 | this.h[2] << 10) & 65535;
|
|
683
|
+
this.h[2] = (this.h[2] >>> 6 | this.h[3] << 7) & 65535;
|
|
684
|
+
this.h[3] = (this.h[3] >>> 9 | this.h[4] << 4) & 65535;
|
|
685
|
+
this.h[4] = (this.h[4] >>> 12 | this.h[5] << 1 | this.h[6] << 14) & 65535;
|
|
686
|
+
this.h[5] = (this.h[6] >>> 2 | this.h[7] << 11) & 65535;
|
|
687
|
+
this.h[6] = (this.h[7] >>> 5 | this.h[8] << 8) & 65535;
|
|
688
|
+
this.h[7] = (this.h[8] >>> 8 | this.h[9] << 5) & 65535;
|
|
689
|
+
f = this.h[0] + this.pad[0];
|
|
690
|
+
this.h[0] = f & 65535;
|
|
691
|
+
for (i = 1; i < 8; i++) {
|
|
692
|
+
f = (this.h[i] + this.pad[i] | 0) + (f >>> 16) | 0;
|
|
693
|
+
this.h[i] = f & 65535;
|
|
694
|
+
}
|
|
695
|
+
mac[macpos + 0] = this.h[0] >>> 0 & 255;
|
|
696
|
+
mac[macpos + 1] = this.h[0] >>> 8 & 255;
|
|
697
|
+
mac[macpos + 2] = this.h[1] >>> 0 & 255;
|
|
698
|
+
mac[macpos + 3] = this.h[1] >>> 8 & 255;
|
|
699
|
+
mac[macpos + 4] = this.h[2] >>> 0 & 255;
|
|
700
|
+
mac[macpos + 5] = this.h[2] >>> 8 & 255;
|
|
701
|
+
mac[macpos + 6] = this.h[3] >>> 0 & 255;
|
|
702
|
+
mac[macpos + 7] = this.h[3] >>> 8 & 255;
|
|
703
|
+
mac[macpos + 8] = this.h[4] >>> 0 & 255;
|
|
704
|
+
mac[macpos + 9] = this.h[4] >>> 8 & 255;
|
|
705
|
+
mac[macpos + 10] = this.h[5] >>> 0 & 255;
|
|
706
|
+
mac[macpos + 11] = this.h[5] >>> 8 & 255;
|
|
707
|
+
mac[macpos + 12] = this.h[6] >>> 0 & 255;
|
|
708
|
+
mac[macpos + 13] = this.h[6] >>> 8 & 255;
|
|
709
|
+
mac[macpos + 14] = this.h[7] >>> 0 & 255;
|
|
710
|
+
mac[macpos + 15] = this.h[7] >>> 8 & 255;
|
|
711
|
+
};
|
|
712
|
+
poly1305.prototype.update = function(m, mpos, bytes) {
|
|
713
|
+
var i, want;
|
|
714
|
+
if (this.leftover) {
|
|
715
|
+
want = 16 - this.leftover;
|
|
716
|
+
if (want > bytes)
|
|
717
|
+
want = bytes;
|
|
718
|
+
for (i = 0; i < want; i++)
|
|
719
|
+
this.buffer[this.leftover + i] = m[mpos + i];
|
|
720
|
+
bytes -= want;
|
|
721
|
+
mpos += want;
|
|
722
|
+
this.leftover += want;
|
|
723
|
+
if (this.leftover < 16)
|
|
724
|
+
return;
|
|
725
|
+
this.blocks(this.buffer, 0, 16);
|
|
726
|
+
this.leftover = 0;
|
|
727
|
+
}
|
|
728
|
+
if (bytes >= 16) {
|
|
729
|
+
want = bytes - bytes % 16;
|
|
730
|
+
this.blocks(m, mpos, want);
|
|
731
|
+
mpos += want;
|
|
732
|
+
bytes -= want;
|
|
733
|
+
}
|
|
734
|
+
if (bytes) {
|
|
735
|
+
for (i = 0; i < bytes; i++)
|
|
736
|
+
this.buffer[this.leftover + i] = m[mpos + i];
|
|
737
|
+
this.leftover += bytes;
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
function crypto_onetimeauth(out, outpos, m, mpos, n, k) {
|
|
741
|
+
var s = new poly1305(k);
|
|
742
|
+
s.update(m, mpos, n);
|
|
743
|
+
s.finish(out, outpos);
|
|
744
|
+
return 0;
|
|
745
|
+
}
|
|
746
|
+
function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) {
|
|
747
|
+
var x = new Uint8Array(16);
|
|
748
|
+
crypto_onetimeauth(x, 0, m, mpos, n, k);
|
|
749
|
+
return crypto_verify_16(h, hpos, x, 0);
|
|
750
|
+
}
|
|
751
|
+
function crypto_secretbox(c, m, d, n, k) {
|
|
752
|
+
var i;
|
|
753
|
+
if (d < 32) return -1;
|
|
754
|
+
crypto_stream_xor(c, 0, m, 0, d, n, k);
|
|
755
|
+
crypto_onetimeauth(c, 16, c, 32, d - 32, c);
|
|
756
|
+
for (i = 0; i < 16; i++) c[i] = 0;
|
|
757
|
+
return 0;
|
|
758
|
+
}
|
|
759
|
+
function crypto_secretbox_open(m, c, d, n, k) {
|
|
760
|
+
var i;
|
|
761
|
+
var x = new Uint8Array(32);
|
|
762
|
+
if (d < 32) return -1;
|
|
763
|
+
crypto_stream(x, 0, 32, n, k);
|
|
764
|
+
if (crypto_onetimeauth_verify(c, 16, c, 32, d - 32, x) !== 0) return -1;
|
|
765
|
+
crypto_stream_xor(m, 0, c, 0, d, n, k);
|
|
766
|
+
for (i = 0; i < 32; i++) m[i] = 0;
|
|
767
|
+
return 0;
|
|
768
|
+
}
|
|
769
|
+
function set25519(r, a) {
|
|
770
|
+
var i;
|
|
771
|
+
for (i = 0; i < 16; i++) r[i] = a[i] | 0;
|
|
772
|
+
}
|
|
773
|
+
function car25519(o) {
|
|
774
|
+
var i, v, c = 1;
|
|
775
|
+
for (i = 0; i < 16; i++) {
|
|
776
|
+
v = o[i] + c + 65535;
|
|
777
|
+
c = Math.floor(v / 65536);
|
|
778
|
+
o[i] = v - c * 65536;
|
|
779
|
+
}
|
|
780
|
+
o[0] += c - 1 + 37 * (c - 1);
|
|
781
|
+
}
|
|
782
|
+
function sel25519(p, q, b) {
|
|
783
|
+
var t, c = ~(b - 1);
|
|
784
|
+
for (var i = 0; i < 16; i++) {
|
|
785
|
+
t = c & (p[i] ^ q[i]);
|
|
786
|
+
p[i] ^= t;
|
|
787
|
+
q[i] ^= t;
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
function pack25519(o, n) {
|
|
791
|
+
var i, j, b;
|
|
792
|
+
var m = gf(), t = gf();
|
|
793
|
+
for (i = 0; i < 16; i++) t[i] = n[i];
|
|
794
|
+
car25519(t);
|
|
795
|
+
car25519(t);
|
|
796
|
+
car25519(t);
|
|
797
|
+
for (j = 0; j < 2; j++) {
|
|
798
|
+
m[0] = t[0] - 65517;
|
|
799
|
+
for (i = 1; i < 15; i++) {
|
|
800
|
+
m[i] = t[i] - 65535 - (m[i - 1] >> 16 & 1);
|
|
801
|
+
m[i - 1] &= 65535;
|
|
802
|
+
}
|
|
803
|
+
m[15] = t[15] - 32767 - (m[14] >> 16 & 1);
|
|
804
|
+
b = m[15] >> 16 & 1;
|
|
805
|
+
m[14] &= 65535;
|
|
806
|
+
sel25519(t, m, 1 - b);
|
|
807
|
+
}
|
|
808
|
+
for (i = 0; i < 16; i++) {
|
|
809
|
+
o[2 * i] = t[i] & 255;
|
|
810
|
+
o[2 * i + 1] = t[i] >> 8;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
function neq25519(a, b) {
|
|
814
|
+
var c = new Uint8Array(32), d = new Uint8Array(32);
|
|
815
|
+
pack25519(c, a);
|
|
816
|
+
pack25519(d, b);
|
|
817
|
+
return crypto_verify_32(c, 0, d, 0);
|
|
818
|
+
}
|
|
819
|
+
function par25519(a) {
|
|
820
|
+
var d = new Uint8Array(32);
|
|
821
|
+
pack25519(d, a);
|
|
822
|
+
return d[0] & 1;
|
|
823
|
+
}
|
|
824
|
+
function unpack25519(o, n) {
|
|
825
|
+
var i;
|
|
826
|
+
for (i = 0; i < 16; i++) o[i] = n[2 * i] + (n[2 * i + 1] << 8);
|
|
827
|
+
o[15] &= 32767;
|
|
828
|
+
}
|
|
829
|
+
function A(o, a, b) {
|
|
830
|
+
for (var i = 0; i < 16; i++) o[i] = a[i] + b[i];
|
|
831
|
+
}
|
|
832
|
+
function Z(o, a, b) {
|
|
833
|
+
for (var i = 0; i < 16; i++) o[i] = a[i] - b[i];
|
|
834
|
+
}
|
|
835
|
+
function M(o, a, b) {
|
|
836
|
+
var v, c, t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0, t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0, t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0, t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0, b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4], b5 = b[5], b6 = b[6], b7 = b[7], b8 = b[8], b9 = b[9], b10 = b[10], b11 = b[11], b12 = b[12], b13 = b[13], b14 = b[14], b15 = b[15];
|
|
837
|
+
v = a[0];
|
|
838
|
+
t0 += v * b0;
|
|
839
|
+
t1 += v * b1;
|
|
840
|
+
t2 += v * b2;
|
|
841
|
+
t3 += v * b3;
|
|
842
|
+
t4 += v * b4;
|
|
843
|
+
t5 += v * b5;
|
|
844
|
+
t6 += v * b6;
|
|
845
|
+
t7 += v * b7;
|
|
846
|
+
t8 += v * b8;
|
|
847
|
+
t9 += v * b9;
|
|
848
|
+
t10 += v * b10;
|
|
849
|
+
t11 += v * b11;
|
|
850
|
+
t12 += v * b12;
|
|
851
|
+
t13 += v * b13;
|
|
852
|
+
t14 += v * b14;
|
|
853
|
+
t15 += v * b15;
|
|
854
|
+
v = a[1];
|
|
855
|
+
t1 += v * b0;
|
|
856
|
+
t2 += v * b1;
|
|
857
|
+
t3 += v * b2;
|
|
858
|
+
t4 += v * b3;
|
|
859
|
+
t5 += v * b4;
|
|
860
|
+
t6 += v * b5;
|
|
861
|
+
t7 += v * b6;
|
|
862
|
+
t8 += v * b7;
|
|
863
|
+
t9 += v * b8;
|
|
864
|
+
t10 += v * b9;
|
|
865
|
+
t11 += v * b10;
|
|
866
|
+
t12 += v * b11;
|
|
867
|
+
t13 += v * b12;
|
|
868
|
+
t14 += v * b13;
|
|
869
|
+
t15 += v * b14;
|
|
870
|
+
t16 += v * b15;
|
|
871
|
+
v = a[2];
|
|
872
|
+
t2 += v * b0;
|
|
873
|
+
t3 += v * b1;
|
|
874
|
+
t4 += v * b2;
|
|
875
|
+
t5 += v * b3;
|
|
876
|
+
t6 += v * b4;
|
|
877
|
+
t7 += v * b5;
|
|
878
|
+
t8 += v * b6;
|
|
879
|
+
t9 += v * b7;
|
|
880
|
+
t10 += v * b8;
|
|
881
|
+
t11 += v * b9;
|
|
882
|
+
t12 += v * b10;
|
|
883
|
+
t13 += v * b11;
|
|
884
|
+
t14 += v * b12;
|
|
885
|
+
t15 += v * b13;
|
|
886
|
+
t16 += v * b14;
|
|
887
|
+
t17 += v * b15;
|
|
888
|
+
v = a[3];
|
|
889
|
+
t3 += v * b0;
|
|
890
|
+
t4 += v * b1;
|
|
891
|
+
t5 += v * b2;
|
|
892
|
+
t6 += v * b3;
|
|
893
|
+
t7 += v * b4;
|
|
894
|
+
t8 += v * b5;
|
|
895
|
+
t9 += v * b6;
|
|
896
|
+
t10 += v * b7;
|
|
897
|
+
t11 += v * b8;
|
|
898
|
+
t12 += v * b9;
|
|
899
|
+
t13 += v * b10;
|
|
900
|
+
t14 += v * b11;
|
|
901
|
+
t15 += v * b12;
|
|
902
|
+
t16 += v * b13;
|
|
903
|
+
t17 += v * b14;
|
|
904
|
+
t18 += v * b15;
|
|
905
|
+
v = a[4];
|
|
906
|
+
t4 += v * b0;
|
|
907
|
+
t5 += v * b1;
|
|
908
|
+
t6 += v * b2;
|
|
909
|
+
t7 += v * b3;
|
|
910
|
+
t8 += v * b4;
|
|
911
|
+
t9 += v * b5;
|
|
912
|
+
t10 += v * b6;
|
|
913
|
+
t11 += v * b7;
|
|
914
|
+
t12 += v * b8;
|
|
915
|
+
t13 += v * b9;
|
|
916
|
+
t14 += v * b10;
|
|
917
|
+
t15 += v * b11;
|
|
918
|
+
t16 += v * b12;
|
|
919
|
+
t17 += v * b13;
|
|
920
|
+
t18 += v * b14;
|
|
921
|
+
t19 += v * b15;
|
|
922
|
+
v = a[5];
|
|
923
|
+
t5 += v * b0;
|
|
924
|
+
t6 += v * b1;
|
|
925
|
+
t7 += v * b2;
|
|
926
|
+
t8 += v * b3;
|
|
927
|
+
t9 += v * b4;
|
|
928
|
+
t10 += v * b5;
|
|
929
|
+
t11 += v * b6;
|
|
930
|
+
t12 += v * b7;
|
|
931
|
+
t13 += v * b8;
|
|
932
|
+
t14 += v * b9;
|
|
933
|
+
t15 += v * b10;
|
|
934
|
+
t16 += v * b11;
|
|
935
|
+
t17 += v * b12;
|
|
936
|
+
t18 += v * b13;
|
|
937
|
+
t19 += v * b14;
|
|
938
|
+
t20 += v * b15;
|
|
939
|
+
v = a[6];
|
|
940
|
+
t6 += v * b0;
|
|
941
|
+
t7 += v * b1;
|
|
942
|
+
t8 += v * b2;
|
|
943
|
+
t9 += v * b3;
|
|
944
|
+
t10 += v * b4;
|
|
945
|
+
t11 += v * b5;
|
|
946
|
+
t12 += v * b6;
|
|
947
|
+
t13 += v * b7;
|
|
948
|
+
t14 += v * b8;
|
|
949
|
+
t15 += v * b9;
|
|
950
|
+
t16 += v * b10;
|
|
951
|
+
t17 += v * b11;
|
|
952
|
+
t18 += v * b12;
|
|
953
|
+
t19 += v * b13;
|
|
954
|
+
t20 += v * b14;
|
|
955
|
+
t21 += v * b15;
|
|
956
|
+
v = a[7];
|
|
957
|
+
t7 += v * b0;
|
|
958
|
+
t8 += v * b1;
|
|
959
|
+
t9 += v * b2;
|
|
960
|
+
t10 += v * b3;
|
|
961
|
+
t11 += v * b4;
|
|
962
|
+
t12 += v * b5;
|
|
963
|
+
t13 += v * b6;
|
|
964
|
+
t14 += v * b7;
|
|
965
|
+
t15 += v * b8;
|
|
966
|
+
t16 += v * b9;
|
|
967
|
+
t17 += v * b10;
|
|
968
|
+
t18 += v * b11;
|
|
969
|
+
t19 += v * b12;
|
|
970
|
+
t20 += v * b13;
|
|
971
|
+
t21 += v * b14;
|
|
972
|
+
t22 += v * b15;
|
|
973
|
+
v = a[8];
|
|
974
|
+
t8 += v * b0;
|
|
975
|
+
t9 += v * b1;
|
|
976
|
+
t10 += v * b2;
|
|
977
|
+
t11 += v * b3;
|
|
978
|
+
t12 += v * b4;
|
|
979
|
+
t13 += v * b5;
|
|
980
|
+
t14 += v * b6;
|
|
981
|
+
t15 += v * b7;
|
|
982
|
+
t16 += v * b8;
|
|
983
|
+
t17 += v * b9;
|
|
984
|
+
t18 += v * b10;
|
|
985
|
+
t19 += v * b11;
|
|
986
|
+
t20 += v * b12;
|
|
987
|
+
t21 += v * b13;
|
|
988
|
+
t22 += v * b14;
|
|
989
|
+
t23 += v * b15;
|
|
990
|
+
v = a[9];
|
|
991
|
+
t9 += v * b0;
|
|
992
|
+
t10 += v * b1;
|
|
993
|
+
t11 += v * b2;
|
|
994
|
+
t12 += v * b3;
|
|
995
|
+
t13 += v * b4;
|
|
996
|
+
t14 += v * b5;
|
|
997
|
+
t15 += v * b6;
|
|
998
|
+
t16 += v * b7;
|
|
999
|
+
t17 += v * b8;
|
|
1000
|
+
t18 += v * b9;
|
|
1001
|
+
t19 += v * b10;
|
|
1002
|
+
t20 += v * b11;
|
|
1003
|
+
t21 += v * b12;
|
|
1004
|
+
t22 += v * b13;
|
|
1005
|
+
t23 += v * b14;
|
|
1006
|
+
t24 += v * b15;
|
|
1007
|
+
v = a[10];
|
|
1008
|
+
t10 += v * b0;
|
|
1009
|
+
t11 += v * b1;
|
|
1010
|
+
t12 += v * b2;
|
|
1011
|
+
t13 += v * b3;
|
|
1012
|
+
t14 += v * b4;
|
|
1013
|
+
t15 += v * b5;
|
|
1014
|
+
t16 += v * b6;
|
|
1015
|
+
t17 += v * b7;
|
|
1016
|
+
t18 += v * b8;
|
|
1017
|
+
t19 += v * b9;
|
|
1018
|
+
t20 += v * b10;
|
|
1019
|
+
t21 += v * b11;
|
|
1020
|
+
t22 += v * b12;
|
|
1021
|
+
t23 += v * b13;
|
|
1022
|
+
t24 += v * b14;
|
|
1023
|
+
t25 += v * b15;
|
|
1024
|
+
v = a[11];
|
|
1025
|
+
t11 += v * b0;
|
|
1026
|
+
t12 += v * b1;
|
|
1027
|
+
t13 += v * b2;
|
|
1028
|
+
t14 += v * b3;
|
|
1029
|
+
t15 += v * b4;
|
|
1030
|
+
t16 += v * b5;
|
|
1031
|
+
t17 += v * b6;
|
|
1032
|
+
t18 += v * b7;
|
|
1033
|
+
t19 += v * b8;
|
|
1034
|
+
t20 += v * b9;
|
|
1035
|
+
t21 += v * b10;
|
|
1036
|
+
t22 += v * b11;
|
|
1037
|
+
t23 += v * b12;
|
|
1038
|
+
t24 += v * b13;
|
|
1039
|
+
t25 += v * b14;
|
|
1040
|
+
t26 += v * b15;
|
|
1041
|
+
v = a[12];
|
|
1042
|
+
t12 += v * b0;
|
|
1043
|
+
t13 += v * b1;
|
|
1044
|
+
t14 += v * b2;
|
|
1045
|
+
t15 += v * b3;
|
|
1046
|
+
t16 += v * b4;
|
|
1047
|
+
t17 += v * b5;
|
|
1048
|
+
t18 += v * b6;
|
|
1049
|
+
t19 += v * b7;
|
|
1050
|
+
t20 += v * b8;
|
|
1051
|
+
t21 += v * b9;
|
|
1052
|
+
t22 += v * b10;
|
|
1053
|
+
t23 += v * b11;
|
|
1054
|
+
t24 += v * b12;
|
|
1055
|
+
t25 += v * b13;
|
|
1056
|
+
t26 += v * b14;
|
|
1057
|
+
t27 += v * b15;
|
|
1058
|
+
v = a[13];
|
|
1059
|
+
t13 += v * b0;
|
|
1060
|
+
t14 += v * b1;
|
|
1061
|
+
t15 += v * b2;
|
|
1062
|
+
t16 += v * b3;
|
|
1063
|
+
t17 += v * b4;
|
|
1064
|
+
t18 += v * b5;
|
|
1065
|
+
t19 += v * b6;
|
|
1066
|
+
t20 += v * b7;
|
|
1067
|
+
t21 += v * b8;
|
|
1068
|
+
t22 += v * b9;
|
|
1069
|
+
t23 += v * b10;
|
|
1070
|
+
t24 += v * b11;
|
|
1071
|
+
t25 += v * b12;
|
|
1072
|
+
t26 += v * b13;
|
|
1073
|
+
t27 += v * b14;
|
|
1074
|
+
t28 += v * b15;
|
|
1075
|
+
v = a[14];
|
|
1076
|
+
t14 += v * b0;
|
|
1077
|
+
t15 += v * b1;
|
|
1078
|
+
t16 += v * b2;
|
|
1079
|
+
t17 += v * b3;
|
|
1080
|
+
t18 += v * b4;
|
|
1081
|
+
t19 += v * b5;
|
|
1082
|
+
t20 += v * b6;
|
|
1083
|
+
t21 += v * b7;
|
|
1084
|
+
t22 += v * b8;
|
|
1085
|
+
t23 += v * b9;
|
|
1086
|
+
t24 += v * b10;
|
|
1087
|
+
t25 += v * b11;
|
|
1088
|
+
t26 += v * b12;
|
|
1089
|
+
t27 += v * b13;
|
|
1090
|
+
t28 += v * b14;
|
|
1091
|
+
t29 += v * b15;
|
|
1092
|
+
v = a[15];
|
|
1093
|
+
t15 += v * b0;
|
|
1094
|
+
t16 += v * b1;
|
|
1095
|
+
t17 += v * b2;
|
|
1096
|
+
t18 += v * b3;
|
|
1097
|
+
t19 += v * b4;
|
|
1098
|
+
t20 += v * b5;
|
|
1099
|
+
t21 += v * b6;
|
|
1100
|
+
t22 += v * b7;
|
|
1101
|
+
t23 += v * b8;
|
|
1102
|
+
t24 += v * b9;
|
|
1103
|
+
t25 += v * b10;
|
|
1104
|
+
t26 += v * b11;
|
|
1105
|
+
t27 += v * b12;
|
|
1106
|
+
t28 += v * b13;
|
|
1107
|
+
t29 += v * b14;
|
|
1108
|
+
t30 += v * b15;
|
|
1109
|
+
t0 += 38 * t16;
|
|
1110
|
+
t1 += 38 * t17;
|
|
1111
|
+
t2 += 38 * t18;
|
|
1112
|
+
t3 += 38 * t19;
|
|
1113
|
+
t4 += 38 * t20;
|
|
1114
|
+
t5 += 38 * t21;
|
|
1115
|
+
t6 += 38 * t22;
|
|
1116
|
+
t7 += 38 * t23;
|
|
1117
|
+
t8 += 38 * t24;
|
|
1118
|
+
t9 += 38 * t25;
|
|
1119
|
+
t10 += 38 * t26;
|
|
1120
|
+
t11 += 38 * t27;
|
|
1121
|
+
t12 += 38 * t28;
|
|
1122
|
+
t13 += 38 * t29;
|
|
1123
|
+
t14 += 38 * t30;
|
|
1124
|
+
c = 1;
|
|
1125
|
+
v = t0 + c + 65535;
|
|
1126
|
+
c = Math.floor(v / 65536);
|
|
1127
|
+
t0 = v - c * 65536;
|
|
1128
|
+
v = t1 + c + 65535;
|
|
1129
|
+
c = Math.floor(v / 65536);
|
|
1130
|
+
t1 = v - c * 65536;
|
|
1131
|
+
v = t2 + c + 65535;
|
|
1132
|
+
c = Math.floor(v / 65536);
|
|
1133
|
+
t2 = v - c * 65536;
|
|
1134
|
+
v = t3 + c + 65535;
|
|
1135
|
+
c = Math.floor(v / 65536);
|
|
1136
|
+
t3 = v - c * 65536;
|
|
1137
|
+
v = t4 + c + 65535;
|
|
1138
|
+
c = Math.floor(v / 65536);
|
|
1139
|
+
t4 = v - c * 65536;
|
|
1140
|
+
v = t5 + c + 65535;
|
|
1141
|
+
c = Math.floor(v / 65536);
|
|
1142
|
+
t5 = v - c * 65536;
|
|
1143
|
+
v = t6 + c + 65535;
|
|
1144
|
+
c = Math.floor(v / 65536);
|
|
1145
|
+
t6 = v - c * 65536;
|
|
1146
|
+
v = t7 + c + 65535;
|
|
1147
|
+
c = Math.floor(v / 65536);
|
|
1148
|
+
t7 = v - c * 65536;
|
|
1149
|
+
v = t8 + c + 65535;
|
|
1150
|
+
c = Math.floor(v / 65536);
|
|
1151
|
+
t8 = v - c * 65536;
|
|
1152
|
+
v = t9 + c + 65535;
|
|
1153
|
+
c = Math.floor(v / 65536);
|
|
1154
|
+
t9 = v - c * 65536;
|
|
1155
|
+
v = t10 + c + 65535;
|
|
1156
|
+
c = Math.floor(v / 65536);
|
|
1157
|
+
t10 = v - c * 65536;
|
|
1158
|
+
v = t11 + c + 65535;
|
|
1159
|
+
c = Math.floor(v / 65536);
|
|
1160
|
+
t11 = v - c * 65536;
|
|
1161
|
+
v = t12 + c + 65535;
|
|
1162
|
+
c = Math.floor(v / 65536);
|
|
1163
|
+
t12 = v - c * 65536;
|
|
1164
|
+
v = t13 + c + 65535;
|
|
1165
|
+
c = Math.floor(v / 65536);
|
|
1166
|
+
t13 = v - c * 65536;
|
|
1167
|
+
v = t14 + c + 65535;
|
|
1168
|
+
c = Math.floor(v / 65536);
|
|
1169
|
+
t14 = v - c * 65536;
|
|
1170
|
+
v = t15 + c + 65535;
|
|
1171
|
+
c = Math.floor(v / 65536);
|
|
1172
|
+
t15 = v - c * 65536;
|
|
1173
|
+
t0 += c - 1 + 37 * (c - 1);
|
|
1174
|
+
c = 1;
|
|
1175
|
+
v = t0 + c + 65535;
|
|
1176
|
+
c = Math.floor(v / 65536);
|
|
1177
|
+
t0 = v - c * 65536;
|
|
1178
|
+
v = t1 + c + 65535;
|
|
1179
|
+
c = Math.floor(v / 65536);
|
|
1180
|
+
t1 = v - c * 65536;
|
|
1181
|
+
v = t2 + c + 65535;
|
|
1182
|
+
c = Math.floor(v / 65536);
|
|
1183
|
+
t2 = v - c * 65536;
|
|
1184
|
+
v = t3 + c + 65535;
|
|
1185
|
+
c = Math.floor(v / 65536);
|
|
1186
|
+
t3 = v - c * 65536;
|
|
1187
|
+
v = t4 + c + 65535;
|
|
1188
|
+
c = Math.floor(v / 65536);
|
|
1189
|
+
t4 = v - c * 65536;
|
|
1190
|
+
v = t5 + c + 65535;
|
|
1191
|
+
c = Math.floor(v / 65536);
|
|
1192
|
+
t5 = v - c * 65536;
|
|
1193
|
+
v = t6 + c + 65535;
|
|
1194
|
+
c = Math.floor(v / 65536);
|
|
1195
|
+
t6 = v - c * 65536;
|
|
1196
|
+
v = t7 + c + 65535;
|
|
1197
|
+
c = Math.floor(v / 65536);
|
|
1198
|
+
t7 = v - c * 65536;
|
|
1199
|
+
v = t8 + c + 65535;
|
|
1200
|
+
c = Math.floor(v / 65536);
|
|
1201
|
+
t8 = v - c * 65536;
|
|
1202
|
+
v = t9 + c + 65535;
|
|
1203
|
+
c = Math.floor(v / 65536);
|
|
1204
|
+
t9 = v - c * 65536;
|
|
1205
|
+
v = t10 + c + 65535;
|
|
1206
|
+
c = Math.floor(v / 65536);
|
|
1207
|
+
t10 = v - c * 65536;
|
|
1208
|
+
v = t11 + c + 65535;
|
|
1209
|
+
c = Math.floor(v / 65536);
|
|
1210
|
+
t11 = v - c * 65536;
|
|
1211
|
+
v = t12 + c + 65535;
|
|
1212
|
+
c = Math.floor(v / 65536);
|
|
1213
|
+
t12 = v - c * 65536;
|
|
1214
|
+
v = t13 + c + 65535;
|
|
1215
|
+
c = Math.floor(v / 65536);
|
|
1216
|
+
t13 = v - c * 65536;
|
|
1217
|
+
v = t14 + c + 65535;
|
|
1218
|
+
c = Math.floor(v / 65536);
|
|
1219
|
+
t14 = v - c * 65536;
|
|
1220
|
+
v = t15 + c + 65535;
|
|
1221
|
+
c = Math.floor(v / 65536);
|
|
1222
|
+
t15 = v - c * 65536;
|
|
1223
|
+
t0 += c - 1 + 37 * (c - 1);
|
|
1224
|
+
o[0] = t0;
|
|
1225
|
+
o[1] = t1;
|
|
1226
|
+
o[2] = t2;
|
|
1227
|
+
o[3] = t3;
|
|
1228
|
+
o[4] = t4;
|
|
1229
|
+
o[5] = t5;
|
|
1230
|
+
o[6] = t6;
|
|
1231
|
+
o[7] = t7;
|
|
1232
|
+
o[8] = t8;
|
|
1233
|
+
o[9] = t9;
|
|
1234
|
+
o[10] = t10;
|
|
1235
|
+
o[11] = t11;
|
|
1236
|
+
o[12] = t12;
|
|
1237
|
+
o[13] = t13;
|
|
1238
|
+
o[14] = t14;
|
|
1239
|
+
o[15] = t15;
|
|
1240
|
+
}
|
|
1241
|
+
function S(o, a) {
|
|
1242
|
+
M(o, a, a);
|
|
1243
|
+
}
|
|
1244
|
+
function inv25519(o, i) {
|
|
1245
|
+
var c = gf();
|
|
1246
|
+
var a;
|
|
1247
|
+
for (a = 0; a < 16; a++) c[a] = i[a];
|
|
1248
|
+
for (a = 253; a >= 0; a--) {
|
|
1249
|
+
S(c, c);
|
|
1250
|
+
if (a !== 2 && a !== 4) M(c, c, i);
|
|
1251
|
+
}
|
|
1252
|
+
for (a = 0; a < 16; a++) o[a] = c[a];
|
|
1253
|
+
}
|
|
1254
|
+
function pow2523(o, i) {
|
|
1255
|
+
var c = gf();
|
|
1256
|
+
var a;
|
|
1257
|
+
for (a = 0; a < 16; a++) c[a] = i[a];
|
|
1258
|
+
for (a = 250; a >= 0; a--) {
|
|
1259
|
+
S(c, c);
|
|
1260
|
+
if (a !== 1) M(c, c, i);
|
|
1261
|
+
}
|
|
1262
|
+
for (a = 0; a < 16; a++) o[a] = c[a];
|
|
1263
|
+
}
|
|
1264
|
+
function crypto_scalarmult(q, n, p) {
|
|
1265
|
+
var z = new Uint8Array(32);
|
|
1266
|
+
var x = new Float64Array(80), r, i;
|
|
1267
|
+
var a = gf(), b = gf(), c = gf(), d = gf(), e = gf(), f = gf();
|
|
1268
|
+
for (i = 0; i < 31; i++) z[i] = n[i];
|
|
1269
|
+
z[31] = n[31] & 127 | 64;
|
|
1270
|
+
z[0] &= 248;
|
|
1271
|
+
unpack25519(x, p);
|
|
1272
|
+
for (i = 0; i < 16; i++) {
|
|
1273
|
+
b[i] = x[i];
|
|
1274
|
+
d[i] = a[i] = c[i] = 0;
|
|
1275
|
+
}
|
|
1276
|
+
a[0] = d[0] = 1;
|
|
1277
|
+
for (i = 254; i >= 0; --i) {
|
|
1278
|
+
r = z[i >>> 3] >>> (i & 7) & 1;
|
|
1279
|
+
sel25519(a, b, r);
|
|
1280
|
+
sel25519(c, d, r);
|
|
1281
|
+
A(e, a, c);
|
|
1282
|
+
Z(a, a, c);
|
|
1283
|
+
A(c, b, d);
|
|
1284
|
+
Z(b, b, d);
|
|
1285
|
+
S(d, e);
|
|
1286
|
+
S(f, a);
|
|
1287
|
+
M(a, c, a);
|
|
1288
|
+
M(c, b, e);
|
|
1289
|
+
A(e, a, c);
|
|
1290
|
+
Z(a, a, c);
|
|
1291
|
+
S(b, a);
|
|
1292
|
+
Z(c, d, f);
|
|
1293
|
+
M(a, c, _121665);
|
|
1294
|
+
A(a, a, d);
|
|
1295
|
+
M(c, c, a);
|
|
1296
|
+
M(a, d, f);
|
|
1297
|
+
M(d, b, x);
|
|
1298
|
+
S(b, e);
|
|
1299
|
+
sel25519(a, b, r);
|
|
1300
|
+
sel25519(c, d, r);
|
|
1301
|
+
}
|
|
1302
|
+
for (i = 0; i < 16; i++) {
|
|
1303
|
+
x[i + 16] = a[i];
|
|
1304
|
+
x[i + 32] = c[i];
|
|
1305
|
+
x[i + 48] = b[i];
|
|
1306
|
+
x[i + 64] = d[i];
|
|
1307
|
+
}
|
|
1308
|
+
var x32 = x.subarray(32);
|
|
1309
|
+
var x16 = x.subarray(16);
|
|
1310
|
+
inv25519(x32, x32);
|
|
1311
|
+
M(x16, x16, x32);
|
|
1312
|
+
pack25519(q, x16);
|
|
1313
|
+
return 0;
|
|
1314
|
+
}
|
|
1315
|
+
function crypto_scalarmult_base(q, n) {
|
|
1316
|
+
return crypto_scalarmult(q, n, _9);
|
|
1317
|
+
}
|
|
1318
|
+
function crypto_box_keypair(y, x) {
|
|
1319
|
+
randombytes(x, 32);
|
|
1320
|
+
return crypto_scalarmult_base(y, x);
|
|
1321
|
+
}
|
|
1322
|
+
function crypto_box_beforenm(k, y, x) {
|
|
1323
|
+
var s = new Uint8Array(32);
|
|
1324
|
+
crypto_scalarmult(s, x, y);
|
|
1325
|
+
return crypto_core_hsalsa20(k, _0, s, sigma);
|
|
1326
|
+
}
|
|
1327
|
+
var crypto_box_afternm = crypto_secretbox;
|
|
1328
|
+
var crypto_box_open_afternm = crypto_secretbox_open;
|
|
1329
|
+
function crypto_box(c, m, d, n, y, x) {
|
|
1330
|
+
var k = new Uint8Array(32);
|
|
1331
|
+
crypto_box_beforenm(k, y, x);
|
|
1332
|
+
return crypto_box_afternm(c, m, d, n, k);
|
|
1333
|
+
}
|
|
1334
|
+
function crypto_box_open(m, c, d, n, y, x) {
|
|
1335
|
+
var k = new Uint8Array(32);
|
|
1336
|
+
crypto_box_beforenm(k, y, x);
|
|
1337
|
+
return crypto_box_open_afternm(m, c, d, n, k);
|
|
1338
|
+
}
|
|
1339
|
+
var K = [
|
|
1340
|
+
1116352408,
|
|
1341
|
+
3609767458,
|
|
1342
|
+
1899447441,
|
|
1343
|
+
602891725,
|
|
1344
|
+
3049323471,
|
|
1345
|
+
3964484399,
|
|
1346
|
+
3921009573,
|
|
1347
|
+
2173295548,
|
|
1348
|
+
961987163,
|
|
1349
|
+
4081628472,
|
|
1350
|
+
1508970993,
|
|
1351
|
+
3053834265,
|
|
1352
|
+
2453635748,
|
|
1353
|
+
2937671579,
|
|
1354
|
+
2870763221,
|
|
1355
|
+
3664609560,
|
|
1356
|
+
3624381080,
|
|
1357
|
+
2734883394,
|
|
1358
|
+
310598401,
|
|
1359
|
+
1164996542,
|
|
1360
|
+
607225278,
|
|
1361
|
+
1323610764,
|
|
1362
|
+
1426881987,
|
|
1363
|
+
3590304994,
|
|
1364
|
+
1925078388,
|
|
1365
|
+
4068182383,
|
|
1366
|
+
2162078206,
|
|
1367
|
+
991336113,
|
|
1368
|
+
2614888103,
|
|
1369
|
+
633803317,
|
|
1370
|
+
3248222580,
|
|
1371
|
+
3479774868,
|
|
1372
|
+
3835390401,
|
|
1373
|
+
2666613458,
|
|
1374
|
+
4022224774,
|
|
1375
|
+
944711139,
|
|
1376
|
+
264347078,
|
|
1377
|
+
2341262773,
|
|
1378
|
+
604807628,
|
|
1379
|
+
2007800933,
|
|
1380
|
+
770255983,
|
|
1381
|
+
1495990901,
|
|
1382
|
+
1249150122,
|
|
1383
|
+
1856431235,
|
|
1384
|
+
1555081692,
|
|
1385
|
+
3175218132,
|
|
1386
|
+
1996064986,
|
|
1387
|
+
2198950837,
|
|
1388
|
+
2554220882,
|
|
1389
|
+
3999719339,
|
|
1390
|
+
2821834349,
|
|
1391
|
+
766784016,
|
|
1392
|
+
2952996808,
|
|
1393
|
+
2566594879,
|
|
1394
|
+
3210313671,
|
|
1395
|
+
3203337956,
|
|
1396
|
+
3336571891,
|
|
1397
|
+
1034457026,
|
|
1398
|
+
3584528711,
|
|
1399
|
+
2466948901,
|
|
1400
|
+
113926993,
|
|
1401
|
+
3758326383,
|
|
1402
|
+
338241895,
|
|
1403
|
+
168717936,
|
|
1404
|
+
666307205,
|
|
1405
|
+
1188179964,
|
|
1406
|
+
773529912,
|
|
1407
|
+
1546045734,
|
|
1408
|
+
1294757372,
|
|
1409
|
+
1522805485,
|
|
1410
|
+
1396182291,
|
|
1411
|
+
2643833823,
|
|
1412
|
+
1695183700,
|
|
1413
|
+
2343527390,
|
|
1414
|
+
1986661051,
|
|
1415
|
+
1014477480,
|
|
1416
|
+
2177026350,
|
|
1417
|
+
1206759142,
|
|
1418
|
+
2456956037,
|
|
1419
|
+
344077627,
|
|
1420
|
+
2730485921,
|
|
1421
|
+
1290863460,
|
|
1422
|
+
2820302411,
|
|
1423
|
+
3158454273,
|
|
1424
|
+
3259730800,
|
|
1425
|
+
3505952657,
|
|
1426
|
+
3345764771,
|
|
1427
|
+
106217008,
|
|
1428
|
+
3516065817,
|
|
1429
|
+
3606008344,
|
|
1430
|
+
3600352804,
|
|
1431
|
+
1432725776,
|
|
1432
|
+
4094571909,
|
|
1433
|
+
1467031594,
|
|
1434
|
+
275423344,
|
|
1435
|
+
851169720,
|
|
1436
|
+
430227734,
|
|
1437
|
+
3100823752,
|
|
1438
|
+
506948616,
|
|
1439
|
+
1363258195,
|
|
1440
|
+
659060556,
|
|
1441
|
+
3750685593,
|
|
1442
|
+
883997877,
|
|
1443
|
+
3785050280,
|
|
1444
|
+
958139571,
|
|
1445
|
+
3318307427,
|
|
1446
|
+
1322822218,
|
|
1447
|
+
3812723403,
|
|
1448
|
+
1537002063,
|
|
1449
|
+
2003034995,
|
|
1450
|
+
1747873779,
|
|
1451
|
+
3602036899,
|
|
1452
|
+
1955562222,
|
|
1453
|
+
1575990012,
|
|
1454
|
+
2024104815,
|
|
1455
|
+
1125592928,
|
|
1456
|
+
2227730452,
|
|
1457
|
+
2716904306,
|
|
1458
|
+
2361852424,
|
|
1459
|
+
442776044,
|
|
1460
|
+
2428436474,
|
|
1461
|
+
593698344,
|
|
1462
|
+
2756734187,
|
|
1463
|
+
3733110249,
|
|
1464
|
+
3204031479,
|
|
1465
|
+
2999351573,
|
|
1466
|
+
3329325298,
|
|
1467
|
+
3815920427,
|
|
1468
|
+
3391569614,
|
|
1469
|
+
3928383900,
|
|
1470
|
+
3515267271,
|
|
1471
|
+
566280711,
|
|
1472
|
+
3940187606,
|
|
1473
|
+
3454069534,
|
|
1474
|
+
4118630271,
|
|
1475
|
+
4000239992,
|
|
1476
|
+
116418474,
|
|
1477
|
+
1914138554,
|
|
1478
|
+
174292421,
|
|
1479
|
+
2731055270,
|
|
1480
|
+
289380356,
|
|
1481
|
+
3203993006,
|
|
1482
|
+
460393269,
|
|
1483
|
+
320620315,
|
|
1484
|
+
685471733,
|
|
1485
|
+
587496836,
|
|
1486
|
+
852142971,
|
|
1487
|
+
1086792851,
|
|
1488
|
+
1017036298,
|
|
1489
|
+
365543100,
|
|
1490
|
+
1126000580,
|
|
1491
|
+
2618297676,
|
|
1492
|
+
1288033470,
|
|
1493
|
+
3409855158,
|
|
1494
|
+
1501505948,
|
|
1495
|
+
4234509866,
|
|
1496
|
+
1607167915,
|
|
1497
|
+
987167468,
|
|
1498
|
+
1816402316,
|
|
1499
|
+
1246189591
|
|
1500
|
+
];
|
|
1501
|
+
function crypto_hashblocks_hl(hh, hl, m, n) {
|
|
1502
|
+
var wh = new Int32Array(16), wl = new Int32Array(16), bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7, bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7, th, tl, i, j, h, l, a, b, c, d;
|
|
1503
|
+
var ah0 = hh[0], ah1 = hh[1], ah2 = hh[2], ah3 = hh[3], ah4 = hh[4], ah5 = hh[5], ah6 = hh[6], ah7 = hh[7], al0 = hl[0], al1 = hl[1], al2 = hl[2], al3 = hl[3], al4 = hl[4], al5 = hl[5], al6 = hl[6], al7 = hl[7];
|
|
1504
|
+
var pos = 0;
|
|
1505
|
+
while (n >= 128) {
|
|
1506
|
+
for (i = 0; i < 16; i++) {
|
|
1507
|
+
j = 8 * i + pos;
|
|
1508
|
+
wh[i] = m[j + 0] << 24 | m[j + 1] << 16 | m[j + 2] << 8 | m[j + 3];
|
|
1509
|
+
wl[i] = m[j + 4] << 24 | m[j + 5] << 16 | m[j + 6] << 8 | m[j + 7];
|
|
1510
|
+
}
|
|
1511
|
+
for (i = 0; i < 80; i++) {
|
|
1512
|
+
bh0 = ah0;
|
|
1513
|
+
bh1 = ah1;
|
|
1514
|
+
bh2 = ah2;
|
|
1515
|
+
bh3 = ah3;
|
|
1516
|
+
bh4 = ah4;
|
|
1517
|
+
bh5 = ah5;
|
|
1518
|
+
bh6 = ah6;
|
|
1519
|
+
bh7 = ah7;
|
|
1520
|
+
bl0 = al0;
|
|
1521
|
+
bl1 = al1;
|
|
1522
|
+
bl2 = al2;
|
|
1523
|
+
bl3 = al3;
|
|
1524
|
+
bl4 = al4;
|
|
1525
|
+
bl5 = al5;
|
|
1526
|
+
bl6 = al6;
|
|
1527
|
+
bl7 = al7;
|
|
1528
|
+
h = ah7;
|
|
1529
|
+
l = al7;
|
|
1530
|
+
a = l & 65535;
|
|
1531
|
+
b = l >>> 16;
|
|
1532
|
+
c = h & 65535;
|
|
1533
|
+
d = h >>> 16;
|
|
1534
|
+
h = (ah4 >>> 14 | al4 << 32 - 14) ^ (ah4 >>> 18 | al4 << 32 - 18) ^ (al4 >>> 41 - 32 | ah4 << 32 - (41 - 32));
|
|
1535
|
+
l = (al4 >>> 14 | ah4 << 32 - 14) ^ (al4 >>> 18 | ah4 << 32 - 18) ^ (ah4 >>> 41 - 32 | al4 << 32 - (41 - 32));
|
|
1536
|
+
a += l & 65535;
|
|
1537
|
+
b += l >>> 16;
|
|
1538
|
+
c += h & 65535;
|
|
1539
|
+
d += h >>> 16;
|
|
1540
|
+
h = ah4 & ah5 ^ ~ah4 & ah6;
|
|
1541
|
+
l = al4 & al5 ^ ~al4 & al6;
|
|
1542
|
+
a += l & 65535;
|
|
1543
|
+
b += l >>> 16;
|
|
1544
|
+
c += h & 65535;
|
|
1545
|
+
d += h >>> 16;
|
|
1546
|
+
h = K[i * 2];
|
|
1547
|
+
l = K[i * 2 + 1];
|
|
1548
|
+
a += l & 65535;
|
|
1549
|
+
b += l >>> 16;
|
|
1550
|
+
c += h & 65535;
|
|
1551
|
+
d += h >>> 16;
|
|
1552
|
+
h = wh[i % 16];
|
|
1553
|
+
l = wl[i % 16];
|
|
1554
|
+
a += l & 65535;
|
|
1555
|
+
b += l >>> 16;
|
|
1556
|
+
c += h & 65535;
|
|
1557
|
+
d += h >>> 16;
|
|
1558
|
+
b += a >>> 16;
|
|
1559
|
+
c += b >>> 16;
|
|
1560
|
+
d += c >>> 16;
|
|
1561
|
+
th = c & 65535 | d << 16;
|
|
1562
|
+
tl = a & 65535 | b << 16;
|
|
1563
|
+
h = th;
|
|
1564
|
+
l = tl;
|
|
1565
|
+
a = l & 65535;
|
|
1566
|
+
b = l >>> 16;
|
|
1567
|
+
c = h & 65535;
|
|
1568
|
+
d = h >>> 16;
|
|
1569
|
+
h = (ah0 >>> 28 | al0 << 32 - 28) ^ (al0 >>> 34 - 32 | ah0 << 32 - (34 - 32)) ^ (al0 >>> 39 - 32 | ah0 << 32 - (39 - 32));
|
|
1570
|
+
l = (al0 >>> 28 | ah0 << 32 - 28) ^ (ah0 >>> 34 - 32 | al0 << 32 - (34 - 32)) ^ (ah0 >>> 39 - 32 | al0 << 32 - (39 - 32));
|
|
1571
|
+
a += l & 65535;
|
|
1572
|
+
b += l >>> 16;
|
|
1573
|
+
c += h & 65535;
|
|
1574
|
+
d += h >>> 16;
|
|
1575
|
+
h = ah0 & ah1 ^ ah0 & ah2 ^ ah1 & ah2;
|
|
1576
|
+
l = al0 & al1 ^ al0 & al2 ^ al1 & al2;
|
|
1577
|
+
a += l & 65535;
|
|
1578
|
+
b += l >>> 16;
|
|
1579
|
+
c += h & 65535;
|
|
1580
|
+
d += h >>> 16;
|
|
1581
|
+
b += a >>> 16;
|
|
1582
|
+
c += b >>> 16;
|
|
1583
|
+
d += c >>> 16;
|
|
1584
|
+
bh7 = c & 65535 | d << 16;
|
|
1585
|
+
bl7 = a & 65535 | b << 16;
|
|
1586
|
+
h = bh3;
|
|
1587
|
+
l = bl3;
|
|
1588
|
+
a = l & 65535;
|
|
1589
|
+
b = l >>> 16;
|
|
1590
|
+
c = h & 65535;
|
|
1591
|
+
d = h >>> 16;
|
|
1592
|
+
h = th;
|
|
1593
|
+
l = tl;
|
|
1594
|
+
a += l & 65535;
|
|
1595
|
+
b += l >>> 16;
|
|
1596
|
+
c += h & 65535;
|
|
1597
|
+
d += h >>> 16;
|
|
1598
|
+
b += a >>> 16;
|
|
1599
|
+
c += b >>> 16;
|
|
1600
|
+
d += c >>> 16;
|
|
1601
|
+
bh3 = c & 65535 | d << 16;
|
|
1602
|
+
bl3 = a & 65535 | b << 16;
|
|
1603
|
+
ah1 = bh0;
|
|
1604
|
+
ah2 = bh1;
|
|
1605
|
+
ah3 = bh2;
|
|
1606
|
+
ah4 = bh3;
|
|
1607
|
+
ah5 = bh4;
|
|
1608
|
+
ah6 = bh5;
|
|
1609
|
+
ah7 = bh6;
|
|
1610
|
+
ah0 = bh7;
|
|
1611
|
+
al1 = bl0;
|
|
1612
|
+
al2 = bl1;
|
|
1613
|
+
al3 = bl2;
|
|
1614
|
+
al4 = bl3;
|
|
1615
|
+
al5 = bl4;
|
|
1616
|
+
al6 = bl5;
|
|
1617
|
+
al7 = bl6;
|
|
1618
|
+
al0 = bl7;
|
|
1619
|
+
if (i % 16 === 15) {
|
|
1620
|
+
for (j = 0; j < 16; j++) {
|
|
1621
|
+
h = wh[j];
|
|
1622
|
+
l = wl[j];
|
|
1623
|
+
a = l & 65535;
|
|
1624
|
+
b = l >>> 16;
|
|
1625
|
+
c = h & 65535;
|
|
1626
|
+
d = h >>> 16;
|
|
1627
|
+
h = wh[(j + 9) % 16];
|
|
1628
|
+
l = wl[(j + 9) % 16];
|
|
1629
|
+
a += l & 65535;
|
|
1630
|
+
b += l >>> 16;
|
|
1631
|
+
c += h & 65535;
|
|
1632
|
+
d += h >>> 16;
|
|
1633
|
+
th = wh[(j + 1) % 16];
|
|
1634
|
+
tl = wl[(j + 1) % 16];
|
|
1635
|
+
h = (th >>> 1 | tl << 32 - 1) ^ (th >>> 8 | tl << 32 - 8) ^ th >>> 7;
|
|
1636
|
+
l = (tl >>> 1 | th << 32 - 1) ^ (tl >>> 8 | th << 32 - 8) ^ (tl >>> 7 | th << 32 - 7);
|
|
1637
|
+
a += l & 65535;
|
|
1638
|
+
b += l >>> 16;
|
|
1639
|
+
c += h & 65535;
|
|
1640
|
+
d += h >>> 16;
|
|
1641
|
+
th = wh[(j + 14) % 16];
|
|
1642
|
+
tl = wl[(j + 14) % 16];
|
|
1643
|
+
h = (th >>> 19 | tl << 32 - 19) ^ (tl >>> 61 - 32 | th << 32 - (61 - 32)) ^ th >>> 6;
|
|
1644
|
+
l = (tl >>> 19 | th << 32 - 19) ^ (th >>> 61 - 32 | tl << 32 - (61 - 32)) ^ (tl >>> 6 | th << 32 - 6);
|
|
1645
|
+
a += l & 65535;
|
|
1646
|
+
b += l >>> 16;
|
|
1647
|
+
c += h & 65535;
|
|
1648
|
+
d += h >>> 16;
|
|
1649
|
+
b += a >>> 16;
|
|
1650
|
+
c += b >>> 16;
|
|
1651
|
+
d += c >>> 16;
|
|
1652
|
+
wh[j] = c & 65535 | d << 16;
|
|
1653
|
+
wl[j] = a & 65535 | b << 16;
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
h = ah0;
|
|
1658
|
+
l = al0;
|
|
1659
|
+
a = l & 65535;
|
|
1660
|
+
b = l >>> 16;
|
|
1661
|
+
c = h & 65535;
|
|
1662
|
+
d = h >>> 16;
|
|
1663
|
+
h = hh[0];
|
|
1664
|
+
l = hl[0];
|
|
1665
|
+
a += l & 65535;
|
|
1666
|
+
b += l >>> 16;
|
|
1667
|
+
c += h & 65535;
|
|
1668
|
+
d += h >>> 16;
|
|
1669
|
+
b += a >>> 16;
|
|
1670
|
+
c += b >>> 16;
|
|
1671
|
+
d += c >>> 16;
|
|
1672
|
+
hh[0] = ah0 = c & 65535 | d << 16;
|
|
1673
|
+
hl[0] = al0 = a & 65535 | b << 16;
|
|
1674
|
+
h = ah1;
|
|
1675
|
+
l = al1;
|
|
1676
|
+
a = l & 65535;
|
|
1677
|
+
b = l >>> 16;
|
|
1678
|
+
c = h & 65535;
|
|
1679
|
+
d = h >>> 16;
|
|
1680
|
+
h = hh[1];
|
|
1681
|
+
l = hl[1];
|
|
1682
|
+
a += l & 65535;
|
|
1683
|
+
b += l >>> 16;
|
|
1684
|
+
c += h & 65535;
|
|
1685
|
+
d += h >>> 16;
|
|
1686
|
+
b += a >>> 16;
|
|
1687
|
+
c += b >>> 16;
|
|
1688
|
+
d += c >>> 16;
|
|
1689
|
+
hh[1] = ah1 = c & 65535 | d << 16;
|
|
1690
|
+
hl[1] = al1 = a & 65535 | b << 16;
|
|
1691
|
+
h = ah2;
|
|
1692
|
+
l = al2;
|
|
1693
|
+
a = l & 65535;
|
|
1694
|
+
b = l >>> 16;
|
|
1695
|
+
c = h & 65535;
|
|
1696
|
+
d = h >>> 16;
|
|
1697
|
+
h = hh[2];
|
|
1698
|
+
l = hl[2];
|
|
1699
|
+
a += l & 65535;
|
|
1700
|
+
b += l >>> 16;
|
|
1701
|
+
c += h & 65535;
|
|
1702
|
+
d += h >>> 16;
|
|
1703
|
+
b += a >>> 16;
|
|
1704
|
+
c += b >>> 16;
|
|
1705
|
+
d += c >>> 16;
|
|
1706
|
+
hh[2] = ah2 = c & 65535 | d << 16;
|
|
1707
|
+
hl[2] = al2 = a & 65535 | b << 16;
|
|
1708
|
+
h = ah3;
|
|
1709
|
+
l = al3;
|
|
1710
|
+
a = l & 65535;
|
|
1711
|
+
b = l >>> 16;
|
|
1712
|
+
c = h & 65535;
|
|
1713
|
+
d = h >>> 16;
|
|
1714
|
+
h = hh[3];
|
|
1715
|
+
l = hl[3];
|
|
1716
|
+
a += l & 65535;
|
|
1717
|
+
b += l >>> 16;
|
|
1718
|
+
c += h & 65535;
|
|
1719
|
+
d += h >>> 16;
|
|
1720
|
+
b += a >>> 16;
|
|
1721
|
+
c += b >>> 16;
|
|
1722
|
+
d += c >>> 16;
|
|
1723
|
+
hh[3] = ah3 = c & 65535 | d << 16;
|
|
1724
|
+
hl[3] = al3 = a & 65535 | b << 16;
|
|
1725
|
+
h = ah4;
|
|
1726
|
+
l = al4;
|
|
1727
|
+
a = l & 65535;
|
|
1728
|
+
b = l >>> 16;
|
|
1729
|
+
c = h & 65535;
|
|
1730
|
+
d = h >>> 16;
|
|
1731
|
+
h = hh[4];
|
|
1732
|
+
l = hl[4];
|
|
1733
|
+
a += l & 65535;
|
|
1734
|
+
b += l >>> 16;
|
|
1735
|
+
c += h & 65535;
|
|
1736
|
+
d += h >>> 16;
|
|
1737
|
+
b += a >>> 16;
|
|
1738
|
+
c += b >>> 16;
|
|
1739
|
+
d += c >>> 16;
|
|
1740
|
+
hh[4] = ah4 = c & 65535 | d << 16;
|
|
1741
|
+
hl[4] = al4 = a & 65535 | b << 16;
|
|
1742
|
+
h = ah5;
|
|
1743
|
+
l = al5;
|
|
1744
|
+
a = l & 65535;
|
|
1745
|
+
b = l >>> 16;
|
|
1746
|
+
c = h & 65535;
|
|
1747
|
+
d = h >>> 16;
|
|
1748
|
+
h = hh[5];
|
|
1749
|
+
l = hl[5];
|
|
1750
|
+
a += l & 65535;
|
|
1751
|
+
b += l >>> 16;
|
|
1752
|
+
c += h & 65535;
|
|
1753
|
+
d += h >>> 16;
|
|
1754
|
+
b += a >>> 16;
|
|
1755
|
+
c += b >>> 16;
|
|
1756
|
+
d += c >>> 16;
|
|
1757
|
+
hh[5] = ah5 = c & 65535 | d << 16;
|
|
1758
|
+
hl[5] = al5 = a & 65535 | b << 16;
|
|
1759
|
+
h = ah6;
|
|
1760
|
+
l = al6;
|
|
1761
|
+
a = l & 65535;
|
|
1762
|
+
b = l >>> 16;
|
|
1763
|
+
c = h & 65535;
|
|
1764
|
+
d = h >>> 16;
|
|
1765
|
+
h = hh[6];
|
|
1766
|
+
l = hl[6];
|
|
1767
|
+
a += l & 65535;
|
|
1768
|
+
b += l >>> 16;
|
|
1769
|
+
c += h & 65535;
|
|
1770
|
+
d += h >>> 16;
|
|
1771
|
+
b += a >>> 16;
|
|
1772
|
+
c += b >>> 16;
|
|
1773
|
+
d += c >>> 16;
|
|
1774
|
+
hh[6] = ah6 = c & 65535 | d << 16;
|
|
1775
|
+
hl[6] = al6 = a & 65535 | b << 16;
|
|
1776
|
+
h = ah7;
|
|
1777
|
+
l = al7;
|
|
1778
|
+
a = l & 65535;
|
|
1779
|
+
b = l >>> 16;
|
|
1780
|
+
c = h & 65535;
|
|
1781
|
+
d = h >>> 16;
|
|
1782
|
+
h = hh[7];
|
|
1783
|
+
l = hl[7];
|
|
1784
|
+
a += l & 65535;
|
|
1785
|
+
b += l >>> 16;
|
|
1786
|
+
c += h & 65535;
|
|
1787
|
+
d += h >>> 16;
|
|
1788
|
+
b += a >>> 16;
|
|
1789
|
+
c += b >>> 16;
|
|
1790
|
+
d += c >>> 16;
|
|
1791
|
+
hh[7] = ah7 = c & 65535 | d << 16;
|
|
1792
|
+
hl[7] = al7 = a & 65535 | b << 16;
|
|
1793
|
+
pos += 128;
|
|
1794
|
+
n -= 128;
|
|
1795
|
+
}
|
|
1796
|
+
return n;
|
|
1797
|
+
}
|
|
1798
|
+
function crypto_hash(out, m, n) {
|
|
1799
|
+
var hh = new Int32Array(8), hl = new Int32Array(8), x = new Uint8Array(256), i, b = n;
|
|
1800
|
+
hh[0] = 1779033703;
|
|
1801
|
+
hh[1] = 3144134277;
|
|
1802
|
+
hh[2] = 1013904242;
|
|
1803
|
+
hh[3] = 2773480762;
|
|
1804
|
+
hh[4] = 1359893119;
|
|
1805
|
+
hh[5] = 2600822924;
|
|
1806
|
+
hh[6] = 528734635;
|
|
1807
|
+
hh[7] = 1541459225;
|
|
1808
|
+
hl[0] = 4089235720;
|
|
1809
|
+
hl[1] = 2227873595;
|
|
1810
|
+
hl[2] = 4271175723;
|
|
1811
|
+
hl[3] = 1595750129;
|
|
1812
|
+
hl[4] = 2917565137;
|
|
1813
|
+
hl[5] = 725511199;
|
|
1814
|
+
hl[6] = 4215389547;
|
|
1815
|
+
hl[7] = 327033209;
|
|
1816
|
+
crypto_hashblocks_hl(hh, hl, m, n);
|
|
1817
|
+
n %= 128;
|
|
1818
|
+
for (i = 0; i < n; i++) x[i] = m[b - n + i];
|
|
1819
|
+
x[n] = 128;
|
|
1820
|
+
n = 256 - 128 * (n < 112 ? 1 : 0);
|
|
1821
|
+
x[n - 9] = 0;
|
|
1822
|
+
ts64(x, n - 8, b / 536870912 | 0, b << 3);
|
|
1823
|
+
crypto_hashblocks_hl(hh, hl, x, n);
|
|
1824
|
+
for (i = 0; i < 8; i++) ts64(out, 8 * i, hh[i], hl[i]);
|
|
1825
|
+
return 0;
|
|
1826
|
+
}
|
|
1827
|
+
function add(p, q) {
|
|
1828
|
+
var a = gf(), b = gf(), c = gf(), d = gf(), e = gf(), f = gf(), g = gf(), h = gf(), t = gf();
|
|
1829
|
+
Z(a, p[1], p[0]);
|
|
1830
|
+
Z(t, q[1], q[0]);
|
|
1831
|
+
M(a, a, t);
|
|
1832
|
+
A(b, p[0], p[1]);
|
|
1833
|
+
A(t, q[0], q[1]);
|
|
1834
|
+
M(b, b, t);
|
|
1835
|
+
M(c, p[3], q[3]);
|
|
1836
|
+
M(c, c, D2);
|
|
1837
|
+
M(d, p[2], q[2]);
|
|
1838
|
+
A(d, d, d);
|
|
1839
|
+
Z(e, b, a);
|
|
1840
|
+
Z(f, d, c);
|
|
1841
|
+
A(g, d, c);
|
|
1842
|
+
A(h, b, a);
|
|
1843
|
+
M(p[0], e, f);
|
|
1844
|
+
M(p[1], h, g);
|
|
1845
|
+
M(p[2], g, f);
|
|
1846
|
+
M(p[3], e, h);
|
|
1847
|
+
}
|
|
1848
|
+
function cswap(p, q, b) {
|
|
1849
|
+
var i;
|
|
1850
|
+
for (i = 0; i < 4; i++) {
|
|
1851
|
+
sel25519(p[i], q[i], b);
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
function pack(r, p) {
|
|
1855
|
+
var tx = gf(), ty = gf(), zi = gf();
|
|
1856
|
+
inv25519(zi, p[2]);
|
|
1857
|
+
M(tx, p[0], zi);
|
|
1858
|
+
M(ty, p[1], zi);
|
|
1859
|
+
pack25519(r, ty);
|
|
1860
|
+
r[31] ^= par25519(tx) << 7;
|
|
1861
|
+
}
|
|
1862
|
+
function scalarmult(p, q, s) {
|
|
1863
|
+
var b, i;
|
|
1864
|
+
set25519(p[0], gf0);
|
|
1865
|
+
set25519(p[1], gf1);
|
|
1866
|
+
set25519(p[2], gf1);
|
|
1867
|
+
set25519(p[3], gf0);
|
|
1868
|
+
for (i = 255; i >= 0; --i) {
|
|
1869
|
+
b = s[i / 8 | 0] >> (i & 7) & 1;
|
|
1870
|
+
cswap(p, q, b);
|
|
1871
|
+
add(q, p);
|
|
1872
|
+
add(p, p);
|
|
1873
|
+
cswap(p, q, b);
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
function scalarbase(p, s) {
|
|
1877
|
+
var q = [gf(), gf(), gf(), gf()];
|
|
1878
|
+
set25519(q[0], X);
|
|
1879
|
+
set25519(q[1], Y);
|
|
1880
|
+
set25519(q[2], gf1);
|
|
1881
|
+
M(q[3], X, Y);
|
|
1882
|
+
scalarmult(p, q, s);
|
|
1883
|
+
}
|
|
1884
|
+
function crypto_sign_keypair(pk, sk, seeded) {
|
|
1885
|
+
var d = new Uint8Array(64);
|
|
1886
|
+
var p = [gf(), gf(), gf(), gf()];
|
|
1887
|
+
var i;
|
|
1888
|
+
if (!seeded) randombytes(sk, 32);
|
|
1889
|
+
crypto_hash(d, sk, 32);
|
|
1890
|
+
d[0] &= 248;
|
|
1891
|
+
d[31] &= 127;
|
|
1892
|
+
d[31] |= 64;
|
|
1893
|
+
scalarbase(p, d);
|
|
1894
|
+
pack(pk, p);
|
|
1895
|
+
for (i = 0; i < 32; i++) sk[i + 32] = pk[i];
|
|
1896
|
+
return 0;
|
|
1897
|
+
}
|
|
1898
|
+
var L = new Float64Array([237, 211, 245, 92, 26, 99, 18, 88, 214, 156, 247, 162, 222, 249, 222, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16]);
|
|
1899
|
+
function modL(r, x) {
|
|
1900
|
+
var carry, i, j, k;
|
|
1901
|
+
for (i = 63; i >= 32; --i) {
|
|
1902
|
+
carry = 0;
|
|
1903
|
+
for (j = i - 32, k = i - 12; j < k; ++j) {
|
|
1904
|
+
x[j] += carry - 16 * x[i] * L[j - (i - 32)];
|
|
1905
|
+
carry = Math.floor((x[j] + 128) / 256);
|
|
1906
|
+
x[j] -= carry * 256;
|
|
1907
|
+
}
|
|
1908
|
+
x[j] += carry;
|
|
1909
|
+
x[i] = 0;
|
|
1910
|
+
}
|
|
1911
|
+
carry = 0;
|
|
1912
|
+
for (j = 0; j < 32; j++) {
|
|
1913
|
+
x[j] += carry - (x[31] >> 4) * L[j];
|
|
1914
|
+
carry = x[j] >> 8;
|
|
1915
|
+
x[j] &= 255;
|
|
1916
|
+
}
|
|
1917
|
+
for (j = 0; j < 32; j++) x[j] -= carry * L[j];
|
|
1918
|
+
for (i = 0; i < 32; i++) {
|
|
1919
|
+
x[i + 1] += x[i] >> 8;
|
|
1920
|
+
r[i] = x[i] & 255;
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
function reduce(r) {
|
|
1924
|
+
var x = new Float64Array(64), i;
|
|
1925
|
+
for (i = 0; i < 64; i++) x[i] = r[i];
|
|
1926
|
+
for (i = 0; i < 64; i++) r[i] = 0;
|
|
1927
|
+
modL(r, x);
|
|
1928
|
+
}
|
|
1929
|
+
function crypto_sign(sm, m, n, sk) {
|
|
1930
|
+
var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64);
|
|
1931
|
+
var i, j, x = new Float64Array(64);
|
|
1932
|
+
var p = [gf(), gf(), gf(), gf()];
|
|
1933
|
+
crypto_hash(d, sk, 32);
|
|
1934
|
+
d[0] &= 248;
|
|
1935
|
+
d[31] &= 127;
|
|
1936
|
+
d[31] |= 64;
|
|
1937
|
+
var smlen = n + 64;
|
|
1938
|
+
for (i = 0; i < n; i++) sm[64 + i] = m[i];
|
|
1939
|
+
for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i];
|
|
1940
|
+
crypto_hash(r, sm.subarray(32), n + 32);
|
|
1941
|
+
reduce(r);
|
|
1942
|
+
scalarbase(p, r);
|
|
1943
|
+
pack(sm, p);
|
|
1944
|
+
for (i = 32; i < 64; i++) sm[i] = sk[i];
|
|
1945
|
+
crypto_hash(h, sm, n + 64);
|
|
1946
|
+
reduce(h);
|
|
1947
|
+
for (i = 0; i < 64; i++) x[i] = 0;
|
|
1948
|
+
for (i = 0; i < 32; i++) x[i] = r[i];
|
|
1949
|
+
for (i = 0; i < 32; i++) {
|
|
1950
|
+
for (j = 0; j < 32; j++) {
|
|
1951
|
+
x[i + j] += h[i] * d[j];
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
modL(sm.subarray(32), x);
|
|
1955
|
+
return smlen;
|
|
1956
|
+
}
|
|
1957
|
+
function unpackneg(r, p) {
|
|
1958
|
+
var t = gf(), chk = gf(), num = gf(), den = gf(), den2 = gf(), den4 = gf(), den6 = gf();
|
|
1959
|
+
set25519(r[2], gf1);
|
|
1960
|
+
unpack25519(r[1], p);
|
|
1961
|
+
S(num, r[1]);
|
|
1962
|
+
M(den, num, D);
|
|
1963
|
+
Z(num, num, r[2]);
|
|
1964
|
+
A(den, r[2], den);
|
|
1965
|
+
S(den2, den);
|
|
1966
|
+
S(den4, den2);
|
|
1967
|
+
M(den6, den4, den2);
|
|
1968
|
+
M(t, den6, num);
|
|
1969
|
+
M(t, t, den);
|
|
1970
|
+
pow2523(t, t);
|
|
1971
|
+
M(t, t, num);
|
|
1972
|
+
M(t, t, den);
|
|
1973
|
+
M(t, t, den);
|
|
1974
|
+
M(r[0], t, den);
|
|
1975
|
+
S(chk, r[0]);
|
|
1976
|
+
M(chk, chk, den);
|
|
1977
|
+
if (neq25519(chk, num)) M(r[0], r[0], I);
|
|
1978
|
+
S(chk, r[0]);
|
|
1979
|
+
M(chk, chk, den);
|
|
1980
|
+
if (neq25519(chk, num)) return -1;
|
|
1981
|
+
if (par25519(r[0]) === p[31] >> 7) Z(r[0], gf0, r[0]);
|
|
1982
|
+
M(r[3], r[0], r[1]);
|
|
1983
|
+
return 0;
|
|
1984
|
+
}
|
|
1985
|
+
function crypto_sign_open(m, sm, n, pk) {
|
|
1986
|
+
var i;
|
|
1987
|
+
var t = new Uint8Array(32), h = new Uint8Array(64);
|
|
1988
|
+
var p = [gf(), gf(), gf(), gf()], q = [gf(), gf(), gf(), gf()];
|
|
1989
|
+
if (n < 64) return -1;
|
|
1990
|
+
if (unpackneg(q, pk)) return -1;
|
|
1991
|
+
for (i = 0; i < n; i++) m[i] = sm[i];
|
|
1992
|
+
for (i = 0; i < 32; i++) m[i + 32] = pk[i];
|
|
1993
|
+
crypto_hash(h, m, n);
|
|
1994
|
+
reduce(h);
|
|
1995
|
+
scalarmult(p, q, h);
|
|
1996
|
+
scalarbase(q, sm.subarray(32));
|
|
1997
|
+
add(p, q);
|
|
1998
|
+
pack(t, p);
|
|
1999
|
+
n -= 64;
|
|
2000
|
+
if (crypto_verify_32(sm, 0, t, 0)) {
|
|
2001
|
+
for (i = 0; i < n; i++) m[i] = 0;
|
|
2002
|
+
return -1;
|
|
2003
|
+
}
|
|
2004
|
+
for (i = 0; i < n; i++) m[i] = sm[i + 64];
|
|
2005
|
+
return n;
|
|
2006
|
+
}
|
|
2007
|
+
var crypto_secretbox_KEYBYTES = 32, crypto_secretbox_NONCEBYTES = 24, crypto_secretbox_ZEROBYTES = 32, crypto_secretbox_BOXZEROBYTES = 16, crypto_scalarmult_BYTES = 32, crypto_scalarmult_SCALARBYTES = 32, crypto_box_PUBLICKEYBYTES = 32, crypto_box_SECRETKEYBYTES = 32, crypto_box_BEFORENMBYTES = 32, crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES, crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES, crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES, crypto_sign_BYTES = 64, crypto_sign_PUBLICKEYBYTES = 32, crypto_sign_SECRETKEYBYTES = 64, crypto_sign_SEEDBYTES = 32, crypto_hash_BYTES = 64;
|
|
2008
|
+
nacl.lowlevel = {
|
|
2009
|
+
crypto_core_hsalsa20,
|
|
2010
|
+
crypto_stream_xor,
|
|
2011
|
+
crypto_stream,
|
|
2012
|
+
crypto_stream_salsa20_xor,
|
|
2013
|
+
crypto_stream_salsa20,
|
|
2014
|
+
crypto_onetimeauth,
|
|
2015
|
+
crypto_onetimeauth_verify,
|
|
2016
|
+
crypto_verify_16,
|
|
2017
|
+
crypto_verify_32,
|
|
2018
|
+
crypto_secretbox,
|
|
2019
|
+
crypto_secretbox_open,
|
|
2020
|
+
crypto_scalarmult,
|
|
2021
|
+
crypto_scalarmult_base,
|
|
2022
|
+
crypto_box_beforenm,
|
|
2023
|
+
crypto_box_afternm,
|
|
2024
|
+
crypto_box,
|
|
2025
|
+
crypto_box_open,
|
|
2026
|
+
crypto_box_keypair,
|
|
2027
|
+
crypto_hash,
|
|
2028
|
+
crypto_sign,
|
|
2029
|
+
crypto_sign_keypair,
|
|
2030
|
+
crypto_sign_open,
|
|
2031
|
+
crypto_secretbox_KEYBYTES,
|
|
2032
|
+
crypto_secretbox_NONCEBYTES,
|
|
2033
|
+
crypto_secretbox_ZEROBYTES,
|
|
2034
|
+
crypto_secretbox_BOXZEROBYTES,
|
|
2035
|
+
crypto_scalarmult_BYTES,
|
|
2036
|
+
crypto_scalarmult_SCALARBYTES,
|
|
2037
|
+
crypto_box_PUBLICKEYBYTES,
|
|
2038
|
+
crypto_box_SECRETKEYBYTES,
|
|
2039
|
+
crypto_box_BEFORENMBYTES,
|
|
2040
|
+
crypto_box_NONCEBYTES,
|
|
2041
|
+
crypto_box_ZEROBYTES,
|
|
2042
|
+
crypto_box_BOXZEROBYTES,
|
|
2043
|
+
crypto_sign_BYTES,
|
|
2044
|
+
crypto_sign_PUBLICKEYBYTES,
|
|
2045
|
+
crypto_sign_SECRETKEYBYTES,
|
|
2046
|
+
crypto_sign_SEEDBYTES,
|
|
2047
|
+
crypto_hash_BYTES,
|
|
2048
|
+
gf,
|
|
2049
|
+
D,
|
|
2050
|
+
L,
|
|
2051
|
+
pack25519,
|
|
2052
|
+
unpack25519,
|
|
2053
|
+
M,
|
|
2054
|
+
A,
|
|
2055
|
+
S,
|
|
2056
|
+
Z,
|
|
2057
|
+
pow2523,
|
|
2058
|
+
add,
|
|
2059
|
+
set25519,
|
|
2060
|
+
modL,
|
|
2061
|
+
scalarmult,
|
|
2062
|
+
scalarbase
|
|
2063
|
+
};
|
|
2064
|
+
function checkLengths(k, n) {
|
|
2065
|
+
if (k.length !== crypto_secretbox_KEYBYTES) throw new Error("bad key size");
|
|
2066
|
+
if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error("bad nonce size");
|
|
2067
|
+
}
|
|
2068
|
+
function checkBoxLengths(pk, sk) {
|
|
2069
|
+
if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error("bad public key size");
|
|
2070
|
+
if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error("bad secret key size");
|
|
2071
|
+
}
|
|
2072
|
+
function checkArrayTypes() {
|
|
2073
|
+
for (var i = 0; i < arguments.length; i++) {
|
|
2074
|
+
if (!(arguments[i] instanceof Uint8Array))
|
|
2075
|
+
throw new TypeError("unexpected type, use Uint8Array");
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
function cleanup(arr) {
|
|
2079
|
+
for (var i = 0; i < arr.length; i++) arr[i] = 0;
|
|
2080
|
+
}
|
|
2081
|
+
nacl.randomBytes = function(n) {
|
|
2082
|
+
var b = new Uint8Array(n);
|
|
2083
|
+
randombytes(b, n);
|
|
2084
|
+
return b;
|
|
2085
|
+
};
|
|
2086
|
+
nacl.secretbox = function(msg, nonce, key) {
|
|
2087
|
+
checkArrayTypes(msg, nonce, key);
|
|
2088
|
+
checkLengths(key, nonce);
|
|
2089
|
+
var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length);
|
|
2090
|
+
var c = new Uint8Array(m.length);
|
|
2091
|
+
for (var i = 0; i < msg.length; i++) m[i + crypto_secretbox_ZEROBYTES] = msg[i];
|
|
2092
|
+
crypto_secretbox(c, m, m.length, nonce, key);
|
|
2093
|
+
return c.subarray(crypto_secretbox_BOXZEROBYTES);
|
|
2094
|
+
};
|
|
2095
|
+
nacl.secretbox.open = function(box, nonce, key) {
|
|
2096
|
+
checkArrayTypes(box, nonce, key);
|
|
2097
|
+
checkLengths(key, nonce);
|
|
2098
|
+
var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length);
|
|
2099
|
+
var m = new Uint8Array(c.length);
|
|
2100
|
+
for (var i = 0; i < box.length; i++) c[i + crypto_secretbox_BOXZEROBYTES] = box[i];
|
|
2101
|
+
if (c.length < 32) return null;
|
|
2102
|
+
if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null;
|
|
2103
|
+
return m.subarray(crypto_secretbox_ZEROBYTES);
|
|
2104
|
+
};
|
|
2105
|
+
nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES;
|
|
2106
|
+
nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES;
|
|
2107
|
+
nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES;
|
|
2108
|
+
nacl.scalarMult = function(n, p) {
|
|
2109
|
+
checkArrayTypes(n, p);
|
|
2110
|
+
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error("bad n size");
|
|
2111
|
+
if (p.length !== crypto_scalarmult_BYTES) throw new Error("bad p size");
|
|
2112
|
+
var q = new Uint8Array(crypto_scalarmult_BYTES);
|
|
2113
|
+
crypto_scalarmult(q, n, p);
|
|
2114
|
+
return q;
|
|
2115
|
+
};
|
|
2116
|
+
nacl.scalarMult.base = function(n) {
|
|
2117
|
+
checkArrayTypes(n);
|
|
2118
|
+
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error("bad n size");
|
|
2119
|
+
var q = new Uint8Array(crypto_scalarmult_BYTES);
|
|
2120
|
+
crypto_scalarmult_base(q, n);
|
|
2121
|
+
return q;
|
|
2122
|
+
};
|
|
2123
|
+
nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES;
|
|
2124
|
+
nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES;
|
|
2125
|
+
nacl.box = function(msg, nonce, publicKey, secretKey) {
|
|
2126
|
+
var k = nacl.box.before(publicKey, secretKey);
|
|
2127
|
+
return nacl.secretbox(msg, nonce, k);
|
|
2128
|
+
};
|
|
2129
|
+
nacl.box.before = function(publicKey, secretKey) {
|
|
2130
|
+
checkArrayTypes(publicKey, secretKey);
|
|
2131
|
+
checkBoxLengths(publicKey, secretKey);
|
|
2132
|
+
var k = new Uint8Array(crypto_box_BEFORENMBYTES);
|
|
2133
|
+
crypto_box_beforenm(k, publicKey, secretKey);
|
|
2134
|
+
return k;
|
|
2135
|
+
};
|
|
2136
|
+
nacl.box.after = nacl.secretbox;
|
|
2137
|
+
nacl.box.open = function(msg, nonce, publicKey, secretKey) {
|
|
2138
|
+
var k = nacl.box.before(publicKey, secretKey);
|
|
2139
|
+
return nacl.secretbox.open(msg, nonce, k);
|
|
2140
|
+
};
|
|
2141
|
+
nacl.box.open.after = nacl.secretbox.open;
|
|
2142
|
+
nacl.box.keyPair = function() {
|
|
2143
|
+
var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
|
|
2144
|
+
var sk = new Uint8Array(crypto_box_SECRETKEYBYTES);
|
|
2145
|
+
crypto_box_keypair(pk, sk);
|
|
2146
|
+
return { publicKey: pk, secretKey: sk };
|
|
2147
|
+
};
|
|
2148
|
+
nacl.box.keyPair.fromSecretKey = function(secretKey) {
|
|
2149
|
+
checkArrayTypes(secretKey);
|
|
2150
|
+
if (secretKey.length !== crypto_box_SECRETKEYBYTES)
|
|
2151
|
+
throw new Error("bad secret key size");
|
|
2152
|
+
var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
|
|
2153
|
+
crypto_scalarmult_base(pk, secretKey);
|
|
2154
|
+
return { publicKey: pk, secretKey: new Uint8Array(secretKey) };
|
|
2155
|
+
};
|
|
2156
|
+
nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES;
|
|
2157
|
+
nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES;
|
|
2158
|
+
nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES;
|
|
2159
|
+
nacl.box.nonceLength = crypto_box_NONCEBYTES;
|
|
2160
|
+
nacl.box.overheadLength = nacl.secretbox.overheadLength;
|
|
2161
|
+
nacl.sign = function(msg, secretKey) {
|
|
2162
|
+
checkArrayTypes(msg, secretKey);
|
|
2163
|
+
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
|
|
2164
|
+
throw new Error("bad secret key size");
|
|
2165
|
+
var signedMsg = new Uint8Array(crypto_sign_BYTES + msg.length);
|
|
2166
|
+
crypto_sign(signedMsg, msg, msg.length, secretKey);
|
|
2167
|
+
return signedMsg;
|
|
2168
|
+
};
|
|
2169
|
+
nacl.sign.open = function(signedMsg, publicKey) {
|
|
2170
|
+
checkArrayTypes(signedMsg, publicKey);
|
|
2171
|
+
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
|
|
2172
|
+
throw new Error("bad public key size");
|
|
2173
|
+
var tmp = new Uint8Array(signedMsg.length);
|
|
2174
|
+
var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey);
|
|
2175
|
+
if (mlen < 0) return null;
|
|
2176
|
+
var m = new Uint8Array(mlen);
|
|
2177
|
+
for (var i = 0; i < m.length; i++) m[i] = tmp[i];
|
|
2178
|
+
return m;
|
|
2179
|
+
};
|
|
2180
|
+
nacl.sign.detached = function(msg, secretKey) {
|
|
2181
|
+
var signedMsg = nacl.sign(msg, secretKey);
|
|
2182
|
+
var sig = new Uint8Array(crypto_sign_BYTES);
|
|
2183
|
+
for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i];
|
|
2184
|
+
return sig;
|
|
2185
|
+
};
|
|
2186
|
+
nacl.sign.detached.verify = function(msg, sig, publicKey) {
|
|
2187
|
+
checkArrayTypes(msg, sig, publicKey);
|
|
2188
|
+
if (sig.length !== crypto_sign_BYTES)
|
|
2189
|
+
throw new Error("bad signature size");
|
|
2190
|
+
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
|
|
2191
|
+
throw new Error("bad public key size");
|
|
2192
|
+
var sm = new Uint8Array(crypto_sign_BYTES + msg.length);
|
|
2193
|
+
var m = new Uint8Array(crypto_sign_BYTES + msg.length);
|
|
2194
|
+
var i;
|
|
2195
|
+
for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i];
|
|
2196
|
+
for (i = 0; i < msg.length; i++) sm[i + crypto_sign_BYTES] = msg[i];
|
|
2197
|
+
return crypto_sign_open(m, sm, sm.length, publicKey) >= 0;
|
|
2198
|
+
};
|
|
2199
|
+
nacl.sign.keyPair = function() {
|
|
2200
|
+
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
2201
|
+
var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
|
|
2202
|
+
crypto_sign_keypair(pk, sk);
|
|
2203
|
+
return { publicKey: pk, secretKey: sk };
|
|
2204
|
+
};
|
|
2205
|
+
nacl.sign.keyPair.fromSecretKey = function(secretKey) {
|
|
2206
|
+
checkArrayTypes(secretKey);
|
|
2207
|
+
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
|
|
2208
|
+
throw new Error("bad secret key size");
|
|
2209
|
+
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
2210
|
+
for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32 + i];
|
|
2211
|
+
return { publicKey: pk, secretKey: new Uint8Array(secretKey) };
|
|
2212
|
+
};
|
|
2213
|
+
nacl.sign.keyPair.fromSeed = function(seed) {
|
|
2214
|
+
checkArrayTypes(seed);
|
|
2215
|
+
if (seed.length !== crypto_sign_SEEDBYTES)
|
|
2216
|
+
throw new Error("bad seed size");
|
|
2217
|
+
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
2218
|
+
var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
|
|
2219
|
+
for (var i = 0; i < 32; i++) sk[i] = seed[i];
|
|
2220
|
+
crypto_sign_keypair(pk, sk, true);
|
|
2221
|
+
return { publicKey: pk, secretKey: sk };
|
|
2222
|
+
};
|
|
2223
|
+
nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES;
|
|
2224
|
+
nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES;
|
|
2225
|
+
nacl.sign.seedLength = crypto_sign_SEEDBYTES;
|
|
2226
|
+
nacl.sign.signatureLength = crypto_sign_BYTES;
|
|
2227
|
+
nacl.hash = function(msg) {
|
|
2228
|
+
checkArrayTypes(msg);
|
|
2229
|
+
var h = new Uint8Array(crypto_hash_BYTES);
|
|
2230
|
+
crypto_hash(h, msg, msg.length);
|
|
2231
|
+
return h;
|
|
2232
|
+
};
|
|
2233
|
+
nacl.hash.hashLength = crypto_hash_BYTES;
|
|
2234
|
+
nacl.verify = function(x, y) {
|
|
2235
|
+
checkArrayTypes(x, y);
|
|
2236
|
+
if (x.length === 0 || y.length === 0) return false;
|
|
2237
|
+
if (x.length !== y.length) return false;
|
|
2238
|
+
return vn(x, 0, y, 0, x.length) === 0 ? true : false;
|
|
2239
|
+
};
|
|
2240
|
+
nacl.setPRNG = function(fn) {
|
|
2241
|
+
randombytes = fn;
|
|
2242
|
+
};
|
|
2243
|
+
(function() {
|
|
2244
|
+
var crypto = typeof self !== "undefined" ? self.crypto || self.msCrypto : null;
|
|
2245
|
+
if (crypto && crypto.getRandomValues) {
|
|
2246
|
+
var QUOTA = 65536;
|
|
2247
|
+
nacl.setPRNG(function(x, n) {
|
|
2248
|
+
var i, v = new Uint8Array(n);
|
|
2249
|
+
for (i = 0; i < n; i += QUOTA) {
|
|
2250
|
+
crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
|
|
2251
|
+
}
|
|
2252
|
+
for (i = 0; i < n; i++) x[i] = v[i];
|
|
2253
|
+
cleanup(v);
|
|
2254
|
+
});
|
|
2255
|
+
} else if (typeof __require !== "undefined") {
|
|
2256
|
+
crypto = __require("crypto");
|
|
2257
|
+
if (crypto && crypto.randomBytes) {
|
|
2258
|
+
nacl.setPRNG(function(x, n) {
|
|
2259
|
+
var i, v = crypto.randomBytes(n);
|
|
2260
|
+
for (i = 0; i < n; i++) x[i] = v[i];
|
|
2261
|
+
cleanup(v);
|
|
2262
|
+
});
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
})();
|
|
2266
|
+
})(typeof module !== "undefined" && module.exports ? module.exports : self.nacl = self.nacl || {});
|
|
2267
|
+
}
|
|
2268
|
+
});
|
|
2269
|
+
|
|
2270
|
+
// ../../node_modules/base-x/src/index.js
|
|
2271
|
+
var require_src = __commonJS({
|
|
2272
|
+
"../../node_modules/base-x/src/index.js"(exports$1, module) {
|
|
2273
|
+
function base(ALPHABET) {
|
|
2274
|
+
if (ALPHABET.length >= 255) {
|
|
2275
|
+
throw new TypeError("Alphabet too long");
|
|
2276
|
+
}
|
|
2277
|
+
var BASE_MAP = new Uint8Array(256);
|
|
2278
|
+
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
2279
|
+
BASE_MAP[j] = 255;
|
|
2280
|
+
}
|
|
2281
|
+
for (var i = 0; i < ALPHABET.length; i++) {
|
|
2282
|
+
var x = ALPHABET.charAt(i);
|
|
2283
|
+
var xc = x.charCodeAt(0);
|
|
2284
|
+
if (BASE_MAP[xc] !== 255) {
|
|
2285
|
+
throw new TypeError(x + " is ambiguous");
|
|
2286
|
+
}
|
|
2287
|
+
BASE_MAP[xc] = i;
|
|
2288
|
+
}
|
|
2289
|
+
var BASE = ALPHABET.length;
|
|
2290
|
+
var LEADER = ALPHABET.charAt(0);
|
|
2291
|
+
var FACTOR = Math.log(BASE) / Math.log(256);
|
|
2292
|
+
var iFACTOR = Math.log(256) / Math.log(BASE);
|
|
2293
|
+
function encode(source) {
|
|
2294
|
+
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
2295
|
+
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
2296
|
+
} else if (Array.isArray(source)) {
|
|
2297
|
+
source = Uint8Array.from(source);
|
|
2298
|
+
}
|
|
2299
|
+
if (!(source instanceof Uint8Array)) {
|
|
2300
|
+
throw new TypeError("Expected Uint8Array");
|
|
2301
|
+
}
|
|
2302
|
+
if (source.length === 0) {
|
|
2303
|
+
return "";
|
|
2304
|
+
}
|
|
2305
|
+
var zeroes = 0;
|
|
2306
|
+
var length = 0;
|
|
2307
|
+
var pbegin = 0;
|
|
2308
|
+
var pend = source.length;
|
|
2309
|
+
while (pbegin !== pend && source[pbegin] === 0) {
|
|
2310
|
+
pbegin++;
|
|
2311
|
+
zeroes++;
|
|
2312
|
+
}
|
|
2313
|
+
var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
|
|
2314
|
+
var b58 = new Uint8Array(size);
|
|
2315
|
+
while (pbegin !== pend) {
|
|
2316
|
+
var carry = source[pbegin];
|
|
2317
|
+
var i2 = 0;
|
|
2318
|
+
for (var it1 = size - 1; (carry !== 0 || i2 < length) && it1 !== -1; it1--, i2++) {
|
|
2319
|
+
carry += 256 * b58[it1] >>> 0;
|
|
2320
|
+
b58[it1] = carry % BASE >>> 0;
|
|
2321
|
+
carry = carry / BASE >>> 0;
|
|
2322
|
+
}
|
|
2323
|
+
if (carry !== 0) {
|
|
2324
|
+
throw new Error("Non-zero carry");
|
|
2325
|
+
}
|
|
2326
|
+
length = i2;
|
|
2327
|
+
pbegin++;
|
|
2328
|
+
}
|
|
2329
|
+
var it2 = size - length;
|
|
2330
|
+
while (it2 !== size && b58[it2] === 0) {
|
|
2331
|
+
it2++;
|
|
2332
|
+
}
|
|
2333
|
+
var str = LEADER.repeat(zeroes);
|
|
2334
|
+
for (; it2 < size; ++it2) {
|
|
2335
|
+
str += ALPHABET.charAt(b58[it2]);
|
|
2336
|
+
}
|
|
2337
|
+
return str;
|
|
2338
|
+
}
|
|
2339
|
+
function decodeUnsafe(source) {
|
|
2340
|
+
if (typeof source !== "string") {
|
|
2341
|
+
throw new TypeError("Expected String");
|
|
2342
|
+
}
|
|
2343
|
+
if (source.length === 0) {
|
|
2344
|
+
return new Uint8Array();
|
|
2345
|
+
}
|
|
2346
|
+
var psz = 0;
|
|
2347
|
+
var zeroes = 0;
|
|
2348
|
+
var length = 0;
|
|
2349
|
+
while (source[psz] === LEADER) {
|
|
2350
|
+
zeroes++;
|
|
2351
|
+
psz++;
|
|
2352
|
+
}
|
|
2353
|
+
var size = (source.length - psz) * FACTOR + 1 >>> 0;
|
|
2354
|
+
var b256 = new Uint8Array(size);
|
|
2355
|
+
while (source[psz]) {
|
|
2356
|
+
var charCode = source.charCodeAt(psz);
|
|
2357
|
+
if (charCode > 255) {
|
|
2358
|
+
return;
|
|
2359
|
+
}
|
|
2360
|
+
var carry = BASE_MAP[charCode];
|
|
2361
|
+
if (carry === 255) {
|
|
2362
|
+
return;
|
|
2363
|
+
}
|
|
2364
|
+
var i2 = 0;
|
|
2365
|
+
for (var it3 = size - 1; (carry !== 0 || i2 < length) && it3 !== -1; it3--, i2++) {
|
|
2366
|
+
carry += BASE * b256[it3] >>> 0;
|
|
2367
|
+
b256[it3] = carry % 256 >>> 0;
|
|
2368
|
+
carry = carry / 256 >>> 0;
|
|
2369
|
+
}
|
|
2370
|
+
if (carry !== 0) {
|
|
2371
|
+
throw new Error("Non-zero carry");
|
|
2372
|
+
}
|
|
2373
|
+
length = i2;
|
|
2374
|
+
psz++;
|
|
2375
|
+
}
|
|
2376
|
+
var it4 = size - length;
|
|
2377
|
+
while (it4 !== size && b256[it4] === 0) {
|
|
2378
|
+
it4++;
|
|
2379
|
+
}
|
|
2380
|
+
var vch = new Uint8Array(zeroes + (size - it4));
|
|
2381
|
+
var j2 = zeroes;
|
|
2382
|
+
while (it4 !== size) {
|
|
2383
|
+
vch[j2++] = b256[it4++];
|
|
2384
|
+
}
|
|
2385
|
+
return vch;
|
|
2386
|
+
}
|
|
2387
|
+
function decode(string) {
|
|
2388
|
+
var buffer = decodeUnsafe(string);
|
|
2389
|
+
if (buffer) {
|
|
2390
|
+
return buffer;
|
|
2391
|
+
}
|
|
2392
|
+
throw new Error("Non-base" + BASE + " character");
|
|
2393
|
+
}
|
|
2394
|
+
return {
|
|
2395
|
+
encode,
|
|
2396
|
+
decodeUnsafe,
|
|
2397
|
+
decode
|
|
2398
|
+
};
|
|
2399
|
+
}
|
|
2400
|
+
module.exports = base;
|
|
2401
|
+
}
|
|
2402
|
+
});
|
|
2403
|
+
|
|
2404
|
+
// ../../node_modules/bs58/index.js
|
|
2405
|
+
var require_bs58 = __commonJS({
|
|
2406
|
+
"../../node_modules/bs58/index.js"(exports$1, module) {
|
|
2407
|
+
var basex = require_src();
|
|
2408
|
+
var ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
2409
|
+
module.exports = basex(ALPHABET);
|
|
2410
|
+
}
|
|
2411
|
+
});
|
|
2412
|
+
|
|
2413
|
+
// ../../node_modules/bs58check/base.js
|
|
2414
|
+
var require_base = __commonJS({
|
|
2415
|
+
"../../node_modules/bs58check/base.js"(exports$1, module) {
|
|
2416
|
+
var base58 = require_bs58();
|
|
2417
|
+
module.exports = function(checksumFn) {
|
|
2418
|
+
function encode(payload) {
|
|
2419
|
+
var payloadU8 = Uint8Array.from(payload);
|
|
2420
|
+
var checksum = checksumFn(payloadU8);
|
|
2421
|
+
var length = payloadU8.length + 4;
|
|
2422
|
+
var both = new Uint8Array(length);
|
|
2423
|
+
both.set(payloadU8, 0);
|
|
2424
|
+
both.set(checksum.subarray(0, 4), payloadU8.length);
|
|
2425
|
+
return base58.encode(both, length);
|
|
2426
|
+
}
|
|
2427
|
+
function decodeRaw(buffer) {
|
|
2428
|
+
var payload = buffer.slice(0, -4);
|
|
2429
|
+
var checksum = buffer.slice(-4);
|
|
2430
|
+
var newChecksum = checksumFn(payload);
|
|
2431
|
+
if (checksum[0] ^ newChecksum[0] | checksum[1] ^ newChecksum[1] | checksum[2] ^ newChecksum[2] | checksum[3] ^ newChecksum[3]) return;
|
|
2432
|
+
return payload;
|
|
2433
|
+
}
|
|
2434
|
+
function decodeUnsafe(string) {
|
|
2435
|
+
var buffer = base58.decodeUnsafe(string);
|
|
2436
|
+
if (!buffer) return;
|
|
2437
|
+
return decodeRaw(buffer);
|
|
2438
|
+
}
|
|
2439
|
+
function decode(string) {
|
|
2440
|
+
var buffer = base58.decode(string);
|
|
2441
|
+
var payload = decodeRaw(buffer);
|
|
2442
|
+
if (!payload) throw new Error("Invalid checksum");
|
|
2443
|
+
return payload;
|
|
2444
|
+
}
|
|
2445
|
+
return {
|
|
2446
|
+
encode,
|
|
2447
|
+
decode,
|
|
2448
|
+
decodeUnsafe
|
|
2449
|
+
};
|
|
2450
|
+
};
|
|
2451
|
+
}
|
|
2452
|
+
});
|
|
2453
|
+
|
|
2454
|
+
// ../../node_modules/bs58check/index.js
|
|
2455
|
+
var require_bs58check = __commonJS({
|
|
2456
|
+
"../../node_modules/bs58check/index.js"(exports$1, module) {
|
|
2457
|
+
var { sha256: sha2562 } = __require("@noble/hashes/sha256");
|
|
2458
|
+
var bs58checkBase = require_base();
|
|
2459
|
+
function sha256x2(buffer) {
|
|
2460
|
+
return sha2562(sha2562(buffer));
|
|
2461
|
+
}
|
|
2462
|
+
module.exports = bs58checkBase(sha256x2);
|
|
2463
|
+
}
|
|
2464
|
+
});
|
|
2465
|
+
|
|
3
2466
|
// src/config/contracts.ts
|
|
4
2467
|
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
5
2468
|
var ZUBARI_CONTRACTS = {
|
|
@@ -220,6 +2683,198 @@ function getWdkApiClient(baseUrl) {
|
|
|
220
2683
|
return wdkApiClient;
|
|
221
2684
|
}
|
|
222
2685
|
|
|
2686
|
+
// src/services/BrowserAddressDerivation.ts
|
|
2687
|
+
var BrowserAddressDerivation_exports = {};
|
|
2688
|
+
__export(BrowserAddressDerivation_exports, {
|
|
2689
|
+
deriveAllAddresses: () => deriveAllAddresses,
|
|
2690
|
+
deriveBitcoinAddress: () => deriveBitcoinAddress,
|
|
2691
|
+
deriveEthereumAddress: () => deriveEthereumAddress,
|
|
2692
|
+
deriveSolanaAddress: () => deriveSolanaAddress,
|
|
2693
|
+
deriveSparkAddress: () => deriveSparkAddress,
|
|
2694
|
+
deriveTonAddress: () => deriveTonAddress,
|
|
2695
|
+
deriveTronAddress: () => deriveTronAddress,
|
|
2696
|
+
generateSeedPhrase: () => generateSeedPhrase,
|
|
2697
|
+
isValidSeed: () => isValidSeed
|
|
2698
|
+
});
|
|
2699
|
+
var DERIVATION_PATHS = {
|
|
2700
|
+
ethereum: "m/44'/60'/0'/0/0",
|
|
2701
|
+
bitcoin_mainnet: "m/84'/0'/0'/0/0",
|
|
2702
|
+
bitcoin_testnet: "m/84'/1'/0'/0/0",
|
|
2703
|
+
ton: "m/44'/607'/0'/0'/0'",
|
|
2704
|
+
tron: "m/44'/195'/0'/0/0",
|
|
2705
|
+
solana: "m/44'/501'/0'/0'",
|
|
2706
|
+
spark: "m/44'/998'/0'/0/0"
|
|
2707
|
+
};
|
|
2708
|
+
function deriveEthereumAddress(seed) {
|
|
2709
|
+
const hdNode = ethers.HDNodeWallet.fromPhrase(seed, void 0, DERIVATION_PATHS.ethereum);
|
|
2710
|
+
return hdNode.address;
|
|
2711
|
+
}
|
|
2712
|
+
function deriveBitcoinAddress(seed, network = "testnet") {
|
|
2713
|
+
try {
|
|
2714
|
+
const seedBytes = bip39.mnemonicToSeedSync(seed);
|
|
2715
|
+
const hdKey = bip32.HDKey.fromMasterSeed(seedBytes);
|
|
2716
|
+
const path = network === "testnet" ? DERIVATION_PATHS.bitcoin_testnet : DERIVATION_PATHS.bitcoin_mainnet;
|
|
2717
|
+
const child = hdKey.derive(path);
|
|
2718
|
+
if (!child.publicKey) {
|
|
2719
|
+
throw new Error("Failed to derive public key");
|
|
2720
|
+
}
|
|
2721
|
+
const pubKeyHash = ripemd160.ripemd160(sha256.sha256(child.publicKey));
|
|
2722
|
+
const witnessVersion = 0;
|
|
2723
|
+
const words = base.bech32.toWords(pubKeyHash);
|
|
2724
|
+
words.unshift(witnessVersion);
|
|
2725
|
+
const hrp = network === "testnet" ? "tb" : "bc";
|
|
2726
|
+
const address = base.bech32.encode(hrp, words);
|
|
2727
|
+
return address;
|
|
2728
|
+
} catch (error) {
|
|
2729
|
+
console.error("Bitcoin address derivation failed:", error);
|
|
2730
|
+
throw error;
|
|
2731
|
+
}
|
|
2732
|
+
}
|
|
2733
|
+
async function deriveSolanaAddress(seed) {
|
|
2734
|
+
try {
|
|
2735
|
+
const [ed25519, nacl, bs58] = await Promise.all([
|
|
2736
|
+
import('ed25519-hd-key'),
|
|
2737
|
+
Promise.resolve().then(() => __toESM(require_nacl_fast())),
|
|
2738
|
+
Promise.resolve().then(() => __toESM(require_bs58()))
|
|
2739
|
+
]);
|
|
2740
|
+
const seedBytes = bip39.mnemonicToSeedSync(seed);
|
|
2741
|
+
const derived = ed25519.derivePath(DERIVATION_PATHS.solana, Buffer.from(seedBytes).toString("hex"));
|
|
2742
|
+
const keypair = nacl.sign.keyPair.fromSeed(new Uint8Array(derived.key));
|
|
2743
|
+
return bs58.encode(keypair.publicKey);
|
|
2744
|
+
} catch (error) {
|
|
2745
|
+
console.error("Solana address derivation failed:", error);
|
|
2746
|
+
throw error;
|
|
2747
|
+
}
|
|
2748
|
+
}
|
|
2749
|
+
async function deriveTonAddress(seed) {
|
|
2750
|
+
try {
|
|
2751
|
+
const [ed25519, nacl] = await Promise.all([
|
|
2752
|
+
import('ed25519-hd-key'),
|
|
2753
|
+
Promise.resolve().then(() => __toESM(require_nacl_fast()))
|
|
2754
|
+
]);
|
|
2755
|
+
const seedBytes = bip39.mnemonicToSeedSync(seed);
|
|
2756
|
+
const derived = ed25519.derivePath(DERIVATION_PATHS.ton, Buffer.from(seedBytes).toString("hex"));
|
|
2757
|
+
const keypair = nacl.sign.keyPair.fromSeed(new Uint8Array(derived.key));
|
|
2758
|
+
const publicKey = keypair.publicKey;
|
|
2759
|
+
const workchain = 0;
|
|
2760
|
+
const flags = 17;
|
|
2761
|
+
const hash = sha256.sha256(publicKey);
|
|
2762
|
+
const addressData = new Uint8Array(34);
|
|
2763
|
+
addressData[0] = flags;
|
|
2764
|
+
addressData[1] = workchain;
|
|
2765
|
+
addressData.set(hash, 2);
|
|
2766
|
+
const crc = crc16(addressData);
|
|
2767
|
+
const fullAddress = new Uint8Array(36);
|
|
2768
|
+
fullAddress.set(addressData);
|
|
2769
|
+
fullAddress[34] = crc >> 8 & 255;
|
|
2770
|
+
fullAddress[35] = crc & 255;
|
|
2771
|
+
const base64 = btoa(String.fromCharCode(...fullAddress)).replace(/\+/g, "-").replace(/\//g, "_");
|
|
2772
|
+
return base64;
|
|
2773
|
+
} catch (error) {
|
|
2774
|
+
console.error("TON address derivation failed:", error);
|
|
2775
|
+
throw error;
|
|
2776
|
+
}
|
|
2777
|
+
}
|
|
2778
|
+
function crc16(data) {
|
|
2779
|
+
let crc = 0;
|
|
2780
|
+
for (const byte of data) {
|
|
2781
|
+
crc ^= byte << 8;
|
|
2782
|
+
for (let i = 0; i < 8; i++) {
|
|
2783
|
+
crc = crc & 32768 ? crc << 1 ^ 4129 : crc << 1;
|
|
2784
|
+
crc &= 65535;
|
|
2785
|
+
}
|
|
2786
|
+
}
|
|
2787
|
+
return crc;
|
|
2788
|
+
}
|
|
2789
|
+
async function deriveTronAddress(seed) {
|
|
2790
|
+
try {
|
|
2791
|
+
const bs58check = await Promise.resolve().then(() => __toESM(require_bs58check()));
|
|
2792
|
+
const hdNode = ethers.HDNodeWallet.fromPhrase(seed, void 0, DERIVATION_PATHS.tron);
|
|
2793
|
+
const ethAddressHex = hdNode.address.slice(2).toLowerCase();
|
|
2794
|
+
const addressBytes = new Uint8Array(21);
|
|
2795
|
+
addressBytes[0] = 65;
|
|
2796
|
+
for (let i = 0; i < 20; i++) {
|
|
2797
|
+
addressBytes[i + 1] = parseInt(ethAddressHex.slice(i * 2, i * 2 + 2), 16);
|
|
2798
|
+
}
|
|
2799
|
+
return bs58check.encode(Buffer.from(addressBytes));
|
|
2800
|
+
} catch (error) {
|
|
2801
|
+
console.error("TRON address derivation failed:", error);
|
|
2802
|
+
throw error;
|
|
2803
|
+
}
|
|
2804
|
+
}
|
|
2805
|
+
function deriveSparkAddress(seed, network = "testnet") {
|
|
2806
|
+
try {
|
|
2807
|
+
const seedBytes = bip39.mnemonicToSeedSync(seed);
|
|
2808
|
+
const hdKey = bip32.HDKey.fromMasterSeed(seedBytes);
|
|
2809
|
+
const child = hdKey.derive(DERIVATION_PATHS.spark);
|
|
2810
|
+
if (!child.publicKey) {
|
|
2811
|
+
throw new Error("Failed to derive public key");
|
|
2812
|
+
}
|
|
2813
|
+
const pubKeyHash = ripemd160.ripemd160(sha256.sha256(child.publicKey));
|
|
2814
|
+
const witnessVersion = 0;
|
|
2815
|
+
const words = base.bech32.toWords(pubKeyHash);
|
|
2816
|
+
words.unshift(witnessVersion);
|
|
2817
|
+
const hrp = network === "testnet" ? "tsp" : "sp";
|
|
2818
|
+
const address = base.bech32.encode(hrp, words);
|
|
2819
|
+
return address;
|
|
2820
|
+
} catch (error) {
|
|
2821
|
+
console.error("Spark address derivation failed:", error);
|
|
2822
|
+
throw error;
|
|
2823
|
+
}
|
|
2824
|
+
}
|
|
2825
|
+
async function deriveAllAddresses(seed, network = "testnet") {
|
|
2826
|
+
const addresses = {
|
|
2827
|
+
ethereum: null,
|
|
2828
|
+
bitcoin: null,
|
|
2829
|
+
ton: null,
|
|
2830
|
+
tron: null,
|
|
2831
|
+
solana: null,
|
|
2832
|
+
spark: null
|
|
2833
|
+
};
|
|
2834
|
+
try {
|
|
2835
|
+
addresses.ethereum = deriveEthereumAddress(seed);
|
|
2836
|
+
} catch (e) {
|
|
2837
|
+
console.error("ETH derivation failed:", e);
|
|
2838
|
+
}
|
|
2839
|
+
try {
|
|
2840
|
+
addresses.bitcoin = deriveBitcoinAddress(seed, network);
|
|
2841
|
+
} catch (e) {
|
|
2842
|
+
console.error("BTC derivation failed:", e);
|
|
2843
|
+
}
|
|
2844
|
+
try {
|
|
2845
|
+
addresses.spark = deriveSparkAddress(seed, network);
|
|
2846
|
+
} catch (e) {
|
|
2847
|
+
console.error("Spark derivation failed:", e);
|
|
2848
|
+
}
|
|
2849
|
+
const [solResult, tonResult, tronResult] = await Promise.allSettled([
|
|
2850
|
+
deriveSolanaAddress(seed),
|
|
2851
|
+
deriveTonAddress(seed),
|
|
2852
|
+
deriveTronAddress(seed)
|
|
2853
|
+
]);
|
|
2854
|
+
if (solResult.status === "fulfilled") {
|
|
2855
|
+
addresses.solana = solResult.value;
|
|
2856
|
+
} else {
|
|
2857
|
+
console.error("SOL derivation failed:", solResult.reason);
|
|
2858
|
+
}
|
|
2859
|
+
if (tonResult.status === "fulfilled") {
|
|
2860
|
+
addresses.ton = tonResult.value;
|
|
2861
|
+
} else {
|
|
2862
|
+
console.error("TON derivation failed:", tonResult.reason);
|
|
2863
|
+
}
|
|
2864
|
+
if (tronResult.status === "fulfilled") {
|
|
2865
|
+
addresses.tron = tronResult.value;
|
|
2866
|
+
} else {
|
|
2867
|
+
console.error("TRON derivation failed:", tronResult.reason);
|
|
2868
|
+
}
|
|
2869
|
+
return addresses;
|
|
2870
|
+
}
|
|
2871
|
+
function isValidSeed(seed) {
|
|
2872
|
+
return bip39.validateMnemonic(seed, english.wordlist);
|
|
2873
|
+
}
|
|
2874
|
+
function generateSeedPhrase() {
|
|
2875
|
+
return bip39.generateMnemonic(english.wordlist);
|
|
2876
|
+
}
|
|
2877
|
+
|
|
223
2878
|
// src/services/WdkService.ts
|
|
224
2879
|
var WdkManager;
|
|
225
2880
|
var WalletManagerBtc;
|
|
@@ -258,7 +2913,7 @@ async function loadWdkModules() {
|
|
|
258
2913
|
throw wdkLoadError;
|
|
259
2914
|
}
|
|
260
2915
|
}
|
|
261
|
-
var
|
|
2916
|
+
var DERIVATION_PATHS2 = {
|
|
262
2917
|
bitcoin: "m/84'/0'/0'/0/0",
|
|
263
2918
|
// BIP-84 for native SegWit
|
|
264
2919
|
ethereum: "m/44'/60'/0'/0/0",
|
|
@@ -424,7 +3079,7 @@ var WdkService = class {
|
|
|
424
3079
|
* Derive address for a specific chain
|
|
425
3080
|
*/
|
|
426
3081
|
async deriveAddress(chain) {
|
|
427
|
-
const path =
|
|
3082
|
+
const path = DERIVATION_PATHS2[chain];
|
|
428
3083
|
try {
|
|
429
3084
|
const wallet = await this.getWallet(chain);
|
|
430
3085
|
const account = await wallet.getAccount(0);
|
|
@@ -544,10 +3199,418 @@ function createWdkService(config) {
|
|
|
544
3199
|
return new WdkService(config);
|
|
545
3200
|
}
|
|
546
3201
|
|
|
3202
|
+
// src/services/TransactionService.ts
|
|
3203
|
+
var WdkManager2;
|
|
3204
|
+
var WalletManagerBtc2;
|
|
3205
|
+
var WalletManagerEvm2;
|
|
3206
|
+
var WalletManagerSolana2;
|
|
3207
|
+
var WalletManagerTon2;
|
|
3208
|
+
var WalletManagerTron2;
|
|
3209
|
+
var WalletManagerSpark2;
|
|
3210
|
+
var wdkLoaded2 = false;
|
|
3211
|
+
var wdkLoadError2 = null;
|
|
3212
|
+
var dynamicImport2 = new Function("specifier", "return import(specifier)");
|
|
3213
|
+
async function loadWdkModules2() {
|
|
3214
|
+
if (wdkLoaded2) return;
|
|
3215
|
+
if (wdkLoadError2) throw wdkLoadError2;
|
|
3216
|
+
try {
|
|
3217
|
+
const [wdk, btc, evm, solana, ton, tron, spark] = await Promise.all([
|
|
3218
|
+
dynamicImport2("@tetherto/wdk"),
|
|
3219
|
+
dynamicImport2("@tetherto/wdk-wallet-btc"),
|
|
3220
|
+
dynamicImport2("@tetherto/wdk-wallet-evm"),
|
|
3221
|
+
dynamicImport2("@tetherto/wdk-wallet-solana"),
|
|
3222
|
+
dynamicImport2("@tetherto/wdk-wallet-ton"),
|
|
3223
|
+
dynamicImport2("@tetherto/wdk-wallet-tron"),
|
|
3224
|
+
dynamicImport2("@tetherto/wdk-wallet-spark")
|
|
3225
|
+
]);
|
|
3226
|
+
WdkManager2 = wdk.default;
|
|
3227
|
+
WalletManagerBtc2 = btc.default;
|
|
3228
|
+
WalletManagerEvm2 = evm.default;
|
|
3229
|
+
WalletManagerSolana2 = solana.default;
|
|
3230
|
+
WalletManagerTon2 = ton.default;
|
|
3231
|
+
WalletManagerTron2 = tron.default;
|
|
3232
|
+
WalletManagerSpark2 = spark.default;
|
|
3233
|
+
wdkLoaded2 = true;
|
|
3234
|
+
} catch (error) {
|
|
3235
|
+
wdkLoadError2 = error instanceof Error ? error : new Error("Failed to load WDK modules");
|
|
3236
|
+
console.error("Failed to load WDK modules:", error);
|
|
3237
|
+
throw wdkLoadError2;
|
|
3238
|
+
}
|
|
3239
|
+
}
|
|
3240
|
+
var DEFAULT_RPC_URLS2 = {
|
|
3241
|
+
mainnet: {
|
|
3242
|
+
ethereum: "https://eth.llamarpc.com",
|
|
3243
|
+
bitcoin: "",
|
|
3244
|
+
// Uses Electrum
|
|
3245
|
+
solana: "https://api.mainnet-beta.solana.com",
|
|
3246
|
+
ton: "https://toncenter.com/api/v2/jsonRPC",
|
|
3247
|
+
tron: "https://api.trongrid.io",
|
|
3248
|
+
spark: ""
|
|
3249
|
+
// Uses Spark network
|
|
3250
|
+
},
|
|
3251
|
+
testnet: {
|
|
3252
|
+
ethereum: "https://ethereum-sepolia-rpc.publicnode.com",
|
|
3253
|
+
bitcoin: "",
|
|
3254
|
+
// Uses Electrum testnet
|
|
3255
|
+
solana: "https://api.devnet.solana.com",
|
|
3256
|
+
ton: "https://testnet.toncenter.com/api/v2/jsonRPC",
|
|
3257
|
+
tron: "https://api.shasta.trongrid.io",
|
|
3258
|
+
spark: ""
|
|
3259
|
+
// Uses Spark testnet
|
|
3260
|
+
}
|
|
3261
|
+
};
|
|
3262
|
+
var EXPLORER_URLS = {
|
|
3263
|
+
mainnet: {
|
|
3264
|
+
ethereum: "https://etherscan.io/tx/",
|
|
3265
|
+
bitcoin: "https://mempool.space/tx/",
|
|
3266
|
+
solana: "https://solscan.io/tx/",
|
|
3267
|
+
ton: "https://tonscan.org/tx/",
|
|
3268
|
+
tron: "https://tronscan.org/#/transaction/",
|
|
3269
|
+
spark: "https://spark.info/tx/"
|
|
3270
|
+
},
|
|
3271
|
+
testnet: {
|
|
3272
|
+
ethereum: "https://sepolia.etherscan.io/tx/",
|
|
3273
|
+
bitcoin: "https://mempool.space/testnet/tx/",
|
|
3274
|
+
solana: "https://solscan.io/tx/?cluster=devnet&tx=",
|
|
3275
|
+
ton: "https://testnet.tonscan.org/tx/",
|
|
3276
|
+
tron: "https://shasta.tronscan.org/#/transaction/",
|
|
3277
|
+
spark: "https://testnet.spark.info/tx/"
|
|
3278
|
+
}
|
|
3279
|
+
};
|
|
3280
|
+
var TransactionService = class {
|
|
3281
|
+
seed = null;
|
|
3282
|
+
config;
|
|
3283
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3284
|
+
wallets = {};
|
|
3285
|
+
constructor(config = {}) {
|
|
3286
|
+
this.config = {
|
|
3287
|
+
network: config.network || "testnet",
|
|
3288
|
+
rpcUrls: config.rpcUrls
|
|
3289
|
+
};
|
|
3290
|
+
}
|
|
3291
|
+
/**
|
|
3292
|
+
* Ensure WDK modules are loaded
|
|
3293
|
+
*/
|
|
3294
|
+
async ensureLoaded() {
|
|
3295
|
+
await loadWdkModules2();
|
|
3296
|
+
}
|
|
3297
|
+
/**
|
|
3298
|
+
* Get RPC URL for a chain
|
|
3299
|
+
*/
|
|
3300
|
+
getRpcUrl(chain) {
|
|
3301
|
+
const networkUrls = DEFAULT_RPC_URLS2[this.config.network];
|
|
3302
|
+
if (this.config.rpcUrls?.[chain]) {
|
|
3303
|
+
return this.config.rpcUrls[chain];
|
|
3304
|
+
}
|
|
3305
|
+
return networkUrls[chain] || "";
|
|
3306
|
+
}
|
|
3307
|
+
/**
|
|
3308
|
+
* Get explorer URL for a transaction
|
|
3309
|
+
*/
|
|
3310
|
+
getExplorerUrl(chain, txHash) {
|
|
3311
|
+
const explorers = EXPLORER_URLS[this.config.network];
|
|
3312
|
+
const baseUrl = explorers[chain] || "";
|
|
3313
|
+
return `${baseUrl}${txHash}`;
|
|
3314
|
+
}
|
|
3315
|
+
/**
|
|
3316
|
+
* Initialize the service with a seed phrase
|
|
3317
|
+
*/
|
|
3318
|
+
async initialize(seed) {
|
|
3319
|
+
await this.ensureLoaded();
|
|
3320
|
+
if (!WdkManager2.isValidSeed(seed)) {
|
|
3321
|
+
throw new Error("Invalid seed phrase");
|
|
3322
|
+
}
|
|
3323
|
+
this.seed = seed;
|
|
3324
|
+
this.wallets = {};
|
|
3325
|
+
}
|
|
3326
|
+
/**
|
|
3327
|
+
* Check if service is initialized
|
|
3328
|
+
*/
|
|
3329
|
+
isInitialized() {
|
|
3330
|
+
return this.seed !== null;
|
|
3331
|
+
}
|
|
3332
|
+
/**
|
|
3333
|
+
* Get or create wallet instance for a specific chain
|
|
3334
|
+
*/
|
|
3335
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3336
|
+
async getWallet(chain) {
|
|
3337
|
+
if (!this.seed) {
|
|
3338
|
+
throw new Error("TransactionService not initialized. Call initialize() first.");
|
|
3339
|
+
}
|
|
3340
|
+
if (this.wallets[chain]) {
|
|
3341
|
+
return this.wallets[chain];
|
|
3342
|
+
}
|
|
3343
|
+
const isTestnet = this.config.network === "testnet";
|
|
3344
|
+
try {
|
|
3345
|
+
switch (chain) {
|
|
3346
|
+
case "ethereum": {
|
|
3347
|
+
const rpcUrl = this.getRpcUrl("ethereum");
|
|
3348
|
+
const wallet = new WalletManagerEvm2(this.seed, { provider: rpcUrl });
|
|
3349
|
+
this.wallets[chain] = wallet;
|
|
3350
|
+
return wallet;
|
|
3351
|
+
}
|
|
3352
|
+
case "bitcoin": {
|
|
3353
|
+
const wallet = new WalletManagerBtc2(this.seed, {
|
|
3354
|
+
network: isTestnet ? "testnet" : "bitcoin"
|
|
3355
|
+
});
|
|
3356
|
+
this.wallets[chain] = wallet;
|
|
3357
|
+
return wallet;
|
|
3358
|
+
}
|
|
3359
|
+
case "solana": {
|
|
3360
|
+
const rpcUrl = this.getRpcUrl("solana");
|
|
3361
|
+
const wallet = new WalletManagerSolana2(this.seed, {
|
|
3362
|
+
rpcUrl
|
|
3363
|
+
});
|
|
3364
|
+
this.wallets[chain] = wallet;
|
|
3365
|
+
return wallet;
|
|
3366
|
+
}
|
|
3367
|
+
case "ton": {
|
|
3368
|
+
const url = this.getRpcUrl("ton");
|
|
3369
|
+
const wallet = new WalletManagerTon2(this.seed, {
|
|
3370
|
+
tonClient: { url }
|
|
3371
|
+
});
|
|
3372
|
+
this.wallets[chain] = wallet;
|
|
3373
|
+
return wallet;
|
|
3374
|
+
}
|
|
3375
|
+
case "tron": {
|
|
3376
|
+
const fullHost = this.getRpcUrl("tron");
|
|
3377
|
+
const wallet = new WalletManagerTron2(this.seed, {
|
|
3378
|
+
provider: fullHost
|
|
3379
|
+
});
|
|
3380
|
+
this.wallets[chain] = wallet;
|
|
3381
|
+
return wallet;
|
|
3382
|
+
}
|
|
3383
|
+
case "spark": {
|
|
3384
|
+
const wallet = new WalletManagerSpark2(this.seed, {
|
|
3385
|
+
network: isTestnet ? "TESTNET" : "MAINNET"
|
|
3386
|
+
});
|
|
3387
|
+
this.wallets[chain] = wallet;
|
|
3388
|
+
return wallet;
|
|
3389
|
+
}
|
|
3390
|
+
default:
|
|
3391
|
+
throw new Error(`Unsupported chain: ${chain}`);
|
|
3392
|
+
}
|
|
3393
|
+
} catch (error) {
|
|
3394
|
+
console.error(`Failed to initialize ${chain} wallet:`, error);
|
|
3395
|
+
throw error;
|
|
3396
|
+
}
|
|
3397
|
+
}
|
|
3398
|
+
/**
|
|
3399
|
+
* Estimate transaction fee
|
|
3400
|
+
*/
|
|
3401
|
+
async estimateFee(chain, params) {
|
|
3402
|
+
const wallet = await this.getWallet(chain);
|
|
3403
|
+
try {
|
|
3404
|
+
const feeRates = await wallet.getFeeRates();
|
|
3405
|
+
if (chain === "ethereum") {
|
|
3406
|
+
return {
|
|
3407
|
+
slow: {
|
|
3408
|
+
fee: `${feeRates.slow || "0"} Gwei`,
|
|
3409
|
+
estimatedTime: "~10 min"
|
|
3410
|
+
},
|
|
3411
|
+
medium: {
|
|
3412
|
+
fee: `${feeRates.medium || feeRates.standard || "0"} Gwei`,
|
|
3413
|
+
estimatedTime: "~3 min"
|
|
3414
|
+
},
|
|
3415
|
+
fast: {
|
|
3416
|
+
fee: `${feeRates.fast || feeRates.high || "0"} Gwei`,
|
|
3417
|
+
estimatedTime: "~30 sec"
|
|
3418
|
+
}
|
|
3419
|
+
};
|
|
3420
|
+
} else if (chain === "bitcoin") {
|
|
3421
|
+
return {
|
|
3422
|
+
slow: {
|
|
3423
|
+
fee: `${feeRates.slow || feeRates.low || "0"} sat/vB`,
|
|
3424
|
+
estimatedTime: "~60 min"
|
|
3425
|
+
},
|
|
3426
|
+
medium: {
|
|
3427
|
+
fee: `${feeRates.medium || feeRates.normal || "0"} sat/vB`,
|
|
3428
|
+
estimatedTime: "~30 min"
|
|
3429
|
+
},
|
|
3430
|
+
fast: {
|
|
3431
|
+
fee: `${feeRates.fast || feeRates.high || "0"} sat/vB`,
|
|
3432
|
+
estimatedTime: "~10 min"
|
|
3433
|
+
}
|
|
3434
|
+
};
|
|
3435
|
+
} else {
|
|
3436
|
+
return {
|
|
3437
|
+
slow: {
|
|
3438
|
+
fee: String(feeRates.slow || feeRates.low || "0"),
|
|
3439
|
+
estimatedTime: "~10 min"
|
|
3440
|
+
},
|
|
3441
|
+
medium: {
|
|
3442
|
+
fee: String(feeRates.medium || feeRates.standard || "0"),
|
|
3443
|
+
estimatedTime: "~3 min"
|
|
3444
|
+
},
|
|
3445
|
+
fast: {
|
|
3446
|
+
fee: String(feeRates.fast || feeRates.high || "0"),
|
|
3447
|
+
estimatedTime: "~1 min"
|
|
3448
|
+
}
|
|
3449
|
+
};
|
|
3450
|
+
}
|
|
3451
|
+
} catch (error) {
|
|
3452
|
+
console.error(`Error estimating fee for ${chain}:`, error);
|
|
3453
|
+
return {
|
|
3454
|
+
slow: { fee: "0", estimatedTime: "Unknown" },
|
|
3455
|
+
medium: { fee: "0", estimatedTime: "Unknown" },
|
|
3456
|
+
fast: { fee: "0", estimatedTime: "Unknown" }
|
|
3457
|
+
};
|
|
3458
|
+
}
|
|
3459
|
+
}
|
|
3460
|
+
/**
|
|
3461
|
+
* Send a transaction
|
|
3462
|
+
*/
|
|
3463
|
+
async send(chain, params) {
|
|
3464
|
+
const wallet = await this.getWallet(chain);
|
|
3465
|
+
const account = await wallet.getAccount(0);
|
|
3466
|
+
const timestamp = Date.now();
|
|
3467
|
+
try {
|
|
3468
|
+
let txHash;
|
|
3469
|
+
if (params.token) {
|
|
3470
|
+
txHash = await account.sendToken(params.to, params.amount, params.token, {
|
|
3471
|
+
memo: params.memo,
|
|
3472
|
+
feePriority: params.feePriority || "medium"
|
|
3473
|
+
});
|
|
3474
|
+
} else {
|
|
3475
|
+
txHash = await account.send(params.to, params.amount, {
|
|
3476
|
+
memo: params.memo,
|
|
3477
|
+
feePriority: params.feePriority || "medium",
|
|
3478
|
+
gasLimit: params.gasLimit,
|
|
3479
|
+
gasPrice: params.gasPrice
|
|
3480
|
+
});
|
|
3481
|
+
}
|
|
3482
|
+
return {
|
|
3483
|
+
hash: txHash,
|
|
3484
|
+
network: chain,
|
|
3485
|
+
status: "pending",
|
|
3486
|
+
explorerUrl: this.getExplorerUrl(chain, txHash),
|
|
3487
|
+
timestamp
|
|
3488
|
+
};
|
|
3489
|
+
} catch (error) {
|
|
3490
|
+
const errorMessage = error instanceof Error ? error.message : "Transaction failed";
|
|
3491
|
+
console.error(`Transaction failed on ${chain}:`, error);
|
|
3492
|
+
return {
|
|
3493
|
+
hash: "",
|
|
3494
|
+
network: chain,
|
|
3495
|
+
status: "failed",
|
|
3496
|
+
error: errorMessage,
|
|
3497
|
+
timestamp
|
|
3498
|
+
};
|
|
3499
|
+
}
|
|
3500
|
+
}
|
|
3501
|
+
/**
|
|
3502
|
+
* Get transaction status
|
|
3503
|
+
*/
|
|
3504
|
+
async getTransactionStatus(chain, txHash) {
|
|
3505
|
+
const wallet = await this.getWallet(chain);
|
|
3506
|
+
try {
|
|
3507
|
+
const tx = await wallet.getTransaction(txHash);
|
|
3508
|
+
return {
|
|
3509
|
+
hash: txHash,
|
|
3510
|
+
network: chain,
|
|
3511
|
+
status: tx.confirmed ? "confirmed" : "pending",
|
|
3512
|
+
blockNumber: tx.blockNumber,
|
|
3513
|
+
gasUsed: tx.gasUsed?.toString(),
|
|
3514
|
+
fee: tx.fee?.toString(),
|
|
3515
|
+
explorerUrl: this.getExplorerUrl(chain, txHash),
|
|
3516
|
+
timestamp: tx.timestamp || Date.now()
|
|
3517
|
+
};
|
|
3518
|
+
} catch (error) {
|
|
3519
|
+
console.error(`Error getting transaction status for ${txHash}:`, error);
|
|
3520
|
+
return {
|
|
3521
|
+
hash: txHash,
|
|
3522
|
+
network: chain,
|
|
3523
|
+
status: "pending",
|
|
3524
|
+
explorerUrl: this.getExplorerUrl(chain, txHash),
|
|
3525
|
+
timestamp: Date.now()
|
|
3526
|
+
};
|
|
3527
|
+
}
|
|
3528
|
+
}
|
|
3529
|
+
/**
|
|
3530
|
+
* Get transaction history for an address
|
|
3531
|
+
*/
|
|
3532
|
+
async getTransactionHistory(chain, limit = 10) {
|
|
3533
|
+
const wallet = await this.getWallet(chain);
|
|
3534
|
+
const account = await wallet.getAccount(0);
|
|
3535
|
+
try {
|
|
3536
|
+
const history = await account.getTransactions({ limit });
|
|
3537
|
+
return history.map((tx) => ({
|
|
3538
|
+
hash: tx.hash || tx.txHash,
|
|
3539
|
+
network: chain,
|
|
3540
|
+
type: tx.type || (tx.from === account.address ? "send" : "receive"),
|
|
3541
|
+
from: tx.from,
|
|
3542
|
+
to: tx.to,
|
|
3543
|
+
amount: tx.amount || tx.value,
|
|
3544
|
+
token: tx.token,
|
|
3545
|
+
fee: tx.fee?.toString(),
|
|
3546
|
+
status: tx.confirmed ? "confirmed" : "pending",
|
|
3547
|
+
timestamp: tx.timestamp || Date.now(),
|
|
3548
|
+
blockNumber: tx.blockNumber
|
|
3549
|
+
}));
|
|
3550
|
+
} catch (error) {
|
|
3551
|
+
console.error(`Error getting transaction history for ${chain}:`, error);
|
|
3552
|
+
return [];
|
|
3553
|
+
}
|
|
3554
|
+
}
|
|
3555
|
+
/**
|
|
3556
|
+
* Get balance for a specific chain
|
|
3557
|
+
*/
|
|
3558
|
+
async getBalance(chain) {
|
|
3559
|
+
const wallet = await this.getWallet(chain);
|
|
3560
|
+
const account = await wallet.getAccount(0);
|
|
3561
|
+
try {
|
|
3562
|
+
const balance = await account.getBalance();
|
|
3563
|
+
return {
|
|
3564
|
+
balance: balance.toString(),
|
|
3565
|
+
balanceUsd: 0
|
|
3566
|
+
// TODO: Implement price fetching
|
|
3567
|
+
};
|
|
3568
|
+
} catch (error) {
|
|
3569
|
+
console.error(`Error getting balance for ${chain}:`, error);
|
|
3570
|
+
return { balance: "0", balanceUsd: 0 };
|
|
3571
|
+
}
|
|
3572
|
+
}
|
|
3573
|
+
/**
|
|
3574
|
+
* Get the current network configuration
|
|
3575
|
+
*/
|
|
3576
|
+
getNetwork() {
|
|
3577
|
+
return this.config.network;
|
|
3578
|
+
}
|
|
3579
|
+
/**
|
|
3580
|
+
* Clean up and dispose of wallet instances
|
|
3581
|
+
*/
|
|
3582
|
+
dispose() {
|
|
3583
|
+
for (const wallet of Object.values(this.wallets)) {
|
|
3584
|
+
if (wallet && typeof wallet.dispose === "function") {
|
|
3585
|
+
try {
|
|
3586
|
+
wallet.dispose();
|
|
3587
|
+
} catch {
|
|
3588
|
+
}
|
|
3589
|
+
}
|
|
3590
|
+
}
|
|
3591
|
+
this.wallets = {};
|
|
3592
|
+
this.seed = null;
|
|
3593
|
+
}
|
|
3594
|
+
};
|
|
3595
|
+
var transactionServiceInstance = null;
|
|
3596
|
+
function getTransactionService(config) {
|
|
3597
|
+
if (!transactionServiceInstance || config && config.network !== transactionServiceInstance.getNetwork()) {
|
|
3598
|
+
transactionServiceInstance = new TransactionService(config);
|
|
3599
|
+
}
|
|
3600
|
+
return transactionServiceInstance;
|
|
3601
|
+
}
|
|
3602
|
+
function createTransactionService(config) {
|
|
3603
|
+
return new TransactionService(config);
|
|
3604
|
+
}
|
|
3605
|
+
|
|
3606
|
+
exports.BrowserAddressDerivation = BrowserAddressDerivation_exports;
|
|
547
3607
|
exports.SwapService = SwapService;
|
|
3608
|
+
exports.TransactionService = TransactionService;
|
|
548
3609
|
exports.WdkApiClient = WdkApiClient;
|
|
549
3610
|
exports.WdkService = WdkService;
|
|
3611
|
+
exports.createTransactionService = createTransactionService;
|
|
550
3612
|
exports.createWdkService = createWdkService;
|
|
3613
|
+
exports.getTransactionService = getTransactionService;
|
|
551
3614
|
exports.getWdkApiClient = getWdkApiClient;
|
|
552
3615
|
exports.getWdkService = getWdkService;
|
|
553
3616
|
//# sourceMappingURL=index.js.map
|