@zubari/sdk 0.1.4 → 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 +502 -2902
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +499 -2906
- 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 +421 -2849
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +423 -2851
- package/dist/react/index.mjs.map +1 -1
- package/dist/services/index.d.mts +290 -55
- package/dist/services/index.d.ts +290 -55
- package/dist/services/index.js +340 -2744
- package/dist/services/index.js.map +1 -1
- package/dist/services/index.mjs +338 -2743
- 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 +420 -2850
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +422 -2852
- 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/react/index.js
CHANGED
|
@@ -5,2462 +5,13 @@ var ethers = require('ethers');
|
|
|
5
5
|
var viem = require('viem');
|
|
6
6
|
var chains = require('viem/chains');
|
|
7
7
|
var bip39 = require('@scure/bip39');
|
|
8
|
-
require('@scure/bip39/wordlists/english');
|
|
8
|
+
var english = require('@scure/bip39/wordlists/english');
|
|
9
9
|
var bip32 = require('@scure/bip32');
|
|
10
10
|
var base = require('@scure/base');
|
|
11
11
|
var sha256 = require('@noble/hashes/sha256');
|
|
12
12
|
var ripemd160 = require('@noble/hashes/ripemd160');
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
var __defProp = Object.defineProperty;
|
|
16
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
17
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
18
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
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;
|
|
36
|
-
};
|
|
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
|
-
|
|
2412
|
-
// ../../node_modules/bs58check/base.js
|
|
2413
|
-
var require_base = __commonJS({
|
|
2414
|
-
"../../node_modules/bs58check/base.js"(exports$1, module) {
|
|
2415
|
-
var base58 = require_bs58();
|
|
2416
|
-
module.exports = function(checksumFn) {
|
|
2417
|
-
function encode(payload) {
|
|
2418
|
-
var payloadU8 = Uint8Array.from(payload);
|
|
2419
|
-
var checksum = checksumFn(payloadU8);
|
|
2420
|
-
var length = payloadU8.length + 4;
|
|
2421
|
-
var both = new Uint8Array(length);
|
|
2422
|
-
both.set(payloadU8, 0);
|
|
2423
|
-
both.set(checksum.subarray(0, 4), payloadU8.length);
|
|
2424
|
-
return base58.encode(both, length);
|
|
2425
|
-
}
|
|
2426
|
-
function decodeRaw(buffer) {
|
|
2427
|
-
var payload = buffer.slice(0, -4);
|
|
2428
|
-
var checksum = buffer.slice(-4);
|
|
2429
|
-
var newChecksum = checksumFn(payload);
|
|
2430
|
-
if (checksum[0] ^ newChecksum[0] | checksum[1] ^ newChecksum[1] | checksum[2] ^ newChecksum[2] | checksum[3] ^ newChecksum[3]) return;
|
|
2431
|
-
return payload;
|
|
2432
|
-
}
|
|
2433
|
-
function decodeUnsafe(string) {
|
|
2434
|
-
var buffer = base58.decodeUnsafe(string);
|
|
2435
|
-
if (!buffer) return;
|
|
2436
|
-
return decodeRaw(buffer);
|
|
2437
|
-
}
|
|
2438
|
-
function decode(string) {
|
|
2439
|
-
var buffer = base58.decode(string);
|
|
2440
|
-
var payload = decodeRaw(buffer);
|
|
2441
|
-
if (!payload) throw new Error("Invalid checksum");
|
|
2442
|
-
return payload;
|
|
2443
|
-
}
|
|
2444
|
-
return {
|
|
2445
|
-
encode,
|
|
2446
|
-
decode,
|
|
2447
|
-
decodeUnsafe
|
|
2448
|
-
};
|
|
2449
|
-
};
|
|
2450
|
-
}
|
|
2451
|
-
});
|
|
2452
|
-
|
|
2453
|
-
// ../../node_modules/bs58check/index.js
|
|
2454
|
-
var require_bs58check = __commonJS({
|
|
2455
|
-
"../../node_modules/bs58check/index.js"(exports$1, module) {
|
|
2456
|
-
var { sha256: sha2562 } = __require("@noble/hashes/sha256");
|
|
2457
|
-
var bs58checkBase = require_base();
|
|
2458
|
-
function sha256x2(buffer) {
|
|
2459
|
-
return sha2562(sha2562(buffer));
|
|
2460
|
-
}
|
|
2461
|
-
module.exports = bs58checkBase(sha256x2);
|
|
2462
|
-
}
|
|
2463
|
-
});
|
|
14
|
+
// src/react/useWalletManager.ts
|
|
2464
15
|
|
|
2465
16
|
// src/config/networks.ts
|
|
2466
17
|
var NETWORKS = {
|
|
@@ -2964,7 +515,7 @@ var WdkApiClient = class {
|
|
|
2964
515
|
}
|
|
2965
516
|
}
|
|
2966
517
|
};
|
|
2967
|
-
var DEFAULT_API_URL = process.env.NEXT_PUBLIC_API_URL || "
|
|
518
|
+
var DEFAULT_API_URL = process.env.NEXT_PUBLIC_API_URL || "https://ckgwifsxka.us-east-2.awsapprunner.com";
|
|
2968
519
|
var wdkApiClient = null;
|
|
2969
520
|
function getWdkApiClient(baseUrl) {
|
|
2970
521
|
if (!wdkApiClient || baseUrl && wdkApiClient["config"].baseUrl !== baseUrl) {
|
|
@@ -2974,321 +525,7 @@ function getWdkApiClient(baseUrl) {
|
|
|
2974
525
|
}
|
|
2975
526
|
return wdkApiClient;
|
|
2976
527
|
}
|
|
2977
|
-
|
|
2978
|
-
// src/services/WdkService.ts
|
|
2979
|
-
var WdkManager;
|
|
2980
|
-
var WalletManagerBtc;
|
|
2981
|
-
var WalletManagerEvm;
|
|
2982
|
-
var WalletManagerSolana;
|
|
2983
|
-
var WalletManagerTon;
|
|
2984
|
-
var WalletManagerTron;
|
|
2985
|
-
var WalletManagerSpark;
|
|
2986
|
-
var wdkLoaded = false;
|
|
2987
|
-
var wdkLoadError = null;
|
|
2988
|
-
var dynamicImport = new Function("specifier", "return import(specifier)");
|
|
2989
|
-
async function loadWdkModules() {
|
|
2990
|
-
if (wdkLoaded) return;
|
|
2991
|
-
if (wdkLoadError) throw wdkLoadError;
|
|
2992
|
-
try {
|
|
2993
|
-
const [wdk, btc, evm, solana, ton, tron, spark] = await Promise.all([
|
|
2994
|
-
dynamicImport("@tetherto/wdk"),
|
|
2995
|
-
dynamicImport("@tetherto/wdk-wallet-btc"),
|
|
2996
|
-
dynamicImport("@tetherto/wdk-wallet-evm"),
|
|
2997
|
-
dynamicImport("@tetherto/wdk-wallet-solana"),
|
|
2998
|
-
dynamicImport("@tetherto/wdk-wallet-ton"),
|
|
2999
|
-
dynamicImport("@tetherto/wdk-wallet-tron"),
|
|
3000
|
-
dynamicImport("@tetherto/wdk-wallet-spark")
|
|
3001
|
-
]);
|
|
3002
|
-
WdkManager = wdk.default;
|
|
3003
|
-
WalletManagerBtc = btc.default;
|
|
3004
|
-
WalletManagerEvm = evm.default;
|
|
3005
|
-
WalletManagerSolana = solana.default;
|
|
3006
|
-
WalletManagerTon = ton.default;
|
|
3007
|
-
WalletManagerTron = tron.default;
|
|
3008
|
-
WalletManagerSpark = spark.default;
|
|
3009
|
-
wdkLoaded = true;
|
|
3010
|
-
} catch (error) {
|
|
3011
|
-
wdkLoadError = error instanceof Error ? error : new Error("Failed to load WDK modules");
|
|
3012
|
-
console.error("Failed to load WDK modules:", error);
|
|
3013
|
-
throw wdkLoadError;
|
|
3014
|
-
}
|
|
3015
|
-
}
|
|
3016
528
|
var DERIVATION_PATHS2 = {
|
|
3017
|
-
bitcoin: "m/84'/0'/0'/0/0",
|
|
3018
|
-
// BIP-84 for native SegWit
|
|
3019
|
-
ethereum: "m/44'/60'/0'/0/0",
|
|
3020
|
-
ton: "m/44'/607'/0'",
|
|
3021
|
-
// Updated for v1.0.0-beta.6+
|
|
3022
|
-
tron: "m/44'/195'/0'/0/0",
|
|
3023
|
-
solana: "m/44'/501'/0'/0'",
|
|
3024
|
-
// Updated for v1.0.0-beta.4+
|
|
3025
|
-
spark: "m/44'/998'/0'/0/0"
|
|
3026
|
-
};
|
|
3027
|
-
var DEFAULT_RPC_URLS = {
|
|
3028
|
-
mainnet: {
|
|
3029
|
-
ethereum: "https://eth.llamarpc.com",
|
|
3030
|
-
solana: "https://api.mainnet-beta.solana.com",
|
|
3031
|
-
ton: "https://toncenter.com/api/v2/jsonRPC",
|
|
3032
|
-
tron: "https://api.trongrid.io"
|
|
3033
|
-
},
|
|
3034
|
-
testnet: {
|
|
3035
|
-
ethereum: "https://ethereum-sepolia-rpc.publicnode.com",
|
|
3036
|
-
solana: "https://api.devnet.solana.com",
|
|
3037
|
-
ton: "https://testnet.toncenter.com/api/v2/jsonRPC",
|
|
3038
|
-
tron: "https://api.shasta.trongrid.io"
|
|
3039
|
-
}
|
|
3040
|
-
};
|
|
3041
|
-
var WdkService = class {
|
|
3042
|
-
seed = null;
|
|
3043
|
-
config;
|
|
3044
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3045
|
-
wallets = {};
|
|
3046
|
-
constructor(config = {}) {
|
|
3047
|
-
this.config = {
|
|
3048
|
-
network: config.network || "testnet",
|
|
3049
|
-
rpcUrls: config.rpcUrls
|
|
3050
|
-
};
|
|
3051
|
-
}
|
|
3052
|
-
/**
|
|
3053
|
-
* Check if WDK modules are loaded
|
|
3054
|
-
*/
|
|
3055
|
-
static isLoaded() {
|
|
3056
|
-
return wdkLoaded;
|
|
3057
|
-
}
|
|
3058
|
-
/**
|
|
3059
|
-
* Ensure WDK modules are loaded
|
|
3060
|
-
*/
|
|
3061
|
-
async ensureLoaded() {
|
|
3062
|
-
await loadWdkModules();
|
|
3063
|
-
}
|
|
3064
|
-
/**
|
|
3065
|
-
* Load WDK modules (call this before using sync methods)
|
|
3066
|
-
*/
|
|
3067
|
-
async loadModules() {
|
|
3068
|
-
await loadWdkModules();
|
|
3069
|
-
}
|
|
3070
|
-
/**
|
|
3071
|
-
* Generate a random BIP-39 seed phrase (12 words)
|
|
3072
|
-
*/
|
|
3073
|
-
async generateSeedPhrase() {
|
|
3074
|
-
await this.ensureLoaded();
|
|
3075
|
-
return WdkManager.getRandomSeedPhrase();
|
|
3076
|
-
}
|
|
3077
|
-
/**
|
|
3078
|
-
* Validate a BIP-39 seed phrase
|
|
3079
|
-
*/
|
|
3080
|
-
async isValidSeed(seed) {
|
|
3081
|
-
await this.ensureLoaded();
|
|
3082
|
-
return WdkManager.isValidSeed(seed);
|
|
3083
|
-
}
|
|
3084
|
-
/**
|
|
3085
|
-
* Validate seed phrase (sync version - basic check)
|
|
3086
|
-
*/
|
|
3087
|
-
isValidSeedSync(seed) {
|
|
3088
|
-
const words = seed.trim().split(/\s+/);
|
|
3089
|
-
return words.length === 12 || words.length === 24;
|
|
3090
|
-
}
|
|
3091
|
-
/**
|
|
3092
|
-
* Initialize the service with a seed phrase
|
|
3093
|
-
*/
|
|
3094
|
-
async initialize(seed) {
|
|
3095
|
-
await this.ensureLoaded();
|
|
3096
|
-
if (!WdkManager.isValidSeed(seed)) {
|
|
3097
|
-
throw new Error("Invalid seed phrase");
|
|
3098
|
-
}
|
|
3099
|
-
this.seed = seed;
|
|
3100
|
-
this.wallets = {};
|
|
3101
|
-
}
|
|
3102
|
-
/**
|
|
3103
|
-
* Get RPC URL for a chain
|
|
3104
|
-
*/
|
|
3105
|
-
getRpcUrl(chain) {
|
|
3106
|
-
const networkUrls = DEFAULT_RPC_URLS[this.config.network];
|
|
3107
|
-
if (this.config.rpcUrls?.[chain]) {
|
|
3108
|
-
return this.config.rpcUrls[chain];
|
|
3109
|
-
}
|
|
3110
|
-
return networkUrls[chain] || "";
|
|
3111
|
-
}
|
|
3112
|
-
/**
|
|
3113
|
-
* Get or create wallet instance for a specific chain
|
|
3114
|
-
*/
|
|
3115
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3116
|
-
async getWallet(chain) {
|
|
3117
|
-
if (!this.seed) {
|
|
3118
|
-
throw new Error("WDK service not initialized. Call initialize() first.");
|
|
3119
|
-
}
|
|
3120
|
-
if (this.wallets[chain]) {
|
|
3121
|
-
return this.wallets[chain];
|
|
3122
|
-
}
|
|
3123
|
-
const isTestnet = this.config.network === "testnet";
|
|
3124
|
-
try {
|
|
3125
|
-
switch (chain) {
|
|
3126
|
-
case "ethereum": {
|
|
3127
|
-
const rpcUrl = this.getRpcUrl("ethereum");
|
|
3128
|
-
const wallet = new WalletManagerEvm(this.seed, { provider: rpcUrl });
|
|
3129
|
-
this.wallets[chain] = wallet;
|
|
3130
|
-
return wallet;
|
|
3131
|
-
}
|
|
3132
|
-
case "bitcoin": {
|
|
3133
|
-
const wallet = new WalletManagerBtc(this.seed, {
|
|
3134
|
-
network: isTestnet ? "testnet" : "bitcoin"
|
|
3135
|
-
});
|
|
3136
|
-
this.wallets[chain] = wallet;
|
|
3137
|
-
return wallet;
|
|
3138
|
-
}
|
|
3139
|
-
case "solana": {
|
|
3140
|
-
const rpcUrl = this.getRpcUrl("solana");
|
|
3141
|
-
const wallet = new WalletManagerSolana(this.seed, {
|
|
3142
|
-
rpcUrl
|
|
3143
|
-
});
|
|
3144
|
-
this.wallets[chain] = wallet;
|
|
3145
|
-
return wallet;
|
|
3146
|
-
}
|
|
3147
|
-
case "ton": {
|
|
3148
|
-
const url = this.getRpcUrl("ton");
|
|
3149
|
-
const wallet = new WalletManagerTon(this.seed, {
|
|
3150
|
-
tonClient: { url }
|
|
3151
|
-
});
|
|
3152
|
-
this.wallets[chain] = wallet;
|
|
3153
|
-
return wallet;
|
|
3154
|
-
}
|
|
3155
|
-
case "tron": {
|
|
3156
|
-
const fullHost = this.getRpcUrl("tron");
|
|
3157
|
-
const wallet = new WalletManagerTron(this.seed, {
|
|
3158
|
-
provider: fullHost
|
|
3159
|
-
});
|
|
3160
|
-
this.wallets[chain] = wallet;
|
|
3161
|
-
return wallet;
|
|
3162
|
-
}
|
|
3163
|
-
case "spark": {
|
|
3164
|
-
const wallet = new WalletManagerSpark(this.seed, {
|
|
3165
|
-
network: isTestnet ? "TESTNET" : "MAINNET"
|
|
3166
|
-
});
|
|
3167
|
-
this.wallets[chain] = wallet;
|
|
3168
|
-
return wallet;
|
|
3169
|
-
}
|
|
3170
|
-
default:
|
|
3171
|
-
throw new Error(`Unsupported chain: ${chain}`);
|
|
3172
|
-
}
|
|
3173
|
-
} catch (error) {
|
|
3174
|
-
console.error(`Failed to initialize ${chain} wallet:`, error);
|
|
3175
|
-
throw error;
|
|
3176
|
-
}
|
|
3177
|
-
}
|
|
3178
|
-
/**
|
|
3179
|
-
* Derive address for a specific chain
|
|
3180
|
-
*/
|
|
3181
|
-
async deriveAddress(chain) {
|
|
3182
|
-
const path = DERIVATION_PATHS2[chain];
|
|
3183
|
-
try {
|
|
3184
|
-
const wallet = await this.getWallet(chain);
|
|
3185
|
-
const account = await wallet.getAccount(0);
|
|
3186
|
-
const address = await account.getAddress();
|
|
3187
|
-
return {
|
|
3188
|
-
chain,
|
|
3189
|
-
address,
|
|
3190
|
-
path
|
|
3191
|
-
};
|
|
3192
|
-
} catch (error) {
|
|
3193
|
-
console.error(`Error deriving ${chain} address:`, error);
|
|
3194
|
-
throw error;
|
|
3195
|
-
}
|
|
3196
|
-
}
|
|
3197
|
-
/**
|
|
3198
|
-
* Derive addresses for all supported chains
|
|
3199
|
-
*/
|
|
3200
|
-
async deriveAllAddresses() {
|
|
3201
|
-
const chains = ["ethereum", "bitcoin", "ton", "tron", "solana", "spark"];
|
|
3202
|
-
const addresses = {
|
|
3203
|
-
ethereum: null,
|
|
3204
|
-
bitcoin: null,
|
|
3205
|
-
ton: null,
|
|
3206
|
-
tron: null,
|
|
3207
|
-
solana: null,
|
|
3208
|
-
spark: null
|
|
3209
|
-
};
|
|
3210
|
-
const results = await Promise.allSettled(
|
|
3211
|
-
chains.map(async (chain) => {
|
|
3212
|
-
const result = await this.deriveAddress(chain);
|
|
3213
|
-
return { chain, address: result.address };
|
|
3214
|
-
})
|
|
3215
|
-
);
|
|
3216
|
-
for (const result of results) {
|
|
3217
|
-
if (result.status === "fulfilled") {
|
|
3218
|
-
addresses[result.value.chain] = result.value.address;
|
|
3219
|
-
} else {
|
|
3220
|
-
console.error("Failed to derive address:", result.reason);
|
|
3221
|
-
}
|
|
3222
|
-
}
|
|
3223
|
-
return addresses;
|
|
3224
|
-
}
|
|
3225
|
-
/**
|
|
3226
|
-
* Derive addresses for specific chains only
|
|
3227
|
-
*/
|
|
3228
|
-
async deriveAddressesForChains(chains) {
|
|
3229
|
-
const addresses = {};
|
|
3230
|
-
const results = await Promise.allSettled(
|
|
3231
|
-
chains.map(async (chain) => {
|
|
3232
|
-
const result = await this.deriveAddress(chain);
|
|
3233
|
-
return { chain, address: result.address };
|
|
3234
|
-
})
|
|
3235
|
-
);
|
|
3236
|
-
for (const result of results) {
|
|
3237
|
-
if (result.status === "fulfilled") {
|
|
3238
|
-
addresses[result.value.chain] = result.value.address;
|
|
3239
|
-
}
|
|
3240
|
-
}
|
|
3241
|
-
return addresses;
|
|
3242
|
-
}
|
|
3243
|
-
/**
|
|
3244
|
-
* Get fee rates for a specific chain
|
|
3245
|
-
*/
|
|
3246
|
-
async getFeeRates(chain) {
|
|
3247
|
-
if (!this.seed) {
|
|
3248
|
-
throw new Error("WDK service not initialized. Call initialize() first.");
|
|
3249
|
-
}
|
|
3250
|
-
try {
|
|
3251
|
-
const wallet = await this.getWallet(chain);
|
|
3252
|
-
const feeRates = await wallet.getFeeRates();
|
|
3253
|
-
return {
|
|
3254
|
-
slow: (feeRates.slow || feeRates.low || "0").toString(),
|
|
3255
|
-
medium: (feeRates.medium || feeRates.normal || feeRates.standard || "0").toString(),
|
|
3256
|
-
fast: (feeRates.fast || feeRates.high || "0").toString()
|
|
3257
|
-
};
|
|
3258
|
-
} catch (error) {
|
|
3259
|
-
console.error(`Error fetching fee rates for ${chain}:`, error);
|
|
3260
|
-
throw error;
|
|
3261
|
-
}
|
|
3262
|
-
}
|
|
3263
|
-
/**
|
|
3264
|
-
* Get the current network configuration
|
|
3265
|
-
*/
|
|
3266
|
-
getNetwork() {
|
|
3267
|
-
return this.config.network;
|
|
3268
|
-
}
|
|
3269
|
-
/**
|
|
3270
|
-
* Check if service is initialized
|
|
3271
|
-
*/
|
|
3272
|
-
isInitialized() {
|
|
3273
|
-
return this.seed !== null;
|
|
3274
|
-
}
|
|
3275
|
-
/**
|
|
3276
|
-
* Clean up and dispose of wallet instances
|
|
3277
|
-
*/
|
|
3278
|
-
dispose() {
|
|
3279
|
-
for (const wallet of Object.values(this.wallets)) {
|
|
3280
|
-
if (wallet && typeof wallet.dispose === "function") {
|
|
3281
|
-
try {
|
|
3282
|
-
wallet.dispose();
|
|
3283
|
-
} catch {
|
|
3284
|
-
}
|
|
3285
|
-
}
|
|
3286
|
-
}
|
|
3287
|
-
this.wallets = {};
|
|
3288
|
-
this.seed = null;
|
|
3289
|
-
}
|
|
3290
|
-
};
|
|
3291
|
-
var DERIVATION_PATHS3 = {
|
|
3292
529
|
ethereum: "m/44'/60'/0'/0/0",
|
|
3293
530
|
bitcoin_mainnet: "m/84'/0'/0'/0/0",
|
|
3294
531
|
bitcoin_testnet: "m/84'/1'/0'/0/0",
|
|
@@ -3298,14 +535,14 @@ var DERIVATION_PATHS3 = {
|
|
|
3298
535
|
spark: "m/44'/998'/0'/0/0"
|
|
3299
536
|
};
|
|
3300
537
|
function deriveEthereumAddress(seed) {
|
|
3301
|
-
const hdNode = ethers.HDNodeWallet.fromPhrase(seed, void 0,
|
|
538
|
+
const hdNode = ethers.HDNodeWallet.fromPhrase(seed, void 0, DERIVATION_PATHS2.ethereum);
|
|
3302
539
|
return hdNode.address;
|
|
3303
540
|
}
|
|
3304
541
|
function deriveBitcoinAddress(seed, network = "testnet") {
|
|
3305
542
|
try {
|
|
3306
543
|
const seedBytes = bip39.mnemonicToSeedSync(seed);
|
|
3307
544
|
const hdKey = bip32.HDKey.fromMasterSeed(seedBytes);
|
|
3308
|
-
const path = network === "testnet" ?
|
|
545
|
+
const path = network === "testnet" ? DERIVATION_PATHS2.bitcoin_testnet : DERIVATION_PATHS2.bitcoin_mainnet;
|
|
3309
546
|
const child = hdKey.derive(path);
|
|
3310
547
|
if (!child.publicKey) {
|
|
3311
548
|
throw new Error("Failed to derive public key");
|
|
@@ -3324,13 +561,14 @@ function deriveBitcoinAddress(seed, network = "testnet") {
|
|
|
3324
561
|
}
|
|
3325
562
|
async function deriveSolanaAddress(seed) {
|
|
3326
563
|
try {
|
|
3327
|
-
const [ed25519, nacl,
|
|
564
|
+
const [ed25519, nacl, bs58Module] = await Promise.all([
|
|
3328
565
|
import('ed25519-hd-key'),
|
|
3329
|
-
|
|
3330
|
-
|
|
566
|
+
import('tweetnacl'),
|
|
567
|
+
import('bs58')
|
|
3331
568
|
]);
|
|
569
|
+
const bs58 = bs58Module.default || bs58Module;
|
|
3332
570
|
const seedBytes = bip39.mnemonicToSeedSync(seed);
|
|
3333
|
-
const derived = ed25519.derivePath(
|
|
571
|
+
const derived = ed25519.derivePath(DERIVATION_PATHS2.solana, Buffer.from(seedBytes).toString("hex"));
|
|
3334
572
|
const keypair = nacl.sign.keyPair.fromSeed(new Uint8Array(derived.key));
|
|
3335
573
|
return bs58.encode(keypair.publicKey);
|
|
3336
574
|
} catch (error) {
|
|
@@ -3342,10 +580,10 @@ async function deriveTonAddress(seed) {
|
|
|
3342
580
|
try {
|
|
3343
581
|
const [ed25519, nacl] = await Promise.all([
|
|
3344
582
|
import('ed25519-hd-key'),
|
|
3345
|
-
|
|
583
|
+
import('tweetnacl')
|
|
3346
584
|
]);
|
|
3347
585
|
const seedBytes = bip39.mnemonicToSeedSync(seed);
|
|
3348
|
-
const derived = ed25519.derivePath(
|
|
586
|
+
const derived = ed25519.derivePath(DERIVATION_PATHS2.ton, Buffer.from(seedBytes).toString("hex"));
|
|
3349
587
|
const keypair = nacl.sign.keyPair.fromSeed(new Uint8Array(derived.key));
|
|
3350
588
|
const publicKey = keypair.publicKey;
|
|
3351
589
|
const workchain = 0;
|
|
@@ -3378,17 +616,17 @@ function crc16(data) {
|
|
|
3378
616
|
}
|
|
3379
617
|
return crc;
|
|
3380
618
|
}
|
|
3381
|
-
|
|
619
|
+
function deriveTronAddress(seed) {
|
|
3382
620
|
try {
|
|
3383
|
-
const
|
|
3384
|
-
const hdNode = ethers.HDNodeWallet.fromPhrase(seed, void 0, DERIVATION_PATHS3.tron);
|
|
621
|
+
const hdNode = ethers.HDNodeWallet.fromPhrase(seed, void 0, DERIVATION_PATHS2.tron);
|
|
3385
622
|
const ethAddressHex = hdNode.address.slice(2).toLowerCase();
|
|
3386
623
|
const addressBytes = new Uint8Array(21);
|
|
3387
624
|
addressBytes[0] = 65;
|
|
3388
625
|
for (let i = 0; i < 20; i++) {
|
|
3389
626
|
addressBytes[i + 1] = parseInt(ethAddressHex.slice(i * 2, i * 2 + 2), 16);
|
|
3390
627
|
}
|
|
3391
|
-
|
|
628
|
+
const tronBase58check = base.base58check(sha256.sha256);
|
|
629
|
+
return tronBase58check.encode(addressBytes);
|
|
3392
630
|
} catch (error) {
|
|
3393
631
|
console.error("TRON address derivation failed:", error);
|
|
3394
632
|
throw error;
|
|
@@ -3398,7 +636,7 @@ function deriveSparkAddress(seed, network = "testnet") {
|
|
|
3398
636
|
try {
|
|
3399
637
|
const seedBytes = bip39.mnemonicToSeedSync(seed);
|
|
3400
638
|
const hdKey = bip32.HDKey.fromMasterSeed(seedBytes);
|
|
3401
|
-
const child = hdKey.derive(
|
|
639
|
+
const child = hdKey.derive(DERIVATION_PATHS2.spark);
|
|
3402
640
|
if (!child.publicKey) {
|
|
3403
641
|
throw new Error("Failed to derive public key");
|
|
3404
642
|
}
|
|
@@ -3438,10 +676,14 @@ async function deriveAllAddresses(seed, network = "testnet") {
|
|
|
3438
676
|
} catch (e) {
|
|
3439
677
|
console.error("Spark derivation failed:", e);
|
|
3440
678
|
}
|
|
3441
|
-
|
|
679
|
+
try {
|
|
680
|
+
addresses.tron = deriveTronAddress(seed);
|
|
681
|
+
} catch (e) {
|
|
682
|
+
console.error("TRON derivation failed:", e);
|
|
683
|
+
}
|
|
684
|
+
const [solResult, tonResult] = await Promise.allSettled([
|
|
3442
685
|
deriveSolanaAddress(seed),
|
|
3443
|
-
deriveTonAddress(seed)
|
|
3444
|
-
deriveTronAddress(seed)
|
|
686
|
+
deriveTonAddress(seed)
|
|
3445
687
|
]);
|
|
3446
688
|
if (solResult.status === "fulfilled") {
|
|
3447
689
|
addresses.solana = solResult.value;
|
|
@@ -3453,13 +695,379 @@ async function deriveAllAddresses(seed, network = "testnet") {
|
|
|
3453
695
|
} else {
|
|
3454
696
|
console.error("TON derivation failed:", tonResult.reason);
|
|
3455
697
|
}
|
|
3456
|
-
if (tronResult.status === "fulfilled") {
|
|
3457
|
-
addresses.tron = tronResult.value;
|
|
3458
|
-
} else {
|
|
3459
|
-
console.error("TRON derivation failed:", tronResult.reason);
|
|
3460
|
-
}
|
|
3461
698
|
return addresses;
|
|
3462
699
|
}
|
|
700
|
+
function isValidSeed(seed) {
|
|
701
|
+
return bip39.validateMnemonic(seed, english.wordlist);
|
|
702
|
+
}
|
|
703
|
+
function generateSeedPhrase() {
|
|
704
|
+
return bip39.generateMnemonic(english.wordlist);
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
// src/services/ZubariWdkService.ts
|
|
708
|
+
var DEFAULT_API_URL2 = "https://ckgwifsxka.us-east-2.awsapprunner.com";
|
|
709
|
+
function isBrowser() {
|
|
710
|
+
return typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
711
|
+
}
|
|
712
|
+
var dynamicImport = new Function("specifier", "return import(specifier)");
|
|
713
|
+
async function canUseNativeWdk() {
|
|
714
|
+
if (isBrowser()) {
|
|
715
|
+
return false;
|
|
716
|
+
}
|
|
717
|
+
try {
|
|
718
|
+
await dynamicImport("@tetherto/wdk");
|
|
719
|
+
return true;
|
|
720
|
+
} catch {
|
|
721
|
+
return false;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
var ZubariWdkService = class {
|
|
725
|
+
config;
|
|
726
|
+
apiClient;
|
|
727
|
+
nativeWdkService = null;
|
|
728
|
+
initialized = false;
|
|
729
|
+
useNativeWdk = false;
|
|
730
|
+
constructor(config = {}) {
|
|
731
|
+
this.config = {
|
|
732
|
+
network: config.network || "testnet",
|
|
733
|
+
apiUrl: config.apiUrl || process.env.NEXT_PUBLIC_API_URL || DEFAULT_API_URL2,
|
|
734
|
+
forceApi: config.forceApi ?? false,
|
|
735
|
+
timeout: config.timeout || 3e4
|
|
736
|
+
};
|
|
737
|
+
this.apiClient = getWdkApiClient(this.config.apiUrl);
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* Initialize the service and determine the best strategy
|
|
741
|
+
*/
|
|
742
|
+
async initialize() {
|
|
743
|
+
if (this.initialized) return;
|
|
744
|
+
if (isBrowser() || this.config.forceApi) {
|
|
745
|
+
this.useNativeWdk = false;
|
|
746
|
+
this.initialized = true;
|
|
747
|
+
return;
|
|
748
|
+
}
|
|
749
|
+
if (await canUseNativeWdk()) {
|
|
750
|
+
try {
|
|
751
|
+
const WdkServiceModule = await dynamicImport("./WdkService");
|
|
752
|
+
const WdkService = WdkServiceModule.WdkService || WdkServiceModule.default;
|
|
753
|
+
this.nativeWdkService = new WdkService({
|
|
754
|
+
network: this.config.network
|
|
755
|
+
});
|
|
756
|
+
this.useNativeWdk = true;
|
|
757
|
+
} catch (error) {
|
|
758
|
+
console.warn("Failed to initialize native WDK, falling back to API:", error);
|
|
759
|
+
this.useNativeWdk = false;
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
this.initialized = true;
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* Get the current execution mode
|
|
766
|
+
*/
|
|
767
|
+
getMode() {
|
|
768
|
+
if (this.useNativeWdk) return "native";
|
|
769
|
+
if (isBrowser()) return "api";
|
|
770
|
+
return "api";
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* Check if running in browser
|
|
774
|
+
*/
|
|
775
|
+
isBrowserEnvironment() {
|
|
776
|
+
return isBrowser();
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* Generate a new BIP-39 seed phrase (12 words)
|
|
780
|
+
*/
|
|
781
|
+
async generateSeed() {
|
|
782
|
+
await this.initialize();
|
|
783
|
+
try {
|
|
784
|
+
const response = await this.apiClient.generateSeed();
|
|
785
|
+
if (response.success && response.seed) {
|
|
786
|
+
return response.seed;
|
|
787
|
+
}
|
|
788
|
+
} catch (error) {
|
|
789
|
+
console.warn("API seed generation failed:", error);
|
|
790
|
+
}
|
|
791
|
+
if (this.useNativeWdk && this.nativeWdkService) {
|
|
792
|
+
try {
|
|
793
|
+
const wdk = this.nativeWdkService;
|
|
794
|
+
return await wdk.generateSeedPhrase();
|
|
795
|
+
} catch (error) {
|
|
796
|
+
console.warn("Native WDK seed generation failed:", error);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
return generateSeedPhrase();
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* Validate a BIP-39 seed phrase
|
|
803
|
+
*/
|
|
804
|
+
async validateSeed(seed) {
|
|
805
|
+
await this.initialize();
|
|
806
|
+
try {
|
|
807
|
+
const response = await this.apiClient.validateSeed(seed);
|
|
808
|
+
if (response.success) {
|
|
809
|
+
return response.isValid ?? false;
|
|
810
|
+
}
|
|
811
|
+
} catch (error) {
|
|
812
|
+
console.warn("API seed validation failed:", error);
|
|
813
|
+
}
|
|
814
|
+
if (this.useNativeWdk && this.nativeWdkService) {
|
|
815
|
+
try {
|
|
816
|
+
const wdk = this.nativeWdkService;
|
|
817
|
+
return await wdk.isValidSeed(seed);
|
|
818
|
+
} catch (error) {
|
|
819
|
+
console.warn("Native WDK seed validation failed:", error);
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
return isValidSeed(seed);
|
|
823
|
+
}
|
|
824
|
+
/**
|
|
825
|
+
* Derive address for a specific chain
|
|
826
|
+
*/
|
|
827
|
+
async deriveAddress(seed, chain) {
|
|
828
|
+
await this.initialize();
|
|
829
|
+
const path = this.getDerivationPath(chain);
|
|
830
|
+
try {
|
|
831
|
+
const response = await this.apiClient.deriveAddress(seed, chain, this.config.network);
|
|
832
|
+
if (response.success && response.address) {
|
|
833
|
+
return {
|
|
834
|
+
chain,
|
|
835
|
+
address: response.address,
|
|
836
|
+
path: response.path || path
|
|
837
|
+
};
|
|
838
|
+
}
|
|
839
|
+
} catch (error) {
|
|
840
|
+
console.warn(`API address derivation failed for ${chain}:`, error);
|
|
841
|
+
}
|
|
842
|
+
if (this.useNativeWdk && this.nativeWdkService) {
|
|
843
|
+
try {
|
|
844
|
+
const wdk = this.nativeWdkService;
|
|
845
|
+
await wdk.initialize(seed);
|
|
846
|
+
return await wdk.deriveAddress(chain);
|
|
847
|
+
} catch (error) {
|
|
848
|
+
console.warn(`Native WDK address derivation failed for ${chain}:`, error);
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
return this.deriveBrowserAddress(seed, chain);
|
|
852
|
+
}
|
|
853
|
+
/**
|
|
854
|
+
* Derive addresses for all supported chains
|
|
855
|
+
*/
|
|
856
|
+
async deriveAllAddresses(seed) {
|
|
857
|
+
await this.initialize();
|
|
858
|
+
try {
|
|
859
|
+
const response = await this.apiClient.deriveAllAddresses(seed, this.config.network);
|
|
860
|
+
if (response.success && response.addresses) {
|
|
861
|
+
return {
|
|
862
|
+
ethereum: response.addresses.ethereum || null,
|
|
863
|
+
bitcoin: response.addresses.bitcoin || null,
|
|
864
|
+
ton: response.addresses.ton || null,
|
|
865
|
+
tron: response.addresses.tron || null,
|
|
866
|
+
solana: response.addresses.solana || null,
|
|
867
|
+
spark: response.addresses.spark || null
|
|
868
|
+
};
|
|
869
|
+
}
|
|
870
|
+
} catch (error) {
|
|
871
|
+
console.warn("API address derivation failed:", error);
|
|
872
|
+
}
|
|
873
|
+
if (this.useNativeWdk && this.nativeWdkService) {
|
|
874
|
+
try {
|
|
875
|
+
const wdk = this.nativeWdkService;
|
|
876
|
+
await wdk.initialize(seed);
|
|
877
|
+
return await wdk.deriveAllAddresses();
|
|
878
|
+
} catch (error) {
|
|
879
|
+
console.warn("Native WDK multi-chain derivation failed:", error);
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
return this.deriveAllBrowserAddresses(seed);
|
|
883
|
+
}
|
|
884
|
+
/**
|
|
885
|
+
* Get balances for all chains
|
|
886
|
+
*/
|
|
887
|
+
async getAllBalances(seed) {
|
|
888
|
+
await this.initialize();
|
|
889
|
+
try {
|
|
890
|
+
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/balances`, {
|
|
891
|
+
method: "POST",
|
|
892
|
+
headers: { "Content-Type": "application/json" },
|
|
893
|
+
body: JSON.stringify({ seed, network: this.config.network })
|
|
894
|
+
});
|
|
895
|
+
if (response.ok) {
|
|
896
|
+
const data = await response.json();
|
|
897
|
+
if (data.success) {
|
|
898
|
+
return data.balances;
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
} catch (error) {
|
|
902
|
+
console.warn("Failed to fetch balances:", error);
|
|
903
|
+
}
|
|
904
|
+
return {};
|
|
905
|
+
}
|
|
906
|
+
/**
|
|
907
|
+
* Get fee rates for a chain
|
|
908
|
+
*/
|
|
909
|
+
async getFeeRates(seed, chain) {
|
|
910
|
+
await this.initialize();
|
|
911
|
+
try {
|
|
912
|
+
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/fee-rates`, {
|
|
913
|
+
method: "POST",
|
|
914
|
+
headers: { "Content-Type": "application/json" },
|
|
915
|
+
body: JSON.stringify({ seed, chain, network: this.config.network })
|
|
916
|
+
});
|
|
917
|
+
if (response.ok) {
|
|
918
|
+
const data = await response.json();
|
|
919
|
+
if (data.success && data.feeRates) {
|
|
920
|
+
return data.feeRates;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
} catch (error) {
|
|
924
|
+
console.warn(`Failed to fetch fee rates for ${chain}:`, error);
|
|
925
|
+
}
|
|
926
|
+
return { slow: "0", normal: "0", fast: "0" };
|
|
927
|
+
}
|
|
928
|
+
/**
|
|
929
|
+
* Estimate transaction fee
|
|
930
|
+
*/
|
|
931
|
+
async estimateFee(seed, chain, to, amount) {
|
|
932
|
+
await this.initialize();
|
|
933
|
+
try {
|
|
934
|
+
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/estimate-fee`, {
|
|
935
|
+
method: "POST",
|
|
936
|
+
headers: { "Content-Type": "application/json" },
|
|
937
|
+
body: JSON.stringify({ seed, chain, to, amount, network: this.config.network })
|
|
938
|
+
});
|
|
939
|
+
if (response.ok) {
|
|
940
|
+
const data = await response.json();
|
|
941
|
+
if (data.success) {
|
|
942
|
+
return { fee: data.fee, symbol: data.symbol };
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
} catch (error) {
|
|
946
|
+
console.warn(`Failed to estimate fee for ${chain}:`, error);
|
|
947
|
+
}
|
|
948
|
+
return { fee: "0", symbol: this.getChainSymbol(chain) };
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* Send a transaction
|
|
952
|
+
*/
|
|
953
|
+
async sendTransaction(seed, chain, to, amount) {
|
|
954
|
+
await this.initialize();
|
|
955
|
+
try {
|
|
956
|
+
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/send`, {
|
|
957
|
+
method: "POST",
|
|
958
|
+
headers: { "Content-Type": "application/json" },
|
|
959
|
+
body: JSON.stringify({ seed, chain, to, amount, network: this.config.network })
|
|
960
|
+
});
|
|
961
|
+
if (response.ok) {
|
|
962
|
+
const data = await response.json();
|
|
963
|
+
return {
|
|
964
|
+
success: data.success,
|
|
965
|
+
txHash: data.txHash,
|
|
966
|
+
from: data.from,
|
|
967
|
+
to: data.to,
|
|
968
|
+
amount: data.amount,
|
|
969
|
+
chain: data.chain,
|
|
970
|
+
network: data.network
|
|
971
|
+
};
|
|
972
|
+
}
|
|
973
|
+
const errorData = await response.json().catch(() => ({}));
|
|
974
|
+
return {
|
|
975
|
+
success: false,
|
|
976
|
+
error: errorData.error || `HTTP ${response.status}`
|
|
977
|
+
};
|
|
978
|
+
} catch (error) {
|
|
979
|
+
return {
|
|
980
|
+
success: false,
|
|
981
|
+
error: error instanceof Error ? error.message : "Transaction failed"
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* Get the network configuration
|
|
987
|
+
*/
|
|
988
|
+
getNetwork() {
|
|
989
|
+
return this.config.network;
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
* Get API URL
|
|
993
|
+
*/
|
|
994
|
+
getApiUrl() {
|
|
995
|
+
return this.config.apiUrl;
|
|
996
|
+
}
|
|
997
|
+
// ==========================================
|
|
998
|
+
// Private Helper Methods
|
|
999
|
+
// ==========================================
|
|
1000
|
+
getDerivationPath(chain) {
|
|
1001
|
+
const paths = {
|
|
1002
|
+
bitcoin: this.config.network === "testnet" ? "m/84'/1'/0'/0/0" : "m/84'/0'/0'/0/0",
|
|
1003
|
+
ethereum: "m/44'/60'/0'/0/0",
|
|
1004
|
+
ton: "m/44'/607'/0'/0'/0'",
|
|
1005
|
+
tron: "m/44'/195'/0'/0/0",
|
|
1006
|
+
solana: "m/44'/501'/0'/0'",
|
|
1007
|
+
spark: "m/44'/998'/0'/0/0"
|
|
1008
|
+
};
|
|
1009
|
+
return paths[chain];
|
|
1010
|
+
}
|
|
1011
|
+
getChainSymbol(chain) {
|
|
1012
|
+
const symbols = {
|
|
1013
|
+
ethereum: "ETH",
|
|
1014
|
+
bitcoin: "BTC",
|
|
1015
|
+
ton: "TON",
|
|
1016
|
+
tron: "TRX",
|
|
1017
|
+
solana: "SOL",
|
|
1018
|
+
spark: "SAT"
|
|
1019
|
+
};
|
|
1020
|
+
return symbols[chain];
|
|
1021
|
+
}
|
|
1022
|
+
/**
|
|
1023
|
+
* Derive address using browser-compatible libraries
|
|
1024
|
+
*/
|
|
1025
|
+
async deriveBrowserAddress(seed, chain) {
|
|
1026
|
+
const path = this.getDerivationPath(chain);
|
|
1027
|
+
try {
|
|
1028
|
+
let address;
|
|
1029
|
+
switch (chain) {
|
|
1030
|
+
case "ethereum":
|
|
1031
|
+
address = deriveEthereumAddress(seed);
|
|
1032
|
+
break;
|
|
1033
|
+
case "bitcoin":
|
|
1034
|
+
address = deriveBitcoinAddress(seed, this.config.network);
|
|
1035
|
+
break;
|
|
1036
|
+
case "tron":
|
|
1037
|
+
address = deriveTronAddress(seed);
|
|
1038
|
+
break;
|
|
1039
|
+
case "spark":
|
|
1040
|
+
address = deriveSparkAddress(seed, this.config.network);
|
|
1041
|
+
break;
|
|
1042
|
+
case "solana":
|
|
1043
|
+
address = await deriveSolanaAddress(seed);
|
|
1044
|
+
break;
|
|
1045
|
+
case "ton":
|
|
1046
|
+
address = await deriveTonAddress(seed);
|
|
1047
|
+
break;
|
|
1048
|
+
default:
|
|
1049
|
+
throw new Error(`Unsupported chain: ${chain}`);
|
|
1050
|
+
}
|
|
1051
|
+
return { chain, address, path };
|
|
1052
|
+
} catch (error) {
|
|
1053
|
+
console.error(`Browser derivation failed for ${chain}:`, error);
|
|
1054
|
+
throw error;
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
/**
|
|
1058
|
+
* Derive all addresses using browser-compatible libraries
|
|
1059
|
+
*/
|
|
1060
|
+
async deriveAllBrowserAddresses(seed) {
|
|
1061
|
+
return deriveAllAddresses(seed, this.config.network);
|
|
1062
|
+
}
|
|
1063
|
+
};
|
|
1064
|
+
var defaultService = null;
|
|
1065
|
+
function getZubariWdkService(config) {
|
|
1066
|
+
if (!defaultService || config && config.network !== defaultService.getNetwork()) {
|
|
1067
|
+
defaultService = new ZubariWdkService(config);
|
|
1068
|
+
}
|
|
1069
|
+
return defaultService;
|
|
1070
|
+
}
|
|
3463
1071
|
|
|
3464
1072
|
// src/wallet/WalletManager.ts
|
|
3465
1073
|
var STORAGE_KEYS = {
|
|
@@ -3483,11 +1091,12 @@ var WalletManager = class _WalletManager {
|
|
|
3483
1091
|
rpcUrl: config.rpcUrl || ethereumConfig.rpcUrl,
|
|
3484
1092
|
storage: config.storage || createSecureStorage(),
|
|
3485
1093
|
enabledChains: config.enabledChains || SUPPORTED_CHAINS,
|
|
3486
|
-
apiUrl: config.apiUrl || process.env.NEXT_PUBLIC_API_URL || "
|
|
1094
|
+
apiUrl: config.apiUrl || process.env.NEXT_PUBLIC_API_URL || "https://ckgwifsxka.us-east-2.awsapprunner.com"
|
|
3487
1095
|
};
|
|
3488
1096
|
this.storage = this.config.storage;
|
|
3489
|
-
this.wdkService =
|
|
3490
|
-
network: this.config.network
|
|
1097
|
+
this.wdkService = getZubariWdkService({
|
|
1098
|
+
network: this.config.network,
|
|
1099
|
+
apiUrl: this.config.apiUrl
|
|
3491
1100
|
});
|
|
3492
1101
|
}
|
|
3493
1102
|
/**
|
|
@@ -3503,17 +1112,17 @@ var WalletManager = class _WalletManager {
|
|
|
3503
1112
|
return mnemonic.phrase;
|
|
3504
1113
|
}
|
|
3505
1114
|
/**
|
|
3506
|
-
* Generate a new BIP-39 seed phrase using
|
|
1115
|
+
* Generate a new BIP-39 seed phrase using Tether WDK (via API in browser)
|
|
3507
1116
|
* This is the recommended method for generating seed phrases
|
|
3508
1117
|
*/
|
|
3509
1118
|
async generateSeedWithWdk() {
|
|
3510
|
-
return await this.wdkService.
|
|
1119
|
+
return await this.wdkService.generateSeed();
|
|
3511
1120
|
}
|
|
3512
1121
|
/**
|
|
3513
|
-
* Validate seed phrase using
|
|
1122
|
+
* Validate seed phrase using WDK (async, more accurate)
|
|
3514
1123
|
*/
|
|
3515
1124
|
async validateSeedWithWdk(seed) {
|
|
3516
|
-
return await this.wdkService.
|
|
1125
|
+
return await this.wdkService.validateSeed(seed);
|
|
3517
1126
|
}
|
|
3518
1127
|
/**
|
|
3519
1128
|
* Validate a BIP-39 seed phrase
|
|
@@ -3592,7 +1201,6 @@ var WalletManager = class _WalletManager {
|
|
|
3592
1201
|
*/
|
|
3593
1202
|
lock() {
|
|
3594
1203
|
this.currentSeed = null;
|
|
3595
|
-
this.wdkService.dispose();
|
|
3596
1204
|
}
|
|
3597
1205
|
/**
|
|
3598
1206
|
* Check if wallet exists in storage
|
|
@@ -3608,7 +1216,6 @@ var WalletManager = class _WalletManager {
|
|
|
3608
1216
|
this.currentSeed = null;
|
|
3609
1217
|
this.derivedAddress = null;
|
|
3610
1218
|
this.derivedAddresses = {};
|
|
3611
|
-
this.wdkService.dispose();
|
|
3612
1219
|
}
|
|
3613
1220
|
/**
|
|
3614
1221
|
* Get current wallet state
|
|
@@ -3708,19 +1315,18 @@ var WalletManager = class _WalletManager {
|
|
|
3708
1315
|
/**
|
|
3709
1316
|
* Derive address for a specific chain (async version)
|
|
3710
1317
|
*
|
|
3711
|
-
*
|
|
3712
|
-
*
|
|
1318
|
+
* Uses the unified WDK service which:
|
|
1319
|
+
* - In browser: Calls the backend API (which has Tether WDK)
|
|
1320
|
+
* - In Node.js: Uses native WDK
|
|
1321
|
+
* - Falls back to browser-compatible derivation if needed
|
|
3713
1322
|
*/
|
|
3714
1323
|
static async deriveAddressForChainAsync(seed, chain, network = "testnet", apiUrl) {
|
|
3715
1324
|
try {
|
|
3716
|
-
const
|
|
3717
|
-
const
|
|
3718
|
-
|
|
3719
|
-
return response.address;
|
|
3720
|
-
}
|
|
3721
|
-
console.warn(`WDK API failed for ${chain}, using local derivation:`, response.error);
|
|
1325
|
+
const wdkService = getZubariWdkService({ network, apiUrl });
|
|
1326
|
+
const result = await wdkService.deriveAddress(seed, chain);
|
|
1327
|
+
return result.address;
|
|
3722
1328
|
} catch (error) {
|
|
3723
|
-
console.warn(`WDK
|
|
1329
|
+
console.warn(`WDK service failed for ${chain}, using local derivation:`, error);
|
|
3724
1330
|
}
|
|
3725
1331
|
return _WalletManager.deriveAddressForChain(seed, chain);
|
|
3726
1332
|
}
|
|
@@ -3816,8 +1422,9 @@ var WalletManager = class _WalletManager {
|
|
|
3816
1422
|
return addresses;
|
|
3817
1423
|
}
|
|
3818
1424
|
/**
|
|
3819
|
-
* Derive addresses for all enabled chains using
|
|
3820
|
-
*
|
|
1425
|
+
* Derive addresses for all enabled chains using Tether WDK
|
|
1426
|
+
* In browser: Uses the backend API (which has Tether WDK)
|
|
1427
|
+
* In Node.js: Uses native WDK directly
|
|
3821
1428
|
* Returns REAL cryptographically valid addresses for all chains.
|
|
3822
1429
|
*/
|
|
3823
1430
|
async deriveAllAddressesWithWdk() {
|
|
@@ -3825,9 +1432,8 @@ var WalletManager = class _WalletManager {
|
|
|
3825
1432
|
throw new Error("Wallet is locked");
|
|
3826
1433
|
}
|
|
3827
1434
|
try {
|
|
3828
|
-
await this.wdkService.
|
|
1435
|
+
const wdkAddresses = await this.wdkService.deriveAllAddresses(this.currentSeed);
|
|
3829
1436
|
const enabledChainsSet = new Set(this.config.enabledChains);
|
|
3830
|
-
const wdkAddresses = await this.wdkService.deriveAllAddresses();
|
|
3831
1437
|
const addresses = {};
|
|
3832
1438
|
for (const [chain, address] of Object.entries(wdkAddresses)) {
|
|
3833
1439
|
if (enabledChainsSet.has(chain) && address) {
|
|
@@ -3837,13 +1443,15 @@ var WalletManager = class _WalletManager {
|
|
|
3837
1443
|
this.derivedAddresses = addresses;
|
|
3838
1444
|
return addresses;
|
|
3839
1445
|
} catch (error) {
|
|
3840
|
-
console.error("
|
|
1446
|
+
console.error("WDK derivation failed:", error);
|
|
3841
1447
|
throw error;
|
|
3842
1448
|
}
|
|
3843
1449
|
}
|
|
3844
1450
|
/**
|
|
3845
1451
|
* Derive addresses for all enabled chains using Tether WDK
|
|
3846
|
-
*
|
|
1452
|
+
* The unified WDK service handles all fallback strategies automatically:
|
|
1453
|
+
* - Browser: API backend -> Browser derivation
|
|
1454
|
+
* - Node.js: Native WDK -> API backend -> Browser derivation
|
|
3847
1455
|
*/
|
|
3848
1456
|
async deriveAllAddressesAsync() {
|
|
3849
1457
|
if (!this.currentSeed) {
|
|
@@ -3851,44 +1459,8 @@ var WalletManager = class _WalletManager {
|
|
|
3851
1459
|
}
|
|
3852
1460
|
try {
|
|
3853
1461
|
return await this.deriveAllAddressesWithWdk();
|
|
3854
|
-
} catch (
|
|
3855
|
-
console.
|
|
3856
|
-
}
|
|
3857
|
-
try {
|
|
3858
|
-
const wdkApi = getWdkApiClient(this.config.apiUrl);
|
|
3859
|
-
const response = await wdkApi.deriveAllAddresses(this.currentSeed, this.config.network);
|
|
3860
|
-
if (response.success && response.addresses) {
|
|
3861
|
-
const addresses = {};
|
|
3862
|
-
for (const chain of this.config.enabledChains) {
|
|
3863
|
-
const address = response.addresses[chain];
|
|
3864
|
-
if (address) {
|
|
3865
|
-
addresses[chain] = address;
|
|
3866
|
-
}
|
|
3867
|
-
}
|
|
3868
|
-
this.derivedAddresses = addresses;
|
|
3869
|
-
return addresses;
|
|
3870
|
-
}
|
|
3871
|
-
console.warn("WDK API call failed:", response.error);
|
|
3872
|
-
} catch (apiError) {
|
|
3873
|
-
console.warn("WDK API unavailable:", apiError);
|
|
3874
|
-
}
|
|
3875
|
-
console.log("Using browser-compatible address derivation...");
|
|
3876
|
-
try {
|
|
3877
|
-
const browserAddresses = await deriveAllAddresses(
|
|
3878
|
-
this.currentSeed,
|
|
3879
|
-
this.config.network
|
|
3880
|
-
);
|
|
3881
|
-
const addresses = {};
|
|
3882
|
-
for (const chain of this.config.enabledChains) {
|
|
3883
|
-
const address = browserAddresses[chain];
|
|
3884
|
-
if (address) {
|
|
3885
|
-
addresses[chain] = address;
|
|
3886
|
-
}
|
|
3887
|
-
}
|
|
3888
|
-
this.derivedAddresses = addresses;
|
|
3889
|
-
return addresses;
|
|
3890
|
-
} catch (browserError) {
|
|
3891
|
-
console.error("Browser derivation failed:", browserError);
|
|
1462
|
+
} catch (error) {
|
|
1463
|
+
console.error("All derivation strategies failed:", error);
|
|
3892
1464
|
const ethAddress = _WalletManager.deriveAddress(this.currentSeed);
|
|
3893
1465
|
this.derivedAddresses = { ethereum: ethAddress };
|
|
3894
1466
|
return this.derivedAddresses;
|