@zubari/sdk 0.1.5 → 0.1.6
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/{WalletManager-CYJNiww6.d.ts → WalletManager-YnFArqAt.d.ts} +22 -17
- package/dist/{WalletManager-Dmmcbtiw.d.mts → WalletManager-zKc_xew_.d.mts} +22 -17
- package/dist/{index-OxzgPoRG.d.ts → index-CLssrNf2.d.ts} +1 -1
- package/dist/{index-poGbMJzn.d.mts → index-DXTHGOnP.d.mts} +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +497 -2843
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +493 -2846
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +2 -2
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +411 -2785
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +412 -2786
- package/dist/react/index.mjs.map +1 -1
- package/dist/services/index.d.mts +288 -54
- package/dist/services/index.d.ts +288 -54
- package/dist/services/index.js +330 -2680
- package/dist/services/index.js.map +1 -1
- package/dist/services/index.mjs +327 -2678
- package/dist/services/index.mjs.map +1 -1
- package/dist/wallet/index.d.mts +2 -2
- package/dist/wallet/index.d.ts +2 -2
- package/dist/wallet/index.js +410 -2786
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +411 -2787
- package/dist/wallet/index.mjs.map +1 -1
- package/package.json +9 -5
- package/dist/TransactionService-CxwB1kpN.d.mts +0 -205
- package/dist/TransactionService-DdL6H6M-.d.ts +0 -205
package/dist/index.js
CHANGED
|
@@ -4,2410 +4,18 @@ var ethers = require('ethers');
|
|
|
4
4
|
var viem = require('viem');
|
|
5
5
|
var chains = require('viem/chains');
|
|
6
6
|
var bip39 = require('@scure/bip39');
|
|
7
|
-
require('@scure/bip39/wordlists/english');
|
|
7
|
+
var english = require('@scure/bip39/wordlists/english');
|
|
8
8
|
var bip32 = require('@scure/bip32');
|
|
9
9
|
var base = require('@scure/base');
|
|
10
10
|
var sha256 = require('@noble/hashes/sha256');
|
|
11
11
|
var ripemd160 = require('@noble/hashes/ripemd160');
|
|
12
12
|
var react = require('react');
|
|
13
13
|
|
|
14
|
-
var __create = Object.create;
|
|
15
14
|
var __defProp = Object.defineProperty;
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
20
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
21
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
22
|
-
}) : x)(function(x) {
|
|
23
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
24
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
25
|
-
});
|
|
26
|
-
var __commonJS = (cb, mod) => function __require2() {
|
|
27
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
28
|
-
};
|
|
29
|
-
var __copyProps = (to, from, except, desc) => {
|
|
30
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
31
|
-
for (let key of __getOwnPropNames(from))
|
|
32
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
33
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
34
|
-
}
|
|
35
|
-
return to;
|
|
15
|
+
var __export = (target, all) => {
|
|
16
|
+
for (var name in all)
|
|
17
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
36
18
|
};
|
|
37
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
38
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
39
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
40
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
41
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
42
|
-
!mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
43
|
-
mod
|
|
44
|
-
));
|
|
45
|
-
|
|
46
|
-
// ../../node_modules/tweetnacl/nacl-fast.js
|
|
47
|
-
var require_nacl_fast = __commonJS({
|
|
48
|
-
"../../node_modules/tweetnacl/nacl-fast.js"(exports$1, module) {
|
|
49
|
-
(function(nacl) {
|
|
50
|
-
var gf = function(init) {
|
|
51
|
-
var i, r = new Float64Array(16);
|
|
52
|
-
if (init) for (i = 0; i < init.length; i++) r[i] = init[i];
|
|
53
|
-
return r;
|
|
54
|
-
};
|
|
55
|
-
var randombytes = function() {
|
|
56
|
-
throw new Error("no PRNG");
|
|
57
|
-
};
|
|
58
|
-
var _0 = new Uint8Array(16);
|
|
59
|
-
var _9 = new Uint8Array(32);
|
|
60
|
-
_9[0] = 9;
|
|
61
|
-
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]);
|
|
62
|
-
function ts64(x, i, h, l) {
|
|
63
|
-
x[i] = h >> 24 & 255;
|
|
64
|
-
x[i + 1] = h >> 16 & 255;
|
|
65
|
-
x[i + 2] = h >> 8 & 255;
|
|
66
|
-
x[i + 3] = h & 255;
|
|
67
|
-
x[i + 4] = l >> 24 & 255;
|
|
68
|
-
x[i + 5] = l >> 16 & 255;
|
|
69
|
-
x[i + 6] = l >> 8 & 255;
|
|
70
|
-
x[i + 7] = l & 255;
|
|
71
|
-
}
|
|
72
|
-
function vn(x, xi, y, yi, n) {
|
|
73
|
-
var i, d = 0;
|
|
74
|
-
for (i = 0; i < n; i++) d |= x[xi + i] ^ y[yi + i];
|
|
75
|
-
return (1 & d - 1 >>> 8) - 1;
|
|
76
|
-
}
|
|
77
|
-
function crypto_verify_16(x, xi, y, yi) {
|
|
78
|
-
return vn(x, xi, y, yi, 16);
|
|
79
|
-
}
|
|
80
|
-
function crypto_verify_32(x, xi, y, yi) {
|
|
81
|
-
return vn(x, xi, y, yi, 32);
|
|
82
|
-
}
|
|
83
|
-
function core_salsa20(o, p, k, c) {
|
|
84
|
-
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;
|
|
85
|
-
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;
|
|
86
|
-
for (var i = 0; i < 20; i += 2) {
|
|
87
|
-
u = x0 + x12 | 0;
|
|
88
|
-
x4 ^= u << 7 | u >>> 32 - 7;
|
|
89
|
-
u = x4 + x0 | 0;
|
|
90
|
-
x8 ^= u << 9 | u >>> 32 - 9;
|
|
91
|
-
u = x8 + x4 | 0;
|
|
92
|
-
x12 ^= u << 13 | u >>> 32 - 13;
|
|
93
|
-
u = x12 + x8 | 0;
|
|
94
|
-
x0 ^= u << 18 | u >>> 32 - 18;
|
|
95
|
-
u = x5 + x1 | 0;
|
|
96
|
-
x9 ^= u << 7 | u >>> 32 - 7;
|
|
97
|
-
u = x9 + x5 | 0;
|
|
98
|
-
x13 ^= u << 9 | u >>> 32 - 9;
|
|
99
|
-
u = x13 + x9 | 0;
|
|
100
|
-
x1 ^= u << 13 | u >>> 32 - 13;
|
|
101
|
-
u = x1 + x13 | 0;
|
|
102
|
-
x5 ^= u << 18 | u >>> 32 - 18;
|
|
103
|
-
u = x10 + x6 | 0;
|
|
104
|
-
x14 ^= u << 7 | u >>> 32 - 7;
|
|
105
|
-
u = x14 + x10 | 0;
|
|
106
|
-
x2 ^= u << 9 | u >>> 32 - 9;
|
|
107
|
-
u = x2 + x14 | 0;
|
|
108
|
-
x6 ^= u << 13 | u >>> 32 - 13;
|
|
109
|
-
u = x6 + x2 | 0;
|
|
110
|
-
x10 ^= u << 18 | u >>> 32 - 18;
|
|
111
|
-
u = x15 + x11 | 0;
|
|
112
|
-
x3 ^= u << 7 | u >>> 32 - 7;
|
|
113
|
-
u = x3 + x15 | 0;
|
|
114
|
-
x7 ^= u << 9 | u >>> 32 - 9;
|
|
115
|
-
u = x7 + x3 | 0;
|
|
116
|
-
x11 ^= u << 13 | u >>> 32 - 13;
|
|
117
|
-
u = x11 + x7 | 0;
|
|
118
|
-
x15 ^= u << 18 | u >>> 32 - 18;
|
|
119
|
-
u = x0 + x3 | 0;
|
|
120
|
-
x1 ^= u << 7 | u >>> 32 - 7;
|
|
121
|
-
u = x1 + x0 | 0;
|
|
122
|
-
x2 ^= u << 9 | u >>> 32 - 9;
|
|
123
|
-
u = x2 + x1 | 0;
|
|
124
|
-
x3 ^= u << 13 | u >>> 32 - 13;
|
|
125
|
-
u = x3 + x2 | 0;
|
|
126
|
-
x0 ^= u << 18 | u >>> 32 - 18;
|
|
127
|
-
u = x5 + x4 | 0;
|
|
128
|
-
x6 ^= u << 7 | u >>> 32 - 7;
|
|
129
|
-
u = x6 + x5 | 0;
|
|
130
|
-
x7 ^= u << 9 | u >>> 32 - 9;
|
|
131
|
-
u = x7 + x6 | 0;
|
|
132
|
-
x4 ^= u << 13 | u >>> 32 - 13;
|
|
133
|
-
u = x4 + x7 | 0;
|
|
134
|
-
x5 ^= u << 18 | u >>> 32 - 18;
|
|
135
|
-
u = x10 + x9 | 0;
|
|
136
|
-
x11 ^= u << 7 | u >>> 32 - 7;
|
|
137
|
-
u = x11 + x10 | 0;
|
|
138
|
-
x8 ^= u << 9 | u >>> 32 - 9;
|
|
139
|
-
u = x8 + x11 | 0;
|
|
140
|
-
x9 ^= u << 13 | u >>> 32 - 13;
|
|
141
|
-
u = x9 + x8 | 0;
|
|
142
|
-
x10 ^= u << 18 | u >>> 32 - 18;
|
|
143
|
-
u = x15 + x14 | 0;
|
|
144
|
-
x12 ^= u << 7 | u >>> 32 - 7;
|
|
145
|
-
u = x12 + x15 | 0;
|
|
146
|
-
x13 ^= u << 9 | u >>> 32 - 9;
|
|
147
|
-
u = x13 + x12 | 0;
|
|
148
|
-
x14 ^= u << 13 | u >>> 32 - 13;
|
|
149
|
-
u = x14 + x13 | 0;
|
|
150
|
-
x15 ^= u << 18 | u >>> 32 - 18;
|
|
151
|
-
}
|
|
152
|
-
x0 = x0 + j0 | 0;
|
|
153
|
-
x1 = x1 + j1 | 0;
|
|
154
|
-
x2 = x2 + j2 | 0;
|
|
155
|
-
x3 = x3 + j3 | 0;
|
|
156
|
-
x4 = x4 + j4 | 0;
|
|
157
|
-
x5 = x5 + j5 | 0;
|
|
158
|
-
x6 = x6 + j6 | 0;
|
|
159
|
-
x7 = x7 + j7 | 0;
|
|
160
|
-
x8 = x8 + j8 | 0;
|
|
161
|
-
x9 = x9 + j9 | 0;
|
|
162
|
-
x10 = x10 + j10 | 0;
|
|
163
|
-
x11 = x11 + j11 | 0;
|
|
164
|
-
x12 = x12 + j12 | 0;
|
|
165
|
-
x13 = x13 + j13 | 0;
|
|
166
|
-
x14 = x14 + j14 | 0;
|
|
167
|
-
x15 = x15 + j15 | 0;
|
|
168
|
-
o[0] = x0 >>> 0 & 255;
|
|
169
|
-
o[1] = x0 >>> 8 & 255;
|
|
170
|
-
o[2] = x0 >>> 16 & 255;
|
|
171
|
-
o[3] = x0 >>> 24 & 255;
|
|
172
|
-
o[4] = x1 >>> 0 & 255;
|
|
173
|
-
o[5] = x1 >>> 8 & 255;
|
|
174
|
-
o[6] = x1 >>> 16 & 255;
|
|
175
|
-
o[7] = x1 >>> 24 & 255;
|
|
176
|
-
o[8] = x2 >>> 0 & 255;
|
|
177
|
-
o[9] = x2 >>> 8 & 255;
|
|
178
|
-
o[10] = x2 >>> 16 & 255;
|
|
179
|
-
o[11] = x2 >>> 24 & 255;
|
|
180
|
-
o[12] = x3 >>> 0 & 255;
|
|
181
|
-
o[13] = x3 >>> 8 & 255;
|
|
182
|
-
o[14] = x3 >>> 16 & 255;
|
|
183
|
-
o[15] = x3 >>> 24 & 255;
|
|
184
|
-
o[16] = x4 >>> 0 & 255;
|
|
185
|
-
o[17] = x4 >>> 8 & 255;
|
|
186
|
-
o[18] = x4 >>> 16 & 255;
|
|
187
|
-
o[19] = x4 >>> 24 & 255;
|
|
188
|
-
o[20] = x5 >>> 0 & 255;
|
|
189
|
-
o[21] = x5 >>> 8 & 255;
|
|
190
|
-
o[22] = x5 >>> 16 & 255;
|
|
191
|
-
o[23] = x5 >>> 24 & 255;
|
|
192
|
-
o[24] = x6 >>> 0 & 255;
|
|
193
|
-
o[25] = x6 >>> 8 & 255;
|
|
194
|
-
o[26] = x6 >>> 16 & 255;
|
|
195
|
-
o[27] = x6 >>> 24 & 255;
|
|
196
|
-
o[28] = x7 >>> 0 & 255;
|
|
197
|
-
o[29] = x7 >>> 8 & 255;
|
|
198
|
-
o[30] = x7 >>> 16 & 255;
|
|
199
|
-
o[31] = x7 >>> 24 & 255;
|
|
200
|
-
o[32] = x8 >>> 0 & 255;
|
|
201
|
-
o[33] = x8 >>> 8 & 255;
|
|
202
|
-
o[34] = x8 >>> 16 & 255;
|
|
203
|
-
o[35] = x8 >>> 24 & 255;
|
|
204
|
-
o[36] = x9 >>> 0 & 255;
|
|
205
|
-
o[37] = x9 >>> 8 & 255;
|
|
206
|
-
o[38] = x9 >>> 16 & 255;
|
|
207
|
-
o[39] = x9 >>> 24 & 255;
|
|
208
|
-
o[40] = x10 >>> 0 & 255;
|
|
209
|
-
o[41] = x10 >>> 8 & 255;
|
|
210
|
-
o[42] = x10 >>> 16 & 255;
|
|
211
|
-
o[43] = x10 >>> 24 & 255;
|
|
212
|
-
o[44] = x11 >>> 0 & 255;
|
|
213
|
-
o[45] = x11 >>> 8 & 255;
|
|
214
|
-
o[46] = x11 >>> 16 & 255;
|
|
215
|
-
o[47] = x11 >>> 24 & 255;
|
|
216
|
-
o[48] = x12 >>> 0 & 255;
|
|
217
|
-
o[49] = x12 >>> 8 & 255;
|
|
218
|
-
o[50] = x12 >>> 16 & 255;
|
|
219
|
-
o[51] = x12 >>> 24 & 255;
|
|
220
|
-
o[52] = x13 >>> 0 & 255;
|
|
221
|
-
o[53] = x13 >>> 8 & 255;
|
|
222
|
-
o[54] = x13 >>> 16 & 255;
|
|
223
|
-
o[55] = x13 >>> 24 & 255;
|
|
224
|
-
o[56] = x14 >>> 0 & 255;
|
|
225
|
-
o[57] = x14 >>> 8 & 255;
|
|
226
|
-
o[58] = x14 >>> 16 & 255;
|
|
227
|
-
o[59] = x14 >>> 24 & 255;
|
|
228
|
-
o[60] = x15 >>> 0 & 255;
|
|
229
|
-
o[61] = x15 >>> 8 & 255;
|
|
230
|
-
o[62] = x15 >>> 16 & 255;
|
|
231
|
-
o[63] = x15 >>> 24 & 255;
|
|
232
|
-
}
|
|
233
|
-
function core_hsalsa20(o, p, k, c) {
|
|
234
|
-
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;
|
|
235
|
-
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;
|
|
236
|
-
for (var i = 0; i < 20; i += 2) {
|
|
237
|
-
u = x0 + x12 | 0;
|
|
238
|
-
x4 ^= u << 7 | u >>> 32 - 7;
|
|
239
|
-
u = x4 + x0 | 0;
|
|
240
|
-
x8 ^= u << 9 | u >>> 32 - 9;
|
|
241
|
-
u = x8 + x4 | 0;
|
|
242
|
-
x12 ^= u << 13 | u >>> 32 - 13;
|
|
243
|
-
u = x12 + x8 | 0;
|
|
244
|
-
x0 ^= u << 18 | u >>> 32 - 18;
|
|
245
|
-
u = x5 + x1 | 0;
|
|
246
|
-
x9 ^= u << 7 | u >>> 32 - 7;
|
|
247
|
-
u = x9 + x5 | 0;
|
|
248
|
-
x13 ^= u << 9 | u >>> 32 - 9;
|
|
249
|
-
u = x13 + x9 | 0;
|
|
250
|
-
x1 ^= u << 13 | u >>> 32 - 13;
|
|
251
|
-
u = x1 + x13 | 0;
|
|
252
|
-
x5 ^= u << 18 | u >>> 32 - 18;
|
|
253
|
-
u = x10 + x6 | 0;
|
|
254
|
-
x14 ^= u << 7 | u >>> 32 - 7;
|
|
255
|
-
u = x14 + x10 | 0;
|
|
256
|
-
x2 ^= u << 9 | u >>> 32 - 9;
|
|
257
|
-
u = x2 + x14 | 0;
|
|
258
|
-
x6 ^= u << 13 | u >>> 32 - 13;
|
|
259
|
-
u = x6 + x2 | 0;
|
|
260
|
-
x10 ^= u << 18 | u >>> 32 - 18;
|
|
261
|
-
u = x15 + x11 | 0;
|
|
262
|
-
x3 ^= u << 7 | u >>> 32 - 7;
|
|
263
|
-
u = x3 + x15 | 0;
|
|
264
|
-
x7 ^= u << 9 | u >>> 32 - 9;
|
|
265
|
-
u = x7 + x3 | 0;
|
|
266
|
-
x11 ^= u << 13 | u >>> 32 - 13;
|
|
267
|
-
u = x11 + x7 | 0;
|
|
268
|
-
x15 ^= u << 18 | u >>> 32 - 18;
|
|
269
|
-
u = x0 + x3 | 0;
|
|
270
|
-
x1 ^= u << 7 | u >>> 32 - 7;
|
|
271
|
-
u = x1 + x0 | 0;
|
|
272
|
-
x2 ^= u << 9 | u >>> 32 - 9;
|
|
273
|
-
u = x2 + x1 | 0;
|
|
274
|
-
x3 ^= u << 13 | u >>> 32 - 13;
|
|
275
|
-
u = x3 + x2 | 0;
|
|
276
|
-
x0 ^= u << 18 | u >>> 32 - 18;
|
|
277
|
-
u = x5 + x4 | 0;
|
|
278
|
-
x6 ^= u << 7 | u >>> 32 - 7;
|
|
279
|
-
u = x6 + x5 | 0;
|
|
280
|
-
x7 ^= u << 9 | u >>> 32 - 9;
|
|
281
|
-
u = x7 + x6 | 0;
|
|
282
|
-
x4 ^= u << 13 | u >>> 32 - 13;
|
|
283
|
-
u = x4 + x7 | 0;
|
|
284
|
-
x5 ^= u << 18 | u >>> 32 - 18;
|
|
285
|
-
u = x10 + x9 | 0;
|
|
286
|
-
x11 ^= u << 7 | u >>> 32 - 7;
|
|
287
|
-
u = x11 + x10 | 0;
|
|
288
|
-
x8 ^= u << 9 | u >>> 32 - 9;
|
|
289
|
-
u = x8 + x11 | 0;
|
|
290
|
-
x9 ^= u << 13 | u >>> 32 - 13;
|
|
291
|
-
u = x9 + x8 | 0;
|
|
292
|
-
x10 ^= u << 18 | u >>> 32 - 18;
|
|
293
|
-
u = x15 + x14 | 0;
|
|
294
|
-
x12 ^= u << 7 | u >>> 32 - 7;
|
|
295
|
-
u = x12 + x15 | 0;
|
|
296
|
-
x13 ^= u << 9 | u >>> 32 - 9;
|
|
297
|
-
u = x13 + x12 | 0;
|
|
298
|
-
x14 ^= u << 13 | u >>> 32 - 13;
|
|
299
|
-
u = x14 + x13 | 0;
|
|
300
|
-
x15 ^= u << 18 | u >>> 32 - 18;
|
|
301
|
-
}
|
|
302
|
-
o[0] = x0 >>> 0 & 255;
|
|
303
|
-
o[1] = x0 >>> 8 & 255;
|
|
304
|
-
o[2] = x0 >>> 16 & 255;
|
|
305
|
-
o[3] = x0 >>> 24 & 255;
|
|
306
|
-
o[4] = x5 >>> 0 & 255;
|
|
307
|
-
o[5] = x5 >>> 8 & 255;
|
|
308
|
-
o[6] = x5 >>> 16 & 255;
|
|
309
|
-
o[7] = x5 >>> 24 & 255;
|
|
310
|
-
o[8] = x10 >>> 0 & 255;
|
|
311
|
-
o[9] = x10 >>> 8 & 255;
|
|
312
|
-
o[10] = x10 >>> 16 & 255;
|
|
313
|
-
o[11] = x10 >>> 24 & 255;
|
|
314
|
-
o[12] = x15 >>> 0 & 255;
|
|
315
|
-
o[13] = x15 >>> 8 & 255;
|
|
316
|
-
o[14] = x15 >>> 16 & 255;
|
|
317
|
-
o[15] = x15 >>> 24 & 255;
|
|
318
|
-
o[16] = x6 >>> 0 & 255;
|
|
319
|
-
o[17] = x6 >>> 8 & 255;
|
|
320
|
-
o[18] = x6 >>> 16 & 255;
|
|
321
|
-
o[19] = x6 >>> 24 & 255;
|
|
322
|
-
o[20] = x7 >>> 0 & 255;
|
|
323
|
-
o[21] = x7 >>> 8 & 255;
|
|
324
|
-
o[22] = x7 >>> 16 & 255;
|
|
325
|
-
o[23] = x7 >>> 24 & 255;
|
|
326
|
-
o[24] = x8 >>> 0 & 255;
|
|
327
|
-
o[25] = x8 >>> 8 & 255;
|
|
328
|
-
o[26] = x8 >>> 16 & 255;
|
|
329
|
-
o[27] = x8 >>> 24 & 255;
|
|
330
|
-
o[28] = x9 >>> 0 & 255;
|
|
331
|
-
o[29] = x9 >>> 8 & 255;
|
|
332
|
-
o[30] = x9 >>> 16 & 255;
|
|
333
|
-
o[31] = x9 >>> 24 & 255;
|
|
334
|
-
}
|
|
335
|
-
function crypto_core_salsa20(out, inp, k, c) {
|
|
336
|
-
core_salsa20(out, inp, k, c);
|
|
337
|
-
}
|
|
338
|
-
function crypto_core_hsalsa20(out, inp, k, c) {
|
|
339
|
-
core_hsalsa20(out, inp, k, c);
|
|
340
|
-
}
|
|
341
|
-
var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]);
|
|
342
|
-
function crypto_stream_salsa20_xor(c, cpos, m, mpos, b, n, k) {
|
|
343
|
-
var z = new Uint8Array(16), x = new Uint8Array(64);
|
|
344
|
-
var u, i;
|
|
345
|
-
for (i = 0; i < 16; i++) z[i] = 0;
|
|
346
|
-
for (i = 0; i < 8; i++) z[i] = n[i];
|
|
347
|
-
while (b >= 64) {
|
|
348
|
-
crypto_core_salsa20(x, z, k, sigma);
|
|
349
|
-
for (i = 0; i < 64; i++) c[cpos + i] = m[mpos + i] ^ x[i];
|
|
350
|
-
u = 1;
|
|
351
|
-
for (i = 8; i < 16; i++) {
|
|
352
|
-
u = u + (z[i] & 255) | 0;
|
|
353
|
-
z[i] = u & 255;
|
|
354
|
-
u >>>= 8;
|
|
355
|
-
}
|
|
356
|
-
b -= 64;
|
|
357
|
-
cpos += 64;
|
|
358
|
-
mpos += 64;
|
|
359
|
-
}
|
|
360
|
-
if (b > 0) {
|
|
361
|
-
crypto_core_salsa20(x, z, k, sigma);
|
|
362
|
-
for (i = 0; i < b; i++) c[cpos + i] = m[mpos + i] ^ x[i];
|
|
363
|
-
}
|
|
364
|
-
return 0;
|
|
365
|
-
}
|
|
366
|
-
function crypto_stream_salsa20(c, cpos, b, n, k) {
|
|
367
|
-
var z = new Uint8Array(16), x = new Uint8Array(64);
|
|
368
|
-
var u, i;
|
|
369
|
-
for (i = 0; i < 16; i++) z[i] = 0;
|
|
370
|
-
for (i = 0; i < 8; i++) z[i] = n[i];
|
|
371
|
-
while (b >= 64) {
|
|
372
|
-
crypto_core_salsa20(x, z, k, sigma);
|
|
373
|
-
for (i = 0; i < 64; i++) c[cpos + i] = x[i];
|
|
374
|
-
u = 1;
|
|
375
|
-
for (i = 8; i < 16; i++) {
|
|
376
|
-
u = u + (z[i] & 255) | 0;
|
|
377
|
-
z[i] = u & 255;
|
|
378
|
-
u >>>= 8;
|
|
379
|
-
}
|
|
380
|
-
b -= 64;
|
|
381
|
-
cpos += 64;
|
|
382
|
-
}
|
|
383
|
-
if (b > 0) {
|
|
384
|
-
crypto_core_salsa20(x, z, k, sigma);
|
|
385
|
-
for (i = 0; i < b; i++) c[cpos + i] = x[i];
|
|
386
|
-
}
|
|
387
|
-
return 0;
|
|
388
|
-
}
|
|
389
|
-
function crypto_stream(c, cpos, d, n, k) {
|
|
390
|
-
var s = new Uint8Array(32);
|
|
391
|
-
crypto_core_hsalsa20(s, n, k, sigma);
|
|
392
|
-
var sn = new Uint8Array(8);
|
|
393
|
-
for (var i = 0; i < 8; i++) sn[i] = n[i + 16];
|
|
394
|
-
return crypto_stream_salsa20(c, cpos, d, sn, s);
|
|
395
|
-
}
|
|
396
|
-
function crypto_stream_xor(c, cpos, m, mpos, d, n, k) {
|
|
397
|
-
var s = new Uint8Array(32);
|
|
398
|
-
crypto_core_hsalsa20(s, n, k, sigma);
|
|
399
|
-
var sn = new Uint8Array(8);
|
|
400
|
-
for (var i = 0; i < 8; i++) sn[i] = n[i + 16];
|
|
401
|
-
return crypto_stream_salsa20_xor(c, cpos, m, mpos, d, sn, s);
|
|
402
|
-
}
|
|
403
|
-
var poly1305 = function(key) {
|
|
404
|
-
this.buffer = new Uint8Array(16);
|
|
405
|
-
this.r = new Uint16Array(10);
|
|
406
|
-
this.h = new Uint16Array(10);
|
|
407
|
-
this.pad = new Uint16Array(8);
|
|
408
|
-
this.leftover = 0;
|
|
409
|
-
this.fin = 0;
|
|
410
|
-
var t0, t1, t2, t3, t4, t5, t6, t7;
|
|
411
|
-
t0 = key[0] & 255 | (key[1] & 255) << 8;
|
|
412
|
-
this.r[0] = t0 & 8191;
|
|
413
|
-
t1 = key[2] & 255 | (key[3] & 255) << 8;
|
|
414
|
-
this.r[1] = (t0 >>> 13 | t1 << 3) & 8191;
|
|
415
|
-
t2 = key[4] & 255 | (key[5] & 255) << 8;
|
|
416
|
-
this.r[2] = (t1 >>> 10 | t2 << 6) & 7939;
|
|
417
|
-
t3 = key[6] & 255 | (key[7] & 255) << 8;
|
|
418
|
-
this.r[3] = (t2 >>> 7 | t3 << 9) & 8191;
|
|
419
|
-
t4 = key[8] & 255 | (key[9] & 255) << 8;
|
|
420
|
-
this.r[4] = (t3 >>> 4 | t4 << 12) & 255;
|
|
421
|
-
this.r[5] = t4 >>> 1 & 8190;
|
|
422
|
-
t5 = key[10] & 255 | (key[11] & 255) << 8;
|
|
423
|
-
this.r[6] = (t4 >>> 14 | t5 << 2) & 8191;
|
|
424
|
-
t6 = key[12] & 255 | (key[13] & 255) << 8;
|
|
425
|
-
this.r[7] = (t5 >>> 11 | t6 << 5) & 8065;
|
|
426
|
-
t7 = key[14] & 255 | (key[15] & 255) << 8;
|
|
427
|
-
this.r[8] = (t6 >>> 8 | t7 << 8) & 8191;
|
|
428
|
-
this.r[9] = t7 >>> 5 & 127;
|
|
429
|
-
this.pad[0] = key[16] & 255 | (key[17] & 255) << 8;
|
|
430
|
-
this.pad[1] = key[18] & 255 | (key[19] & 255) << 8;
|
|
431
|
-
this.pad[2] = key[20] & 255 | (key[21] & 255) << 8;
|
|
432
|
-
this.pad[3] = key[22] & 255 | (key[23] & 255) << 8;
|
|
433
|
-
this.pad[4] = key[24] & 255 | (key[25] & 255) << 8;
|
|
434
|
-
this.pad[5] = key[26] & 255 | (key[27] & 255) << 8;
|
|
435
|
-
this.pad[6] = key[28] & 255 | (key[29] & 255) << 8;
|
|
436
|
-
this.pad[7] = key[30] & 255 | (key[31] & 255) << 8;
|
|
437
|
-
};
|
|
438
|
-
poly1305.prototype.blocks = function(m, mpos, bytes) {
|
|
439
|
-
var hibit = this.fin ? 0 : 1 << 11;
|
|
440
|
-
var t0, t1, t2, t3, t4, t5, t6, t7, c;
|
|
441
|
-
var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9;
|
|
442
|
-
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];
|
|
443
|
-
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];
|
|
444
|
-
while (bytes >= 16) {
|
|
445
|
-
t0 = m[mpos + 0] & 255 | (m[mpos + 1] & 255) << 8;
|
|
446
|
-
h0 += t0 & 8191;
|
|
447
|
-
t1 = m[mpos + 2] & 255 | (m[mpos + 3] & 255) << 8;
|
|
448
|
-
h1 += (t0 >>> 13 | t1 << 3) & 8191;
|
|
449
|
-
t2 = m[mpos + 4] & 255 | (m[mpos + 5] & 255) << 8;
|
|
450
|
-
h2 += (t1 >>> 10 | t2 << 6) & 8191;
|
|
451
|
-
t3 = m[mpos + 6] & 255 | (m[mpos + 7] & 255) << 8;
|
|
452
|
-
h3 += (t2 >>> 7 | t3 << 9) & 8191;
|
|
453
|
-
t4 = m[mpos + 8] & 255 | (m[mpos + 9] & 255) << 8;
|
|
454
|
-
h4 += (t3 >>> 4 | t4 << 12) & 8191;
|
|
455
|
-
h5 += t4 >>> 1 & 8191;
|
|
456
|
-
t5 = m[mpos + 10] & 255 | (m[mpos + 11] & 255) << 8;
|
|
457
|
-
h6 += (t4 >>> 14 | t5 << 2) & 8191;
|
|
458
|
-
t6 = m[mpos + 12] & 255 | (m[mpos + 13] & 255) << 8;
|
|
459
|
-
h7 += (t5 >>> 11 | t6 << 5) & 8191;
|
|
460
|
-
t7 = m[mpos + 14] & 255 | (m[mpos + 15] & 255) << 8;
|
|
461
|
-
h8 += (t6 >>> 8 | t7 << 8) & 8191;
|
|
462
|
-
h9 += t7 >>> 5 | hibit;
|
|
463
|
-
c = 0;
|
|
464
|
-
d0 = c;
|
|
465
|
-
d0 += h0 * r0;
|
|
466
|
-
d0 += h1 * (5 * r9);
|
|
467
|
-
d0 += h2 * (5 * r8);
|
|
468
|
-
d0 += h3 * (5 * r7);
|
|
469
|
-
d0 += h4 * (5 * r6);
|
|
470
|
-
c = d0 >>> 13;
|
|
471
|
-
d0 &= 8191;
|
|
472
|
-
d0 += h5 * (5 * r5);
|
|
473
|
-
d0 += h6 * (5 * r4);
|
|
474
|
-
d0 += h7 * (5 * r3);
|
|
475
|
-
d0 += h8 * (5 * r2);
|
|
476
|
-
d0 += h9 * (5 * r1);
|
|
477
|
-
c += d0 >>> 13;
|
|
478
|
-
d0 &= 8191;
|
|
479
|
-
d1 = c;
|
|
480
|
-
d1 += h0 * r1;
|
|
481
|
-
d1 += h1 * r0;
|
|
482
|
-
d1 += h2 * (5 * r9);
|
|
483
|
-
d1 += h3 * (5 * r8);
|
|
484
|
-
d1 += h4 * (5 * r7);
|
|
485
|
-
c = d1 >>> 13;
|
|
486
|
-
d1 &= 8191;
|
|
487
|
-
d1 += h5 * (5 * r6);
|
|
488
|
-
d1 += h6 * (5 * r5);
|
|
489
|
-
d1 += h7 * (5 * r4);
|
|
490
|
-
d1 += h8 * (5 * r3);
|
|
491
|
-
d1 += h9 * (5 * r2);
|
|
492
|
-
c += d1 >>> 13;
|
|
493
|
-
d1 &= 8191;
|
|
494
|
-
d2 = c;
|
|
495
|
-
d2 += h0 * r2;
|
|
496
|
-
d2 += h1 * r1;
|
|
497
|
-
d2 += h2 * r0;
|
|
498
|
-
d2 += h3 * (5 * r9);
|
|
499
|
-
d2 += h4 * (5 * r8);
|
|
500
|
-
c = d2 >>> 13;
|
|
501
|
-
d2 &= 8191;
|
|
502
|
-
d2 += h5 * (5 * r7);
|
|
503
|
-
d2 += h6 * (5 * r6);
|
|
504
|
-
d2 += h7 * (5 * r5);
|
|
505
|
-
d2 += h8 * (5 * r4);
|
|
506
|
-
d2 += h9 * (5 * r3);
|
|
507
|
-
c += d2 >>> 13;
|
|
508
|
-
d2 &= 8191;
|
|
509
|
-
d3 = c;
|
|
510
|
-
d3 += h0 * r3;
|
|
511
|
-
d3 += h1 * r2;
|
|
512
|
-
d3 += h2 * r1;
|
|
513
|
-
d3 += h3 * r0;
|
|
514
|
-
d3 += h4 * (5 * r9);
|
|
515
|
-
c = d3 >>> 13;
|
|
516
|
-
d3 &= 8191;
|
|
517
|
-
d3 += h5 * (5 * r8);
|
|
518
|
-
d3 += h6 * (5 * r7);
|
|
519
|
-
d3 += h7 * (5 * r6);
|
|
520
|
-
d3 += h8 * (5 * r5);
|
|
521
|
-
d3 += h9 * (5 * r4);
|
|
522
|
-
c += d3 >>> 13;
|
|
523
|
-
d3 &= 8191;
|
|
524
|
-
d4 = c;
|
|
525
|
-
d4 += h0 * r4;
|
|
526
|
-
d4 += h1 * r3;
|
|
527
|
-
d4 += h2 * r2;
|
|
528
|
-
d4 += h3 * r1;
|
|
529
|
-
d4 += h4 * r0;
|
|
530
|
-
c = d4 >>> 13;
|
|
531
|
-
d4 &= 8191;
|
|
532
|
-
d4 += h5 * (5 * r9);
|
|
533
|
-
d4 += h6 * (5 * r8);
|
|
534
|
-
d4 += h7 * (5 * r7);
|
|
535
|
-
d4 += h8 * (5 * r6);
|
|
536
|
-
d4 += h9 * (5 * r5);
|
|
537
|
-
c += d4 >>> 13;
|
|
538
|
-
d4 &= 8191;
|
|
539
|
-
d5 = c;
|
|
540
|
-
d5 += h0 * r5;
|
|
541
|
-
d5 += h1 * r4;
|
|
542
|
-
d5 += h2 * r3;
|
|
543
|
-
d5 += h3 * r2;
|
|
544
|
-
d5 += h4 * r1;
|
|
545
|
-
c = d5 >>> 13;
|
|
546
|
-
d5 &= 8191;
|
|
547
|
-
d5 += h5 * r0;
|
|
548
|
-
d5 += h6 * (5 * r9);
|
|
549
|
-
d5 += h7 * (5 * r8);
|
|
550
|
-
d5 += h8 * (5 * r7);
|
|
551
|
-
d5 += h9 * (5 * r6);
|
|
552
|
-
c += d5 >>> 13;
|
|
553
|
-
d5 &= 8191;
|
|
554
|
-
d6 = c;
|
|
555
|
-
d6 += h0 * r6;
|
|
556
|
-
d6 += h1 * r5;
|
|
557
|
-
d6 += h2 * r4;
|
|
558
|
-
d6 += h3 * r3;
|
|
559
|
-
d6 += h4 * r2;
|
|
560
|
-
c = d6 >>> 13;
|
|
561
|
-
d6 &= 8191;
|
|
562
|
-
d6 += h5 * r1;
|
|
563
|
-
d6 += h6 * r0;
|
|
564
|
-
d6 += h7 * (5 * r9);
|
|
565
|
-
d6 += h8 * (5 * r8);
|
|
566
|
-
d6 += h9 * (5 * r7);
|
|
567
|
-
c += d6 >>> 13;
|
|
568
|
-
d6 &= 8191;
|
|
569
|
-
d7 = c;
|
|
570
|
-
d7 += h0 * r7;
|
|
571
|
-
d7 += h1 * r6;
|
|
572
|
-
d7 += h2 * r5;
|
|
573
|
-
d7 += h3 * r4;
|
|
574
|
-
d7 += h4 * r3;
|
|
575
|
-
c = d7 >>> 13;
|
|
576
|
-
d7 &= 8191;
|
|
577
|
-
d7 += h5 * r2;
|
|
578
|
-
d7 += h6 * r1;
|
|
579
|
-
d7 += h7 * r0;
|
|
580
|
-
d7 += h8 * (5 * r9);
|
|
581
|
-
d7 += h9 * (5 * r8);
|
|
582
|
-
c += d7 >>> 13;
|
|
583
|
-
d7 &= 8191;
|
|
584
|
-
d8 = c;
|
|
585
|
-
d8 += h0 * r8;
|
|
586
|
-
d8 += h1 * r7;
|
|
587
|
-
d8 += h2 * r6;
|
|
588
|
-
d8 += h3 * r5;
|
|
589
|
-
d8 += h4 * r4;
|
|
590
|
-
c = d8 >>> 13;
|
|
591
|
-
d8 &= 8191;
|
|
592
|
-
d8 += h5 * r3;
|
|
593
|
-
d8 += h6 * r2;
|
|
594
|
-
d8 += h7 * r1;
|
|
595
|
-
d8 += h8 * r0;
|
|
596
|
-
d8 += h9 * (5 * r9);
|
|
597
|
-
c += d8 >>> 13;
|
|
598
|
-
d8 &= 8191;
|
|
599
|
-
d9 = c;
|
|
600
|
-
d9 += h0 * r9;
|
|
601
|
-
d9 += h1 * r8;
|
|
602
|
-
d9 += h2 * r7;
|
|
603
|
-
d9 += h3 * r6;
|
|
604
|
-
d9 += h4 * r5;
|
|
605
|
-
c = d9 >>> 13;
|
|
606
|
-
d9 &= 8191;
|
|
607
|
-
d9 += h5 * r4;
|
|
608
|
-
d9 += h6 * r3;
|
|
609
|
-
d9 += h7 * r2;
|
|
610
|
-
d9 += h8 * r1;
|
|
611
|
-
d9 += h9 * r0;
|
|
612
|
-
c += d9 >>> 13;
|
|
613
|
-
d9 &= 8191;
|
|
614
|
-
c = (c << 2) + c | 0;
|
|
615
|
-
c = c + d0 | 0;
|
|
616
|
-
d0 = c & 8191;
|
|
617
|
-
c = c >>> 13;
|
|
618
|
-
d1 += c;
|
|
619
|
-
h0 = d0;
|
|
620
|
-
h1 = d1;
|
|
621
|
-
h2 = d2;
|
|
622
|
-
h3 = d3;
|
|
623
|
-
h4 = d4;
|
|
624
|
-
h5 = d5;
|
|
625
|
-
h6 = d6;
|
|
626
|
-
h7 = d7;
|
|
627
|
-
h8 = d8;
|
|
628
|
-
h9 = d9;
|
|
629
|
-
mpos += 16;
|
|
630
|
-
bytes -= 16;
|
|
631
|
-
}
|
|
632
|
-
this.h[0] = h0;
|
|
633
|
-
this.h[1] = h1;
|
|
634
|
-
this.h[2] = h2;
|
|
635
|
-
this.h[3] = h3;
|
|
636
|
-
this.h[4] = h4;
|
|
637
|
-
this.h[5] = h5;
|
|
638
|
-
this.h[6] = h6;
|
|
639
|
-
this.h[7] = h7;
|
|
640
|
-
this.h[8] = h8;
|
|
641
|
-
this.h[9] = h9;
|
|
642
|
-
};
|
|
643
|
-
poly1305.prototype.finish = function(mac, macpos) {
|
|
644
|
-
var g = new Uint16Array(10);
|
|
645
|
-
var c, mask, f, i;
|
|
646
|
-
if (this.leftover) {
|
|
647
|
-
i = this.leftover;
|
|
648
|
-
this.buffer[i++] = 1;
|
|
649
|
-
for (; i < 16; i++) this.buffer[i] = 0;
|
|
650
|
-
this.fin = 1;
|
|
651
|
-
this.blocks(this.buffer, 0, 16);
|
|
652
|
-
}
|
|
653
|
-
c = this.h[1] >>> 13;
|
|
654
|
-
this.h[1] &= 8191;
|
|
655
|
-
for (i = 2; i < 10; i++) {
|
|
656
|
-
this.h[i] += c;
|
|
657
|
-
c = this.h[i] >>> 13;
|
|
658
|
-
this.h[i] &= 8191;
|
|
659
|
-
}
|
|
660
|
-
this.h[0] += c * 5;
|
|
661
|
-
c = this.h[0] >>> 13;
|
|
662
|
-
this.h[0] &= 8191;
|
|
663
|
-
this.h[1] += c;
|
|
664
|
-
c = this.h[1] >>> 13;
|
|
665
|
-
this.h[1] &= 8191;
|
|
666
|
-
this.h[2] += c;
|
|
667
|
-
g[0] = this.h[0] + 5;
|
|
668
|
-
c = g[0] >>> 13;
|
|
669
|
-
g[0] &= 8191;
|
|
670
|
-
for (i = 1; i < 10; i++) {
|
|
671
|
-
g[i] = this.h[i] + c;
|
|
672
|
-
c = g[i] >>> 13;
|
|
673
|
-
g[i] &= 8191;
|
|
674
|
-
}
|
|
675
|
-
g[9] -= 1 << 13;
|
|
676
|
-
mask = (c ^ 1) - 1;
|
|
677
|
-
for (i = 0; i < 10; i++) g[i] &= mask;
|
|
678
|
-
mask = ~mask;
|
|
679
|
-
for (i = 0; i < 10; i++) this.h[i] = this.h[i] & mask | g[i];
|
|
680
|
-
this.h[0] = (this.h[0] | this.h[1] << 13) & 65535;
|
|
681
|
-
this.h[1] = (this.h[1] >>> 3 | this.h[2] << 10) & 65535;
|
|
682
|
-
this.h[2] = (this.h[2] >>> 6 | this.h[3] << 7) & 65535;
|
|
683
|
-
this.h[3] = (this.h[3] >>> 9 | this.h[4] << 4) & 65535;
|
|
684
|
-
this.h[4] = (this.h[4] >>> 12 | this.h[5] << 1 | this.h[6] << 14) & 65535;
|
|
685
|
-
this.h[5] = (this.h[6] >>> 2 | this.h[7] << 11) & 65535;
|
|
686
|
-
this.h[6] = (this.h[7] >>> 5 | this.h[8] << 8) & 65535;
|
|
687
|
-
this.h[7] = (this.h[8] >>> 8 | this.h[9] << 5) & 65535;
|
|
688
|
-
f = this.h[0] + this.pad[0];
|
|
689
|
-
this.h[0] = f & 65535;
|
|
690
|
-
for (i = 1; i < 8; i++) {
|
|
691
|
-
f = (this.h[i] + this.pad[i] | 0) + (f >>> 16) | 0;
|
|
692
|
-
this.h[i] = f & 65535;
|
|
693
|
-
}
|
|
694
|
-
mac[macpos + 0] = this.h[0] >>> 0 & 255;
|
|
695
|
-
mac[macpos + 1] = this.h[0] >>> 8 & 255;
|
|
696
|
-
mac[macpos + 2] = this.h[1] >>> 0 & 255;
|
|
697
|
-
mac[macpos + 3] = this.h[1] >>> 8 & 255;
|
|
698
|
-
mac[macpos + 4] = this.h[2] >>> 0 & 255;
|
|
699
|
-
mac[macpos + 5] = this.h[2] >>> 8 & 255;
|
|
700
|
-
mac[macpos + 6] = this.h[3] >>> 0 & 255;
|
|
701
|
-
mac[macpos + 7] = this.h[3] >>> 8 & 255;
|
|
702
|
-
mac[macpos + 8] = this.h[4] >>> 0 & 255;
|
|
703
|
-
mac[macpos + 9] = this.h[4] >>> 8 & 255;
|
|
704
|
-
mac[macpos + 10] = this.h[5] >>> 0 & 255;
|
|
705
|
-
mac[macpos + 11] = this.h[5] >>> 8 & 255;
|
|
706
|
-
mac[macpos + 12] = this.h[6] >>> 0 & 255;
|
|
707
|
-
mac[macpos + 13] = this.h[6] >>> 8 & 255;
|
|
708
|
-
mac[macpos + 14] = this.h[7] >>> 0 & 255;
|
|
709
|
-
mac[macpos + 15] = this.h[7] >>> 8 & 255;
|
|
710
|
-
};
|
|
711
|
-
poly1305.prototype.update = function(m, mpos, bytes) {
|
|
712
|
-
var i, want;
|
|
713
|
-
if (this.leftover) {
|
|
714
|
-
want = 16 - this.leftover;
|
|
715
|
-
if (want > bytes)
|
|
716
|
-
want = bytes;
|
|
717
|
-
for (i = 0; i < want; i++)
|
|
718
|
-
this.buffer[this.leftover + i] = m[mpos + i];
|
|
719
|
-
bytes -= want;
|
|
720
|
-
mpos += want;
|
|
721
|
-
this.leftover += want;
|
|
722
|
-
if (this.leftover < 16)
|
|
723
|
-
return;
|
|
724
|
-
this.blocks(this.buffer, 0, 16);
|
|
725
|
-
this.leftover = 0;
|
|
726
|
-
}
|
|
727
|
-
if (bytes >= 16) {
|
|
728
|
-
want = bytes - bytes % 16;
|
|
729
|
-
this.blocks(m, mpos, want);
|
|
730
|
-
mpos += want;
|
|
731
|
-
bytes -= want;
|
|
732
|
-
}
|
|
733
|
-
if (bytes) {
|
|
734
|
-
for (i = 0; i < bytes; i++)
|
|
735
|
-
this.buffer[this.leftover + i] = m[mpos + i];
|
|
736
|
-
this.leftover += bytes;
|
|
737
|
-
}
|
|
738
|
-
};
|
|
739
|
-
function crypto_onetimeauth(out, outpos, m, mpos, n, k) {
|
|
740
|
-
var s = new poly1305(k);
|
|
741
|
-
s.update(m, mpos, n);
|
|
742
|
-
s.finish(out, outpos);
|
|
743
|
-
return 0;
|
|
744
|
-
}
|
|
745
|
-
function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) {
|
|
746
|
-
var x = new Uint8Array(16);
|
|
747
|
-
crypto_onetimeauth(x, 0, m, mpos, n, k);
|
|
748
|
-
return crypto_verify_16(h, hpos, x, 0);
|
|
749
|
-
}
|
|
750
|
-
function crypto_secretbox(c, m, d, n, k) {
|
|
751
|
-
var i;
|
|
752
|
-
if (d < 32) return -1;
|
|
753
|
-
crypto_stream_xor(c, 0, m, 0, d, n, k);
|
|
754
|
-
crypto_onetimeauth(c, 16, c, 32, d - 32, c);
|
|
755
|
-
for (i = 0; i < 16; i++) c[i] = 0;
|
|
756
|
-
return 0;
|
|
757
|
-
}
|
|
758
|
-
function crypto_secretbox_open(m, c, d, n, k) {
|
|
759
|
-
var i;
|
|
760
|
-
var x = new Uint8Array(32);
|
|
761
|
-
if (d < 32) return -1;
|
|
762
|
-
crypto_stream(x, 0, 32, n, k);
|
|
763
|
-
if (crypto_onetimeauth_verify(c, 16, c, 32, d - 32, x) !== 0) return -1;
|
|
764
|
-
crypto_stream_xor(m, 0, c, 0, d, n, k);
|
|
765
|
-
for (i = 0; i < 32; i++) m[i] = 0;
|
|
766
|
-
return 0;
|
|
767
|
-
}
|
|
768
|
-
function set25519(r, a) {
|
|
769
|
-
var i;
|
|
770
|
-
for (i = 0; i < 16; i++) r[i] = a[i] | 0;
|
|
771
|
-
}
|
|
772
|
-
function car25519(o) {
|
|
773
|
-
var i, v, c = 1;
|
|
774
|
-
for (i = 0; i < 16; i++) {
|
|
775
|
-
v = o[i] + c + 65535;
|
|
776
|
-
c = Math.floor(v / 65536);
|
|
777
|
-
o[i] = v - c * 65536;
|
|
778
|
-
}
|
|
779
|
-
o[0] += c - 1 + 37 * (c - 1);
|
|
780
|
-
}
|
|
781
|
-
function sel25519(p, q, b) {
|
|
782
|
-
var t, c = ~(b - 1);
|
|
783
|
-
for (var i = 0; i < 16; i++) {
|
|
784
|
-
t = c & (p[i] ^ q[i]);
|
|
785
|
-
p[i] ^= t;
|
|
786
|
-
q[i] ^= t;
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
function pack25519(o, n) {
|
|
790
|
-
var i, j, b;
|
|
791
|
-
var m = gf(), t = gf();
|
|
792
|
-
for (i = 0; i < 16; i++) t[i] = n[i];
|
|
793
|
-
car25519(t);
|
|
794
|
-
car25519(t);
|
|
795
|
-
car25519(t);
|
|
796
|
-
for (j = 0; j < 2; j++) {
|
|
797
|
-
m[0] = t[0] - 65517;
|
|
798
|
-
for (i = 1; i < 15; i++) {
|
|
799
|
-
m[i] = t[i] - 65535 - (m[i - 1] >> 16 & 1);
|
|
800
|
-
m[i - 1] &= 65535;
|
|
801
|
-
}
|
|
802
|
-
m[15] = t[15] - 32767 - (m[14] >> 16 & 1);
|
|
803
|
-
b = m[15] >> 16 & 1;
|
|
804
|
-
m[14] &= 65535;
|
|
805
|
-
sel25519(t, m, 1 - b);
|
|
806
|
-
}
|
|
807
|
-
for (i = 0; i < 16; i++) {
|
|
808
|
-
o[2 * i] = t[i] & 255;
|
|
809
|
-
o[2 * i + 1] = t[i] >> 8;
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
function neq25519(a, b) {
|
|
813
|
-
var c = new Uint8Array(32), d = new Uint8Array(32);
|
|
814
|
-
pack25519(c, a);
|
|
815
|
-
pack25519(d, b);
|
|
816
|
-
return crypto_verify_32(c, 0, d, 0);
|
|
817
|
-
}
|
|
818
|
-
function par25519(a) {
|
|
819
|
-
var d = new Uint8Array(32);
|
|
820
|
-
pack25519(d, a);
|
|
821
|
-
return d[0] & 1;
|
|
822
|
-
}
|
|
823
|
-
function unpack25519(o, n) {
|
|
824
|
-
var i;
|
|
825
|
-
for (i = 0; i < 16; i++) o[i] = n[2 * i] + (n[2 * i + 1] << 8);
|
|
826
|
-
o[15] &= 32767;
|
|
827
|
-
}
|
|
828
|
-
function A(o, a, b) {
|
|
829
|
-
for (var i = 0; i < 16; i++) o[i] = a[i] + b[i];
|
|
830
|
-
}
|
|
831
|
-
function Z(o, a, b) {
|
|
832
|
-
for (var i = 0; i < 16; i++) o[i] = a[i] - b[i];
|
|
833
|
-
}
|
|
834
|
-
function M(o, a, b) {
|
|
835
|
-
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];
|
|
836
|
-
v = a[0];
|
|
837
|
-
t0 += v * b0;
|
|
838
|
-
t1 += v * b1;
|
|
839
|
-
t2 += v * b2;
|
|
840
|
-
t3 += v * b3;
|
|
841
|
-
t4 += v * b4;
|
|
842
|
-
t5 += v * b5;
|
|
843
|
-
t6 += v * b6;
|
|
844
|
-
t7 += v * b7;
|
|
845
|
-
t8 += v * b8;
|
|
846
|
-
t9 += v * b9;
|
|
847
|
-
t10 += v * b10;
|
|
848
|
-
t11 += v * b11;
|
|
849
|
-
t12 += v * b12;
|
|
850
|
-
t13 += v * b13;
|
|
851
|
-
t14 += v * b14;
|
|
852
|
-
t15 += v * b15;
|
|
853
|
-
v = a[1];
|
|
854
|
-
t1 += v * b0;
|
|
855
|
-
t2 += v * b1;
|
|
856
|
-
t3 += v * b2;
|
|
857
|
-
t4 += v * b3;
|
|
858
|
-
t5 += v * b4;
|
|
859
|
-
t6 += v * b5;
|
|
860
|
-
t7 += v * b6;
|
|
861
|
-
t8 += v * b7;
|
|
862
|
-
t9 += v * b8;
|
|
863
|
-
t10 += v * b9;
|
|
864
|
-
t11 += v * b10;
|
|
865
|
-
t12 += v * b11;
|
|
866
|
-
t13 += v * b12;
|
|
867
|
-
t14 += v * b13;
|
|
868
|
-
t15 += v * b14;
|
|
869
|
-
t16 += v * b15;
|
|
870
|
-
v = a[2];
|
|
871
|
-
t2 += v * b0;
|
|
872
|
-
t3 += v * b1;
|
|
873
|
-
t4 += v * b2;
|
|
874
|
-
t5 += v * b3;
|
|
875
|
-
t6 += v * b4;
|
|
876
|
-
t7 += v * b5;
|
|
877
|
-
t8 += v * b6;
|
|
878
|
-
t9 += v * b7;
|
|
879
|
-
t10 += v * b8;
|
|
880
|
-
t11 += v * b9;
|
|
881
|
-
t12 += v * b10;
|
|
882
|
-
t13 += v * b11;
|
|
883
|
-
t14 += v * b12;
|
|
884
|
-
t15 += v * b13;
|
|
885
|
-
t16 += v * b14;
|
|
886
|
-
t17 += v * b15;
|
|
887
|
-
v = a[3];
|
|
888
|
-
t3 += v * b0;
|
|
889
|
-
t4 += v * b1;
|
|
890
|
-
t5 += v * b2;
|
|
891
|
-
t6 += v * b3;
|
|
892
|
-
t7 += v * b4;
|
|
893
|
-
t8 += v * b5;
|
|
894
|
-
t9 += v * b6;
|
|
895
|
-
t10 += v * b7;
|
|
896
|
-
t11 += v * b8;
|
|
897
|
-
t12 += v * b9;
|
|
898
|
-
t13 += v * b10;
|
|
899
|
-
t14 += v * b11;
|
|
900
|
-
t15 += v * b12;
|
|
901
|
-
t16 += v * b13;
|
|
902
|
-
t17 += v * b14;
|
|
903
|
-
t18 += v * b15;
|
|
904
|
-
v = a[4];
|
|
905
|
-
t4 += v * b0;
|
|
906
|
-
t5 += v * b1;
|
|
907
|
-
t6 += v * b2;
|
|
908
|
-
t7 += v * b3;
|
|
909
|
-
t8 += v * b4;
|
|
910
|
-
t9 += v * b5;
|
|
911
|
-
t10 += v * b6;
|
|
912
|
-
t11 += v * b7;
|
|
913
|
-
t12 += v * b8;
|
|
914
|
-
t13 += v * b9;
|
|
915
|
-
t14 += v * b10;
|
|
916
|
-
t15 += v * b11;
|
|
917
|
-
t16 += v * b12;
|
|
918
|
-
t17 += v * b13;
|
|
919
|
-
t18 += v * b14;
|
|
920
|
-
t19 += v * b15;
|
|
921
|
-
v = a[5];
|
|
922
|
-
t5 += v * b0;
|
|
923
|
-
t6 += v * b1;
|
|
924
|
-
t7 += v * b2;
|
|
925
|
-
t8 += v * b3;
|
|
926
|
-
t9 += v * b4;
|
|
927
|
-
t10 += v * b5;
|
|
928
|
-
t11 += v * b6;
|
|
929
|
-
t12 += v * b7;
|
|
930
|
-
t13 += v * b8;
|
|
931
|
-
t14 += v * b9;
|
|
932
|
-
t15 += v * b10;
|
|
933
|
-
t16 += v * b11;
|
|
934
|
-
t17 += v * b12;
|
|
935
|
-
t18 += v * b13;
|
|
936
|
-
t19 += v * b14;
|
|
937
|
-
t20 += v * b15;
|
|
938
|
-
v = a[6];
|
|
939
|
-
t6 += v * b0;
|
|
940
|
-
t7 += v * b1;
|
|
941
|
-
t8 += v * b2;
|
|
942
|
-
t9 += v * b3;
|
|
943
|
-
t10 += v * b4;
|
|
944
|
-
t11 += v * b5;
|
|
945
|
-
t12 += v * b6;
|
|
946
|
-
t13 += v * b7;
|
|
947
|
-
t14 += v * b8;
|
|
948
|
-
t15 += v * b9;
|
|
949
|
-
t16 += v * b10;
|
|
950
|
-
t17 += v * b11;
|
|
951
|
-
t18 += v * b12;
|
|
952
|
-
t19 += v * b13;
|
|
953
|
-
t20 += v * b14;
|
|
954
|
-
t21 += v * b15;
|
|
955
|
-
v = a[7];
|
|
956
|
-
t7 += v * b0;
|
|
957
|
-
t8 += v * b1;
|
|
958
|
-
t9 += v * b2;
|
|
959
|
-
t10 += v * b3;
|
|
960
|
-
t11 += v * b4;
|
|
961
|
-
t12 += v * b5;
|
|
962
|
-
t13 += v * b6;
|
|
963
|
-
t14 += v * b7;
|
|
964
|
-
t15 += v * b8;
|
|
965
|
-
t16 += v * b9;
|
|
966
|
-
t17 += v * b10;
|
|
967
|
-
t18 += v * b11;
|
|
968
|
-
t19 += v * b12;
|
|
969
|
-
t20 += v * b13;
|
|
970
|
-
t21 += v * b14;
|
|
971
|
-
t22 += v * b15;
|
|
972
|
-
v = a[8];
|
|
973
|
-
t8 += v * b0;
|
|
974
|
-
t9 += v * b1;
|
|
975
|
-
t10 += v * b2;
|
|
976
|
-
t11 += v * b3;
|
|
977
|
-
t12 += v * b4;
|
|
978
|
-
t13 += v * b5;
|
|
979
|
-
t14 += v * b6;
|
|
980
|
-
t15 += v * b7;
|
|
981
|
-
t16 += v * b8;
|
|
982
|
-
t17 += v * b9;
|
|
983
|
-
t18 += v * b10;
|
|
984
|
-
t19 += v * b11;
|
|
985
|
-
t20 += v * b12;
|
|
986
|
-
t21 += v * b13;
|
|
987
|
-
t22 += v * b14;
|
|
988
|
-
t23 += v * b15;
|
|
989
|
-
v = a[9];
|
|
990
|
-
t9 += v * b0;
|
|
991
|
-
t10 += v * b1;
|
|
992
|
-
t11 += v * b2;
|
|
993
|
-
t12 += v * b3;
|
|
994
|
-
t13 += v * b4;
|
|
995
|
-
t14 += v * b5;
|
|
996
|
-
t15 += v * b6;
|
|
997
|
-
t16 += v * b7;
|
|
998
|
-
t17 += v * b8;
|
|
999
|
-
t18 += v * b9;
|
|
1000
|
-
t19 += v * b10;
|
|
1001
|
-
t20 += v * b11;
|
|
1002
|
-
t21 += v * b12;
|
|
1003
|
-
t22 += v * b13;
|
|
1004
|
-
t23 += v * b14;
|
|
1005
|
-
t24 += v * b15;
|
|
1006
|
-
v = a[10];
|
|
1007
|
-
t10 += v * b0;
|
|
1008
|
-
t11 += v * b1;
|
|
1009
|
-
t12 += v * b2;
|
|
1010
|
-
t13 += v * b3;
|
|
1011
|
-
t14 += v * b4;
|
|
1012
|
-
t15 += v * b5;
|
|
1013
|
-
t16 += v * b6;
|
|
1014
|
-
t17 += v * b7;
|
|
1015
|
-
t18 += v * b8;
|
|
1016
|
-
t19 += v * b9;
|
|
1017
|
-
t20 += v * b10;
|
|
1018
|
-
t21 += v * b11;
|
|
1019
|
-
t22 += v * b12;
|
|
1020
|
-
t23 += v * b13;
|
|
1021
|
-
t24 += v * b14;
|
|
1022
|
-
t25 += v * b15;
|
|
1023
|
-
v = a[11];
|
|
1024
|
-
t11 += v * b0;
|
|
1025
|
-
t12 += v * b1;
|
|
1026
|
-
t13 += v * b2;
|
|
1027
|
-
t14 += v * b3;
|
|
1028
|
-
t15 += v * b4;
|
|
1029
|
-
t16 += v * b5;
|
|
1030
|
-
t17 += v * b6;
|
|
1031
|
-
t18 += v * b7;
|
|
1032
|
-
t19 += v * b8;
|
|
1033
|
-
t20 += v * b9;
|
|
1034
|
-
t21 += v * b10;
|
|
1035
|
-
t22 += v * b11;
|
|
1036
|
-
t23 += v * b12;
|
|
1037
|
-
t24 += v * b13;
|
|
1038
|
-
t25 += v * b14;
|
|
1039
|
-
t26 += v * b15;
|
|
1040
|
-
v = a[12];
|
|
1041
|
-
t12 += v * b0;
|
|
1042
|
-
t13 += v * b1;
|
|
1043
|
-
t14 += v * b2;
|
|
1044
|
-
t15 += v * b3;
|
|
1045
|
-
t16 += v * b4;
|
|
1046
|
-
t17 += v * b5;
|
|
1047
|
-
t18 += v * b6;
|
|
1048
|
-
t19 += v * b7;
|
|
1049
|
-
t20 += v * b8;
|
|
1050
|
-
t21 += v * b9;
|
|
1051
|
-
t22 += v * b10;
|
|
1052
|
-
t23 += v * b11;
|
|
1053
|
-
t24 += v * b12;
|
|
1054
|
-
t25 += v * b13;
|
|
1055
|
-
t26 += v * b14;
|
|
1056
|
-
t27 += v * b15;
|
|
1057
|
-
v = a[13];
|
|
1058
|
-
t13 += v * b0;
|
|
1059
|
-
t14 += v * b1;
|
|
1060
|
-
t15 += v * b2;
|
|
1061
|
-
t16 += v * b3;
|
|
1062
|
-
t17 += v * b4;
|
|
1063
|
-
t18 += v * b5;
|
|
1064
|
-
t19 += v * b6;
|
|
1065
|
-
t20 += v * b7;
|
|
1066
|
-
t21 += v * b8;
|
|
1067
|
-
t22 += v * b9;
|
|
1068
|
-
t23 += v * b10;
|
|
1069
|
-
t24 += v * b11;
|
|
1070
|
-
t25 += v * b12;
|
|
1071
|
-
t26 += v * b13;
|
|
1072
|
-
t27 += v * b14;
|
|
1073
|
-
t28 += v * b15;
|
|
1074
|
-
v = a[14];
|
|
1075
|
-
t14 += v * b0;
|
|
1076
|
-
t15 += v * b1;
|
|
1077
|
-
t16 += v * b2;
|
|
1078
|
-
t17 += v * b3;
|
|
1079
|
-
t18 += v * b4;
|
|
1080
|
-
t19 += v * b5;
|
|
1081
|
-
t20 += v * b6;
|
|
1082
|
-
t21 += v * b7;
|
|
1083
|
-
t22 += v * b8;
|
|
1084
|
-
t23 += v * b9;
|
|
1085
|
-
t24 += v * b10;
|
|
1086
|
-
t25 += v * b11;
|
|
1087
|
-
t26 += v * b12;
|
|
1088
|
-
t27 += v * b13;
|
|
1089
|
-
t28 += v * b14;
|
|
1090
|
-
t29 += v * b15;
|
|
1091
|
-
v = a[15];
|
|
1092
|
-
t15 += v * b0;
|
|
1093
|
-
t16 += v * b1;
|
|
1094
|
-
t17 += v * b2;
|
|
1095
|
-
t18 += v * b3;
|
|
1096
|
-
t19 += v * b4;
|
|
1097
|
-
t20 += v * b5;
|
|
1098
|
-
t21 += v * b6;
|
|
1099
|
-
t22 += v * b7;
|
|
1100
|
-
t23 += v * b8;
|
|
1101
|
-
t24 += v * b9;
|
|
1102
|
-
t25 += v * b10;
|
|
1103
|
-
t26 += v * b11;
|
|
1104
|
-
t27 += v * b12;
|
|
1105
|
-
t28 += v * b13;
|
|
1106
|
-
t29 += v * b14;
|
|
1107
|
-
t30 += v * b15;
|
|
1108
|
-
t0 += 38 * t16;
|
|
1109
|
-
t1 += 38 * t17;
|
|
1110
|
-
t2 += 38 * t18;
|
|
1111
|
-
t3 += 38 * t19;
|
|
1112
|
-
t4 += 38 * t20;
|
|
1113
|
-
t5 += 38 * t21;
|
|
1114
|
-
t6 += 38 * t22;
|
|
1115
|
-
t7 += 38 * t23;
|
|
1116
|
-
t8 += 38 * t24;
|
|
1117
|
-
t9 += 38 * t25;
|
|
1118
|
-
t10 += 38 * t26;
|
|
1119
|
-
t11 += 38 * t27;
|
|
1120
|
-
t12 += 38 * t28;
|
|
1121
|
-
t13 += 38 * t29;
|
|
1122
|
-
t14 += 38 * t30;
|
|
1123
|
-
c = 1;
|
|
1124
|
-
v = t0 + c + 65535;
|
|
1125
|
-
c = Math.floor(v / 65536);
|
|
1126
|
-
t0 = v - c * 65536;
|
|
1127
|
-
v = t1 + c + 65535;
|
|
1128
|
-
c = Math.floor(v / 65536);
|
|
1129
|
-
t1 = v - c * 65536;
|
|
1130
|
-
v = t2 + c + 65535;
|
|
1131
|
-
c = Math.floor(v / 65536);
|
|
1132
|
-
t2 = v - c * 65536;
|
|
1133
|
-
v = t3 + c + 65535;
|
|
1134
|
-
c = Math.floor(v / 65536);
|
|
1135
|
-
t3 = v - c * 65536;
|
|
1136
|
-
v = t4 + c + 65535;
|
|
1137
|
-
c = Math.floor(v / 65536);
|
|
1138
|
-
t4 = v - c * 65536;
|
|
1139
|
-
v = t5 + c + 65535;
|
|
1140
|
-
c = Math.floor(v / 65536);
|
|
1141
|
-
t5 = v - c * 65536;
|
|
1142
|
-
v = t6 + c + 65535;
|
|
1143
|
-
c = Math.floor(v / 65536);
|
|
1144
|
-
t6 = v - c * 65536;
|
|
1145
|
-
v = t7 + c + 65535;
|
|
1146
|
-
c = Math.floor(v / 65536);
|
|
1147
|
-
t7 = v - c * 65536;
|
|
1148
|
-
v = t8 + c + 65535;
|
|
1149
|
-
c = Math.floor(v / 65536);
|
|
1150
|
-
t8 = v - c * 65536;
|
|
1151
|
-
v = t9 + c + 65535;
|
|
1152
|
-
c = Math.floor(v / 65536);
|
|
1153
|
-
t9 = v - c * 65536;
|
|
1154
|
-
v = t10 + c + 65535;
|
|
1155
|
-
c = Math.floor(v / 65536);
|
|
1156
|
-
t10 = v - c * 65536;
|
|
1157
|
-
v = t11 + c + 65535;
|
|
1158
|
-
c = Math.floor(v / 65536);
|
|
1159
|
-
t11 = v - c * 65536;
|
|
1160
|
-
v = t12 + c + 65535;
|
|
1161
|
-
c = Math.floor(v / 65536);
|
|
1162
|
-
t12 = v - c * 65536;
|
|
1163
|
-
v = t13 + c + 65535;
|
|
1164
|
-
c = Math.floor(v / 65536);
|
|
1165
|
-
t13 = v - c * 65536;
|
|
1166
|
-
v = t14 + c + 65535;
|
|
1167
|
-
c = Math.floor(v / 65536);
|
|
1168
|
-
t14 = v - c * 65536;
|
|
1169
|
-
v = t15 + c + 65535;
|
|
1170
|
-
c = Math.floor(v / 65536);
|
|
1171
|
-
t15 = v - c * 65536;
|
|
1172
|
-
t0 += c - 1 + 37 * (c - 1);
|
|
1173
|
-
c = 1;
|
|
1174
|
-
v = t0 + c + 65535;
|
|
1175
|
-
c = Math.floor(v / 65536);
|
|
1176
|
-
t0 = v - c * 65536;
|
|
1177
|
-
v = t1 + c + 65535;
|
|
1178
|
-
c = Math.floor(v / 65536);
|
|
1179
|
-
t1 = v - c * 65536;
|
|
1180
|
-
v = t2 + c + 65535;
|
|
1181
|
-
c = Math.floor(v / 65536);
|
|
1182
|
-
t2 = v - c * 65536;
|
|
1183
|
-
v = t3 + c + 65535;
|
|
1184
|
-
c = Math.floor(v / 65536);
|
|
1185
|
-
t3 = v - c * 65536;
|
|
1186
|
-
v = t4 + c + 65535;
|
|
1187
|
-
c = Math.floor(v / 65536);
|
|
1188
|
-
t4 = v - c * 65536;
|
|
1189
|
-
v = t5 + c + 65535;
|
|
1190
|
-
c = Math.floor(v / 65536);
|
|
1191
|
-
t5 = v - c * 65536;
|
|
1192
|
-
v = t6 + c + 65535;
|
|
1193
|
-
c = Math.floor(v / 65536);
|
|
1194
|
-
t6 = v - c * 65536;
|
|
1195
|
-
v = t7 + c + 65535;
|
|
1196
|
-
c = Math.floor(v / 65536);
|
|
1197
|
-
t7 = v - c * 65536;
|
|
1198
|
-
v = t8 + c + 65535;
|
|
1199
|
-
c = Math.floor(v / 65536);
|
|
1200
|
-
t8 = v - c * 65536;
|
|
1201
|
-
v = t9 + c + 65535;
|
|
1202
|
-
c = Math.floor(v / 65536);
|
|
1203
|
-
t9 = v - c * 65536;
|
|
1204
|
-
v = t10 + c + 65535;
|
|
1205
|
-
c = Math.floor(v / 65536);
|
|
1206
|
-
t10 = v - c * 65536;
|
|
1207
|
-
v = t11 + c + 65535;
|
|
1208
|
-
c = Math.floor(v / 65536);
|
|
1209
|
-
t11 = v - c * 65536;
|
|
1210
|
-
v = t12 + c + 65535;
|
|
1211
|
-
c = Math.floor(v / 65536);
|
|
1212
|
-
t12 = v - c * 65536;
|
|
1213
|
-
v = t13 + c + 65535;
|
|
1214
|
-
c = Math.floor(v / 65536);
|
|
1215
|
-
t13 = v - c * 65536;
|
|
1216
|
-
v = t14 + c + 65535;
|
|
1217
|
-
c = Math.floor(v / 65536);
|
|
1218
|
-
t14 = v - c * 65536;
|
|
1219
|
-
v = t15 + c + 65535;
|
|
1220
|
-
c = Math.floor(v / 65536);
|
|
1221
|
-
t15 = v - c * 65536;
|
|
1222
|
-
t0 += c - 1 + 37 * (c - 1);
|
|
1223
|
-
o[0] = t0;
|
|
1224
|
-
o[1] = t1;
|
|
1225
|
-
o[2] = t2;
|
|
1226
|
-
o[3] = t3;
|
|
1227
|
-
o[4] = t4;
|
|
1228
|
-
o[5] = t5;
|
|
1229
|
-
o[6] = t6;
|
|
1230
|
-
o[7] = t7;
|
|
1231
|
-
o[8] = t8;
|
|
1232
|
-
o[9] = t9;
|
|
1233
|
-
o[10] = t10;
|
|
1234
|
-
o[11] = t11;
|
|
1235
|
-
o[12] = t12;
|
|
1236
|
-
o[13] = t13;
|
|
1237
|
-
o[14] = t14;
|
|
1238
|
-
o[15] = t15;
|
|
1239
|
-
}
|
|
1240
|
-
function S(o, a) {
|
|
1241
|
-
M(o, a, a);
|
|
1242
|
-
}
|
|
1243
|
-
function inv25519(o, i) {
|
|
1244
|
-
var c = gf();
|
|
1245
|
-
var a;
|
|
1246
|
-
for (a = 0; a < 16; a++) c[a] = i[a];
|
|
1247
|
-
for (a = 253; a >= 0; a--) {
|
|
1248
|
-
S(c, c);
|
|
1249
|
-
if (a !== 2 && a !== 4) M(c, c, i);
|
|
1250
|
-
}
|
|
1251
|
-
for (a = 0; a < 16; a++) o[a] = c[a];
|
|
1252
|
-
}
|
|
1253
|
-
function pow2523(o, i) {
|
|
1254
|
-
var c = gf();
|
|
1255
|
-
var a;
|
|
1256
|
-
for (a = 0; a < 16; a++) c[a] = i[a];
|
|
1257
|
-
for (a = 250; a >= 0; a--) {
|
|
1258
|
-
S(c, c);
|
|
1259
|
-
if (a !== 1) M(c, c, i);
|
|
1260
|
-
}
|
|
1261
|
-
for (a = 0; a < 16; a++) o[a] = c[a];
|
|
1262
|
-
}
|
|
1263
|
-
function crypto_scalarmult(q, n, p) {
|
|
1264
|
-
var z = new Uint8Array(32);
|
|
1265
|
-
var x = new Float64Array(80), r, i;
|
|
1266
|
-
var a = gf(), b = gf(), c = gf(), d = gf(), e = gf(), f = gf();
|
|
1267
|
-
for (i = 0; i < 31; i++) z[i] = n[i];
|
|
1268
|
-
z[31] = n[31] & 127 | 64;
|
|
1269
|
-
z[0] &= 248;
|
|
1270
|
-
unpack25519(x, p);
|
|
1271
|
-
for (i = 0; i < 16; i++) {
|
|
1272
|
-
b[i] = x[i];
|
|
1273
|
-
d[i] = a[i] = c[i] = 0;
|
|
1274
|
-
}
|
|
1275
|
-
a[0] = d[0] = 1;
|
|
1276
|
-
for (i = 254; i >= 0; --i) {
|
|
1277
|
-
r = z[i >>> 3] >>> (i & 7) & 1;
|
|
1278
|
-
sel25519(a, b, r);
|
|
1279
|
-
sel25519(c, d, r);
|
|
1280
|
-
A(e, a, c);
|
|
1281
|
-
Z(a, a, c);
|
|
1282
|
-
A(c, b, d);
|
|
1283
|
-
Z(b, b, d);
|
|
1284
|
-
S(d, e);
|
|
1285
|
-
S(f, a);
|
|
1286
|
-
M(a, c, a);
|
|
1287
|
-
M(c, b, e);
|
|
1288
|
-
A(e, a, c);
|
|
1289
|
-
Z(a, a, c);
|
|
1290
|
-
S(b, a);
|
|
1291
|
-
Z(c, d, f);
|
|
1292
|
-
M(a, c, _121665);
|
|
1293
|
-
A(a, a, d);
|
|
1294
|
-
M(c, c, a);
|
|
1295
|
-
M(a, d, f);
|
|
1296
|
-
M(d, b, x);
|
|
1297
|
-
S(b, e);
|
|
1298
|
-
sel25519(a, b, r);
|
|
1299
|
-
sel25519(c, d, r);
|
|
1300
|
-
}
|
|
1301
|
-
for (i = 0; i < 16; i++) {
|
|
1302
|
-
x[i + 16] = a[i];
|
|
1303
|
-
x[i + 32] = c[i];
|
|
1304
|
-
x[i + 48] = b[i];
|
|
1305
|
-
x[i + 64] = d[i];
|
|
1306
|
-
}
|
|
1307
|
-
var x32 = x.subarray(32);
|
|
1308
|
-
var x16 = x.subarray(16);
|
|
1309
|
-
inv25519(x32, x32);
|
|
1310
|
-
M(x16, x16, x32);
|
|
1311
|
-
pack25519(q, x16);
|
|
1312
|
-
return 0;
|
|
1313
|
-
}
|
|
1314
|
-
function crypto_scalarmult_base(q, n) {
|
|
1315
|
-
return crypto_scalarmult(q, n, _9);
|
|
1316
|
-
}
|
|
1317
|
-
function crypto_box_keypair(y, x) {
|
|
1318
|
-
randombytes(x, 32);
|
|
1319
|
-
return crypto_scalarmult_base(y, x);
|
|
1320
|
-
}
|
|
1321
|
-
function crypto_box_beforenm(k, y, x) {
|
|
1322
|
-
var s = new Uint8Array(32);
|
|
1323
|
-
crypto_scalarmult(s, x, y);
|
|
1324
|
-
return crypto_core_hsalsa20(k, _0, s, sigma);
|
|
1325
|
-
}
|
|
1326
|
-
var crypto_box_afternm = crypto_secretbox;
|
|
1327
|
-
var crypto_box_open_afternm = crypto_secretbox_open;
|
|
1328
|
-
function crypto_box(c, m, d, n, y, x) {
|
|
1329
|
-
var k = new Uint8Array(32);
|
|
1330
|
-
crypto_box_beforenm(k, y, x);
|
|
1331
|
-
return crypto_box_afternm(c, m, d, n, k);
|
|
1332
|
-
}
|
|
1333
|
-
function crypto_box_open(m, c, d, n, y, x) {
|
|
1334
|
-
var k = new Uint8Array(32);
|
|
1335
|
-
crypto_box_beforenm(k, y, x);
|
|
1336
|
-
return crypto_box_open_afternm(m, c, d, n, k);
|
|
1337
|
-
}
|
|
1338
|
-
var K = [
|
|
1339
|
-
1116352408,
|
|
1340
|
-
3609767458,
|
|
1341
|
-
1899447441,
|
|
1342
|
-
602891725,
|
|
1343
|
-
3049323471,
|
|
1344
|
-
3964484399,
|
|
1345
|
-
3921009573,
|
|
1346
|
-
2173295548,
|
|
1347
|
-
961987163,
|
|
1348
|
-
4081628472,
|
|
1349
|
-
1508970993,
|
|
1350
|
-
3053834265,
|
|
1351
|
-
2453635748,
|
|
1352
|
-
2937671579,
|
|
1353
|
-
2870763221,
|
|
1354
|
-
3664609560,
|
|
1355
|
-
3624381080,
|
|
1356
|
-
2734883394,
|
|
1357
|
-
310598401,
|
|
1358
|
-
1164996542,
|
|
1359
|
-
607225278,
|
|
1360
|
-
1323610764,
|
|
1361
|
-
1426881987,
|
|
1362
|
-
3590304994,
|
|
1363
|
-
1925078388,
|
|
1364
|
-
4068182383,
|
|
1365
|
-
2162078206,
|
|
1366
|
-
991336113,
|
|
1367
|
-
2614888103,
|
|
1368
|
-
633803317,
|
|
1369
|
-
3248222580,
|
|
1370
|
-
3479774868,
|
|
1371
|
-
3835390401,
|
|
1372
|
-
2666613458,
|
|
1373
|
-
4022224774,
|
|
1374
|
-
944711139,
|
|
1375
|
-
264347078,
|
|
1376
|
-
2341262773,
|
|
1377
|
-
604807628,
|
|
1378
|
-
2007800933,
|
|
1379
|
-
770255983,
|
|
1380
|
-
1495990901,
|
|
1381
|
-
1249150122,
|
|
1382
|
-
1856431235,
|
|
1383
|
-
1555081692,
|
|
1384
|
-
3175218132,
|
|
1385
|
-
1996064986,
|
|
1386
|
-
2198950837,
|
|
1387
|
-
2554220882,
|
|
1388
|
-
3999719339,
|
|
1389
|
-
2821834349,
|
|
1390
|
-
766784016,
|
|
1391
|
-
2952996808,
|
|
1392
|
-
2566594879,
|
|
1393
|
-
3210313671,
|
|
1394
|
-
3203337956,
|
|
1395
|
-
3336571891,
|
|
1396
|
-
1034457026,
|
|
1397
|
-
3584528711,
|
|
1398
|
-
2466948901,
|
|
1399
|
-
113926993,
|
|
1400
|
-
3758326383,
|
|
1401
|
-
338241895,
|
|
1402
|
-
168717936,
|
|
1403
|
-
666307205,
|
|
1404
|
-
1188179964,
|
|
1405
|
-
773529912,
|
|
1406
|
-
1546045734,
|
|
1407
|
-
1294757372,
|
|
1408
|
-
1522805485,
|
|
1409
|
-
1396182291,
|
|
1410
|
-
2643833823,
|
|
1411
|
-
1695183700,
|
|
1412
|
-
2343527390,
|
|
1413
|
-
1986661051,
|
|
1414
|
-
1014477480,
|
|
1415
|
-
2177026350,
|
|
1416
|
-
1206759142,
|
|
1417
|
-
2456956037,
|
|
1418
|
-
344077627,
|
|
1419
|
-
2730485921,
|
|
1420
|
-
1290863460,
|
|
1421
|
-
2820302411,
|
|
1422
|
-
3158454273,
|
|
1423
|
-
3259730800,
|
|
1424
|
-
3505952657,
|
|
1425
|
-
3345764771,
|
|
1426
|
-
106217008,
|
|
1427
|
-
3516065817,
|
|
1428
|
-
3606008344,
|
|
1429
|
-
3600352804,
|
|
1430
|
-
1432725776,
|
|
1431
|
-
4094571909,
|
|
1432
|
-
1467031594,
|
|
1433
|
-
275423344,
|
|
1434
|
-
851169720,
|
|
1435
|
-
430227734,
|
|
1436
|
-
3100823752,
|
|
1437
|
-
506948616,
|
|
1438
|
-
1363258195,
|
|
1439
|
-
659060556,
|
|
1440
|
-
3750685593,
|
|
1441
|
-
883997877,
|
|
1442
|
-
3785050280,
|
|
1443
|
-
958139571,
|
|
1444
|
-
3318307427,
|
|
1445
|
-
1322822218,
|
|
1446
|
-
3812723403,
|
|
1447
|
-
1537002063,
|
|
1448
|
-
2003034995,
|
|
1449
|
-
1747873779,
|
|
1450
|
-
3602036899,
|
|
1451
|
-
1955562222,
|
|
1452
|
-
1575990012,
|
|
1453
|
-
2024104815,
|
|
1454
|
-
1125592928,
|
|
1455
|
-
2227730452,
|
|
1456
|
-
2716904306,
|
|
1457
|
-
2361852424,
|
|
1458
|
-
442776044,
|
|
1459
|
-
2428436474,
|
|
1460
|
-
593698344,
|
|
1461
|
-
2756734187,
|
|
1462
|
-
3733110249,
|
|
1463
|
-
3204031479,
|
|
1464
|
-
2999351573,
|
|
1465
|
-
3329325298,
|
|
1466
|
-
3815920427,
|
|
1467
|
-
3391569614,
|
|
1468
|
-
3928383900,
|
|
1469
|
-
3515267271,
|
|
1470
|
-
566280711,
|
|
1471
|
-
3940187606,
|
|
1472
|
-
3454069534,
|
|
1473
|
-
4118630271,
|
|
1474
|
-
4000239992,
|
|
1475
|
-
116418474,
|
|
1476
|
-
1914138554,
|
|
1477
|
-
174292421,
|
|
1478
|
-
2731055270,
|
|
1479
|
-
289380356,
|
|
1480
|
-
3203993006,
|
|
1481
|
-
460393269,
|
|
1482
|
-
320620315,
|
|
1483
|
-
685471733,
|
|
1484
|
-
587496836,
|
|
1485
|
-
852142971,
|
|
1486
|
-
1086792851,
|
|
1487
|
-
1017036298,
|
|
1488
|
-
365543100,
|
|
1489
|
-
1126000580,
|
|
1490
|
-
2618297676,
|
|
1491
|
-
1288033470,
|
|
1492
|
-
3409855158,
|
|
1493
|
-
1501505948,
|
|
1494
|
-
4234509866,
|
|
1495
|
-
1607167915,
|
|
1496
|
-
987167468,
|
|
1497
|
-
1816402316,
|
|
1498
|
-
1246189591
|
|
1499
|
-
];
|
|
1500
|
-
function crypto_hashblocks_hl(hh, hl, m, n) {
|
|
1501
|
-
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;
|
|
1502
|
-
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];
|
|
1503
|
-
var pos = 0;
|
|
1504
|
-
while (n >= 128) {
|
|
1505
|
-
for (i = 0; i < 16; i++) {
|
|
1506
|
-
j = 8 * i + pos;
|
|
1507
|
-
wh[i] = m[j + 0] << 24 | m[j + 1] << 16 | m[j + 2] << 8 | m[j + 3];
|
|
1508
|
-
wl[i] = m[j + 4] << 24 | m[j + 5] << 16 | m[j + 6] << 8 | m[j + 7];
|
|
1509
|
-
}
|
|
1510
|
-
for (i = 0; i < 80; i++) {
|
|
1511
|
-
bh0 = ah0;
|
|
1512
|
-
bh1 = ah1;
|
|
1513
|
-
bh2 = ah2;
|
|
1514
|
-
bh3 = ah3;
|
|
1515
|
-
bh4 = ah4;
|
|
1516
|
-
bh5 = ah5;
|
|
1517
|
-
bh6 = ah6;
|
|
1518
|
-
bh7 = ah7;
|
|
1519
|
-
bl0 = al0;
|
|
1520
|
-
bl1 = al1;
|
|
1521
|
-
bl2 = al2;
|
|
1522
|
-
bl3 = al3;
|
|
1523
|
-
bl4 = al4;
|
|
1524
|
-
bl5 = al5;
|
|
1525
|
-
bl6 = al6;
|
|
1526
|
-
bl7 = al7;
|
|
1527
|
-
h = ah7;
|
|
1528
|
-
l = al7;
|
|
1529
|
-
a = l & 65535;
|
|
1530
|
-
b = l >>> 16;
|
|
1531
|
-
c = h & 65535;
|
|
1532
|
-
d = h >>> 16;
|
|
1533
|
-
h = (ah4 >>> 14 | al4 << 32 - 14) ^ (ah4 >>> 18 | al4 << 32 - 18) ^ (al4 >>> 41 - 32 | ah4 << 32 - (41 - 32));
|
|
1534
|
-
l = (al4 >>> 14 | ah4 << 32 - 14) ^ (al4 >>> 18 | ah4 << 32 - 18) ^ (ah4 >>> 41 - 32 | al4 << 32 - (41 - 32));
|
|
1535
|
-
a += l & 65535;
|
|
1536
|
-
b += l >>> 16;
|
|
1537
|
-
c += h & 65535;
|
|
1538
|
-
d += h >>> 16;
|
|
1539
|
-
h = ah4 & ah5 ^ ~ah4 & ah6;
|
|
1540
|
-
l = al4 & al5 ^ ~al4 & al6;
|
|
1541
|
-
a += l & 65535;
|
|
1542
|
-
b += l >>> 16;
|
|
1543
|
-
c += h & 65535;
|
|
1544
|
-
d += h >>> 16;
|
|
1545
|
-
h = K[i * 2];
|
|
1546
|
-
l = K[i * 2 + 1];
|
|
1547
|
-
a += l & 65535;
|
|
1548
|
-
b += l >>> 16;
|
|
1549
|
-
c += h & 65535;
|
|
1550
|
-
d += h >>> 16;
|
|
1551
|
-
h = wh[i % 16];
|
|
1552
|
-
l = wl[i % 16];
|
|
1553
|
-
a += l & 65535;
|
|
1554
|
-
b += l >>> 16;
|
|
1555
|
-
c += h & 65535;
|
|
1556
|
-
d += h >>> 16;
|
|
1557
|
-
b += a >>> 16;
|
|
1558
|
-
c += b >>> 16;
|
|
1559
|
-
d += c >>> 16;
|
|
1560
|
-
th = c & 65535 | d << 16;
|
|
1561
|
-
tl = a & 65535 | b << 16;
|
|
1562
|
-
h = th;
|
|
1563
|
-
l = tl;
|
|
1564
|
-
a = l & 65535;
|
|
1565
|
-
b = l >>> 16;
|
|
1566
|
-
c = h & 65535;
|
|
1567
|
-
d = h >>> 16;
|
|
1568
|
-
h = (ah0 >>> 28 | al0 << 32 - 28) ^ (al0 >>> 34 - 32 | ah0 << 32 - (34 - 32)) ^ (al0 >>> 39 - 32 | ah0 << 32 - (39 - 32));
|
|
1569
|
-
l = (al0 >>> 28 | ah0 << 32 - 28) ^ (ah0 >>> 34 - 32 | al0 << 32 - (34 - 32)) ^ (ah0 >>> 39 - 32 | al0 << 32 - (39 - 32));
|
|
1570
|
-
a += l & 65535;
|
|
1571
|
-
b += l >>> 16;
|
|
1572
|
-
c += h & 65535;
|
|
1573
|
-
d += h >>> 16;
|
|
1574
|
-
h = ah0 & ah1 ^ ah0 & ah2 ^ ah1 & ah2;
|
|
1575
|
-
l = al0 & al1 ^ al0 & al2 ^ al1 & al2;
|
|
1576
|
-
a += l & 65535;
|
|
1577
|
-
b += l >>> 16;
|
|
1578
|
-
c += h & 65535;
|
|
1579
|
-
d += h >>> 16;
|
|
1580
|
-
b += a >>> 16;
|
|
1581
|
-
c += b >>> 16;
|
|
1582
|
-
d += c >>> 16;
|
|
1583
|
-
bh7 = c & 65535 | d << 16;
|
|
1584
|
-
bl7 = a & 65535 | b << 16;
|
|
1585
|
-
h = bh3;
|
|
1586
|
-
l = bl3;
|
|
1587
|
-
a = l & 65535;
|
|
1588
|
-
b = l >>> 16;
|
|
1589
|
-
c = h & 65535;
|
|
1590
|
-
d = h >>> 16;
|
|
1591
|
-
h = th;
|
|
1592
|
-
l = tl;
|
|
1593
|
-
a += l & 65535;
|
|
1594
|
-
b += l >>> 16;
|
|
1595
|
-
c += h & 65535;
|
|
1596
|
-
d += h >>> 16;
|
|
1597
|
-
b += a >>> 16;
|
|
1598
|
-
c += b >>> 16;
|
|
1599
|
-
d += c >>> 16;
|
|
1600
|
-
bh3 = c & 65535 | d << 16;
|
|
1601
|
-
bl3 = a & 65535 | b << 16;
|
|
1602
|
-
ah1 = bh0;
|
|
1603
|
-
ah2 = bh1;
|
|
1604
|
-
ah3 = bh2;
|
|
1605
|
-
ah4 = bh3;
|
|
1606
|
-
ah5 = bh4;
|
|
1607
|
-
ah6 = bh5;
|
|
1608
|
-
ah7 = bh6;
|
|
1609
|
-
ah0 = bh7;
|
|
1610
|
-
al1 = bl0;
|
|
1611
|
-
al2 = bl1;
|
|
1612
|
-
al3 = bl2;
|
|
1613
|
-
al4 = bl3;
|
|
1614
|
-
al5 = bl4;
|
|
1615
|
-
al6 = bl5;
|
|
1616
|
-
al7 = bl6;
|
|
1617
|
-
al0 = bl7;
|
|
1618
|
-
if (i % 16 === 15) {
|
|
1619
|
-
for (j = 0; j < 16; j++) {
|
|
1620
|
-
h = wh[j];
|
|
1621
|
-
l = wl[j];
|
|
1622
|
-
a = l & 65535;
|
|
1623
|
-
b = l >>> 16;
|
|
1624
|
-
c = h & 65535;
|
|
1625
|
-
d = h >>> 16;
|
|
1626
|
-
h = wh[(j + 9) % 16];
|
|
1627
|
-
l = wl[(j + 9) % 16];
|
|
1628
|
-
a += l & 65535;
|
|
1629
|
-
b += l >>> 16;
|
|
1630
|
-
c += h & 65535;
|
|
1631
|
-
d += h >>> 16;
|
|
1632
|
-
th = wh[(j + 1) % 16];
|
|
1633
|
-
tl = wl[(j + 1) % 16];
|
|
1634
|
-
h = (th >>> 1 | tl << 32 - 1) ^ (th >>> 8 | tl << 32 - 8) ^ th >>> 7;
|
|
1635
|
-
l = (tl >>> 1 | th << 32 - 1) ^ (tl >>> 8 | th << 32 - 8) ^ (tl >>> 7 | th << 32 - 7);
|
|
1636
|
-
a += l & 65535;
|
|
1637
|
-
b += l >>> 16;
|
|
1638
|
-
c += h & 65535;
|
|
1639
|
-
d += h >>> 16;
|
|
1640
|
-
th = wh[(j + 14) % 16];
|
|
1641
|
-
tl = wl[(j + 14) % 16];
|
|
1642
|
-
h = (th >>> 19 | tl << 32 - 19) ^ (tl >>> 61 - 32 | th << 32 - (61 - 32)) ^ th >>> 6;
|
|
1643
|
-
l = (tl >>> 19 | th << 32 - 19) ^ (th >>> 61 - 32 | tl << 32 - (61 - 32)) ^ (tl >>> 6 | th << 32 - 6);
|
|
1644
|
-
a += l & 65535;
|
|
1645
|
-
b += l >>> 16;
|
|
1646
|
-
c += h & 65535;
|
|
1647
|
-
d += h >>> 16;
|
|
1648
|
-
b += a >>> 16;
|
|
1649
|
-
c += b >>> 16;
|
|
1650
|
-
d += c >>> 16;
|
|
1651
|
-
wh[j] = c & 65535 | d << 16;
|
|
1652
|
-
wl[j] = a & 65535 | b << 16;
|
|
1653
|
-
}
|
|
1654
|
-
}
|
|
1655
|
-
}
|
|
1656
|
-
h = ah0;
|
|
1657
|
-
l = al0;
|
|
1658
|
-
a = l & 65535;
|
|
1659
|
-
b = l >>> 16;
|
|
1660
|
-
c = h & 65535;
|
|
1661
|
-
d = h >>> 16;
|
|
1662
|
-
h = hh[0];
|
|
1663
|
-
l = hl[0];
|
|
1664
|
-
a += l & 65535;
|
|
1665
|
-
b += l >>> 16;
|
|
1666
|
-
c += h & 65535;
|
|
1667
|
-
d += h >>> 16;
|
|
1668
|
-
b += a >>> 16;
|
|
1669
|
-
c += b >>> 16;
|
|
1670
|
-
d += c >>> 16;
|
|
1671
|
-
hh[0] = ah0 = c & 65535 | d << 16;
|
|
1672
|
-
hl[0] = al0 = a & 65535 | b << 16;
|
|
1673
|
-
h = ah1;
|
|
1674
|
-
l = al1;
|
|
1675
|
-
a = l & 65535;
|
|
1676
|
-
b = l >>> 16;
|
|
1677
|
-
c = h & 65535;
|
|
1678
|
-
d = h >>> 16;
|
|
1679
|
-
h = hh[1];
|
|
1680
|
-
l = hl[1];
|
|
1681
|
-
a += l & 65535;
|
|
1682
|
-
b += l >>> 16;
|
|
1683
|
-
c += h & 65535;
|
|
1684
|
-
d += h >>> 16;
|
|
1685
|
-
b += a >>> 16;
|
|
1686
|
-
c += b >>> 16;
|
|
1687
|
-
d += c >>> 16;
|
|
1688
|
-
hh[1] = ah1 = c & 65535 | d << 16;
|
|
1689
|
-
hl[1] = al1 = a & 65535 | b << 16;
|
|
1690
|
-
h = ah2;
|
|
1691
|
-
l = al2;
|
|
1692
|
-
a = l & 65535;
|
|
1693
|
-
b = l >>> 16;
|
|
1694
|
-
c = h & 65535;
|
|
1695
|
-
d = h >>> 16;
|
|
1696
|
-
h = hh[2];
|
|
1697
|
-
l = hl[2];
|
|
1698
|
-
a += l & 65535;
|
|
1699
|
-
b += l >>> 16;
|
|
1700
|
-
c += h & 65535;
|
|
1701
|
-
d += h >>> 16;
|
|
1702
|
-
b += a >>> 16;
|
|
1703
|
-
c += b >>> 16;
|
|
1704
|
-
d += c >>> 16;
|
|
1705
|
-
hh[2] = ah2 = c & 65535 | d << 16;
|
|
1706
|
-
hl[2] = al2 = a & 65535 | b << 16;
|
|
1707
|
-
h = ah3;
|
|
1708
|
-
l = al3;
|
|
1709
|
-
a = l & 65535;
|
|
1710
|
-
b = l >>> 16;
|
|
1711
|
-
c = h & 65535;
|
|
1712
|
-
d = h >>> 16;
|
|
1713
|
-
h = hh[3];
|
|
1714
|
-
l = hl[3];
|
|
1715
|
-
a += l & 65535;
|
|
1716
|
-
b += l >>> 16;
|
|
1717
|
-
c += h & 65535;
|
|
1718
|
-
d += h >>> 16;
|
|
1719
|
-
b += a >>> 16;
|
|
1720
|
-
c += b >>> 16;
|
|
1721
|
-
d += c >>> 16;
|
|
1722
|
-
hh[3] = ah3 = c & 65535 | d << 16;
|
|
1723
|
-
hl[3] = al3 = a & 65535 | b << 16;
|
|
1724
|
-
h = ah4;
|
|
1725
|
-
l = al4;
|
|
1726
|
-
a = l & 65535;
|
|
1727
|
-
b = l >>> 16;
|
|
1728
|
-
c = h & 65535;
|
|
1729
|
-
d = h >>> 16;
|
|
1730
|
-
h = hh[4];
|
|
1731
|
-
l = hl[4];
|
|
1732
|
-
a += l & 65535;
|
|
1733
|
-
b += l >>> 16;
|
|
1734
|
-
c += h & 65535;
|
|
1735
|
-
d += h >>> 16;
|
|
1736
|
-
b += a >>> 16;
|
|
1737
|
-
c += b >>> 16;
|
|
1738
|
-
d += c >>> 16;
|
|
1739
|
-
hh[4] = ah4 = c & 65535 | d << 16;
|
|
1740
|
-
hl[4] = al4 = a & 65535 | b << 16;
|
|
1741
|
-
h = ah5;
|
|
1742
|
-
l = al5;
|
|
1743
|
-
a = l & 65535;
|
|
1744
|
-
b = l >>> 16;
|
|
1745
|
-
c = h & 65535;
|
|
1746
|
-
d = h >>> 16;
|
|
1747
|
-
h = hh[5];
|
|
1748
|
-
l = hl[5];
|
|
1749
|
-
a += l & 65535;
|
|
1750
|
-
b += l >>> 16;
|
|
1751
|
-
c += h & 65535;
|
|
1752
|
-
d += h >>> 16;
|
|
1753
|
-
b += a >>> 16;
|
|
1754
|
-
c += b >>> 16;
|
|
1755
|
-
d += c >>> 16;
|
|
1756
|
-
hh[5] = ah5 = c & 65535 | d << 16;
|
|
1757
|
-
hl[5] = al5 = a & 65535 | b << 16;
|
|
1758
|
-
h = ah6;
|
|
1759
|
-
l = al6;
|
|
1760
|
-
a = l & 65535;
|
|
1761
|
-
b = l >>> 16;
|
|
1762
|
-
c = h & 65535;
|
|
1763
|
-
d = h >>> 16;
|
|
1764
|
-
h = hh[6];
|
|
1765
|
-
l = hl[6];
|
|
1766
|
-
a += l & 65535;
|
|
1767
|
-
b += l >>> 16;
|
|
1768
|
-
c += h & 65535;
|
|
1769
|
-
d += h >>> 16;
|
|
1770
|
-
b += a >>> 16;
|
|
1771
|
-
c += b >>> 16;
|
|
1772
|
-
d += c >>> 16;
|
|
1773
|
-
hh[6] = ah6 = c & 65535 | d << 16;
|
|
1774
|
-
hl[6] = al6 = a & 65535 | b << 16;
|
|
1775
|
-
h = ah7;
|
|
1776
|
-
l = al7;
|
|
1777
|
-
a = l & 65535;
|
|
1778
|
-
b = l >>> 16;
|
|
1779
|
-
c = h & 65535;
|
|
1780
|
-
d = h >>> 16;
|
|
1781
|
-
h = hh[7];
|
|
1782
|
-
l = hl[7];
|
|
1783
|
-
a += l & 65535;
|
|
1784
|
-
b += l >>> 16;
|
|
1785
|
-
c += h & 65535;
|
|
1786
|
-
d += h >>> 16;
|
|
1787
|
-
b += a >>> 16;
|
|
1788
|
-
c += b >>> 16;
|
|
1789
|
-
d += c >>> 16;
|
|
1790
|
-
hh[7] = ah7 = c & 65535 | d << 16;
|
|
1791
|
-
hl[7] = al7 = a & 65535 | b << 16;
|
|
1792
|
-
pos += 128;
|
|
1793
|
-
n -= 128;
|
|
1794
|
-
}
|
|
1795
|
-
return n;
|
|
1796
|
-
}
|
|
1797
|
-
function crypto_hash(out, m, n) {
|
|
1798
|
-
var hh = new Int32Array(8), hl = new Int32Array(8), x = new Uint8Array(256), i, b = n;
|
|
1799
|
-
hh[0] = 1779033703;
|
|
1800
|
-
hh[1] = 3144134277;
|
|
1801
|
-
hh[2] = 1013904242;
|
|
1802
|
-
hh[3] = 2773480762;
|
|
1803
|
-
hh[4] = 1359893119;
|
|
1804
|
-
hh[5] = 2600822924;
|
|
1805
|
-
hh[6] = 528734635;
|
|
1806
|
-
hh[7] = 1541459225;
|
|
1807
|
-
hl[0] = 4089235720;
|
|
1808
|
-
hl[1] = 2227873595;
|
|
1809
|
-
hl[2] = 4271175723;
|
|
1810
|
-
hl[3] = 1595750129;
|
|
1811
|
-
hl[4] = 2917565137;
|
|
1812
|
-
hl[5] = 725511199;
|
|
1813
|
-
hl[6] = 4215389547;
|
|
1814
|
-
hl[7] = 327033209;
|
|
1815
|
-
crypto_hashblocks_hl(hh, hl, m, n);
|
|
1816
|
-
n %= 128;
|
|
1817
|
-
for (i = 0; i < n; i++) x[i] = m[b - n + i];
|
|
1818
|
-
x[n] = 128;
|
|
1819
|
-
n = 256 - 128 * (n < 112 ? 1 : 0);
|
|
1820
|
-
x[n - 9] = 0;
|
|
1821
|
-
ts64(x, n - 8, b / 536870912 | 0, b << 3);
|
|
1822
|
-
crypto_hashblocks_hl(hh, hl, x, n);
|
|
1823
|
-
for (i = 0; i < 8; i++) ts64(out, 8 * i, hh[i], hl[i]);
|
|
1824
|
-
return 0;
|
|
1825
|
-
}
|
|
1826
|
-
function add(p, q) {
|
|
1827
|
-
var a = gf(), b = gf(), c = gf(), d = gf(), e = gf(), f = gf(), g = gf(), h = gf(), t = gf();
|
|
1828
|
-
Z(a, p[1], p[0]);
|
|
1829
|
-
Z(t, q[1], q[0]);
|
|
1830
|
-
M(a, a, t);
|
|
1831
|
-
A(b, p[0], p[1]);
|
|
1832
|
-
A(t, q[0], q[1]);
|
|
1833
|
-
M(b, b, t);
|
|
1834
|
-
M(c, p[3], q[3]);
|
|
1835
|
-
M(c, c, D2);
|
|
1836
|
-
M(d, p[2], q[2]);
|
|
1837
|
-
A(d, d, d);
|
|
1838
|
-
Z(e, b, a);
|
|
1839
|
-
Z(f, d, c);
|
|
1840
|
-
A(g, d, c);
|
|
1841
|
-
A(h, b, a);
|
|
1842
|
-
M(p[0], e, f);
|
|
1843
|
-
M(p[1], h, g);
|
|
1844
|
-
M(p[2], g, f);
|
|
1845
|
-
M(p[3], e, h);
|
|
1846
|
-
}
|
|
1847
|
-
function cswap(p, q, b) {
|
|
1848
|
-
var i;
|
|
1849
|
-
for (i = 0; i < 4; i++) {
|
|
1850
|
-
sel25519(p[i], q[i], b);
|
|
1851
|
-
}
|
|
1852
|
-
}
|
|
1853
|
-
function pack(r, p) {
|
|
1854
|
-
var tx = gf(), ty = gf(), zi = gf();
|
|
1855
|
-
inv25519(zi, p[2]);
|
|
1856
|
-
M(tx, p[0], zi);
|
|
1857
|
-
M(ty, p[1], zi);
|
|
1858
|
-
pack25519(r, ty);
|
|
1859
|
-
r[31] ^= par25519(tx) << 7;
|
|
1860
|
-
}
|
|
1861
|
-
function scalarmult(p, q, s) {
|
|
1862
|
-
var b, i;
|
|
1863
|
-
set25519(p[0], gf0);
|
|
1864
|
-
set25519(p[1], gf1);
|
|
1865
|
-
set25519(p[2], gf1);
|
|
1866
|
-
set25519(p[3], gf0);
|
|
1867
|
-
for (i = 255; i >= 0; --i) {
|
|
1868
|
-
b = s[i / 8 | 0] >> (i & 7) & 1;
|
|
1869
|
-
cswap(p, q, b);
|
|
1870
|
-
add(q, p);
|
|
1871
|
-
add(p, p);
|
|
1872
|
-
cswap(p, q, b);
|
|
1873
|
-
}
|
|
1874
|
-
}
|
|
1875
|
-
function scalarbase(p, s) {
|
|
1876
|
-
var q = [gf(), gf(), gf(), gf()];
|
|
1877
|
-
set25519(q[0], X);
|
|
1878
|
-
set25519(q[1], Y);
|
|
1879
|
-
set25519(q[2], gf1);
|
|
1880
|
-
M(q[3], X, Y);
|
|
1881
|
-
scalarmult(p, q, s);
|
|
1882
|
-
}
|
|
1883
|
-
function crypto_sign_keypair(pk, sk, seeded) {
|
|
1884
|
-
var d = new Uint8Array(64);
|
|
1885
|
-
var p = [gf(), gf(), gf(), gf()];
|
|
1886
|
-
var i;
|
|
1887
|
-
if (!seeded) randombytes(sk, 32);
|
|
1888
|
-
crypto_hash(d, sk, 32);
|
|
1889
|
-
d[0] &= 248;
|
|
1890
|
-
d[31] &= 127;
|
|
1891
|
-
d[31] |= 64;
|
|
1892
|
-
scalarbase(p, d);
|
|
1893
|
-
pack(pk, p);
|
|
1894
|
-
for (i = 0; i < 32; i++) sk[i + 32] = pk[i];
|
|
1895
|
-
return 0;
|
|
1896
|
-
}
|
|
1897
|
-
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]);
|
|
1898
|
-
function modL(r, x) {
|
|
1899
|
-
var carry, i, j, k;
|
|
1900
|
-
for (i = 63; i >= 32; --i) {
|
|
1901
|
-
carry = 0;
|
|
1902
|
-
for (j = i - 32, k = i - 12; j < k; ++j) {
|
|
1903
|
-
x[j] += carry - 16 * x[i] * L[j - (i - 32)];
|
|
1904
|
-
carry = Math.floor((x[j] + 128) / 256);
|
|
1905
|
-
x[j] -= carry * 256;
|
|
1906
|
-
}
|
|
1907
|
-
x[j] += carry;
|
|
1908
|
-
x[i] = 0;
|
|
1909
|
-
}
|
|
1910
|
-
carry = 0;
|
|
1911
|
-
for (j = 0; j < 32; j++) {
|
|
1912
|
-
x[j] += carry - (x[31] >> 4) * L[j];
|
|
1913
|
-
carry = x[j] >> 8;
|
|
1914
|
-
x[j] &= 255;
|
|
1915
|
-
}
|
|
1916
|
-
for (j = 0; j < 32; j++) x[j] -= carry * L[j];
|
|
1917
|
-
for (i = 0; i < 32; i++) {
|
|
1918
|
-
x[i + 1] += x[i] >> 8;
|
|
1919
|
-
r[i] = x[i] & 255;
|
|
1920
|
-
}
|
|
1921
|
-
}
|
|
1922
|
-
function reduce(r) {
|
|
1923
|
-
var x = new Float64Array(64), i;
|
|
1924
|
-
for (i = 0; i < 64; i++) x[i] = r[i];
|
|
1925
|
-
for (i = 0; i < 64; i++) r[i] = 0;
|
|
1926
|
-
modL(r, x);
|
|
1927
|
-
}
|
|
1928
|
-
function crypto_sign(sm, m, n, sk) {
|
|
1929
|
-
var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64);
|
|
1930
|
-
var i, j, x = new Float64Array(64);
|
|
1931
|
-
var p = [gf(), gf(), gf(), gf()];
|
|
1932
|
-
crypto_hash(d, sk, 32);
|
|
1933
|
-
d[0] &= 248;
|
|
1934
|
-
d[31] &= 127;
|
|
1935
|
-
d[31] |= 64;
|
|
1936
|
-
var smlen = n + 64;
|
|
1937
|
-
for (i = 0; i < n; i++) sm[64 + i] = m[i];
|
|
1938
|
-
for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i];
|
|
1939
|
-
crypto_hash(r, sm.subarray(32), n + 32);
|
|
1940
|
-
reduce(r);
|
|
1941
|
-
scalarbase(p, r);
|
|
1942
|
-
pack(sm, p);
|
|
1943
|
-
for (i = 32; i < 64; i++) sm[i] = sk[i];
|
|
1944
|
-
crypto_hash(h, sm, n + 64);
|
|
1945
|
-
reduce(h);
|
|
1946
|
-
for (i = 0; i < 64; i++) x[i] = 0;
|
|
1947
|
-
for (i = 0; i < 32; i++) x[i] = r[i];
|
|
1948
|
-
for (i = 0; i < 32; i++) {
|
|
1949
|
-
for (j = 0; j < 32; j++) {
|
|
1950
|
-
x[i + j] += h[i] * d[j];
|
|
1951
|
-
}
|
|
1952
|
-
}
|
|
1953
|
-
modL(sm.subarray(32), x);
|
|
1954
|
-
return smlen;
|
|
1955
|
-
}
|
|
1956
|
-
function unpackneg(r, p) {
|
|
1957
|
-
var t = gf(), chk = gf(), num = gf(), den = gf(), den2 = gf(), den4 = gf(), den6 = gf();
|
|
1958
|
-
set25519(r[2], gf1);
|
|
1959
|
-
unpack25519(r[1], p);
|
|
1960
|
-
S(num, r[1]);
|
|
1961
|
-
M(den, num, D);
|
|
1962
|
-
Z(num, num, r[2]);
|
|
1963
|
-
A(den, r[2], den);
|
|
1964
|
-
S(den2, den);
|
|
1965
|
-
S(den4, den2);
|
|
1966
|
-
M(den6, den4, den2);
|
|
1967
|
-
M(t, den6, num);
|
|
1968
|
-
M(t, t, den);
|
|
1969
|
-
pow2523(t, t);
|
|
1970
|
-
M(t, t, num);
|
|
1971
|
-
M(t, t, den);
|
|
1972
|
-
M(t, t, den);
|
|
1973
|
-
M(r[0], t, den);
|
|
1974
|
-
S(chk, r[0]);
|
|
1975
|
-
M(chk, chk, den);
|
|
1976
|
-
if (neq25519(chk, num)) M(r[0], r[0], I);
|
|
1977
|
-
S(chk, r[0]);
|
|
1978
|
-
M(chk, chk, den);
|
|
1979
|
-
if (neq25519(chk, num)) return -1;
|
|
1980
|
-
if (par25519(r[0]) === p[31] >> 7) Z(r[0], gf0, r[0]);
|
|
1981
|
-
M(r[3], r[0], r[1]);
|
|
1982
|
-
return 0;
|
|
1983
|
-
}
|
|
1984
|
-
function crypto_sign_open(m, sm, n, pk) {
|
|
1985
|
-
var i;
|
|
1986
|
-
var t = new Uint8Array(32), h = new Uint8Array(64);
|
|
1987
|
-
var p = [gf(), gf(), gf(), gf()], q = [gf(), gf(), gf(), gf()];
|
|
1988
|
-
if (n < 64) return -1;
|
|
1989
|
-
if (unpackneg(q, pk)) return -1;
|
|
1990
|
-
for (i = 0; i < n; i++) m[i] = sm[i];
|
|
1991
|
-
for (i = 0; i < 32; i++) m[i + 32] = pk[i];
|
|
1992
|
-
crypto_hash(h, m, n);
|
|
1993
|
-
reduce(h);
|
|
1994
|
-
scalarmult(p, q, h);
|
|
1995
|
-
scalarbase(q, sm.subarray(32));
|
|
1996
|
-
add(p, q);
|
|
1997
|
-
pack(t, p);
|
|
1998
|
-
n -= 64;
|
|
1999
|
-
if (crypto_verify_32(sm, 0, t, 0)) {
|
|
2000
|
-
for (i = 0; i < n; i++) m[i] = 0;
|
|
2001
|
-
return -1;
|
|
2002
|
-
}
|
|
2003
|
-
for (i = 0; i < n; i++) m[i] = sm[i + 64];
|
|
2004
|
-
return n;
|
|
2005
|
-
}
|
|
2006
|
-
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;
|
|
2007
|
-
nacl.lowlevel = {
|
|
2008
|
-
crypto_core_hsalsa20,
|
|
2009
|
-
crypto_stream_xor,
|
|
2010
|
-
crypto_stream,
|
|
2011
|
-
crypto_stream_salsa20_xor,
|
|
2012
|
-
crypto_stream_salsa20,
|
|
2013
|
-
crypto_onetimeauth,
|
|
2014
|
-
crypto_onetimeauth_verify,
|
|
2015
|
-
crypto_verify_16,
|
|
2016
|
-
crypto_verify_32,
|
|
2017
|
-
crypto_secretbox,
|
|
2018
|
-
crypto_secretbox_open,
|
|
2019
|
-
crypto_scalarmult,
|
|
2020
|
-
crypto_scalarmult_base,
|
|
2021
|
-
crypto_box_beforenm,
|
|
2022
|
-
crypto_box_afternm,
|
|
2023
|
-
crypto_box,
|
|
2024
|
-
crypto_box_open,
|
|
2025
|
-
crypto_box_keypair,
|
|
2026
|
-
crypto_hash,
|
|
2027
|
-
crypto_sign,
|
|
2028
|
-
crypto_sign_keypair,
|
|
2029
|
-
crypto_sign_open,
|
|
2030
|
-
crypto_secretbox_KEYBYTES,
|
|
2031
|
-
crypto_secretbox_NONCEBYTES,
|
|
2032
|
-
crypto_secretbox_ZEROBYTES,
|
|
2033
|
-
crypto_secretbox_BOXZEROBYTES,
|
|
2034
|
-
crypto_scalarmult_BYTES,
|
|
2035
|
-
crypto_scalarmult_SCALARBYTES,
|
|
2036
|
-
crypto_box_PUBLICKEYBYTES,
|
|
2037
|
-
crypto_box_SECRETKEYBYTES,
|
|
2038
|
-
crypto_box_BEFORENMBYTES,
|
|
2039
|
-
crypto_box_NONCEBYTES,
|
|
2040
|
-
crypto_box_ZEROBYTES,
|
|
2041
|
-
crypto_box_BOXZEROBYTES,
|
|
2042
|
-
crypto_sign_BYTES,
|
|
2043
|
-
crypto_sign_PUBLICKEYBYTES,
|
|
2044
|
-
crypto_sign_SECRETKEYBYTES,
|
|
2045
|
-
crypto_sign_SEEDBYTES,
|
|
2046
|
-
crypto_hash_BYTES,
|
|
2047
|
-
gf,
|
|
2048
|
-
D,
|
|
2049
|
-
L,
|
|
2050
|
-
pack25519,
|
|
2051
|
-
unpack25519,
|
|
2052
|
-
M,
|
|
2053
|
-
A,
|
|
2054
|
-
S,
|
|
2055
|
-
Z,
|
|
2056
|
-
pow2523,
|
|
2057
|
-
add,
|
|
2058
|
-
set25519,
|
|
2059
|
-
modL,
|
|
2060
|
-
scalarmult,
|
|
2061
|
-
scalarbase
|
|
2062
|
-
};
|
|
2063
|
-
function checkLengths(k, n) {
|
|
2064
|
-
if (k.length !== crypto_secretbox_KEYBYTES) throw new Error("bad key size");
|
|
2065
|
-
if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error("bad nonce size");
|
|
2066
|
-
}
|
|
2067
|
-
function checkBoxLengths(pk, sk) {
|
|
2068
|
-
if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error("bad public key size");
|
|
2069
|
-
if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error("bad secret key size");
|
|
2070
|
-
}
|
|
2071
|
-
function checkArrayTypes() {
|
|
2072
|
-
for (var i = 0; i < arguments.length; i++) {
|
|
2073
|
-
if (!(arguments[i] instanceof Uint8Array))
|
|
2074
|
-
throw new TypeError("unexpected type, use Uint8Array");
|
|
2075
|
-
}
|
|
2076
|
-
}
|
|
2077
|
-
function cleanup(arr) {
|
|
2078
|
-
for (var i = 0; i < arr.length; i++) arr[i] = 0;
|
|
2079
|
-
}
|
|
2080
|
-
nacl.randomBytes = function(n) {
|
|
2081
|
-
var b = new Uint8Array(n);
|
|
2082
|
-
randombytes(b, n);
|
|
2083
|
-
return b;
|
|
2084
|
-
};
|
|
2085
|
-
nacl.secretbox = function(msg, nonce, key) {
|
|
2086
|
-
checkArrayTypes(msg, nonce, key);
|
|
2087
|
-
checkLengths(key, nonce);
|
|
2088
|
-
var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length);
|
|
2089
|
-
var c = new Uint8Array(m.length);
|
|
2090
|
-
for (var i = 0; i < msg.length; i++) m[i + crypto_secretbox_ZEROBYTES] = msg[i];
|
|
2091
|
-
crypto_secretbox(c, m, m.length, nonce, key);
|
|
2092
|
-
return c.subarray(crypto_secretbox_BOXZEROBYTES);
|
|
2093
|
-
};
|
|
2094
|
-
nacl.secretbox.open = function(box, nonce, key) {
|
|
2095
|
-
checkArrayTypes(box, nonce, key);
|
|
2096
|
-
checkLengths(key, nonce);
|
|
2097
|
-
var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length);
|
|
2098
|
-
var m = new Uint8Array(c.length);
|
|
2099
|
-
for (var i = 0; i < box.length; i++) c[i + crypto_secretbox_BOXZEROBYTES] = box[i];
|
|
2100
|
-
if (c.length < 32) return null;
|
|
2101
|
-
if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null;
|
|
2102
|
-
return m.subarray(crypto_secretbox_ZEROBYTES);
|
|
2103
|
-
};
|
|
2104
|
-
nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES;
|
|
2105
|
-
nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES;
|
|
2106
|
-
nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES;
|
|
2107
|
-
nacl.scalarMult = function(n, p) {
|
|
2108
|
-
checkArrayTypes(n, p);
|
|
2109
|
-
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error("bad n size");
|
|
2110
|
-
if (p.length !== crypto_scalarmult_BYTES) throw new Error("bad p size");
|
|
2111
|
-
var q = new Uint8Array(crypto_scalarmult_BYTES);
|
|
2112
|
-
crypto_scalarmult(q, n, p);
|
|
2113
|
-
return q;
|
|
2114
|
-
};
|
|
2115
|
-
nacl.scalarMult.base = function(n) {
|
|
2116
|
-
checkArrayTypes(n);
|
|
2117
|
-
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error("bad n size");
|
|
2118
|
-
var q = new Uint8Array(crypto_scalarmult_BYTES);
|
|
2119
|
-
crypto_scalarmult_base(q, n);
|
|
2120
|
-
return q;
|
|
2121
|
-
};
|
|
2122
|
-
nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES;
|
|
2123
|
-
nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES;
|
|
2124
|
-
nacl.box = function(msg, nonce, publicKey, secretKey) {
|
|
2125
|
-
var k = nacl.box.before(publicKey, secretKey);
|
|
2126
|
-
return nacl.secretbox(msg, nonce, k);
|
|
2127
|
-
};
|
|
2128
|
-
nacl.box.before = function(publicKey, secretKey) {
|
|
2129
|
-
checkArrayTypes(publicKey, secretKey);
|
|
2130
|
-
checkBoxLengths(publicKey, secretKey);
|
|
2131
|
-
var k = new Uint8Array(crypto_box_BEFORENMBYTES);
|
|
2132
|
-
crypto_box_beforenm(k, publicKey, secretKey);
|
|
2133
|
-
return k;
|
|
2134
|
-
};
|
|
2135
|
-
nacl.box.after = nacl.secretbox;
|
|
2136
|
-
nacl.box.open = function(msg, nonce, publicKey, secretKey) {
|
|
2137
|
-
var k = nacl.box.before(publicKey, secretKey);
|
|
2138
|
-
return nacl.secretbox.open(msg, nonce, k);
|
|
2139
|
-
};
|
|
2140
|
-
nacl.box.open.after = nacl.secretbox.open;
|
|
2141
|
-
nacl.box.keyPair = function() {
|
|
2142
|
-
var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
|
|
2143
|
-
var sk = new Uint8Array(crypto_box_SECRETKEYBYTES);
|
|
2144
|
-
crypto_box_keypair(pk, sk);
|
|
2145
|
-
return { publicKey: pk, secretKey: sk };
|
|
2146
|
-
};
|
|
2147
|
-
nacl.box.keyPair.fromSecretKey = function(secretKey) {
|
|
2148
|
-
checkArrayTypes(secretKey);
|
|
2149
|
-
if (secretKey.length !== crypto_box_SECRETKEYBYTES)
|
|
2150
|
-
throw new Error("bad secret key size");
|
|
2151
|
-
var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
|
|
2152
|
-
crypto_scalarmult_base(pk, secretKey);
|
|
2153
|
-
return { publicKey: pk, secretKey: new Uint8Array(secretKey) };
|
|
2154
|
-
};
|
|
2155
|
-
nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES;
|
|
2156
|
-
nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES;
|
|
2157
|
-
nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES;
|
|
2158
|
-
nacl.box.nonceLength = crypto_box_NONCEBYTES;
|
|
2159
|
-
nacl.box.overheadLength = nacl.secretbox.overheadLength;
|
|
2160
|
-
nacl.sign = function(msg, secretKey) {
|
|
2161
|
-
checkArrayTypes(msg, secretKey);
|
|
2162
|
-
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
|
|
2163
|
-
throw new Error("bad secret key size");
|
|
2164
|
-
var signedMsg = new Uint8Array(crypto_sign_BYTES + msg.length);
|
|
2165
|
-
crypto_sign(signedMsg, msg, msg.length, secretKey);
|
|
2166
|
-
return signedMsg;
|
|
2167
|
-
};
|
|
2168
|
-
nacl.sign.open = function(signedMsg, publicKey) {
|
|
2169
|
-
checkArrayTypes(signedMsg, publicKey);
|
|
2170
|
-
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
|
|
2171
|
-
throw new Error("bad public key size");
|
|
2172
|
-
var tmp = new Uint8Array(signedMsg.length);
|
|
2173
|
-
var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey);
|
|
2174
|
-
if (mlen < 0) return null;
|
|
2175
|
-
var m = new Uint8Array(mlen);
|
|
2176
|
-
for (var i = 0; i < m.length; i++) m[i] = tmp[i];
|
|
2177
|
-
return m;
|
|
2178
|
-
};
|
|
2179
|
-
nacl.sign.detached = function(msg, secretKey) {
|
|
2180
|
-
var signedMsg = nacl.sign(msg, secretKey);
|
|
2181
|
-
var sig = new Uint8Array(crypto_sign_BYTES);
|
|
2182
|
-
for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i];
|
|
2183
|
-
return sig;
|
|
2184
|
-
};
|
|
2185
|
-
nacl.sign.detached.verify = function(msg, sig, publicKey) {
|
|
2186
|
-
checkArrayTypes(msg, sig, publicKey);
|
|
2187
|
-
if (sig.length !== crypto_sign_BYTES)
|
|
2188
|
-
throw new Error("bad signature size");
|
|
2189
|
-
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
|
|
2190
|
-
throw new Error("bad public key size");
|
|
2191
|
-
var sm = new Uint8Array(crypto_sign_BYTES + msg.length);
|
|
2192
|
-
var m = new Uint8Array(crypto_sign_BYTES + msg.length);
|
|
2193
|
-
var i;
|
|
2194
|
-
for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i];
|
|
2195
|
-
for (i = 0; i < msg.length; i++) sm[i + crypto_sign_BYTES] = msg[i];
|
|
2196
|
-
return crypto_sign_open(m, sm, sm.length, publicKey) >= 0;
|
|
2197
|
-
};
|
|
2198
|
-
nacl.sign.keyPair = function() {
|
|
2199
|
-
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
2200
|
-
var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
|
|
2201
|
-
crypto_sign_keypair(pk, sk);
|
|
2202
|
-
return { publicKey: pk, secretKey: sk };
|
|
2203
|
-
};
|
|
2204
|
-
nacl.sign.keyPair.fromSecretKey = function(secretKey) {
|
|
2205
|
-
checkArrayTypes(secretKey);
|
|
2206
|
-
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
|
|
2207
|
-
throw new Error("bad secret key size");
|
|
2208
|
-
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
2209
|
-
for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32 + i];
|
|
2210
|
-
return { publicKey: pk, secretKey: new Uint8Array(secretKey) };
|
|
2211
|
-
};
|
|
2212
|
-
nacl.sign.keyPair.fromSeed = function(seed) {
|
|
2213
|
-
checkArrayTypes(seed);
|
|
2214
|
-
if (seed.length !== crypto_sign_SEEDBYTES)
|
|
2215
|
-
throw new Error("bad seed size");
|
|
2216
|
-
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
2217
|
-
var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
|
|
2218
|
-
for (var i = 0; i < 32; i++) sk[i] = seed[i];
|
|
2219
|
-
crypto_sign_keypair(pk, sk, true);
|
|
2220
|
-
return { publicKey: pk, secretKey: sk };
|
|
2221
|
-
};
|
|
2222
|
-
nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES;
|
|
2223
|
-
nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES;
|
|
2224
|
-
nacl.sign.seedLength = crypto_sign_SEEDBYTES;
|
|
2225
|
-
nacl.sign.signatureLength = crypto_sign_BYTES;
|
|
2226
|
-
nacl.hash = function(msg) {
|
|
2227
|
-
checkArrayTypes(msg);
|
|
2228
|
-
var h = new Uint8Array(crypto_hash_BYTES);
|
|
2229
|
-
crypto_hash(h, msg, msg.length);
|
|
2230
|
-
return h;
|
|
2231
|
-
};
|
|
2232
|
-
nacl.hash.hashLength = crypto_hash_BYTES;
|
|
2233
|
-
nacl.verify = function(x, y) {
|
|
2234
|
-
checkArrayTypes(x, y);
|
|
2235
|
-
if (x.length === 0 || y.length === 0) return false;
|
|
2236
|
-
if (x.length !== y.length) return false;
|
|
2237
|
-
return vn(x, 0, y, 0, x.length) === 0 ? true : false;
|
|
2238
|
-
};
|
|
2239
|
-
nacl.setPRNG = function(fn) {
|
|
2240
|
-
randombytes = fn;
|
|
2241
|
-
};
|
|
2242
|
-
(function() {
|
|
2243
|
-
var crypto2 = typeof self !== "undefined" ? self.crypto || self.msCrypto : null;
|
|
2244
|
-
if (crypto2 && crypto2.getRandomValues) {
|
|
2245
|
-
var QUOTA = 65536;
|
|
2246
|
-
nacl.setPRNG(function(x, n) {
|
|
2247
|
-
var i, v = new Uint8Array(n);
|
|
2248
|
-
for (i = 0; i < n; i += QUOTA) {
|
|
2249
|
-
crypto2.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
|
|
2250
|
-
}
|
|
2251
|
-
for (i = 0; i < n; i++) x[i] = v[i];
|
|
2252
|
-
cleanup(v);
|
|
2253
|
-
});
|
|
2254
|
-
} else if (typeof __require !== "undefined") {
|
|
2255
|
-
crypto2 = __require("crypto");
|
|
2256
|
-
if (crypto2 && crypto2.randomBytes) {
|
|
2257
|
-
nacl.setPRNG(function(x, n) {
|
|
2258
|
-
var i, v = crypto2.randomBytes(n);
|
|
2259
|
-
for (i = 0; i < n; i++) x[i] = v[i];
|
|
2260
|
-
cleanup(v);
|
|
2261
|
-
});
|
|
2262
|
-
}
|
|
2263
|
-
}
|
|
2264
|
-
})();
|
|
2265
|
-
})(typeof module !== "undefined" && module.exports ? module.exports : self.nacl = self.nacl || {});
|
|
2266
|
-
}
|
|
2267
|
-
});
|
|
2268
|
-
|
|
2269
|
-
// ../../node_modules/base-x/src/index.js
|
|
2270
|
-
var require_src = __commonJS({
|
|
2271
|
-
"../../node_modules/base-x/src/index.js"(exports$1, module) {
|
|
2272
|
-
function base(ALPHABET) {
|
|
2273
|
-
if (ALPHABET.length >= 255) {
|
|
2274
|
-
throw new TypeError("Alphabet too long");
|
|
2275
|
-
}
|
|
2276
|
-
var BASE_MAP = new Uint8Array(256);
|
|
2277
|
-
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
2278
|
-
BASE_MAP[j] = 255;
|
|
2279
|
-
}
|
|
2280
|
-
for (var i = 0; i < ALPHABET.length; i++) {
|
|
2281
|
-
var x = ALPHABET.charAt(i);
|
|
2282
|
-
var xc = x.charCodeAt(0);
|
|
2283
|
-
if (BASE_MAP[xc] !== 255) {
|
|
2284
|
-
throw new TypeError(x + " is ambiguous");
|
|
2285
|
-
}
|
|
2286
|
-
BASE_MAP[xc] = i;
|
|
2287
|
-
}
|
|
2288
|
-
var BASE = ALPHABET.length;
|
|
2289
|
-
var LEADER = ALPHABET.charAt(0);
|
|
2290
|
-
var FACTOR = Math.log(BASE) / Math.log(256);
|
|
2291
|
-
var iFACTOR = Math.log(256) / Math.log(BASE);
|
|
2292
|
-
function encode(source) {
|
|
2293
|
-
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
2294
|
-
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
2295
|
-
} else if (Array.isArray(source)) {
|
|
2296
|
-
source = Uint8Array.from(source);
|
|
2297
|
-
}
|
|
2298
|
-
if (!(source instanceof Uint8Array)) {
|
|
2299
|
-
throw new TypeError("Expected Uint8Array");
|
|
2300
|
-
}
|
|
2301
|
-
if (source.length === 0) {
|
|
2302
|
-
return "";
|
|
2303
|
-
}
|
|
2304
|
-
var zeroes = 0;
|
|
2305
|
-
var length = 0;
|
|
2306
|
-
var pbegin = 0;
|
|
2307
|
-
var pend = source.length;
|
|
2308
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
2309
|
-
pbegin++;
|
|
2310
|
-
zeroes++;
|
|
2311
|
-
}
|
|
2312
|
-
var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
|
|
2313
|
-
var b58 = new Uint8Array(size);
|
|
2314
|
-
while (pbegin !== pend) {
|
|
2315
|
-
var carry = source[pbegin];
|
|
2316
|
-
var i2 = 0;
|
|
2317
|
-
for (var it1 = size - 1; (carry !== 0 || i2 < length) && it1 !== -1; it1--, i2++) {
|
|
2318
|
-
carry += 256 * b58[it1] >>> 0;
|
|
2319
|
-
b58[it1] = carry % BASE >>> 0;
|
|
2320
|
-
carry = carry / BASE >>> 0;
|
|
2321
|
-
}
|
|
2322
|
-
if (carry !== 0) {
|
|
2323
|
-
throw new Error("Non-zero carry");
|
|
2324
|
-
}
|
|
2325
|
-
length = i2;
|
|
2326
|
-
pbegin++;
|
|
2327
|
-
}
|
|
2328
|
-
var it2 = size - length;
|
|
2329
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
2330
|
-
it2++;
|
|
2331
|
-
}
|
|
2332
|
-
var str = LEADER.repeat(zeroes);
|
|
2333
|
-
for (; it2 < size; ++it2) {
|
|
2334
|
-
str += ALPHABET.charAt(b58[it2]);
|
|
2335
|
-
}
|
|
2336
|
-
return str;
|
|
2337
|
-
}
|
|
2338
|
-
function decodeUnsafe(source) {
|
|
2339
|
-
if (typeof source !== "string") {
|
|
2340
|
-
throw new TypeError("Expected String");
|
|
2341
|
-
}
|
|
2342
|
-
if (source.length === 0) {
|
|
2343
|
-
return new Uint8Array();
|
|
2344
|
-
}
|
|
2345
|
-
var psz = 0;
|
|
2346
|
-
var zeroes = 0;
|
|
2347
|
-
var length = 0;
|
|
2348
|
-
while (source[psz] === LEADER) {
|
|
2349
|
-
zeroes++;
|
|
2350
|
-
psz++;
|
|
2351
|
-
}
|
|
2352
|
-
var size = (source.length - psz) * FACTOR + 1 >>> 0;
|
|
2353
|
-
var b256 = new Uint8Array(size);
|
|
2354
|
-
while (source[psz]) {
|
|
2355
|
-
var charCode = source.charCodeAt(psz);
|
|
2356
|
-
if (charCode > 255) {
|
|
2357
|
-
return;
|
|
2358
|
-
}
|
|
2359
|
-
var carry = BASE_MAP[charCode];
|
|
2360
|
-
if (carry === 255) {
|
|
2361
|
-
return;
|
|
2362
|
-
}
|
|
2363
|
-
var i2 = 0;
|
|
2364
|
-
for (var it3 = size - 1; (carry !== 0 || i2 < length) && it3 !== -1; it3--, i2++) {
|
|
2365
|
-
carry += BASE * b256[it3] >>> 0;
|
|
2366
|
-
b256[it3] = carry % 256 >>> 0;
|
|
2367
|
-
carry = carry / 256 >>> 0;
|
|
2368
|
-
}
|
|
2369
|
-
if (carry !== 0) {
|
|
2370
|
-
throw new Error("Non-zero carry");
|
|
2371
|
-
}
|
|
2372
|
-
length = i2;
|
|
2373
|
-
psz++;
|
|
2374
|
-
}
|
|
2375
|
-
var it4 = size - length;
|
|
2376
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
2377
|
-
it4++;
|
|
2378
|
-
}
|
|
2379
|
-
var vch = new Uint8Array(zeroes + (size - it4));
|
|
2380
|
-
var j2 = zeroes;
|
|
2381
|
-
while (it4 !== size) {
|
|
2382
|
-
vch[j2++] = b256[it4++];
|
|
2383
|
-
}
|
|
2384
|
-
return vch;
|
|
2385
|
-
}
|
|
2386
|
-
function decode(string) {
|
|
2387
|
-
var buffer = decodeUnsafe(string);
|
|
2388
|
-
if (buffer) {
|
|
2389
|
-
return buffer;
|
|
2390
|
-
}
|
|
2391
|
-
throw new Error("Non-base" + BASE + " character");
|
|
2392
|
-
}
|
|
2393
|
-
return {
|
|
2394
|
-
encode,
|
|
2395
|
-
decodeUnsafe,
|
|
2396
|
-
decode
|
|
2397
|
-
};
|
|
2398
|
-
}
|
|
2399
|
-
module.exports = base;
|
|
2400
|
-
}
|
|
2401
|
-
});
|
|
2402
|
-
|
|
2403
|
-
// ../../node_modules/bs58/index.js
|
|
2404
|
-
var require_bs58 = __commonJS({
|
|
2405
|
-
"../../node_modules/bs58/index.js"(exports$1, module) {
|
|
2406
|
-
var basex = require_src();
|
|
2407
|
-
var ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
2408
|
-
module.exports = basex(ALPHABET);
|
|
2409
|
-
}
|
|
2410
|
-
});
|
|
2411
19
|
|
|
2412
20
|
// src/config/networks.ts
|
|
2413
21
|
var NETWORKS = {
|
|
@@ -3216,352 +824,52 @@ var WdkApiClient = class {
|
|
|
3216
824
|
};
|
|
3217
825
|
}
|
|
3218
826
|
}
|
|
3219
|
-
/**
|
|
3220
|
-
* Derive addresses for all chains using Tether WDK
|
|
3221
|
-
*/
|
|
3222
|
-
async deriveAllAddresses(seed, network = "testnet") {
|
|
3223
|
-
try {
|
|
3224
|
-
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/derive-all`, {
|
|
3225
|
-
method: "POST",
|
|
3226
|
-
headers: {
|
|
3227
|
-
"Content-Type": "application/json"
|
|
3228
|
-
},
|
|
3229
|
-
body: JSON.stringify({ seed, network })
|
|
3230
|
-
});
|
|
3231
|
-
return await response.json();
|
|
3232
|
-
} catch (error) {
|
|
3233
|
-
return {
|
|
3234
|
-
success: false,
|
|
3235
|
-
error: error instanceof Error ? error.message : "Failed to derive addresses"
|
|
3236
|
-
};
|
|
3237
|
-
}
|
|
3238
|
-
}
|
|
3239
|
-
};
|
|
3240
|
-
var DEFAULT_API_URL = process.env.NEXT_PUBLIC_API_URL || "http://localhost:3001";
|
|
3241
|
-
var wdkApiClient = null;
|
|
3242
|
-
function getWdkApiClient(baseUrl) {
|
|
3243
|
-
if (!wdkApiClient || baseUrl && wdkApiClient["config"].baseUrl !== baseUrl) {
|
|
3244
|
-
wdkApiClient = new WdkApiClient({
|
|
3245
|
-
baseUrl: baseUrl || DEFAULT_API_URL
|
|
3246
|
-
});
|
|
3247
|
-
}
|
|
3248
|
-
return wdkApiClient;
|
|
3249
|
-
}
|
|
3250
|
-
|
|
3251
|
-
// src/services/WdkService.ts
|
|
3252
|
-
var WdkManager;
|
|
3253
|
-
var WalletManagerBtc;
|
|
3254
|
-
var WalletManagerEvm;
|
|
3255
|
-
var WalletManagerSolana;
|
|
3256
|
-
var WalletManagerTon;
|
|
3257
|
-
var WalletManagerTron;
|
|
3258
|
-
var WalletManagerSpark;
|
|
3259
|
-
var wdkLoaded = false;
|
|
3260
|
-
var wdkLoadError = null;
|
|
3261
|
-
var dynamicImport = new Function("specifier", "return import(specifier)");
|
|
3262
|
-
async function loadWdkModules() {
|
|
3263
|
-
if (wdkLoaded) return;
|
|
3264
|
-
if (wdkLoadError) throw wdkLoadError;
|
|
3265
|
-
try {
|
|
3266
|
-
const [wdk, btc, evm, solana, ton, tron, spark] = await Promise.all([
|
|
3267
|
-
dynamicImport("@tetherto/wdk"),
|
|
3268
|
-
dynamicImport("@tetherto/wdk-wallet-btc"),
|
|
3269
|
-
dynamicImport("@tetherto/wdk-wallet-evm"),
|
|
3270
|
-
dynamicImport("@tetherto/wdk-wallet-solana"),
|
|
3271
|
-
dynamicImport("@tetherto/wdk-wallet-ton"),
|
|
3272
|
-
dynamicImport("@tetherto/wdk-wallet-tron"),
|
|
3273
|
-
dynamicImport("@tetherto/wdk-wallet-spark")
|
|
3274
|
-
]);
|
|
3275
|
-
WdkManager = wdk.default;
|
|
3276
|
-
WalletManagerBtc = btc.default;
|
|
3277
|
-
WalletManagerEvm = evm.default;
|
|
3278
|
-
WalletManagerSolana = solana.default;
|
|
3279
|
-
WalletManagerTon = ton.default;
|
|
3280
|
-
WalletManagerTron = tron.default;
|
|
3281
|
-
WalletManagerSpark = spark.default;
|
|
3282
|
-
wdkLoaded = true;
|
|
3283
|
-
} catch (error) {
|
|
3284
|
-
wdkLoadError = error instanceof Error ? error : new Error("Failed to load WDK modules");
|
|
3285
|
-
console.error("Failed to load WDK modules:", error);
|
|
3286
|
-
throw wdkLoadError;
|
|
3287
|
-
}
|
|
3288
|
-
}
|
|
3289
|
-
var DERIVATION_PATHS2 = {
|
|
3290
|
-
bitcoin: "m/84'/0'/0'/0/0",
|
|
3291
|
-
// BIP-84 for native SegWit
|
|
3292
|
-
ethereum: "m/44'/60'/0'/0/0",
|
|
3293
|
-
ton: "m/44'/607'/0'",
|
|
3294
|
-
// Updated for v1.0.0-beta.6+
|
|
3295
|
-
tron: "m/44'/195'/0'/0/0",
|
|
3296
|
-
solana: "m/44'/501'/0'/0'",
|
|
3297
|
-
// Updated for v1.0.0-beta.4+
|
|
3298
|
-
spark: "m/44'/998'/0'/0/0"
|
|
3299
|
-
};
|
|
3300
|
-
var DEFAULT_RPC_URLS = {
|
|
3301
|
-
mainnet: {
|
|
3302
|
-
ethereum: "https://eth.llamarpc.com",
|
|
3303
|
-
solana: "https://api.mainnet-beta.solana.com",
|
|
3304
|
-
ton: "https://toncenter.com/api/v2/jsonRPC",
|
|
3305
|
-
tron: "https://api.trongrid.io"
|
|
3306
|
-
},
|
|
3307
|
-
testnet: {
|
|
3308
|
-
ethereum: "https://ethereum-sepolia-rpc.publicnode.com",
|
|
3309
|
-
solana: "https://api.devnet.solana.com",
|
|
3310
|
-
ton: "https://testnet.toncenter.com/api/v2/jsonRPC",
|
|
3311
|
-
tron: "https://api.shasta.trongrid.io"
|
|
3312
|
-
}
|
|
3313
|
-
};
|
|
3314
|
-
var WdkService = class {
|
|
3315
|
-
seed = null;
|
|
3316
|
-
config;
|
|
3317
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3318
|
-
wallets = {};
|
|
3319
|
-
constructor(config = {}) {
|
|
3320
|
-
this.config = {
|
|
3321
|
-
network: config.network || "testnet",
|
|
3322
|
-
rpcUrls: config.rpcUrls
|
|
3323
|
-
};
|
|
3324
|
-
}
|
|
3325
|
-
/**
|
|
3326
|
-
* Check if WDK modules are loaded
|
|
3327
|
-
*/
|
|
3328
|
-
static isLoaded() {
|
|
3329
|
-
return wdkLoaded;
|
|
3330
|
-
}
|
|
3331
|
-
/**
|
|
3332
|
-
* Ensure WDK modules are loaded
|
|
3333
|
-
*/
|
|
3334
|
-
async ensureLoaded() {
|
|
3335
|
-
await loadWdkModules();
|
|
3336
|
-
}
|
|
3337
|
-
/**
|
|
3338
|
-
* Load WDK modules (call this before using sync methods)
|
|
3339
|
-
*/
|
|
3340
|
-
async loadModules() {
|
|
3341
|
-
await loadWdkModules();
|
|
3342
|
-
}
|
|
3343
|
-
/**
|
|
3344
|
-
* Generate a random BIP-39 seed phrase (12 words)
|
|
3345
|
-
*/
|
|
3346
|
-
async generateSeedPhrase() {
|
|
3347
|
-
await this.ensureLoaded();
|
|
3348
|
-
return WdkManager.getRandomSeedPhrase();
|
|
3349
|
-
}
|
|
3350
|
-
/**
|
|
3351
|
-
* Validate a BIP-39 seed phrase
|
|
3352
|
-
*/
|
|
3353
|
-
async isValidSeed(seed) {
|
|
3354
|
-
await this.ensureLoaded();
|
|
3355
|
-
return WdkManager.isValidSeed(seed);
|
|
3356
|
-
}
|
|
3357
|
-
/**
|
|
3358
|
-
* Validate seed phrase (sync version - basic check)
|
|
3359
|
-
*/
|
|
3360
|
-
isValidSeedSync(seed) {
|
|
3361
|
-
const words = seed.trim().split(/\s+/);
|
|
3362
|
-
return words.length === 12 || words.length === 24;
|
|
3363
|
-
}
|
|
3364
|
-
/**
|
|
3365
|
-
* Initialize the service with a seed phrase
|
|
3366
|
-
*/
|
|
3367
|
-
async initialize(seed) {
|
|
3368
|
-
await this.ensureLoaded();
|
|
3369
|
-
if (!WdkManager.isValidSeed(seed)) {
|
|
3370
|
-
throw new Error("Invalid seed phrase");
|
|
3371
|
-
}
|
|
3372
|
-
this.seed = seed;
|
|
3373
|
-
this.wallets = {};
|
|
3374
|
-
}
|
|
3375
|
-
/**
|
|
3376
|
-
* Get RPC URL for a chain
|
|
3377
|
-
*/
|
|
3378
|
-
getRpcUrl(chain) {
|
|
3379
|
-
const networkUrls = DEFAULT_RPC_URLS[this.config.network];
|
|
3380
|
-
if (this.config.rpcUrls?.[chain]) {
|
|
3381
|
-
return this.config.rpcUrls[chain];
|
|
3382
|
-
}
|
|
3383
|
-
return networkUrls[chain] || "";
|
|
3384
|
-
}
|
|
3385
|
-
/**
|
|
3386
|
-
* Get or create wallet instance for a specific chain
|
|
3387
|
-
*/
|
|
3388
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3389
|
-
async getWallet(chain) {
|
|
3390
|
-
if (!this.seed) {
|
|
3391
|
-
throw new Error("WDK service not initialized. Call initialize() first.");
|
|
3392
|
-
}
|
|
3393
|
-
if (this.wallets[chain]) {
|
|
3394
|
-
return this.wallets[chain];
|
|
3395
|
-
}
|
|
3396
|
-
const isTestnet = this.config.network === "testnet";
|
|
3397
|
-
try {
|
|
3398
|
-
switch (chain) {
|
|
3399
|
-
case "ethereum": {
|
|
3400
|
-
const rpcUrl = this.getRpcUrl("ethereum");
|
|
3401
|
-
const wallet = new WalletManagerEvm(this.seed, { provider: rpcUrl });
|
|
3402
|
-
this.wallets[chain] = wallet;
|
|
3403
|
-
return wallet;
|
|
3404
|
-
}
|
|
3405
|
-
case "bitcoin": {
|
|
3406
|
-
const wallet = new WalletManagerBtc(this.seed, {
|
|
3407
|
-
network: isTestnet ? "testnet" : "bitcoin"
|
|
3408
|
-
});
|
|
3409
|
-
this.wallets[chain] = wallet;
|
|
3410
|
-
return wallet;
|
|
3411
|
-
}
|
|
3412
|
-
case "solana": {
|
|
3413
|
-
const rpcUrl = this.getRpcUrl("solana");
|
|
3414
|
-
const wallet = new WalletManagerSolana(this.seed, {
|
|
3415
|
-
rpcUrl
|
|
3416
|
-
});
|
|
3417
|
-
this.wallets[chain] = wallet;
|
|
3418
|
-
return wallet;
|
|
3419
|
-
}
|
|
3420
|
-
case "ton": {
|
|
3421
|
-
const url = this.getRpcUrl("ton");
|
|
3422
|
-
const wallet = new WalletManagerTon(this.seed, {
|
|
3423
|
-
tonClient: { url }
|
|
3424
|
-
});
|
|
3425
|
-
this.wallets[chain] = wallet;
|
|
3426
|
-
return wallet;
|
|
3427
|
-
}
|
|
3428
|
-
case "tron": {
|
|
3429
|
-
const fullHost = this.getRpcUrl("tron");
|
|
3430
|
-
const wallet = new WalletManagerTron(this.seed, {
|
|
3431
|
-
provider: fullHost
|
|
3432
|
-
});
|
|
3433
|
-
this.wallets[chain] = wallet;
|
|
3434
|
-
return wallet;
|
|
3435
|
-
}
|
|
3436
|
-
case "spark": {
|
|
3437
|
-
const wallet = new WalletManagerSpark(this.seed, {
|
|
3438
|
-
network: isTestnet ? "TESTNET" : "MAINNET"
|
|
3439
|
-
});
|
|
3440
|
-
this.wallets[chain] = wallet;
|
|
3441
|
-
return wallet;
|
|
3442
|
-
}
|
|
3443
|
-
default:
|
|
3444
|
-
throw new Error(`Unsupported chain: ${chain}`);
|
|
3445
|
-
}
|
|
3446
|
-
} catch (error) {
|
|
3447
|
-
console.error(`Failed to initialize ${chain} wallet:`, error);
|
|
3448
|
-
throw error;
|
|
3449
|
-
}
|
|
3450
|
-
}
|
|
3451
|
-
/**
|
|
3452
|
-
* Derive address for a specific chain
|
|
3453
|
-
*/
|
|
3454
|
-
async deriveAddress(chain) {
|
|
3455
|
-
const path = DERIVATION_PATHS2[chain];
|
|
3456
|
-
try {
|
|
3457
|
-
const wallet = await this.getWallet(chain);
|
|
3458
|
-
const account = await wallet.getAccount(0);
|
|
3459
|
-
const address = await account.getAddress();
|
|
3460
|
-
return {
|
|
3461
|
-
chain,
|
|
3462
|
-
address,
|
|
3463
|
-
path
|
|
3464
|
-
};
|
|
3465
|
-
} catch (error) {
|
|
3466
|
-
console.error(`Error deriving ${chain} address:`, error);
|
|
3467
|
-
throw error;
|
|
3468
|
-
}
|
|
3469
|
-
}
|
|
3470
|
-
/**
|
|
3471
|
-
* Derive addresses for all supported chains
|
|
3472
|
-
*/
|
|
3473
|
-
async deriveAllAddresses() {
|
|
3474
|
-
const chains = ["ethereum", "bitcoin", "ton", "tron", "solana", "spark"];
|
|
3475
|
-
const addresses = {
|
|
3476
|
-
ethereum: null,
|
|
3477
|
-
bitcoin: null,
|
|
3478
|
-
ton: null,
|
|
3479
|
-
tron: null,
|
|
3480
|
-
solana: null,
|
|
3481
|
-
spark: null
|
|
3482
|
-
};
|
|
3483
|
-
const results = await Promise.allSettled(
|
|
3484
|
-
chains.map(async (chain) => {
|
|
3485
|
-
const result = await this.deriveAddress(chain);
|
|
3486
|
-
return { chain, address: result.address };
|
|
3487
|
-
})
|
|
3488
|
-
);
|
|
3489
|
-
for (const result of results) {
|
|
3490
|
-
if (result.status === "fulfilled") {
|
|
3491
|
-
addresses[result.value.chain] = result.value.address;
|
|
3492
|
-
} else {
|
|
3493
|
-
console.error("Failed to derive address:", result.reason);
|
|
3494
|
-
}
|
|
3495
|
-
}
|
|
3496
|
-
return addresses;
|
|
3497
|
-
}
|
|
3498
|
-
/**
|
|
3499
|
-
* Derive addresses for specific chains only
|
|
3500
|
-
*/
|
|
3501
|
-
async deriveAddressesForChains(chains) {
|
|
3502
|
-
const addresses = {};
|
|
3503
|
-
const results = await Promise.allSettled(
|
|
3504
|
-
chains.map(async (chain) => {
|
|
3505
|
-
const result = await this.deriveAddress(chain);
|
|
3506
|
-
return { chain, address: result.address };
|
|
3507
|
-
})
|
|
3508
|
-
);
|
|
3509
|
-
for (const result of results) {
|
|
3510
|
-
if (result.status === "fulfilled") {
|
|
3511
|
-
addresses[result.value.chain] = result.value.address;
|
|
3512
|
-
}
|
|
3513
|
-
}
|
|
3514
|
-
return addresses;
|
|
3515
|
-
}
|
|
3516
|
-
/**
|
|
3517
|
-
* Get fee rates for a specific chain
|
|
3518
|
-
*/
|
|
3519
|
-
async getFeeRates(chain) {
|
|
3520
|
-
if (!this.seed) {
|
|
3521
|
-
throw new Error("WDK service not initialized. Call initialize() first.");
|
|
3522
|
-
}
|
|
3523
|
-
try {
|
|
3524
|
-
const wallet = await this.getWallet(chain);
|
|
3525
|
-
const feeRates = await wallet.getFeeRates();
|
|
3526
|
-
return {
|
|
3527
|
-
slow: (feeRates.slow || feeRates.low || "0").toString(),
|
|
3528
|
-
medium: (feeRates.medium || feeRates.normal || feeRates.standard || "0").toString(),
|
|
3529
|
-
fast: (feeRates.fast || feeRates.high || "0").toString()
|
|
3530
|
-
};
|
|
3531
|
-
} catch (error) {
|
|
3532
|
-
console.error(`Error fetching fee rates for ${chain}:`, error);
|
|
3533
|
-
throw error;
|
|
3534
|
-
}
|
|
3535
|
-
}
|
|
3536
|
-
/**
|
|
3537
|
-
* Get the current network configuration
|
|
3538
|
-
*/
|
|
3539
|
-
getNetwork() {
|
|
3540
|
-
return this.config.network;
|
|
3541
|
-
}
|
|
3542
|
-
/**
|
|
3543
|
-
* Check if service is initialized
|
|
3544
|
-
*/
|
|
3545
|
-
isInitialized() {
|
|
3546
|
-
return this.seed !== null;
|
|
3547
|
-
}
|
|
3548
|
-
/**
|
|
3549
|
-
* Clean up and dispose of wallet instances
|
|
3550
|
-
*/
|
|
3551
|
-
dispose() {
|
|
3552
|
-
for (const wallet of Object.values(this.wallets)) {
|
|
3553
|
-
if (wallet && typeof wallet.dispose === "function") {
|
|
3554
|
-
try {
|
|
3555
|
-
wallet.dispose();
|
|
3556
|
-
} catch {
|
|
3557
|
-
}
|
|
3558
|
-
}
|
|
827
|
+
/**
|
|
828
|
+
* Derive addresses for all chains using Tether WDK
|
|
829
|
+
*/
|
|
830
|
+
async deriveAllAddresses(seed, network = "testnet") {
|
|
831
|
+
try {
|
|
832
|
+
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/derive-all`, {
|
|
833
|
+
method: "POST",
|
|
834
|
+
headers: {
|
|
835
|
+
"Content-Type": "application/json"
|
|
836
|
+
},
|
|
837
|
+
body: JSON.stringify({ seed, network })
|
|
838
|
+
});
|
|
839
|
+
return await response.json();
|
|
840
|
+
} catch (error) {
|
|
841
|
+
return {
|
|
842
|
+
success: false,
|
|
843
|
+
error: error instanceof Error ? error.message : "Failed to derive addresses"
|
|
844
|
+
};
|
|
3559
845
|
}
|
|
3560
|
-
this.wallets = {};
|
|
3561
|
-
this.seed = null;
|
|
3562
846
|
}
|
|
3563
847
|
};
|
|
3564
|
-
var
|
|
848
|
+
var DEFAULT_API_URL = process.env.NEXT_PUBLIC_API_URL || "https://ckgwifsxka.us-east-2.awsapprunner.com";
|
|
849
|
+
var wdkApiClient = null;
|
|
850
|
+
function getWdkApiClient(baseUrl) {
|
|
851
|
+
if (!wdkApiClient || baseUrl && wdkApiClient["config"].baseUrl !== baseUrl) {
|
|
852
|
+
wdkApiClient = new WdkApiClient({
|
|
853
|
+
baseUrl: baseUrl || DEFAULT_API_URL
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
return wdkApiClient;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
// src/services/BrowserAddressDerivation.ts
|
|
860
|
+
var BrowserAddressDerivation_exports = {};
|
|
861
|
+
__export(BrowserAddressDerivation_exports, {
|
|
862
|
+
deriveAllAddresses: () => deriveAllAddresses,
|
|
863
|
+
deriveBitcoinAddress: () => deriveBitcoinAddress,
|
|
864
|
+
deriveEthereumAddress: () => deriveEthereumAddress,
|
|
865
|
+
deriveSolanaAddress: () => deriveSolanaAddress,
|
|
866
|
+
deriveSparkAddress: () => deriveSparkAddress,
|
|
867
|
+
deriveTonAddress: () => deriveTonAddress,
|
|
868
|
+
deriveTronAddress: () => deriveTronAddress,
|
|
869
|
+
generateSeedPhrase: () => generateSeedPhrase,
|
|
870
|
+
isValidSeed: () => isValidSeed
|
|
871
|
+
});
|
|
872
|
+
var DERIVATION_PATHS2 = {
|
|
3565
873
|
ethereum: "m/44'/60'/0'/0/0",
|
|
3566
874
|
bitcoin_mainnet: "m/84'/0'/0'/0/0",
|
|
3567
875
|
bitcoin_testnet: "m/84'/1'/0'/0/0",
|
|
@@ -3571,14 +879,14 @@ var DERIVATION_PATHS3 = {
|
|
|
3571
879
|
spark: "m/44'/998'/0'/0/0"
|
|
3572
880
|
};
|
|
3573
881
|
function deriveEthereumAddress(seed) {
|
|
3574
|
-
const hdNode = ethers.HDNodeWallet.fromPhrase(seed, void 0,
|
|
882
|
+
const hdNode = ethers.HDNodeWallet.fromPhrase(seed, void 0, DERIVATION_PATHS2.ethereum);
|
|
3575
883
|
return hdNode.address;
|
|
3576
884
|
}
|
|
3577
885
|
function deriveBitcoinAddress(seed, network = "testnet") {
|
|
3578
886
|
try {
|
|
3579
887
|
const seedBytes = bip39.mnemonicToSeedSync(seed);
|
|
3580
888
|
const hdKey = bip32.HDKey.fromMasterSeed(seedBytes);
|
|
3581
|
-
const path = network === "testnet" ?
|
|
889
|
+
const path = network === "testnet" ? DERIVATION_PATHS2.bitcoin_testnet : DERIVATION_PATHS2.bitcoin_mainnet;
|
|
3582
890
|
const child = hdKey.derive(path);
|
|
3583
891
|
if (!child.publicKey) {
|
|
3584
892
|
throw new Error("Failed to derive public key");
|
|
@@ -3597,13 +905,14 @@ function deriveBitcoinAddress(seed, network = "testnet") {
|
|
|
3597
905
|
}
|
|
3598
906
|
async function deriveSolanaAddress(seed) {
|
|
3599
907
|
try {
|
|
3600
|
-
const [ed25519, nacl,
|
|
908
|
+
const [ed25519, nacl, bs58Module] = await Promise.all([
|
|
3601
909
|
import('ed25519-hd-key'),
|
|
3602
|
-
|
|
3603
|
-
|
|
910
|
+
import('tweetnacl'),
|
|
911
|
+
import('bs58')
|
|
3604
912
|
]);
|
|
913
|
+
const bs58 = bs58Module.default || bs58Module;
|
|
3605
914
|
const seedBytes = bip39.mnemonicToSeedSync(seed);
|
|
3606
|
-
const derived = ed25519.derivePath(
|
|
915
|
+
const derived = ed25519.derivePath(DERIVATION_PATHS2.solana, Buffer.from(seedBytes).toString("hex"));
|
|
3607
916
|
const keypair = nacl.sign.keyPair.fromSeed(new Uint8Array(derived.key));
|
|
3608
917
|
return bs58.encode(keypair.publicKey);
|
|
3609
918
|
} catch (error) {
|
|
@@ -3615,10 +924,10 @@ async function deriveTonAddress(seed) {
|
|
|
3615
924
|
try {
|
|
3616
925
|
const [ed25519, nacl] = await Promise.all([
|
|
3617
926
|
import('ed25519-hd-key'),
|
|
3618
|
-
|
|
927
|
+
import('tweetnacl')
|
|
3619
928
|
]);
|
|
3620
929
|
const seedBytes = bip39.mnemonicToSeedSync(seed);
|
|
3621
|
-
const derived = ed25519.derivePath(
|
|
930
|
+
const derived = ed25519.derivePath(DERIVATION_PATHS2.ton, Buffer.from(seedBytes).toString("hex"));
|
|
3622
931
|
const keypair = nacl.sign.keyPair.fromSeed(new Uint8Array(derived.key));
|
|
3623
932
|
const publicKey = keypair.publicKey;
|
|
3624
933
|
const workchain = 0;
|
|
@@ -3653,7 +962,7 @@ function crc16(data) {
|
|
|
3653
962
|
}
|
|
3654
963
|
function deriveTronAddress(seed) {
|
|
3655
964
|
try {
|
|
3656
|
-
const hdNode = ethers.HDNodeWallet.fromPhrase(seed, void 0,
|
|
965
|
+
const hdNode = ethers.HDNodeWallet.fromPhrase(seed, void 0, DERIVATION_PATHS2.tron);
|
|
3657
966
|
const ethAddressHex = hdNode.address.slice(2).toLowerCase();
|
|
3658
967
|
const addressBytes = new Uint8Array(21);
|
|
3659
968
|
addressBytes[0] = 65;
|
|
@@ -3671,7 +980,7 @@ function deriveSparkAddress(seed, network = "testnet") {
|
|
|
3671
980
|
try {
|
|
3672
981
|
const seedBytes = bip39.mnemonicToSeedSync(seed);
|
|
3673
982
|
const hdKey = bip32.HDKey.fromMasterSeed(seedBytes);
|
|
3674
|
-
const child = hdKey.derive(
|
|
983
|
+
const child = hdKey.derive(DERIVATION_PATHS2.spark);
|
|
3675
984
|
if (!child.publicKey) {
|
|
3676
985
|
throw new Error("Failed to derive public key");
|
|
3677
986
|
}
|
|
@@ -3732,6 +1041,380 @@ async function deriveAllAddresses(seed, network = "testnet") {
|
|
|
3732
1041
|
}
|
|
3733
1042
|
return addresses;
|
|
3734
1043
|
}
|
|
1044
|
+
function isValidSeed(seed) {
|
|
1045
|
+
return bip39.validateMnemonic(seed, english.wordlist);
|
|
1046
|
+
}
|
|
1047
|
+
function generateSeedPhrase() {
|
|
1048
|
+
return bip39.generateMnemonic(english.wordlist);
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
// src/services/ZubariWdkService.ts
|
|
1052
|
+
var DEFAULT_API_URL2 = "https://ckgwifsxka.us-east-2.awsapprunner.com";
|
|
1053
|
+
function isBrowser() {
|
|
1054
|
+
return typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
1055
|
+
}
|
|
1056
|
+
var dynamicImport = new Function("specifier", "return import(specifier)");
|
|
1057
|
+
async function canUseNativeWdk() {
|
|
1058
|
+
if (isBrowser()) {
|
|
1059
|
+
return false;
|
|
1060
|
+
}
|
|
1061
|
+
try {
|
|
1062
|
+
await dynamicImport("@tetherto/wdk");
|
|
1063
|
+
return true;
|
|
1064
|
+
} catch {
|
|
1065
|
+
return false;
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
var ZubariWdkService = class {
|
|
1069
|
+
config;
|
|
1070
|
+
apiClient;
|
|
1071
|
+
nativeWdkService = null;
|
|
1072
|
+
initialized = false;
|
|
1073
|
+
useNativeWdk = false;
|
|
1074
|
+
constructor(config = {}) {
|
|
1075
|
+
this.config = {
|
|
1076
|
+
network: config.network || "testnet",
|
|
1077
|
+
apiUrl: config.apiUrl || process.env.NEXT_PUBLIC_API_URL || DEFAULT_API_URL2,
|
|
1078
|
+
forceApi: config.forceApi ?? false,
|
|
1079
|
+
timeout: config.timeout || 3e4
|
|
1080
|
+
};
|
|
1081
|
+
this.apiClient = getWdkApiClient(this.config.apiUrl);
|
|
1082
|
+
}
|
|
1083
|
+
/**
|
|
1084
|
+
* Initialize the service and determine the best strategy
|
|
1085
|
+
*/
|
|
1086
|
+
async initialize() {
|
|
1087
|
+
if (this.initialized) return;
|
|
1088
|
+
if (isBrowser() || this.config.forceApi) {
|
|
1089
|
+
this.useNativeWdk = false;
|
|
1090
|
+
this.initialized = true;
|
|
1091
|
+
return;
|
|
1092
|
+
}
|
|
1093
|
+
if (await canUseNativeWdk()) {
|
|
1094
|
+
try {
|
|
1095
|
+
const WdkServiceModule = await dynamicImport("./WdkService");
|
|
1096
|
+
const WdkService = WdkServiceModule.WdkService || WdkServiceModule.default;
|
|
1097
|
+
this.nativeWdkService = new WdkService({
|
|
1098
|
+
network: this.config.network
|
|
1099
|
+
});
|
|
1100
|
+
this.useNativeWdk = true;
|
|
1101
|
+
} catch (error) {
|
|
1102
|
+
console.warn("Failed to initialize native WDK, falling back to API:", error);
|
|
1103
|
+
this.useNativeWdk = false;
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
this.initialized = true;
|
|
1107
|
+
}
|
|
1108
|
+
/**
|
|
1109
|
+
* Get the current execution mode
|
|
1110
|
+
*/
|
|
1111
|
+
getMode() {
|
|
1112
|
+
if (this.useNativeWdk) return "native";
|
|
1113
|
+
if (isBrowser()) return "api";
|
|
1114
|
+
return "api";
|
|
1115
|
+
}
|
|
1116
|
+
/**
|
|
1117
|
+
* Check if running in browser
|
|
1118
|
+
*/
|
|
1119
|
+
isBrowserEnvironment() {
|
|
1120
|
+
return isBrowser();
|
|
1121
|
+
}
|
|
1122
|
+
/**
|
|
1123
|
+
* Generate a new BIP-39 seed phrase (12 words)
|
|
1124
|
+
*/
|
|
1125
|
+
async generateSeed() {
|
|
1126
|
+
await this.initialize();
|
|
1127
|
+
try {
|
|
1128
|
+
const response = await this.apiClient.generateSeed();
|
|
1129
|
+
if (response.success && response.seed) {
|
|
1130
|
+
return response.seed;
|
|
1131
|
+
}
|
|
1132
|
+
} catch (error) {
|
|
1133
|
+
console.warn("API seed generation failed:", error);
|
|
1134
|
+
}
|
|
1135
|
+
if (this.useNativeWdk && this.nativeWdkService) {
|
|
1136
|
+
try {
|
|
1137
|
+
const wdk = this.nativeWdkService;
|
|
1138
|
+
return await wdk.generateSeedPhrase();
|
|
1139
|
+
} catch (error) {
|
|
1140
|
+
console.warn("Native WDK seed generation failed:", error);
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
return generateSeedPhrase();
|
|
1144
|
+
}
|
|
1145
|
+
/**
|
|
1146
|
+
* Validate a BIP-39 seed phrase
|
|
1147
|
+
*/
|
|
1148
|
+
async validateSeed(seed) {
|
|
1149
|
+
await this.initialize();
|
|
1150
|
+
try {
|
|
1151
|
+
const response = await this.apiClient.validateSeed(seed);
|
|
1152
|
+
if (response.success) {
|
|
1153
|
+
return response.isValid ?? false;
|
|
1154
|
+
}
|
|
1155
|
+
} catch (error) {
|
|
1156
|
+
console.warn("API seed validation failed:", error);
|
|
1157
|
+
}
|
|
1158
|
+
if (this.useNativeWdk && this.nativeWdkService) {
|
|
1159
|
+
try {
|
|
1160
|
+
const wdk = this.nativeWdkService;
|
|
1161
|
+
return await wdk.isValidSeed(seed);
|
|
1162
|
+
} catch (error) {
|
|
1163
|
+
console.warn("Native WDK seed validation failed:", error);
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
return isValidSeed(seed);
|
|
1167
|
+
}
|
|
1168
|
+
/**
|
|
1169
|
+
* Derive address for a specific chain
|
|
1170
|
+
*/
|
|
1171
|
+
async deriveAddress(seed, chain) {
|
|
1172
|
+
await this.initialize();
|
|
1173
|
+
const path = this.getDerivationPath(chain);
|
|
1174
|
+
try {
|
|
1175
|
+
const response = await this.apiClient.deriveAddress(seed, chain, this.config.network);
|
|
1176
|
+
if (response.success && response.address) {
|
|
1177
|
+
return {
|
|
1178
|
+
chain,
|
|
1179
|
+
address: response.address,
|
|
1180
|
+
path: response.path || path
|
|
1181
|
+
};
|
|
1182
|
+
}
|
|
1183
|
+
} catch (error) {
|
|
1184
|
+
console.warn(`API address derivation failed for ${chain}:`, error);
|
|
1185
|
+
}
|
|
1186
|
+
if (this.useNativeWdk && this.nativeWdkService) {
|
|
1187
|
+
try {
|
|
1188
|
+
const wdk = this.nativeWdkService;
|
|
1189
|
+
await wdk.initialize(seed);
|
|
1190
|
+
return await wdk.deriveAddress(chain);
|
|
1191
|
+
} catch (error) {
|
|
1192
|
+
console.warn(`Native WDK address derivation failed for ${chain}:`, error);
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
return this.deriveBrowserAddress(seed, chain);
|
|
1196
|
+
}
|
|
1197
|
+
/**
|
|
1198
|
+
* Derive addresses for all supported chains
|
|
1199
|
+
*/
|
|
1200
|
+
async deriveAllAddresses(seed) {
|
|
1201
|
+
await this.initialize();
|
|
1202
|
+
try {
|
|
1203
|
+
const response = await this.apiClient.deriveAllAddresses(seed, this.config.network);
|
|
1204
|
+
if (response.success && response.addresses) {
|
|
1205
|
+
return {
|
|
1206
|
+
ethereum: response.addresses.ethereum || null,
|
|
1207
|
+
bitcoin: response.addresses.bitcoin || null,
|
|
1208
|
+
ton: response.addresses.ton || null,
|
|
1209
|
+
tron: response.addresses.tron || null,
|
|
1210
|
+
solana: response.addresses.solana || null,
|
|
1211
|
+
spark: response.addresses.spark || null
|
|
1212
|
+
};
|
|
1213
|
+
}
|
|
1214
|
+
} catch (error) {
|
|
1215
|
+
console.warn("API address derivation failed:", error);
|
|
1216
|
+
}
|
|
1217
|
+
if (this.useNativeWdk && this.nativeWdkService) {
|
|
1218
|
+
try {
|
|
1219
|
+
const wdk = this.nativeWdkService;
|
|
1220
|
+
await wdk.initialize(seed);
|
|
1221
|
+
return await wdk.deriveAllAddresses();
|
|
1222
|
+
} catch (error) {
|
|
1223
|
+
console.warn("Native WDK multi-chain derivation failed:", error);
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
return this.deriveAllBrowserAddresses(seed);
|
|
1227
|
+
}
|
|
1228
|
+
/**
|
|
1229
|
+
* Get balances for all chains
|
|
1230
|
+
*/
|
|
1231
|
+
async getAllBalances(seed) {
|
|
1232
|
+
await this.initialize();
|
|
1233
|
+
try {
|
|
1234
|
+
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/balances`, {
|
|
1235
|
+
method: "POST",
|
|
1236
|
+
headers: { "Content-Type": "application/json" },
|
|
1237
|
+
body: JSON.stringify({ seed, network: this.config.network })
|
|
1238
|
+
});
|
|
1239
|
+
if (response.ok) {
|
|
1240
|
+
const data = await response.json();
|
|
1241
|
+
if (data.success) {
|
|
1242
|
+
return data.balances;
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
} catch (error) {
|
|
1246
|
+
console.warn("Failed to fetch balances:", error);
|
|
1247
|
+
}
|
|
1248
|
+
return {};
|
|
1249
|
+
}
|
|
1250
|
+
/**
|
|
1251
|
+
* Get fee rates for a chain
|
|
1252
|
+
*/
|
|
1253
|
+
async getFeeRates(seed, chain) {
|
|
1254
|
+
await this.initialize();
|
|
1255
|
+
try {
|
|
1256
|
+
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/fee-rates`, {
|
|
1257
|
+
method: "POST",
|
|
1258
|
+
headers: { "Content-Type": "application/json" },
|
|
1259
|
+
body: JSON.stringify({ seed, chain, network: this.config.network })
|
|
1260
|
+
});
|
|
1261
|
+
if (response.ok) {
|
|
1262
|
+
const data = await response.json();
|
|
1263
|
+
if (data.success && data.feeRates) {
|
|
1264
|
+
return data.feeRates;
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
} catch (error) {
|
|
1268
|
+
console.warn(`Failed to fetch fee rates for ${chain}:`, error);
|
|
1269
|
+
}
|
|
1270
|
+
return { slow: "0", normal: "0", fast: "0" };
|
|
1271
|
+
}
|
|
1272
|
+
/**
|
|
1273
|
+
* Estimate transaction fee
|
|
1274
|
+
*/
|
|
1275
|
+
async estimateFee(seed, chain, to, amount) {
|
|
1276
|
+
await this.initialize();
|
|
1277
|
+
try {
|
|
1278
|
+
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/estimate-fee`, {
|
|
1279
|
+
method: "POST",
|
|
1280
|
+
headers: { "Content-Type": "application/json" },
|
|
1281
|
+
body: JSON.stringify({ seed, chain, to, amount, network: this.config.network })
|
|
1282
|
+
});
|
|
1283
|
+
if (response.ok) {
|
|
1284
|
+
const data = await response.json();
|
|
1285
|
+
if (data.success) {
|
|
1286
|
+
return { fee: data.fee, symbol: data.symbol };
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
} catch (error) {
|
|
1290
|
+
console.warn(`Failed to estimate fee for ${chain}:`, error);
|
|
1291
|
+
}
|
|
1292
|
+
return { fee: "0", symbol: this.getChainSymbol(chain) };
|
|
1293
|
+
}
|
|
1294
|
+
/**
|
|
1295
|
+
* Send a transaction
|
|
1296
|
+
*/
|
|
1297
|
+
async sendTransaction(seed, chain, to, amount) {
|
|
1298
|
+
await this.initialize();
|
|
1299
|
+
try {
|
|
1300
|
+
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/send`, {
|
|
1301
|
+
method: "POST",
|
|
1302
|
+
headers: { "Content-Type": "application/json" },
|
|
1303
|
+
body: JSON.stringify({ seed, chain, to, amount, network: this.config.network })
|
|
1304
|
+
});
|
|
1305
|
+
if (response.ok) {
|
|
1306
|
+
const data = await response.json();
|
|
1307
|
+
return {
|
|
1308
|
+
success: data.success,
|
|
1309
|
+
txHash: data.txHash,
|
|
1310
|
+
from: data.from,
|
|
1311
|
+
to: data.to,
|
|
1312
|
+
amount: data.amount,
|
|
1313
|
+
chain: data.chain,
|
|
1314
|
+
network: data.network
|
|
1315
|
+
};
|
|
1316
|
+
}
|
|
1317
|
+
const errorData = await response.json().catch(() => ({}));
|
|
1318
|
+
return {
|
|
1319
|
+
success: false,
|
|
1320
|
+
error: errorData.error || `HTTP ${response.status}`
|
|
1321
|
+
};
|
|
1322
|
+
} catch (error) {
|
|
1323
|
+
return {
|
|
1324
|
+
success: false,
|
|
1325
|
+
error: error instanceof Error ? error.message : "Transaction failed"
|
|
1326
|
+
};
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
/**
|
|
1330
|
+
* Get the network configuration
|
|
1331
|
+
*/
|
|
1332
|
+
getNetwork() {
|
|
1333
|
+
return this.config.network;
|
|
1334
|
+
}
|
|
1335
|
+
/**
|
|
1336
|
+
* Get API URL
|
|
1337
|
+
*/
|
|
1338
|
+
getApiUrl() {
|
|
1339
|
+
return this.config.apiUrl;
|
|
1340
|
+
}
|
|
1341
|
+
// ==========================================
|
|
1342
|
+
// Private Helper Methods
|
|
1343
|
+
// ==========================================
|
|
1344
|
+
getDerivationPath(chain) {
|
|
1345
|
+
const paths = {
|
|
1346
|
+
bitcoin: this.config.network === "testnet" ? "m/84'/1'/0'/0/0" : "m/84'/0'/0'/0/0",
|
|
1347
|
+
ethereum: "m/44'/60'/0'/0/0",
|
|
1348
|
+
ton: "m/44'/607'/0'/0'/0'",
|
|
1349
|
+
tron: "m/44'/195'/0'/0/0",
|
|
1350
|
+
solana: "m/44'/501'/0'/0'",
|
|
1351
|
+
spark: "m/44'/998'/0'/0/0"
|
|
1352
|
+
};
|
|
1353
|
+
return paths[chain];
|
|
1354
|
+
}
|
|
1355
|
+
getChainSymbol(chain) {
|
|
1356
|
+
const symbols = {
|
|
1357
|
+
ethereum: "ETH",
|
|
1358
|
+
bitcoin: "BTC",
|
|
1359
|
+
ton: "TON",
|
|
1360
|
+
tron: "TRX",
|
|
1361
|
+
solana: "SOL",
|
|
1362
|
+
spark: "SAT"
|
|
1363
|
+
};
|
|
1364
|
+
return symbols[chain];
|
|
1365
|
+
}
|
|
1366
|
+
/**
|
|
1367
|
+
* Derive address using browser-compatible libraries
|
|
1368
|
+
*/
|
|
1369
|
+
async deriveBrowserAddress(seed, chain) {
|
|
1370
|
+
const path = this.getDerivationPath(chain);
|
|
1371
|
+
try {
|
|
1372
|
+
let address;
|
|
1373
|
+
switch (chain) {
|
|
1374
|
+
case "ethereum":
|
|
1375
|
+
address = deriveEthereumAddress(seed);
|
|
1376
|
+
break;
|
|
1377
|
+
case "bitcoin":
|
|
1378
|
+
address = deriveBitcoinAddress(seed, this.config.network);
|
|
1379
|
+
break;
|
|
1380
|
+
case "tron":
|
|
1381
|
+
address = deriveTronAddress(seed);
|
|
1382
|
+
break;
|
|
1383
|
+
case "spark":
|
|
1384
|
+
address = deriveSparkAddress(seed, this.config.network);
|
|
1385
|
+
break;
|
|
1386
|
+
case "solana":
|
|
1387
|
+
address = await deriveSolanaAddress(seed);
|
|
1388
|
+
break;
|
|
1389
|
+
case "ton":
|
|
1390
|
+
address = await deriveTonAddress(seed);
|
|
1391
|
+
break;
|
|
1392
|
+
default:
|
|
1393
|
+
throw new Error(`Unsupported chain: ${chain}`);
|
|
1394
|
+
}
|
|
1395
|
+
return { chain, address, path };
|
|
1396
|
+
} catch (error) {
|
|
1397
|
+
console.error(`Browser derivation failed for ${chain}:`, error);
|
|
1398
|
+
throw error;
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
/**
|
|
1402
|
+
* Derive all addresses using browser-compatible libraries
|
|
1403
|
+
*/
|
|
1404
|
+
async deriveAllBrowserAddresses(seed) {
|
|
1405
|
+
return deriveAllAddresses(seed, this.config.network);
|
|
1406
|
+
}
|
|
1407
|
+
};
|
|
1408
|
+
var defaultService = null;
|
|
1409
|
+
function getZubariWdkService(config) {
|
|
1410
|
+
if (!defaultService || config && config.network !== defaultService.getNetwork()) {
|
|
1411
|
+
defaultService = new ZubariWdkService(config);
|
|
1412
|
+
}
|
|
1413
|
+
return defaultService;
|
|
1414
|
+
}
|
|
1415
|
+
function createZubariWdkService(config) {
|
|
1416
|
+
return new ZubariWdkService(config);
|
|
1417
|
+
}
|
|
3735
1418
|
|
|
3736
1419
|
// src/wallet/WalletManager.ts
|
|
3737
1420
|
var STORAGE_KEYS = {
|
|
@@ -3755,11 +1438,12 @@ var WalletManager = class _WalletManager {
|
|
|
3755
1438
|
rpcUrl: config.rpcUrl || ethereumConfig.rpcUrl,
|
|
3756
1439
|
storage: config.storage || createSecureStorage(),
|
|
3757
1440
|
enabledChains: config.enabledChains || SUPPORTED_CHAINS,
|
|
3758
|
-
apiUrl: config.apiUrl || process.env.NEXT_PUBLIC_API_URL || "
|
|
1441
|
+
apiUrl: config.apiUrl || process.env.NEXT_PUBLIC_API_URL || "https://ckgwifsxka.us-east-2.awsapprunner.com"
|
|
3759
1442
|
};
|
|
3760
1443
|
this.storage = this.config.storage;
|
|
3761
|
-
this.wdkService =
|
|
3762
|
-
network: this.config.network
|
|
1444
|
+
this.wdkService = getZubariWdkService({
|
|
1445
|
+
network: this.config.network,
|
|
1446
|
+
apiUrl: this.config.apiUrl
|
|
3763
1447
|
});
|
|
3764
1448
|
}
|
|
3765
1449
|
/**
|
|
@@ -3775,17 +1459,17 @@ var WalletManager = class _WalletManager {
|
|
|
3775
1459
|
return mnemonic.phrase;
|
|
3776
1460
|
}
|
|
3777
1461
|
/**
|
|
3778
|
-
* Generate a new BIP-39 seed phrase using
|
|
1462
|
+
* Generate a new BIP-39 seed phrase using Tether WDK (via API in browser)
|
|
3779
1463
|
* This is the recommended method for generating seed phrases
|
|
3780
1464
|
*/
|
|
3781
1465
|
async generateSeedWithWdk() {
|
|
3782
|
-
return await this.wdkService.
|
|
1466
|
+
return await this.wdkService.generateSeed();
|
|
3783
1467
|
}
|
|
3784
1468
|
/**
|
|
3785
|
-
* Validate seed phrase using
|
|
1469
|
+
* Validate seed phrase using WDK (async, more accurate)
|
|
3786
1470
|
*/
|
|
3787
1471
|
async validateSeedWithWdk(seed) {
|
|
3788
|
-
return await this.wdkService.
|
|
1472
|
+
return await this.wdkService.validateSeed(seed);
|
|
3789
1473
|
}
|
|
3790
1474
|
/**
|
|
3791
1475
|
* Validate a BIP-39 seed phrase
|
|
@@ -3864,7 +1548,6 @@ var WalletManager = class _WalletManager {
|
|
|
3864
1548
|
*/
|
|
3865
1549
|
lock() {
|
|
3866
1550
|
this.currentSeed = null;
|
|
3867
|
-
this.wdkService.dispose();
|
|
3868
1551
|
}
|
|
3869
1552
|
/**
|
|
3870
1553
|
* Check if wallet exists in storage
|
|
@@ -3880,7 +1563,6 @@ var WalletManager = class _WalletManager {
|
|
|
3880
1563
|
this.currentSeed = null;
|
|
3881
1564
|
this.derivedAddress = null;
|
|
3882
1565
|
this.derivedAddresses = {};
|
|
3883
|
-
this.wdkService.dispose();
|
|
3884
1566
|
}
|
|
3885
1567
|
/**
|
|
3886
1568
|
* Get current wallet state
|
|
@@ -3980,19 +1662,18 @@ var WalletManager = class _WalletManager {
|
|
|
3980
1662
|
/**
|
|
3981
1663
|
* Derive address for a specific chain (async version)
|
|
3982
1664
|
*
|
|
3983
|
-
*
|
|
3984
|
-
*
|
|
1665
|
+
* Uses the unified WDK service which:
|
|
1666
|
+
* - In browser: Calls the backend API (which has Tether WDK)
|
|
1667
|
+
* - In Node.js: Uses native WDK
|
|
1668
|
+
* - Falls back to browser-compatible derivation if needed
|
|
3985
1669
|
*/
|
|
3986
1670
|
static async deriveAddressForChainAsync(seed, chain, network = "testnet", apiUrl) {
|
|
3987
1671
|
try {
|
|
3988
|
-
const
|
|
3989
|
-
const
|
|
3990
|
-
|
|
3991
|
-
return response.address;
|
|
3992
|
-
}
|
|
3993
|
-
console.warn(`WDK API failed for ${chain}, using local derivation:`, response.error);
|
|
1672
|
+
const wdkService = getZubariWdkService({ network, apiUrl });
|
|
1673
|
+
const result = await wdkService.deriveAddress(seed, chain);
|
|
1674
|
+
return result.address;
|
|
3994
1675
|
} catch (error) {
|
|
3995
|
-
console.warn(`WDK
|
|
1676
|
+
console.warn(`WDK service failed for ${chain}, using local derivation:`, error);
|
|
3996
1677
|
}
|
|
3997
1678
|
return _WalletManager.deriveAddressForChain(seed, chain);
|
|
3998
1679
|
}
|
|
@@ -4088,8 +1769,9 @@ var WalletManager = class _WalletManager {
|
|
|
4088
1769
|
return addresses;
|
|
4089
1770
|
}
|
|
4090
1771
|
/**
|
|
4091
|
-
* Derive addresses for all enabled chains using
|
|
4092
|
-
*
|
|
1772
|
+
* Derive addresses for all enabled chains using Tether WDK
|
|
1773
|
+
* In browser: Uses the backend API (which has Tether WDK)
|
|
1774
|
+
* In Node.js: Uses native WDK directly
|
|
4093
1775
|
* Returns REAL cryptographically valid addresses for all chains.
|
|
4094
1776
|
*/
|
|
4095
1777
|
async deriveAllAddressesWithWdk() {
|
|
@@ -4097,9 +1779,8 @@ var WalletManager = class _WalletManager {
|
|
|
4097
1779
|
throw new Error("Wallet is locked");
|
|
4098
1780
|
}
|
|
4099
1781
|
try {
|
|
4100
|
-
await this.wdkService.
|
|
1782
|
+
const wdkAddresses = await this.wdkService.deriveAllAddresses(this.currentSeed);
|
|
4101
1783
|
const enabledChainsSet = new Set(this.config.enabledChains);
|
|
4102
|
-
const wdkAddresses = await this.wdkService.deriveAllAddresses();
|
|
4103
1784
|
const addresses = {};
|
|
4104
1785
|
for (const [chain, address] of Object.entries(wdkAddresses)) {
|
|
4105
1786
|
if (enabledChainsSet.has(chain) && address) {
|
|
@@ -4109,13 +1790,15 @@ var WalletManager = class _WalletManager {
|
|
|
4109
1790
|
this.derivedAddresses = addresses;
|
|
4110
1791
|
return addresses;
|
|
4111
1792
|
} catch (error) {
|
|
4112
|
-
console.error("
|
|
1793
|
+
console.error("WDK derivation failed:", error);
|
|
4113
1794
|
throw error;
|
|
4114
1795
|
}
|
|
4115
1796
|
}
|
|
4116
1797
|
/**
|
|
4117
1798
|
* Derive addresses for all enabled chains using Tether WDK
|
|
4118
|
-
*
|
|
1799
|
+
* The unified WDK service handles all fallback strategies automatically:
|
|
1800
|
+
* - Browser: API backend -> Browser derivation
|
|
1801
|
+
* - Node.js: Native WDK -> API backend -> Browser derivation
|
|
4119
1802
|
*/
|
|
4120
1803
|
async deriveAllAddressesAsync() {
|
|
4121
1804
|
if (!this.currentSeed) {
|
|
@@ -4123,44 +1806,8 @@ var WalletManager = class _WalletManager {
|
|
|
4123
1806
|
}
|
|
4124
1807
|
try {
|
|
4125
1808
|
return await this.deriveAllAddressesWithWdk();
|
|
4126
|
-
} catch (
|
|
4127
|
-
console.
|
|
4128
|
-
}
|
|
4129
|
-
try {
|
|
4130
|
-
const wdkApi = getWdkApiClient(this.config.apiUrl);
|
|
4131
|
-
const response = await wdkApi.deriveAllAddresses(this.currentSeed, this.config.network);
|
|
4132
|
-
if (response.success && response.addresses) {
|
|
4133
|
-
const addresses = {};
|
|
4134
|
-
for (const chain of this.config.enabledChains) {
|
|
4135
|
-
const address = response.addresses[chain];
|
|
4136
|
-
if (address) {
|
|
4137
|
-
addresses[chain] = address;
|
|
4138
|
-
}
|
|
4139
|
-
}
|
|
4140
|
-
this.derivedAddresses = addresses;
|
|
4141
|
-
return addresses;
|
|
4142
|
-
}
|
|
4143
|
-
console.warn("WDK API call failed:", response.error);
|
|
4144
|
-
} catch (apiError) {
|
|
4145
|
-
console.warn("WDK API unavailable:", apiError);
|
|
4146
|
-
}
|
|
4147
|
-
console.log("Using browser-compatible address derivation...");
|
|
4148
|
-
try {
|
|
4149
|
-
const browserAddresses = await deriveAllAddresses(
|
|
4150
|
-
this.currentSeed,
|
|
4151
|
-
this.config.network
|
|
4152
|
-
);
|
|
4153
|
-
const addresses = {};
|
|
4154
|
-
for (const chain of this.config.enabledChains) {
|
|
4155
|
-
const address = browserAddresses[chain];
|
|
4156
|
-
if (address) {
|
|
4157
|
-
addresses[chain] = address;
|
|
4158
|
-
}
|
|
4159
|
-
}
|
|
4160
|
-
this.derivedAddresses = addresses;
|
|
4161
|
-
return addresses;
|
|
4162
|
-
} catch (browserError) {
|
|
4163
|
-
console.error("Browser derivation failed:", browserError);
|
|
1809
|
+
} catch (error) {
|
|
1810
|
+
console.error("All derivation strategies failed:", error);
|
|
4164
1811
|
const ethAddress = _WalletManager.deriveAddress(this.currentSeed);
|
|
4165
1812
|
this.derivedAddresses = { ethereum: ethAddress };
|
|
4166
1813
|
return this.derivedAddresses;
|
|
@@ -4809,19 +2456,19 @@ var SwapService = class {
|
|
|
4809
2456
|
};
|
|
4810
2457
|
|
|
4811
2458
|
// src/services/TransactionService.ts
|
|
4812
|
-
var
|
|
4813
|
-
var
|
|
4814
|
-
var
|
|
4815
|
-
var
|
|
4816
|
-
var
|
|
4817
|
-
var
|
|
4818
|
-
var
|
|
4819
|
-
var
|
|
4820
|
-
var
|
|
2459
|
+
var WdkManager;
|
|
2460
|
+
var WalletManagerBtc;
|
|
2461
|
+
var WalletManagerEvm;
|
|
2462
|
+
var WalletManagerSolana;
|
|
2463
|
+
var WalletManagerTon;
|
|
2464
|
+
var WalletManagerTron;
|
|
2465
|
+
var WalletManagerSpark;
|
|
2466
|
+
var wdkLoaded = false;
|
|
2467
|
+
var wdkLoadError = null;
|
|
4821
2468
|
var dynamicImport2 = new Function("specifier", "return import(specifier)");
|
|
4822
|
-
async function
|
|
4823
|
-
if (
|
|
4824
|
-
if (
|
|
2469
|
+
async function loadWdkModules() {
|
|
2470
|
+
if (wdkLoaded) return;
|
|
2471
|
+
if (wdkLoadError) throw wdkLoadError;
|
|
4825
2472
|
try {
|
|
4826
2473
|
const [wdk, btc, evm, solana, ton, tron, spark] = await Promise.all([
|
|
4827
2474
|
dynamicImport2("@tetherto/wdk"),
|
|
@@ -4832,21 +2479,21 @@ async function loadWdkModules2() {
|
|
|
4832
2479
|
dynamicImport2("@tetherto/wdk-wallet-tron"),
|
|
4833
2480
|
dynamicImport2("@tetherto/wdk-wallet-spark")
|
|
4834
2481
|
]);
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
2482
|
+
WdkManager = wdk.default;
|
|
2483
|
+
WalletManagerBtc = btc.default;
|
|
2484
|
+
WalletManagerEvm = evm.default;
|
|
2485
|
+
WalletManagerSolana = solana.default;
|
|
2486
|
+
WalletManagerTon = ton.default;
|
|
2487
|
+
WalletManagerTron = tron.default;
|
|
2488
|
+
WalletManagerSpark = spark.default;
|
|
2489
|
+
wdkLoaded = true;
|
|
4843
2490
|
} catch (error) {
|
|
4844
|
-
|
|
2491
|
+
wdkLoadError = error instanceof Error ? error : new Error("Failed to load WDK modules");
|
|
4845
2492
|
console.error("Failed to load WDK modules:", error);
|
|
4846
|
-
throw
|
|
2493
|
+
throw wdkLoadError;
|
|
4847
2494
|
}
|
|
4848
2495
|
}
|
|
4849
|
-
var
|
|
2496
|
+
var DEFAULT_RPC_URLS = {
|
|
4850
2497
|
mainnet: {
|
|
4851
2498
|
ethereum: "https://eth.llamarpc.com",
|
|
4852
2499
|
bitcoin: "",
|
|
@@ -4901,13 +2548,13 @@ var TransactionService = class {
|
|
|
4901
2548
|
* Ensure WDK modules are loaded
|
|
4902
2549
|
*/
|
|
4903
2550
|
async ensureLoaded() {
|
|
4904
|
-
await
|
|
2551
|
+
await loadWdkModules();
|
|
4905
2552
|
}
|
|
4906
2553
|
/**
|
|
4907
2554
|
* Get RPC URL for a chain
|
|
4908
2555
|
*/
|
|
4909
2556
|
getRpcUrl(chain) {
|
|
4910
|
-
const networkUrls =
|
|
2557
|
+
const networkUrls = DEFAULT_RPC_URLS[this.config.network];
|
|
4911
2558
|
if (this.config.rpcUrls?.[chain]) {
|
|
4912
2559
|
return this.config.rpcUrls[chain];
|
|
4913
2560
|
}
|
|
@@ -4926,7 +2573,7 @@ var TransactionService = class {
|
|
|
4926
2573
|
*/
|
|
4927
2574
|
async initialize(seed) {
|
|
4928
2575
|
await this.ensureLoaded();
|
|
4929
|
-
if (!
|
|
2576
|
+
if (!WdkManager.isValidSeed(seed)) {
|
|
4930
2577
|
throw new Error("Invalid seed phrase");
|
|
4931
2578
|
}
|
|
4932
2579
|
this.seed = seed;
|
|
@@ -4954,12 +2601,12 @@ var TransactionService = class {
|
|
|
4954
2601
|
switch (chain) {
|
|
4955
2602
|
case "ethereum": {
|
|
4956
2603
|
const rpcUrl = this.getRpcUrl("ethereum");
|
|
4957
|
-
const wallet = new
|
|
2604
|
+
const wallet = new WalletManagerEvm(this.seed, { provider: rpcUrl });
|
|
4958
2605
|
this.wallets[chain] = wallet;
|
|
4959
2606
|
return wallet;
|
|
4960
2607
|
}
|
|
4961
2608
|
case "bitcoin": {
|
|
4962
|
-
const wallet = new
|
|
2609
|
+
const wallet = new WalletManagerBtc(this.seed, {
|
|
4963
2610
|
network: isTestnet ? "testnet" : "bitcoin"
|
|
4964
2611
|
});
|
|
4965
2612
|
this.wallets[chain] = wallet;
|
|
@@ -4967,7 +2614,7 @@ var TransactionService = class {
|
|
|
4967
2614
|
}
|
|
4968
2615
|
case "solana": {
|
|
4969
2616
|
const rpcUrl = this.getRpcUrl("solana");
|
|
4970
|
-
const wallet = new
|
|
2617
|
+
const wallet = new WalletManagerSolana(this.seed, {
|
|
4971
2618
|
rpcUrl
|
|
4972
2619
|
});
|
|
4973
2620
|
this.wallets[chain] = wallet;
|
|
@@ -4975,7 +2622,7 @@ var TransactionService = class {
|
|
|
4975
2622
|
}
|
|
4976
2623
|
case "ton": {
|
|
4977
2624
|
const url = this.getRpcUrl("ton");
|
|
4978
|
-
const wallet = new
|
|
2625
|
+
const wallet = new WalletManagerTon(this.seed, {
|
|
4979
2626
|
tonClient: { url }
|
|
4980
2627
|
});
|
|
4981
2628
|
this.wallets[chain] = wallet;
|
|
@@ -4983,14 +2630,14 @@ var TransactionService = class {
|
|
|
4983
2630
|
}
|
|
4984
2631
|
case "tron": {
|
|
4985
2632
|
const fullHost = this.getRpcUrl("tron");
|
|
4986
|
-
const wallet = new
|
|
2633
|
+
const wallet = new WalletManagerTron(this.seed, {
|
|
4987
2634
|
provider: fullHost
|
|
4988
2635
|
});
|
|
4989
2636
|
this.wallets[chain] = wallet;
|
|
4990
2637
|
return wallet;
|
|
4991
2638
|
}
|
|
4992
2639
|
case "spark": {
|
|
4993
|
-
const wallet = new
|
|
2640
|
+
const wallet = new WalletManagerSpark(this.seed, {
|
|
4994
2641
|
network: isTestnet ? "TESTNET" : "MAINNET"
|
|
4995
2642
|
});
|
|
4996
2643
|
this.wallets[chain] = wallet;
|
|
@@ -5436,6 +3083,7 @@ function normalizeAddress(address) {
|
|
|
5436
3083
|
return address.toLowerCase();
|
|
5437
3084
|
}
|
|
5438
3085
|
|
|
3086
|
+
exports.BrowserAddressDerivation = BrowserAddressDerivation_exports;
|
|
5439
3087
|
exports.DERIVATION_PATHS = DERIVATION_PATHS;
|
|
5440
3088
|
exports.KeyManager = KeyManager;
|
|
5441
3089
|
exports.MemoryStorageAdapter = MemoryStorageAdapter;
|
|
@@ -5445,6 +3093,7 @@ exports.SwapService = SwapService;
|
|
|
5445
3093
|
exports.TESTNET_NETWORKS = TESTNET_NETWORKS;
|
|
5446
3094
|
exports.TransactionService = TransactionService;
|
|
5447
3095
|
exports.WalletManager = WalletManager;
|
|
3096
|
+
exports.WdkApiClient = WdkApiClient;
|
|
5448
3097
|
exports.WebEncryptedStorageAdapter = WebEncryptedStorageAdapter;
|
|
5449
3098
|
exports.ZUBARI_CONTRACTS = ZUBARI_CONTRACTS;
|
|
5450
3099
|
exports.ZubariError = ZubariError;
|
|
@@ -5453,13 +3102,18 @@ exports.ZubariPayoutsProtocol = ZubariPayoutsProtocol;
|
|
|
5453
3102
|
exports.ZubariSubscriptionProtocol = ZubariSubscriptionProtocol;
|
|
5454
3103
|
exports.ZubariTipsProtocol = ZubariTipsProtocol;
|
|
5455
3104
|
exports.ZubariWallet = ZubariWallet;
|
|
3105
|
+
exports.ZubariWdkService = ZubariWdkService;
|
|
5456
3106
|
exports.createSecureStorage = createSecureStorage;
|
|
5457
3107
|
exports.createTransactionService = createTransactionService;
|
|
3108
|
+
exports.createZubariWdkService = createZubariWdkService;
|
|
5458
3109
|
exports.formatAddress = formatAddress;
|
|
5459
3110
|
exports.formatBalance = formatBalance;
|
|
5460
3111
|
exports.getContractAddresses = getContractAddresses;
|
|
5461
3112
|
exports.getNetworkConfig = getNetworkConfig;
|
|
5462
3113
|
exports.getTransactionService = getTransactionService;
|
|
3114
|
+
exports.getWdkApiClient = getWdkApiClient;
|
|
3115
|
+
exports.getZubariWdkService = getZubariWdkService;
|
|
3116
|
+
exports.isBrowser = isBrowser;
|
|
5463
3117
|
exports.isValidAddress = isValidAddress;
|
|
5464
3118
|
exports.normalizeAddress = normalizeAddress;
|
|
5465
3119
|
exports.useWalletManager = useWalletManager;
|