@moonpay/cli 0.3.4 → 0.3.5

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/index.js CHANGED
@@ -1,2636 +1,27 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire as __createRequire } from "module"; const require = __createRequire(import.meta.url);
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
10
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
11
- }) : x)(function(x) {
12
- if (typeof require !== "undefined") return require.apply(this, arguments);
13
- throw Error('Dynamic require of "' + x + '" is not supported');
14
- });
15
- var __commonJS = (cb, mod) => function __require2() {
16
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
17
- };
18
- var __copyProps = (to, from, except, desc) => {
19
- if (from && typeof from === "object" || typeof from === "function") {
20
- for (let key of __getOwnPropNames(from))
21
- if (!__hasOwnProp.call(to, key) && key !== except)
22
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
- }
24
- return to;
25
- };
26
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
27
- // If the importer is in node compatibility mode or this is not an ESM
28
- // file that has been converted to a CommonJS file using a Babel-
29
- // compatible transform (i.e. "__esModule" has not been set), then set
30
- // "default" to the CommonJS "module.exports" for node compatibility.
31
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
32
- mod
33
- ));
34
-
35
- // ../../node_modules/tweetnacl/nacl-fast.js
36
- var require_nacl_fast = __commonJS({
37
- "../../node_modules/tweetnacl/nacl-fast.js"(exports, module) {
38
- "use strict";
39
- (function(nacl2) {
40
- "use strict";
41
- var gf = function(init) {
42
- var i, r = new Float64Array(16);
43
- if (init) for (i = 0; i < init.length; i++) r[i] = init[i];
44
- return r;
45
- };
46
- var randombytes = function() {
47
- throw new Error("no PRNG");
48
- };
49
- var _0 = new Uint8Array(16);
50
- var _9 = new Uint8Array(32);
51
- _9[0] = 9;
52
- 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]);
53
- function ts64(x, i, h, l) {
54
- x[i] = h >> 24 & 255;
55
- x[i + 1] = h >> 16 & 255;
56
- x[i + 2] = h >> 8 & 255;
57
- x[i + 3] = h & 255;
58
- x[i + 4] = l >> 24 & 255;
59
- x[i + 5] = l >> 16 & 255;
60
- x[i + 6] = l >> 8 & 255;
61
- x[i + 7] = l & 255;
62
- }
63
- function vn(x, xi, y, yi, n) {
64
- var i, d = 0;
65
- for (i = 0; i < n; i++) d |= x[xi + i] ^ y[yi + i];
66
- return (1 & d - 1 >>> 8) - 1;
67
- }
68
- function crypto_verify_16(x, xi, y, yi) {
69
- return vn(x, xi, y, yi, 16);
70
- }
71
- function crypto_verify_32(x, xi, y, yi) {
72
- return vn(x, xi, y, yi, 32);
73
- }
74
- function core_salsa20(o, p, k, c) {
75
- 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;
76
- 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;
77
- for (var i = 0; i < 20; i += 2) {
78
- u = x0 + x12 | 0;
79
- x4 ^= u << 7 | u >>> 32 - 7;
80
- u = x4 + x0 | 0;
81
- x8 ^= u << 9 | u >>> 32 - 9;
82
- u = x8 + x4 | 0;
83
- x12 ^= u << 13 | u >>> 32 - 13;
84
- u = x12 + x8 | 0;
85
- x0 ^= u << 18 | u >>> 32 - 18;
86
- u = x5 + x1 | 0;
87
- x9 ^= u << 7 | u >>> 32 - 7;
88
- u = x9 + x5 | 0;
89
- x13 ^= u << 9 | u >>> 32 - 9;
90
- u = x13 + x9 | 0;
91
- x1 ^= u << 13 | u >>> 32 - 13;
92
- u = x1 + x13 | 0;
93
- x5 ^= u << 18 | u >>> 32 - 18;
94
- u = x10 + x6 | 0;
95
- x14 ^= u << 7 | u >>> 32 - 7;
96
- u = x14 + x10 | 0;
97
- x2 ^= u << 9 | u >>> 32 - 9;
98
- u = x2 + x14 | 0;
99
- x6 ^= u << 13 | u >>> 32 - 13;
100
- u = x6 + x2 | 0;
101
- x10 ^= u << 18 | u >>> 32 - 18;
102
- u = x15 + x11 | 0;
103
- x3 ^= u << 7 | u >>> 32 - 7;
104
- u = x3 + x15 | 0;
105
- x7 ^= u << 9 | u >>> 32 - 9;
106
- u = x7 + x3 | 0;
107
- x11 ^= u << 13 | u >>> 32 - 13;
108
- u = x11 + x7 | 0;
109
- x15 ^= u << 18 | u >>> 32 - 18;
110
- u = x0 + x3 | 0;
111
- x1 ^= u << 7 | u >>> 32 - 7;
112
- u = x1 + x0 | 0;
113
- x2 ^= u << 9 | u >>> 32 - 9;
114
- u = x2 + x1 | 0;
115
- x3 ^= u << 13 | u >>> 32 - 13;
116
- u = x3 + x2 | 0;
117
- x0 ^= u << 18 | u >>> 32 - 18;
118
- u = x5 + x4 | 0;
119
- x6 ^= u << 7 | u >>> 32 - 7;
120
- u = x6 + x5 | 0;
121
- x7 ^= u << 9 | u >>> 32 - 9;
122
- u = x7 + x6 | 0;
123
- x4 ^= u << 13 | u >>> 32 - 13;
124
- u = x4 + x7 | 0;
125
- x5 ^= u << 18 | u >>> 32 - 18;
126
- u = x10 + x9 | 0;
127
- x11 ^= u << 7 | u >>> 32 - 7;
128
- u = x11 + x10 | 0;
129
- x8 ^= u << 9 | u >>> 32 - 9;
130
- u = x8 + x11 | 0;
131
- x9 ^= u << 13 | u >>> 32 - 13;
132
- u = x9 + x8 | 0;
133
- x10 ^= u << 18 | u >>> 32 - 18;
134
- u = x15 + x14 | 0;
135
- x12 ^= u << 7 | u >>> 32 - 7;
136
- u = x12 + x15 | 0;
137
- x13 ^= u << 9 | u >>> 32 - 9;
138
- u = x13 + x12 | 0;
139
- x14 ^= u << 13 | u >>> 32 - 13;
140
- u = x14 + x13 | 0;
141
- x15 ^= u << 18 | u >>> 32 - 18;
142
- }
143
- x0 = x0 + j0 | 0;
144
- x1 = x1 + j1 | 0;
145
- x2 = x2 + j2 | 0;
146
- x3 = x3 + j3 | 0;
147
- x4 = x4 + j4 | 0;
148
- x5 = x5 + j5 | 0;
149
- x6 = x6 + j6 | 0;
150
- x7 = x7 + j7 | 0;
151
- x8 = x8 + j8 | 0;
152
- x9 = x9 + j9 | 0;
153
- x10 = x10 + j10 | 0;
154
- x11 = x11 + j11 | 0;
155
- x12 = x12 + j12 | 0;
156
- x13 = x13 + j13 | 0;
157
- x14 = x14 + j14 | 0;
158
- x15 = x15 + j15 | 0;
159
- o[0] = x0 >>> 0 & 255;
160
- o[1] = x0 >>> 8 & 255;
161
- o[2] = x0 >>> 16 & 255;
162
- o[3] = x0 >>> 24 & 255;
163
- o[4] = x1 >>> 0 & 255;
164
- o[5] = x1 >>> 8 & 255;
165
- o[6] = x1 >>> 16 & 255;
166
- o[7] = x1 >>> 24 & 255;
167
- o[8] = x2 >>> 0 & 255;
168
- o[9] = x2 >>> 8 & 255;
169
- o[10] = x2 >>> 16 & 255;
170
- o[11] = x2 >>> 24 & 255;
171
- o[12] = x3 >>> 0 & 255;
172
- o[13] = x3 >>> 8 & 255;
173
- o[14] = x3 >>> 16 & 255;
174
- o[15] = x3 >>> 24 & 255;
175
- o[16] = x4 >>> 0 & 255;
176
- o[17] = x4 >>> 8 & 255;
177
- o[18] = x4 >>> 16 & 255;
178
- o[19] = x4 >>> 24 & 255;
179
- o[20] = x5 >>> 0 & 255;
180
- o[21] = x5 >>> 8 & 255;
181
- o[22] = x5 >>> 16 & 255;
182
- o[23] = x5 >>> 24 & 255;
183
- o[24] = x6 >>> 0 & 255;
184
- o[25] = x6 >>> 8 & 255;
185
- o[26] = x6 >>> 16 & 255;
186
- o[27] = x6 >>> 24 & 255;
187
- o[28] = x7 >>> 0 & 255;
188
- o[29] = x7 >>> 8 & 255;
189
- o[30] = x7 >>> 16 & 255;
190
- o[31] = x7 >>> 24 & 255;
191
- o[32] = x8 >>> 0 & 255;
192
- o[33] = x8 >>> 8 & 255;
193
- o[34] = x8 >>> 16 & 255;
194
- o[35] = x8 >>> 24 & 255;
195
- o[36] = x9 >>> 0 & 255;
196
- o[37] = x9 >>> 8 & 255;
197
- o[38] = x9 >>> 16 & 255;
198
- o[39] = x9 >>> 24 & 255;
199
- o[40] = x10 >>> 0 & 255;
200
- o[41] = x10 >>> 8 & 255;
201
- o[42] = x10 >>> 16 & 255;
202
- o[43] = x10 >>> 24 & 255;
203
- o[44] = x11 >>> 0 & 255;
204
- o[45] = x11 >>> 8 & 255;
205
- o[46] = x11 >>> 16 & 255;
206
- o[47] = x11 >>> 24 & 255;
207
- o[48] = x12 >>> 0 & 255;
208
- o[49] = x12 >>> 8 & 255;
209
- o[50] = x12 >>> 16 & 255;
210
- o[51] = x12 >>> 24 & 255;
211
- o[52] = x13 >>> 0 & 255;
212
- o[53] = x13 >>> 8 & 255;
213
- o[54] = x13 >>> 16 & 255;
214
- o[55] = x13 >>> 24 & 255;
215
- o[56] = x14 >>> 0 & 255;
216
- o[57] = x14 >>> 8 & 255;
217
- o[58] = x14 >>> 16 & 255;
218
- o[59] = x14 >>> 24 & 255;
219
- o[60] = x15 >>> 0 & 255;
220
- o[61] = x15 >>> 8 & 255;
221
- o[62] = x15 >>> 16 & 255;
222
- o[63] = x15 >>> 24 & 255;
223
- }
224
- function core_hsalsa20(o, p, k, c) {
225
- 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;
226
- 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;
227
- for (var i = 0; i < 20; i += 2) {
228
- u = x0 + x12 | 0;
229
- x4 ^= u << 7 | u >>> 32 - 7;
230
- u = x4 + x0 | 0;
231
- x8 ^= u << 9 | u >>> 32 - 9;
232
- u = x8 + x4 | 0;
233
- x12 ^= u << 13 | u >>> 32 - 13;
234
- u = x12 + x8 | 0;
235
- x0 ^= u << 18 | u >>> 32 - 18;
236
- u = x5 + x1 | 0;
237
- x9 ^= u << 7 | u >>> 32 - 7;
238
- u = x9 + x5 | 0;
239
- x13 ^= u << 9 | u >>> 32 - 9;
240
- u = x13 + x9 | 0;
241
- x1 ^= u << 13 | u >>> 32 - 13;
242
- u = x1 + x13 | 0;
243
- x5 ^= u << 18 | u >>> 32 - 18;
244
- u = x10 + x6 | 0;
245
- x14 ^= u << 7 | u >>> 32 - 7;
246
- u = x14 + x10 | 0;
247
- x2 ^= u << 9 | u >>> 32 - 9;
248
- u = x2 + x14 | 0;
249
- x6 ^= u << 13 | u >>> 32 - 13;
250
- u = x6 + x2 | 0;
251
- x10 ^= u << 18 | u >>> 32 - 18;
252
- u = x15 + x11 | 0;
253
- x3 ^= u << 7 | u >>> 32 - 7;
254
- u = x3 + x15 | 0;
255
- x7 ^= u << 9 | u >>> 32 - 9;
256
- u = x7 + x3 | 0;
257
- x11 ^= u << 13 | u >>> 32 - 13;
258
- u = x11 + x7 | 0;
259
- x15 ^= u << 18 | u >>> 32 - 18;
260
- u = x0 + x3 | 0;
261
- x1 ^= u << 7 | u >>> 32 - 7;
262
- u = x1 + x0 | 0;
263
- x2 ^= u << 9 | u >>> 32 - 9;
264
- u = x2 + x1 | 0;
265
- x3 ^= u << 13 | u >>> 32 - 13;
266
- u = x3 + x2 | 0;
267
- x0 ^= u << 18 | u >>> 32 - 18;
268
- u = x5 + x4 | 0;
269
- x6 ^= u << 7 | u >>> 32 - 7;
270
- u = x6 + x5 | 0;
271
- x7 ^= u << 9 | u >>> 32 - 9;
272
- u = x7 + x6 | 0;
273
- x4 ^= u << 13 | u >>> 32 - 13;
274
- u = x4 + x7 | 0;
275
- x5 ^= u << 18 | u >>> 32 - 18;
276
- u = x10 + x9 | 0;
277
- x11 ^= u << 7 | u >>> 32 - 7;
278
- u = x11 + x10 | 0;
279
- x8 ^= u << 9 | u >>> 32 - 9;
280
- u = x8 + x11 | 0;
281
- x9 ^= u << 13 | u >>> 32 - 13;
282
- u = x9 + x8 | 0;
283
- x10 ^= u << 18 | u >>> 32 - 18;
284
- u = x15 + x14 | 0;
285
- x12 ^= u << 7 | u >>> 32 - 7;
286
- u = x12 + x15 | 0;
287
- x13 ^= u << 9 | u >>> 32 - 9;
288
- u = x13 + x12 | 0;
289
- x14 ^= u << 13 | u >>> 32 - 13;
290
- u = x14 + x13 | 0;
291
- x15 ^= u << 18 | u >>> 32 - 18;
292
- }
293
- o[0] = x0 >>> 0 & 255;
294
- o[1] = x0 >>> 8 & 255;
295
- o[2] = x0 >>> 16 & 255;
296
- o[3] = x0 >>> 24 & 255;
297
- o[4] = x5 >>> 0 & 255;
298
- o[5] = x5 >>> 8 & 255;
299
- o[6] = x5 >>> 16 & 255;
300
- o[7] = x5 >>> 24 & 255;
301
- o[8] = x10 >>> 0 & 255;
302
- o[9] = x10 >>> 8 & 255;
303
- o[10] = x10 >>> 16 & 255;
304
- o[11] = x10 >>> 24 & 255;
305
- o[12] = x15 >>> 0 & 255;
306
- o[13] = x15 >>> 8 & 255;
307
- o[14] = x15 >>> 16 & 255;
308
- o[15] = x15 >>> 24 & 255;
309
- o[16] = x6 >>> 0 & 255;
310
- o[17] = x6 >>> 8 & 255;
311
- o[18] = x6 >>> 16 & 255;
312
- o[19] = x6 >>> 24 & 255;
313
- o[20] = x7 >>> 0 & 255;
314
- o[21] = x7 >>> 8 & 255;
315
- o[22] = x7 >>> 16 & 255;
316
- o[23] = x7 >>> 24 & 255;
317
- o[24] = x8 >>> 0 & 255;
318
- o[25] = x8 >>> 8 & 255;
319
- o[26] = x8 >>> 16 & 255;
320
- o[27] = x8 >>> 24 & 255;
321
- o[28] = x9 >>> 0 & 255;
322
- o[29] = x9 >>> 8 & 255;
323
- o[30] = x9 >>> 16 & 255;
324
- o[31] = x9 >>> 24 & 255;
325
- }
326
- function crypto_core_salsa20(out, inp, k, c) {
327
- core_salsa20(out, inp, k, c);
328
- }
329
- function crypto_core_hsalsa20(out, inp, k, c) {
330
- core_hsalsa20(out, inp, k, c);
331
- }
332
- var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]);
333
- function crypto_stream_salsa20_xor(c, cpos, m, mpos, b, n, k) {
334
- var z12 = new Uint8Array(16), x = new Uint8Array(64);
335
- var u, i;
336
- for (i = 0; i < 16; i++) z12[i] = 0;
337
- for (i = 0; i < 8; i++) z12[i] = n[i];
338
- while (b >= 64) {
339
- crypto_core_salsa20(x, z12, k, sigma);
340
- for (i = 0; i < 64; i++) c[cpos + i] = m[mpos + i] ^ x[i];
341
- u = 1;
342
- for (i = 8; i < 16; i++) {
343
- u = u + (z12[i] & 255) | 0;
344
- z12[i] = u & 255;
345
- u >>>= 8;
346
- }
347
- b -= 64;
348
- cpos += 64;
349
- mpos += 64;
350
- }
351
- if (b > 0) {
352
- crypto_core_salsa20(x, z12, k, sigma);
353
- for (i = 0; i < b; i++) c[cpos + i] = m[mpos + i] ^ x[i];
354
- }
355
- return 0;
356
- }
357
- function crypto_stream_salsa20(c, cpos, b, n, k) {
358
- var z12 = new Uint8Array(16), x = new Uint8Array(64);
359
- var u, i;
360
- for (i = 0; i < 16; i++) z12[i] = 0;
361
- for (i = 0; i < 8; i++) z12[i] = n[i];
362
- while (b >= 64) {
363
- crypto_core_salsa20(x, z12, k, sigma);
364
- for (i = 0; i < 64; i++) c[cpos + i] = x[i];
365
- u = 1;
366
- for (i = 8; i < 16; i++) {
367
- u = u + (z12[i] & 255) | 0;
368
- z12[i] = u & 255;
369
- u >>>= 8;
370
- }
371
- b -= 64;
372
- cpos += 64;
373
- }
374
- if (b > 0) {
375
- crypto_core_salsa20(x, z12, k, sigma);
376
- for (i = 0; i < b; i++) c[cpos + i] = x[i];
377
- }
378
- return 0;
379
- }
380
- function crypto_stream(c, cpos, d, n, k) {
381
- var s = new Uint8Array(32);
382
- crypto_core_hsalsa20(s, n, k, sigma);
383
- var sn = new Uint8Array(8);
384
- for (var i = 0; i < 8; i++) sn[i] = n[i + 16];
385
- return crypto_stream_salsa20(c, cpos, d, sn, s);
386
- }
387
- function crypto_stream_xor(c, cpos, m, mpos, d, n, k) {
388
- var s = new Uint8Array(32);
389
- crypto_core_hsalsa20(s, n, k, sigma);
390
- var sn = new Uint8Array(8);
391
- for (var i = 0; i < 8; i++) sn[i] = n[i + 16];
392
- return crypto_stream_salsa20_xor(c, cpos, m, mpos, d, sn, s);
393
- }
394
- var poly1305 = function(key) {
395
- this.buffer = new Uint8Array(16);
396
- this.r = new Uint16Array(10);
397
- this.h = new Uint16Array(10);
398
- this.pad = new Uint16Array(8);
399
- this.leftover = 0;
400
- this.fin = 0;
401
- var t0, t1, t2, t3, t4, t5, t6, t7;
402
- t0 = key[0] & 255 | (key[1] & 255) << 8;
403
- this.r[0] = t0 & 8191;
404
- t1 = key[2] & 255 | (key[3] & 255) << 8;
405
- this.r[1] = (t0 >>> 13 | t1 << 3) & 8191;
406
- t2 = key[4] & 255 | (key[5] & 255) << 8;
407
- this.r[2] = (t1 >>> 10 | t2 << 6) & 7939;
408
- t3 = key[6] & 255 | (key[7] & 255) << 8;
409
- this.r[3] = (t2 >>> 7 | t3 << 9) & 8191;
410
- t4 = key[8] & 255 | (key[9] & 255) << 8;
411
- this.r[4] = (t3 >>> 4 | t4 << 12) & 255;
412
- this.r[5] = t4 >>> 1 & 8190;
413
- t5 = key[10] & 255 | (key[11] & 255) << 8;
414
- this.r[6] = (t4 >>> 14 | t5 << 2) & 8191;
415
- t6 = key[12] & 255 | (key[13] & 255) << 8;
416
- this.r[7] = (t5 >>> 11 | t6 << 5) & 8065;
417
- t7 = key[14] & 255 | (key[15] & 255) << 8;
418
- this.r[8] = (t6 >>> 8 | t7 << 8) & 8191;
419
- this.r[9] = t7 >>> 5 & 127;
420
- this.pad[0] = key[16] & 255 | (key[17] & 255) << 8;
421
- this.pad[1] = key[18] & 255 | (key[19] & 255) << 8;
422
- this.pad[2] = key[20] & 255 | (key[21] & 255) << 8;
423
- this.pad[3] = key[22] & 255 | (key[23] & 255) << 8;
424
- this.pad[4] = key[24] & 255 | (key[25] & 255) << 8;
425
- this.pad[5] = key[26] & 255 | (key[27] & 255) << 8;
426
- this.pad[6] = key[28] & 255 | (key[29] & 255) << 8;
427
- this.pad[7] = key[30] & 255 | (key[31] & 255) << 8;
428
- };
429
- poly1305.prototype.blocks = function(m, mpos, bytes) {
430
- var hibit = this.fin ? 0 : 1 << 11;
431
- var t0, t1, t2, t3, t4, t5, t6, t7, c;
432
- var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9;
433
- 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];
434
- 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];
435
- while (bytes >= 16) {
436
- t0 = m[mpos + 0] & 255 | (m[mpos + 1] & 255) << 8;
437
- h0 += t0 & 8191;
438
- t1 = m[mpos + 2] & 255 | (m[mpos + 3] & 255) << 8;
439
- h1 += (t0 >>> 13 | t1 << 3) & 8191;
440
- t2 = m[mpos + 4] & 255 | (m[mpos + 5] & 255) << 8;
441
- h2 += (t1 >>> 10 | t2 << 6) & 8191;
442
- t3 = m[mpos + 6] & 255 | (m[mpos + 7] & 255) << 8;
443
- h3 += (t2 >>> 7 | t3 << 9) & 8191;
444
- t4 = m[mpos + 8] & 255 | (m[mpos + 9] & 255) << 8;
445
- h4 += (t3 >>> 4 | t4 << 12) & 8191;
446
- h5 += t4 >>> 1 & 8191;
447
- t5 = m[mpos + 10] & 255 | (m[mpos + 11] & 255) << 8;
448
- h6 += (t4 >>> 14 | t5 << 2) & 8191;
449
- t6 = m[mpos + 12] & 255 | (m[mpos + 13] & 255) << 8;
450
- h7 += (t5 >>> 11 | t6 << 5) & 8191;
451
- t7 = m[mpos + 14] & 255 | (m[mpos + 15] & 255) << 8;
452
- h8 += (t6 >>> 8 | t7 << 8) & 8191;
453
- h9 += t7 >>> 5 | hibit;
454
- c = 0;
455
- d0 = c;
456
- d0 += h0 * r0;
457
- d0 += h1 * (5 * r9);
458
- d0 += h2 * (5 * r8);
459
- d0 += h3 * (5 * r7);
460
- d0 += h4 * (5 * r6);
461
- c = d0 >>> 13;
462
- d0 &= 8191;
463
- d0 += h5 * (5 * r5);
464
- d0 += h6 * (5 * r4);
465
- d0 += h7 * (5 * r3);
466
- d0 += h8 * (5 * r2);
467
- d0 += h9 * (5 * r1);
468
- c += d0 >>> 13;
469
- d0 &= 8191;
470
- d1 = c;
471
- d1 += h0 * r1;
472
- d1 += h1 * r0;
473
- d1 += h2 * (5 * r9);
474
- d1 += h3 * (5 * r8);
475
- d1 += h4 * (5 * r7);
476
- c = d1 >>> 13;
477
- d1 &= 8191;
478
- d1 += h5 * (5 * r6);
479
- d1 += h6 * (5 * r5);
480
- d1 += h7 * (5 * r4);
481
- d1 += h8 * (5 * r3);
482
- d1 += h9 * (5 * r2);
483
- c += d1 >>> 13;
484
- d1 &= 8191;
485
- d2 = c;
486
- d2 += h0 * r2;
487
- d2 += h1 * r1;
488
- d2 += h2 * r0;
489
- d2 += h3 * (5 * r9);
490
- d2 += h4 * (5 * r8);
491
- c = d2 >>> 13;
492
- d2 &= 8191;
493
- d2 += h5 * (5 * r7);
494
- d2 += h6 * (5 * r6);
495
- d2 += h7 * (5 * r5);
496
- d2 += h8 * (5 * r4);
497
- d2 += h9 * (5 * r3);
498
- c += d2 >>> 13;
499
- d2 &= 8191;
500
- d3 = c;
501
- d3 += h0 * r3;
502
- d3 += h1 * r2;
503
- d3 += h2 * r1;
504
- d3 += h3 * r0;
505
- d3 += h4 * (5 * r9);
506
- c = d3 >>> 13;
507
- d3 &= 8191;
508
- d3 += h5 * (5 * r8);
509
- d3 += h6 * (5 * r7);
510
- d3 += h7 * (5 * r6);
511
- d3 += h8 * (5 * r5);
512
- d3 += h9 * (5 * r4);
513
- c += d3 >>> 13;
514
- d3 &= 8191;
515
- d4 = c;
516
- d4 += h0 * r4;
517
- d4 += h1 * r3;
518
- d4 += h2 * r2;
519
- d4 += h3 * r1;
520
- d4 += h4 * r0;
521
- c = d4 >>> 13;
522
- d4 &= 8191;
523
- d4 += h5 * (5 * r9);
524
- d4 += h6 * (5 * r8);
525
- d4 += h7 * (5 * r7);
526
- d4 += h8 * (5 * r6);
527
- d4 += h9 * (5 * r5);
528
- c += d4 >>> 13;
529
- d4 &= 8191;
530
- d5 = c;
531
- d5 += h0 * r5;
532
- d5 += h1 * r4;
533
- d5 += h2 * r3;
534
- d5 += h3 * r2;
535
- d5 += h4 * r1;
536
- c = d5 >>> 13;
537
- d5 &= 8191;
538
- d5 += h5 * r0;
539
- d5 += h6 * (5 * r9);
540
- d5 += h7 * (5 * r8);
541
- d5 += h8 * (5 * r7);
542
- d5 += h9 * (5 * r6);
543
- c += d5 >>> 13;
544
- d5 &= 8191;
545
- d6 = c;
546
- d6 += h0 * r6;
547
- d6 += h1 * r5;
548
- d6 += h2 * r4;
549
- d6 += h3 * r3;
550
- d6 += h4 * r2;
551
- c = d6 >>> 13;
552
- d6 &= 8191;
553
- d6 += h5 * r1;
554
- d6 += h6 * r0;
555
- d6 += h7 * (5 * r9);
556
- d6 += h8 * (5 * r8);
557
- d6 += h9 * (5 * r7);
558
- c += d6 >>> 13;
559
- d6 &= 8191;
560
- d7 = c;
561
- d7 += h0 * r7;
562
- d7 += h1 * r6;
563
- d7 += h2 * r5;
564
- d7 += h3 * r4;
565
- d7 += h4 * r3;
566
- c = d7 >>> 13;
567
- d7 &= 8191;
568
- d7 += h5 * r2;
569
- d7 += h6 * r1;
570
- d7 += h7 * r0;
571
- d7 += h8 * (5 * r9);
572
- d7 += h9 * (5 * r8);
573
- c += d7 >>> 13;
574
- d7 &= 8191;
575
- d8 = c;
576
- d8 += h0 * r8;
577
- d8 += h1 * r7;
578
- d8 += h2 * r6;
579
- d8 += h3 * r5;
580
- d8 += h4 * r4;
581
- c = d8 >>> 13;
582
- d8 &= 8191;
583
- d8 += h5 * r3;
584
- d8 += h6 * r2;
585
- d8 += h7 * r1;
586
- d8 += h8 * r0;
587
- d8 += h9 * (5 * r9);
588
- c += d8 >>> 13;
589
- d8 &= 8191;
590
- d9 = c;
591
- d9 += h0 * r9;
592
- d9 += h1 * r8;
593
- d9 += h2 * r7;
594
- d9 += h3 * r6;
595
- d9 += h4 * r5;
596
- c = d9 >>> 13;
597
- d9 &= 8191;
598
- d9 += h5 * r4;
599
- d9 += h6 * r3;
600
- d9 += h7 * r2;
601
- d9 += h8 * r1;
602
- d9 += h9 * r0;
603
- c += d9 >>> 13;
604
- d9 &= 8191;
605
- c = (c << 2) + c | 0;
606
- c = c + d0 | 0;
607
- d0 = c & 8191;
608
- c = c >>> 13;
609
- d1 += c;
610
- h0 = d0;
611
- h1 = d1;
612
- h2 = d2;
613
- h3 = d3;
614
- h4 = d4;
615
- h5 = d5;
616
- h6 = d6;
617
- h7 = d7;
618
- h8 = d8;
619
- h9 = d9;
620
- mpos += 16;
621
- bytes -= 16;
622
- }
623
- this.h[0] = h0;
624
- this.h[1] = h1;
625
- this.h[2] = h2;
626
- this.h[3] = h3;
627
- this.h[4] = h4;
628
- this.h[5] = h5;
629
- this.h[6] = h6;
630
- this.h[7] = h7;
631
- this.h[8] = h8;
632
- this.h[9] = h9;
633
- };
634
- poly1305.prototype.finish = function(mac, macpos) {
635
- var g = new Uint16Array(10);
636
- var c, mask, f, i;
637
- if (this.leftover) {
638
- i = this.leftover;
639
- this.buffer[i++] = 1;
640
- for (; i < 16; i++) this.buffer[i] = 0;
641
- this.fin = 1;
642
- this.blocks(this.buffer, 0, 16);
643
- }
644
- c = this.h[1] >>> 13;
645
- this.h[1] &= 8191;
646
- for (i = 2; i < 10; i++) {
647
- this.h[i] += c;
648
- c = this.h[i] >>> 13;
649
- this.h[i] &= 8191;
650
- }
651
- this.h[0] += c * 5;
652
- c = this.h[0] >>> 13;
653
- this.h[0] &= 8191;
654
- this.h[1] += c;
655
- c = this.h[1] >>> 13;
656
- this.h[1] &= 8191;
657
- this.h[2] += c;
658
- g[0] = this.h[0] + 5;
659
- c = g[0] >>> 13;
660
- g[0] &= 8191;
661
- for (i = 1; i < 10; i++) {
662
- g[i] = this.h[i] + c;
663
- c = g[i] >>> 13;
664
- g[i] &= 8191;
665
- }
666
- g[9] -= 1 << 13;
667
- mask = (c ^ 1) - 1;
668
- for (i = 0; i < 10; i++) g[i] &= mask;
669
- mask = ~mask;
670
- for (i = 0; i < 10; i++) this.h[i] = this.h[i] & mask | g[i];
671
- this.h[0] = (this.h[0] | this.h[1] << 13) & 65535;
672
- this.h[1] = (this.h[1] >>> 3 | this.h[2] << 10) & 65535;
673
- this.h[2] = (this.h[2] >>> 6 | this.h[3] << 7) & 65535;
674
- this.h[3] = (this.h[3] >>> 9 | this.h[4] << 4) & 65535;
675
- this.h[4] = (this.h[4] >>> 12 | this.h[5] << 1 | this.h[6] << 14) & 65535;
676
- this.h[5] = (this.h[6] >>> 2 | this.h[7] << 11) & 65535;
677
- this.h[6] = (this.h[7] >>> 5 | this.h[8] << 8) & 65535;
678
- this.h[7] = (this.h[8] >>> 8 | this.h[9] << 5) & 65535;
679
- f = this.h[0] + this.pad[0];
680
- this.h[0] = f & 65535;
681
- for (i = 1; i < 8; i++) {
682
- f = (this.h[i] + this.pad[i] | 0) + (f >>> 16) | 0;
683
- this.h[i] = f & 65535;
684
- }
685
- mac[macpos + 0] = this.h[0] >>> 0 & 255;
686
- mac[macpos + 1] = this.h[0] >>> 8 & 255;
687
- mac[macpos + 2] = this.h[1] >>> 0 & 255;
688
- mac[macpos + 3] = this.h[1] >>> 8 & 255;
689
- mac[macpos + 4] = this.h[2] >>> 0 & 255;
690
- mac[macpos + 5] = this.h[2] >>> 8 & 255;
691
- mac[macpos + 6] = this.h[3] >>> 0 & 255;
692
- mac[macpos + 7] = this.h[3] >>> 8 & 255;
693
- mac[macpos + 8] = this.h[4] >>> 0 & 255;
694
- mac[macpos + 9] = this.h[4] >>> 8 & 255;
695
- mac[macpos + 10] = this.h[5] >>> 0 & 255;
696
- mac[macpos + 11] = this.h[5] >>> 8 & 255;
697
- mac[macpos + 12] = this.h[6] >>> 0 & 255;
698
- mac[macpos + 13] = this.h[6] >>> 8 & 255;
699
- mac[macpos + 14] = this.h[7] >>> 0 & 255;
700
- mac[macpos + 15] = this.h[7] >>> 8 & 255;
701
- };
702
- poly1305.prototype.update = function(m, mpos, bytes) {
703
- var i, want;
704
- if (this.leftover) {
705
- want = 16 - this.leftover;
706
- if (want > bytes)
707
- want = bytes;
708
- for (i = 0; i < want; i++)
709
- this.buffer[this.leftover + i] = m[mpos + i];
710
- bytes -= want;
711
- mpos += want;
712
- this.leftover += want;
713
- if (this.leftover < 16)
714
- return;
715
- this.blocks(this.buffer, 0, 16);
716
- this.leftover = 0;
717
- }
718
- if (bytes >= 16) {
719
- want = bytes - bytes % 16;
720
- this.blocks(m, mpos, want);
721
- mpos += want;
722
- bytes -= want;
723
- }
724
- if (bytes) {
725
- for (i = 0; i < bytes; i++)
726
- this.buffer[this.leftover + i] = m[mpos + i];
727
- this.leftover += bytes;
728
- }
729
- };
730
- function crypto_onetimeauth(out, outpos, m, mpos, n, k) {
731
- var s = new poly1305(k);
732
- s.update(m, mpos, n);
733
- s.finish(out, outpos);
734
- return 0;
735
- }
736
- function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) {
737
- var x = new Uint8Array(16);
738
- crypto_onetimeauth(x, 0, m, mpos, n, k);
739
- return crypto_verify_16(h, hpos, x, 0);
740
- }
741
- function crypto_secretbox(c, m, d, n, k) {
742
- var i;
743
- if (d < 32) return -1;
744
- crypto_stream_xor(c, 0, m, 0, d, n, k);
745
- crypto_onetimeauth(c, 16, c, 32, d - 32, c);
746
- for (i = 0; i < 16; i++) c[i] = 0;
747
- return 0;
748
- }
749
- function crypto_secretbox_open(m, c, d, n, k) {
750
- var i;
751
- var x = new Uint8Array(32);
752
- if (d < 32) return -1;
753
- crypto_stream(x, 0, 32, n, k);
754
- if (crypto_onetimeauth_verify(c, 16, c, 32, d - 32, x) !== 0) return -1;
755
- crypto_stream_xor(m, 0, c, 0, d, n, k);
756
- for (i = 0; i < 32; i++) m[i] = 0;
757
- return 0;
758
- }
759
- function set25519(r, a) {
760
- var i;
761
- for (i = 0; i < 16; i++) r[i] = a[i] | 0;
762
- }
763
- function car25519(o) {
764
- var i, v, c = 1;
765
- for (i = 0; i < 16; i++) {
766
- v = o[i] + c + 65535;
767
- c = Math.floor(v / 65536);
768
- o[i] = v - c * 65536;
769
- }
770
- o[0] += c - 1 + 37 * (c - 1);
771
- }
772
- function sel25519(p, q, b) {
773
- var t, c = ~(b - 1);
774
- for (var i = 0; i < 16; i++) {
775
- t = c & (p[i] ^ q[i]);
776
- p[i] ^= t;
777
- q[i] ^= t;
778
- }
779
- }
780
- function pack25519(o, n) {
781
- var i, j, b;
782
- var m = gf(), t = gf();
783
- for (i = 0; i < 16; i++) t[i] = n[i];
784
- car25519(t);
785
- car25519(t);
786
- car25519(t);
787
- for (j = 0; j < 2; j++) {
788
- m[0] = t[0] - 65517;
789
- for (i = 1; i < 15; i++) {
790
- m[i] = t[i] - 65535 - (m[i - 1] >> 16 & 1);
791
- m[i - 1] &= 65535;
792
- }
793
- m[15] = t[15] - 32767 - (m[14] >> 16 & 1);
794
- b = m[15] >> 16 & 1;
795
- m[14] &= 65535;
796
- sel25519(t, m, 1 - b);
797
- }
798
- for (i = 0; i < 16; i++) {
799
- o[2 * i] = t[i] & 255;
800
- o[2 * i + 1] = t[i] >> 8;
801
- }
802
- }
803
- function neq25519(a, b) {
804
- var c = new Uint8Array(32), d = new Uint8Array(32);
805
- pack25519(c, a);
806
- pack25519(d, b);
807
- return crypto_verify_32(c, 0, d, 0);
808
- }
809
- function par25519(a) {
810
- var d = new Uint8Array(32);
811
- pack25519(d, a);
812
- return d[0] & 1;
813
- }
814
- function unpack25519(o, n) {
815
- var i;
816
- for (i = 0; i < 16; i++) o[i] = n[2 * i] + (n[2 * i + 1] << 8);
817
- o[15] &= 32767;
818
- }
819
- function A(o, a, b) {
820
- for (var i = 0; i < 16; i++) o[i] = a[i] + b[i];
821
- }
822
- function Z(o, a, b) {
823
- for (var i = 0; i < 16; i++) o[i] = a[i] - b[i];
824
- }
825
- function M(o, a, b) {
826
- 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];
827
- v = a[0];
828
- t0 += v * b0;
829
- t1 += v * b1;
830
- t2 += v * b2;
831
- t3 += v * b3;
832
- t4 += v * b4;
833
- t5 += v * b5;
834
- t6 += v * b6;
835
- t7 += v * b7;
836
- t8 += v * b8;
837
- t9 += v * b9;
838
- t10 += v * b10;
839
- t11 += v * b11;
840
- t12 += v * b12;
841
- t13 += v * b13;
842
- t14 += v * b14;
843
- t15 += v * b15;
844
- v = a[1];
845
- t1 += v * b0;
846
- t2 += v * b1;
847
- t3 += v * b2;
848
- t4 += v * b3;
849
- t5 += v * b4;
850
- t6 += v * b5;
851
- t7 += v * b6;
852
- t8 += v * b7;
853
- t9 += v * b8;
854
- t10 += v * b9;
855
- t11 += v * b10;
856
- t12 += v * b11;
857
- t13 += v * b12;
858
- t14 += v * b13;
859
- t15 += v * b14;
860
- t16 += v * b15;
861
- v = a[2];
862
- t2 += v * b0;
863
- t3 += v * b1;
864
- t4 += v * b2;
865
- t5 += v * b3;
866
- t6 += v * b4;
867
- t7 += v * b5;
868
- t8 += v * b6;
869
- t9 += v * b7;
870
- t10 += v * b8;
871
- t11 += v * b9;
872
- t12 += v * b10;
873
- t13 += v * b11;
874
- t14 += v * b12;
875
- t15 += v * b13;
876
- t16 += v * b14;
877
- t17 += v * b15;
878
- v = a[3];
879
- t3 += v * b0;
880
- t4 += v * b1;
881
- t5 += v * b2;
882
- t6 += v * b3;
883
- t7 += v * b4;
884
- t8 += v * b5;
885
- t9 += v * b6;
886
- t10 += v * b7;
887
- t11 += v * b8;
888
- t12 += v * b9;
889
- t13 += v * b10;
890
- t14 += v * b11;
891
- t15 += v * b12;
892
- t16 += v * b13;
893
- t17 += v * b14;
894
- t18 += v * b15;
895
- v = a[4];
896
- t4 += v * b0;
897
- t5 += v * b1;
898
- t6 += v * b2;
899
- t7 += v * b3;
900
- t8 += v * b4;
901
- t9 += v * b5;
902
- t10 += v * b6;
903
- t11 += v * b7;
904
- t12 += v * b8;
905
- t13 += v * b9;
906
- t14 += v * b10;
907
- t15 += v * b11;
908
- t16 += v * b12;
909
- t17 += v * b13;
910
- t18 += v * b14;
911
- t19 += v * b15;
912
- v = a[5];
913
- t5 += v * b0;
914
- t6 += v * b1;
915
- t7 += v * b2;
916
- t8 += v * b3;
917
- t9 += v * b4;
918
- t10 += v * b5;
919
- t11 += v * b6;
920
- t12 += v * b7;
921
- t13 += v * b8;
922
- t14 += v * b9;
923
- t15 += v * b10;
924
- t16 += v * b11;
925
- t17 += v * b12;
926
- t18 += v * b13;
927
- t19 += v * b14;
928
- t20 += v * b15;
929
- v = a[6];
930
- t6 += v * b0;
931
- t7 += v * b1;
932
- t8 += v * b2;
933
- t9 += v * b3;
934
- t10 += v * b4;
935
- t11 += v * b5;
936
- t12 += v * b6;
937
- t13 += v * b7;
938
- t14 += v * b8;
939
- t15 += v * b9;
940
- t16 += v * b10;
941
- t17 += v * b11;
942
- t18 += v * b12;
943
- t19 += v * b13;
944
- t20 += v * b14;
945
- t21 += v * b15;
946
- v = a[7];
947
- t7 += v * b0;
948
- t8 += v * b1;
949
- t9 += v * b2;
950
- t10 += v * b3;
951
- t11 += v * b4;
952
- t12 += v * b5;
953
- t13 += v * b6;
954
- t14 += v * b7;
955
- t15 += v * b8;
956
- t16 += v * b9;
957
- t17 += v * b10;
958
- t18 += v * b11;
959
- t19 += v * b12;
960
- t20 += v * b13;
961
- t21 += v * b14;
962
- t22 += v * b15;
963
- v = a[8];
964
- t8 += v * b0;
965
- t9 += v * b1;
966
- t10 += v * b2;
967
- t11 += v * b3;
968
- t12 += v * b4;
969
- t13 += v * b5;
970
- t14 += v * b6;
971
- t15 += v * b7;
972
- t16 += v * b8;
973
- t17 += v * b9;
974
- t18 += v * b10;
975
- t19 += v * b11;
976
- t20 += v * b12;
977
- t21 += v * b13;
978
- t22 += v * b14;
979
- t23 += v * b15;
980
- v = a[9];
981
- t9 += v * b0;
982
- t10 += v * b1;
983
- t11 += v * b2;
984
- t12 += v * b3;
985
- t13 += v * b4;
986
- t14 += v * b5;
987
- t15 += v * b6;
988
- t16 += v * b7;
989
- t17 += v * b8;
990
- t18 += v * b9;
991
- t19 += v * b10;
992
- t20 += v * b11;
993
- t21 += v * b12;
994
- t22 += v * b13;
995
- t23 += v * b14;
996
- t24 += v * b15;
997
- v = a[10];
998
- t10 += v * b0;
999
- t11 += v * b1;
1000
- t12 += v * b2;
1001
- t13 += v * b3;
1002
- t14 += v * b4;
1003
- t15 += v * b5;
1004
- t16 += v * b6;
1005
- t17 += v * b7;
1006
- t18 += v * b8;
1007
- t19 += v * b9;
1008
- t20 += v * b10;
1009
- t21 += v * b11;
1010
- t22 += v * b12;
1011
- t23 += v * b13;
1012
- t24 += v * b14;
1013
- t25 += v * b15;
1014
- v = a[11];
1015
- t11 += v * b0;
1016
- t12 += v * b1;
1017
- t13 += v * b2;
1018
- t14 += v * b3;
1019
- t15 += v * b4;
1020
- t16 += v * b5;
1021
- t17 += v * b6;
1022
- t18 += v * b7;
1023
- t19 += v * b8;
1024
- t20 += v * b9;
1025
- t21 += v * b10;
1026
- t22 += v * b11;
1027
- t23 += v * b12;
1028
- t24 += v * b13;
1029
- t25 += v * b14;
1030
- t26 += v * b15;
1031
- v = a[12];
1032
- t12 += v * b0;
1033
- t13 += v * b1;
1034
- t14 += v * b2;
1035
- t15 += v * b3;
1036
- t16 += v * b4;
1037
- t17 += v * b5;
1038
- t18 += v * b6;
1039
- t19 += v * b7;
1040
- t20 += v * b8;
1041
- t21 += v * b9;
1042
- t22 += v * b10;
1043
- t23 += v * b11;
1044
- t24 += v * b12;
1045
- t25 += v * b13;
1046
- t26 += v * b14;
1047
- t27 += v * b15;
1048
- v = a[13];
1049
- t13 += v * b0;
1050
- t14 += v * b1;
1051
- t15 += v * b2;
1052
- t16 += v * b3;
1053
- t17 += v * b4;
1054
- t18 += v * b5;
1055
- t19 += v * b6;
1056
- t20 += v * b7;
1057
- t21 += v * b8;
1058
- t22 += v * b9;
1059
- t23 += v * b10;
1060
- t24 += v * b11;
1061
- t25 += v * b12;
1062
- t26 += v * b13;
1063
- t27 += v * b14;
1064
- t28 += v * b15;
1065
- v = a[14];
1066
- t14 += v * b0;
1067
- t15 += v * b1;
1068
- t16 += v * b2;
1069
- t17 += v * b3;
1070
- t18 += v * b4;
1071
- t19 += v * b5;
1072
- t20 += v * b6;
1073
- t21 += v * b7;
1074
- t22 += v * b8;
1075
- t23 += v * b9;
1076
- t24 += v * b10;
1077
- t25 += v * b11;
1078
- t26 += v * b12;
1079
- t27 += v * b13;
1080
- t28 += v * b14;
1081
- t29 += v * b15;
1082
- v = a[15];
1083
- t15 += v * b0;
1084
- t16 += v * b1;
1085
- t17 += v * b2;
1086
- t18 += v * b3;
1087
- t19 += v * b4;
1088
- t20 += v * b5;
1089
- t21 += v * b6;
1090
- t22 += v * b7;
1091
- t23 += v * b8;
1092
- t24 += v * b9;
1093
- t25 += v * b10;
1094
- t26 += v * b11;
1095
- t27 += v * b12;
1096
- t28 += v * b13;
1097
- t29 += v * b14;
1098
- t30 += v * b15;
1099
- t0 += 38 * t16;
1100
- t1 += 38 * t17;
1101
- t2 += 38 * t18;
1102
- t3 += 38 * t19;
1103
- t4 += 38 * t20;
1104
- t5 += 38 * t21;
1105
- t6 += 38 * t22;
1106
- t7 += 38 * t23;
1107
- t8 += 38 * t24;
1108
- t9 += 38 * t25;
1109
- t10 += 38 * t26;
1110
- t11 += 38 * t27;
1111
- t12 += 38 * t28;
1112
- t13 += 38 * t29;
1113
- t14 += 38 * t30;
1114
- c = 1;
1115
- v = t0 + c + 65535;
1116
- c = Math.floor(v / 65536);
1117
- t0 = v - c * 65536;
1118
- v = t1 + c + 65535;
1119
- c = Math.floor(v / 65536);
1120
- t1 = v - c * 65536;
1121
- v = t2 + c + 65535;
1122
- c = Math.floor(v / 65536);
1123
- t2 = v - c * 65536;
1124
- v = t3 + c + 65535;
1125
- c = Math.floor(v / 65536);
1126
- t3 = v - c * 65536;
1127
- v = t4 + c + 65535;
1128
- c = Math.floor(v / 65536);
1129
- t4 = v - c * 65536;
1130
- v = t5 + c + 65535;
1131
- c = Math.floor(v / 65536);
1132
- t5 = v - c * 65536;
1133
- v = t6 + c + 65535;
1134
- c = Math.floor(v / 65536);
1135
- t6 = v - c * 65536;
1136
- v = t7 + c + 65535;
1137
- c = Math.floor(v / 65536);
1138
- t7 = v - c * 65536;
1139
- v = t8 + c + 65535;
1140
- c = Math.floor(v / 65536);
1141
- t8 = v - c * 65536;
1142
- v = t9 + c + 65535;
1143
- c = Math.floor(v / 65536);
1144
- t9 = v - c * 65536;
1145
- v = t10 + c + 65535;
1146
- c = Math.floor(v / 65536);
1147
- t10 = v - c * 65536;
1148
- v = t11 + c + 65535;
1149
- c = Math.floor(v / 65536);
1150
- t11 = v - c * 65536;
1151
- v = t12 + c + 65535;
1152
- c = Math.floor(v / 65536);
1153
- t12 = v - c * 65536;
1154
- v = t13 + c + 65535;
1155
- c = Math.floor(v / 65536);
1156
- t13 = v - c * 65536;
1157
- v = t14 + c + 65535;
1158
- c = Math.floor(v / 65536);
1159
- t14 = v - c * 65536;
1160
- v = t15 + c + 65535;
1161
- c = Math.floor(v / 65536);
1162
- t15 = v - c * 65536;
1163
- t0 += c - 1 + 37 * (c - 1);
1164
- c = 1;
1165
- v = t0 + c + 65535;
1166
- c = Math.floor(v / 65536);
1167
- t0 = v - c * 65536;
1168
- v = t1 + c + 65535;
1169
- c = Math.floor(v / 65536);
1170
- t1 = v - c * 65536;
1171
- v = t2 + c + 65535;
1172
- c = Math.floor(v / 65536);
1173
- t2 = v - c * 65536;
1174
- v = t3 + c + 65535;
1175
- c = Math.floor(v / 65536);
1176
- t3 = v - c * 65536;
1177
- v = t4 + c + 65535;
1178
- c = Math.floor(v / 65536);
1179
- t4 = v - c * 65536;
1180
- v = t5 + c + 65535;
1181
- c = Math.floor(v / 65536);
1182
- t5 = v - c * 65536;
1183
- v = t6 + c + 65535;
1184
- c = Math.floor(v / 65536);
1185
- t6 = v - c * 65536;
1186
- v = t7 + c + 65535;
1187
- c = Math.floor(v / 65536);
1188
- t7 = v - c * 65536;
1189
- v = t8 + c + 65535;
1190
- c = Math.floor(v / 65536);
1191
- t8 = v - c * 65536;
1192
- v = t9 + c + 65535;
1193
- c = Math.floor(v / 65536);
1194
- t9 = v - c * 65536;
1195
- v = t10 + c + 65535;
1196
- c = Math.floor(v / 65536);
1197
- t10 = v - c * 65536;
1198
- v = t11 + c + 65535;
1199
- c = Math.floor(v / 65536);
1200
- t11 = v - c * 65536;
1201
- v = t12 + c + 65535;
1202
- c = Math.floor(v / 65536);
1203
- t12 = v - c * 65536;
1204
- v = t13 + c + 65535;
1205
- c = Math.floor(v / 65536);
1206
- t13 = v - c * 65536;
1207
- v = t14 + c + 65535;
1208
- c = Math.floor(v / 65536);
1209
- t14 = v - c * 65536;
1210
- v = t15 + c + 65535;
1211
- c = Math.floor(v / 65536);
1212
- t15 = v - c * 65536;
1213
- t0 += c - 1 + 37 * (c - 1);
1214
- o[0] = t0;
1215
- o[1] = t1;
1216
- o[2] = t2;
1217
- o[3] = t3;
1218
- o[4] = t4;
1219
- o[5] = t5;
1220
- o[6] = t6;
1221
- o[7] = t7;
1222
- o[8] = t8;
1223
- o[9] = t9;
1224
- o[10] = t10;
1225
- o[11] = t11;
1226
- o[12] = t12;
1227
- o[13] = t13;
1228
- o[14] = t14;
1229
- o[15] = t15;
1230
- }
1231
- function S(o, a) {
1232
- M(o, a, a);
1233
- }
1234
- function inv25519(o, i) {
1235
- var c = gf();
1236
- var a;
1237
- for (a = 0; a < 16; a++) c[a] = i[a];
1238
- for (a = 253; a >= 0; a--) {
1239
- S(c, c);
1240
- if (a !== 2 && a !== 4) M(c, c, i);
1241
- }
1242
- for (a = 0; a < 16; a++) o[a] = c[a];
1243
- }
1244
- function pow2523(o, i) {
1245
- var c = gf();
1246
- var a;
1247
- for (a = 0; a < 16; a++) c[a] = i[a];
1248
- for (a = 250; a >= 0; a--) {
1249
- S(c, c);
1250
- if (a !== 1) M(c, c, i);
1251
- }
1252
- for (a = 0; a < 16; a++) o[a] = c[a];
1253
- }
1254
- function crypto_scalarmult(q, n, p) {
1255
- var z12 = new Uint8Array(32);
1256
- var x = new Float64Array(80), r, i;
1257
- var a = gf(), b = gf(), c = gf(), d = gf(), e = gf(), f = gf();
1258
- for (i = 0; i < 31; i++) z12[i] = n[i];
1259
- z12[31] = n[31] & 127 | 64;
1260
- z12[0] &= 248;
1261
- unpack25519(x, p);
1262
- for (i = 0; i < 16; i++) {
1263
- b[i] = x[i];
1264
- d[i] = a[i] = c[i] = 0;
1265
- }
1266
- a[0] = d[0] = 1;
1267
- for (i = 254; i >= 0; --i) {
1268
- r = z12[i >>> 3] >>> (i & 7) & 1;
1269
- sel25519(a, b, r);
1270
- sel25519(c, d, r);
1271
- A(e, a, c);
1272
- Z(a, a, c);
1273
- A(c, b, d);
1274
- Z(b, b, d);
1275
- S(d, e);
1276
- S(f, a);
1277
- M(a, c, a);
1278
- M(c, b, e);
1279
- A(e, a, c);
1280
- Z(a, a, c);
1281
- S(b, a);
1282
- Z(c, d, f);
1283
- M(a, c, _121665);
1284
- A(a, a, d);
1285
- M(c, c, a);
1286
- M(a, d, f);
1287
- M(d, b, x);
1288
- S(b, e);
1289
- sel25519(a, b, r);
1290
- sel25519(c, d, r);
1291
- }
1292
- for (i = 0; i < 16; i++) {
1293
- x[i + 16] = a[i];
1294
- x[i + 32] = c[i];
1295
- x[i + 48] = b[i];
1296
- x[i + 64] = d[i];
1297
- }
1298
- var x32 = x.subarray(32);
1299
- var x16 = x.subarray(16);
1300
- inv25519(x32, x32);
1301
- M(x16, x16, x32);
1302
- pack25519(q, x16);
1303
- return 0;
1304
- }
1305
- function crypto_scalarmult_base(q, n) {
1306
- return crypto_scalarmult(q, n, _9);
1307
- }
1308
- function crypto_box_keypair(y, x) {
1309
- randombytes(x, 32);
1310
- return crypto_scalarmult_base(y, x);
1311
- }
1312
- function crypto_box_beforenm(k, y, x) {
1313
- var s = new Uint8Array(32);
1314
- crypto_scalarmult(s, x, y);
1315
- return crypto_core_hsalsa20(k, _0, s, sigma);
1316
- }
1317
- var crypto_box_afternm = crypto_secretbox;
1318
- var crypto_box_open_afternm = crypto_secretbox_open;
1319
- function crypto_box(c, m, d, n, y, x) {
1320
- var k = new Uint8Array(32);
1321
- crypto_box_beforenm(k, y, x);
1322
- return crypto_box_afternm(c, m, d, n, k);
1323
- }
1324
- function crypto_box_open(m, c, d, n, y, x) {
1325
- var k = new Uint8Array(32);
1326
- crypto_box_beforenm(k, y, x);
1327
- return crypto_box_open_afternm(m, c, d, n, k);
1328
- }
1329
- var K = [
1330
- 1116352408,
1331
- 3609767458,
1332
- 1899447441,
1333
- 602891725,
1334
- 3049323471,
1335
- 3964484399,
1336
- 3921009573,
1337
- 2173295548,
1338
- 961987163,
1339
- 4081628472,
1340
- 1508970993,
1341
- 3053834265,
1342
- 2453635748,
1343
- 2937671579,
1344
- 2870763221,
1345
- 3664609560,
1346
- 3624381080,
1347
- 2734883394,
1348
- 310598401,
1349
- 1164996542,
1350
- 607225278,
1351
- 1323610764,
1352
- 1426881987,
1353
- 3590304994,
1354
- 1925078388,
1355
- 4068182383,
1356
- 2162078206,
1357
- 991336113,
1358
- 2614888103,
1359
- 633803317,
1360
- 3248222580,
1361
- 3479774868,
1362
- 3835390401,
1363
- 2666613458,
1364
- 4022224774,
1365
- 944711139,
1366
- 264347078,
1367
- 2341262773,
1368
- 604807628,
1369
- 2007800933,
1370
- 770255983,
1371
- 1495990901,
1372
- 1249150122,
1373
- 1856431235,
1374
- 1555081692,
1375
- 3175218132,
1376
- 1996064986,
1377
- 2198950837,
1378
- 2554220882,
1379
- 3999719339,
1380
- 2821834349,
1381
- 766784016,
1382
- 2952996808,
1383
- 2566594879,
1384
- 3210313671,
1385
- 3203337956,
1386
- 3336571891,
1387
- 1034457026,
1388
- 3584528711,
1389
- 2466948901,
1390
- 113926993,
1391
- 3758326383,
1392
- 338241895,
1393
- 168717936,
1394
- 666307205,
1395
- 1188179964,
1396
- 773529912,
1397
- 1546045734,
1398
- 1294757372,
1399
- 1522805485,
1400
- 1396182291,
1401
- 2643833823,
1402
- 1695183700,
1403
- 2343527390,
1404
- 1986661051,
1405
- 1014477480,
1406
- 2177026350,
1407
- 1206759142,
1408
- 2456956037,
1409
- 344077627,
1410
- 2730485921,
1411
- 1290863460,
1412
- 2820302411,
1413
- 3158454273,
1414
- 3259730800,
1415
- 3505952657,
1416
- 3345764771,
1417
- 106217008,
1418
- 3516065817,
1419
- 3606008344,
1420
- 3600352804,
1421
- 1432725776,
1422
- 4094571909,
1423
- 1467031594,
1424
- 275423344,
1425
- 851169720,
1426
- 430227734,
1427
- 3100823752,
1428
- 506948616,
1429
- 1363258195,
1430
- 659060556,
1431
- 3750685593,
1432
- 883997877,
1433
- 3785050280,
1434
- 958139571,
1435
- 3318307427,
1436
- 1322822218,
1437
- 3812723403,
1438
- 1537002063,
1439
- 2003034995,
1440
- 1747873779,
1441
- 3602036899,
1442
- 1955562222,
1443
- 1575990012,
1444
- 2024104815,
1445
- 1125592928,
1446
- 2227730452,
1447
- 2716904306,
1448
- 2361852424,
1449
- 442776044,
1450
- 2428436474,
1451
- 593698344,
1452
- 2756734187,
1453
- 3733110249,
1454
- 3204031479,
1455
- 2999351573,
1456
- 3329325298,
1457
- 3815920427,
1458
- 3391569614,
1459
- 3928383900,
1460
- 3515267271,
1461
- 566280711,
1462
- 3940187606,
1463
- 3454069534,
1464
- 4118630271,
1465
- 4000239992,
1466
- 116418474,
1467
- 1914138554,
1468
- 174292421,
1469
- 2731055270,
1470
- 289380356,
1471
- 3203993006,
1472
- 460393269,
1473
- 320620315,
1474
- 685471733,
1475
- 587496836,
1476
- 852142971,
1477
- 1086792851,
1478
- 1017036298,
1479
- 365543100,
1480
- 1126000580,
1481
- 2618297676,
1482
- 1288033470,
1483
- 3409855158,
1484
- 1501505948,
1485
- 4234509866,
1486
- 1607167915,
1487
- 987167468,
1488
- 1816402316,
1489
- 1246189591
1490
- ];
1491
- function crypto_hashblocks_hl(hh, hl, m, n) {
1492
- 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;
1493
- 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];
1494
- var pos = 0;
1495
- while (n >= 128) {
1496
- for (i = 0; i < 16; i++) {
1497
- j = 8 * i + pos;
1498
- wh[i] = m[j + 0] << 24 | m[j + 1] << 16 | m[j + 2] << 8 | m[j + 3];
1499
- wl[i] = m[j + 4] << 24 | m[j + 5] << 16 | m[j + 6] << 8 | m[j + 7];
1500
- }
1501
- for (i = 0; i < 80; i++) {
1502
- bh0 = ah0;
1503
- bh1 = ah1;
1504
- bh2 = ah2;
1505
- bh3 = ah3;
1506
- bh4 = ah4;
1507
- bh5 = ah5;
1508
- bh6 = ah6;
1509
- bh7 = ah7;
1510
- bl0 = al0;
1511
- bl1 = al1;
1512
- bl2 = al2;
1513
- bl3 = al3;
1514
- bl4 = al4;
1515
- bl5 = al5;
1516
- bl6 = al6;
1517
- bl7 = al7;
1518
- h = ah7;
1519
- l = al7;
1520
- a = l & 65535;
1521
- b = l >>> 16;
1522
- c = h & 65535;
1523
- d = h >>> 16;
1524
- h = (ah4 >>> 14 | al4 << 32 - 14) ^ (ah4 >>> 18 | al4 << 32 - 18) ^ (al4 >>> 41 - 32 | ah4 << 32 - (41 - 32));
1525
- l = (al4 >>> 14 | ah4 << 32 - 14) ^ (al4 >>> 18 | ah4 << 32 - 18) ^ (ah4 >>> 41 - 32 | al4 << 32 - (41 - 32));
1526
- a += l & 65535;
1527
- b += l >>> 16;
1528
- c += h & 65535;
1529
- d += h >>> 16;
1530
- h = ah4 & ah5 ^ ~ah4 & ah6;
1531
- l = al4 & al5 ^ ~al4 & al6;
1532
- a += l & 65535;
1533
- b += l >>> 16;
1534
- c += h & 65535;
1535
- d += h >>> 16;
1536
- h = K[i * 2];
1537
- l = K[i * 2 + 1];
1538
- a += l & 65535;
1539
- b += l >>> 16;
1540
- c += h & 65535;
1541
- d += h >>> 16;
1542
- h = wh[i % 16];
1543
- l = wl[i % 16];
1544
- a += l & 65535;
1545
- b += l >>> 16;
1546
- c += h & 65535;
1547
- d += h >>> 16;
1548
- b += a >>> 16;
1549
- c += b >>> 16;
1550
- d += c >>> 16;
1551
- th = c & 65535 | d << 16;
1552
- tl = a & 65535 | b << 16;
1553
- h = th;
1554
- l = tl;
1555
- a = l & 65535;
1556
- b = l >>> 16;
1557
- c = h & 65535;
1558
- d = h >>> 16;
1559
- h = (ah0 >>> 28 | al0 << 32 - 28) ^ (al0 >>> 34 - 32 | ah0 << 32 - (34 - 32)) ^ (al0 >>> 39 - 32 | ah0 << 32 - (39 - 32));
1560
- l = (al0 >>> 28 | ah0 << 32 - 28) ^ (ah0 >>> 34 - 32 | al0 << 32 - (34 - 32)) ^ (ah0 >>> 39 - 32 | al0 << 32 - (39 - 32));
1561
- a += l & 65535;
1562
- b += l >>> 16;
1563
- c += h & 65535;
1564
- d += h >>> 16;
1565
- h = ah0 & ah1 ^ ah0 & ah2 ^ ah1 & ah2;
1566
- l = al0 & al1 ^ al0 & al2 ^ al1 & al2;
1567
- a += l & 65535;
1568
- b += l >>> 16;
1569
- c += h & 65535;
1570
- d += h >>> 16;
1571
- b += a >>> 16;
1572
- c += b >>> 16;
1573
- d += c >>> 16;
1574
- bh7 = c & 65535 | d << 16;
1575
- bl7 = a & 65535 | b << 16;
1576
- h = bh3;
1577
- l = bl3;
1578
- a = l & 65535;
1579
- b = l >>> 16;
1580
- c = h & 65535;
1581
- d = h >>> 16;
1582
- h = th;
1583
- l = tl;
1584
- a += l & 65535;
1585
- b += l >>> 16;
1586
- c += h & 65535;
1587
- d += h >>> 16;
1588
- b += a >>> 16;
1589
- c += b >>> 16;
1590
- d += c >>> 16;
1591
- bh3 = c & 65535 | d << 16;
1592
- bl3 = a & 65535 | b << 16;
1593
- ah1 = bh0;
1594
- ah2 = bh1;
1595
- ah3 = bh2;
1596
- ah4 = bh3;
1597
- ah5 = bh4;
1598
- ah6 = bh5;
1599
- ah7 = bh6;
1600
- ah0 = bh7;
1601
- al1 = bl0;
1602
- al2 = bl1;
1603
- al3 = bl2;
1604
- al4 = bl3;
1605
- al5 = bl4;
1606
- al6 = bl5;
1607
- al7 = bl6;
1608
- al0 = bl7;
1609
- if (i % 16 === 15) {
1610
- for (j = 0; j < 16; j++) {
1611
- h = wh[j];
1612
- l = wl[j];
1613
- a = l & 65535;
1614
- b = l >>> 16;
1615
- c = h & 65535;
1616
- d = h >>> 16;
1617
- h = wh[(j + 9) % 16];
1618
- l = wl[(j + 9) % 16];
1619
- a += l & 65535;
1620
- b += l >>> 16;
1621
- c += h & 65535;
1622
- d += h >>> 16;
1623
- th = wh[(j + 1) % 16];
1624
- tl = wl[(j + 1) % 16];
1625
- h = (th >>> 1 | tl << 32 - 1) ^ (th >>> 8 | tl << 32 - 8) ^ th >>> 7;
1626
- l = (tl >>> 1 | th << 32 - 1) ^ (tl >>> 8 | th << 32 - 8) ^ (tl >>> 7 | th << 32 - 7);
1627
- a += l & 65535;
1628
- b += l >>> 16;
1629
- c += h & 65535;
1630
- d += h >>> 16;
1631
- th = wh[(j + 14) % 16];
1632
- tl = wl[(j + 14) % 16];
1633
- h = (th >>> 19 | tl << 32 - 19) ^ (tl >>> 61 - 32 | th << 32 - (61 - 32)) ^ th >>> 6;
1634
- l = (tl >>> 19 | th << 32 - 19) ^ (th >>> 61 - 32 | tl << 32 - (61 - 32)) ^ (tl >>> 6 | th << 32 - 6);
1635
- a += l & 65535;
1636
- b += l >>> 16;
1637
- c += h & 65535;
1638
- d += h >>> 16;
1639
- b += a >>> 16;
1640
- c += b >>> 16;
1641
- d += c >>> 16;
1642
- wh[j] = c & 65535 | d << 16;
1643
- wl[j] = a & 65535 | b << 16;
1644
- }
1645
- }
1646
- }
1647
- h = ah0;
1648
- l = al0;
1649
- a = l & 65535;
1650
- b = l >>> 16;
1651
- c = h & 65535;
1652
- d = h >>> 16;
1653
- h = hh[0];
1654
- l = hl[0];
1655
- a += l & 65535;
1656
- b += l >>> 16;
1657
- c += h & 65535;
1658
- d += h >>> 16;
1659
- b += a >>> 16;
1660
- c += b >>> 16;
1661
- d += c >>> 16;
1662
- hh[0] = ah0 = c & 65535 | d << 16;
1663
- hl[0] = al0 = a & 65535 | b << 16;
1664
- h = ah1;
1665
- l = al1;
1666
- a = l & 65535;
1667
- b = l >>> 16;
1668
- c = h & 65535;
1669
- d = h >>> 16;
1670
- h = hh[1];
1671
- l = hl[1];
1672
- a += l & 65535;
1673
- b += l >>> 16;
1674
- c += h & 65535;
1675
- d += h >>> 16;
1676
- b += a >>> 16;
1677
- c += b >>> 16;
1678
- d += c >>> 16;
1679
- hh[1] = ah1 = c & 65535 | d << 16;
1680
- hl[1] = al1 = a & 65535 | b << 16;
1681
- h = ah2;
1682
- l = al2;
1683
- a = l & 65535;
1684
- b = l >>> 16;
1685
- c = h & 65535;
1686
- d = h >>> 16;
1687
- h = hh[2];
1688
- l = hl[2];
1689
- a += l & 65535;
1690
- b += l >>> 16;
1691
- c += h & 65535;
1692
- d += h >>> 16;
1693
- b += a >>> 16;
1694
- c += b >>> 16;
1695
- d += c >>> 16;
1696
- hh[2] = ah2 = c & 65535 | d << 16;
1697
- hl[2] = al2 = a & 65535 | b << 16;
1698
- h = ah3;
1699
- l = al3;
1700
- a = l & 65535;
1701
- b = l >>> 16;
1702
- c = h & 65535;
1703
- d = h >>> 16;
1704
- h = hh[3];
1705
- l = hl[3];
1706
- a += l & 65535;
1707
- b += l >>> 16;
1708
- c += h & 65535;
1709
- d += h >>> 16;
1710
- b += a >>> 16;
1711
- c += b >>> 16;
1712
- d += c >>> 16;
1713
- hh[3] = ah3 = c & 65535 | d << 16;
1714
- hl[3] = al3 = a & 65535 | b << 16;
1715
- h = ah4;
1716
- l = al4;
1717
- a = l & 65535;
1718
- b = l >>> 16;
1719
- c = h & 65535;
1720
- d = h >>> 16;
1721
- h = hh[4];
1722
- l = hl[4];
1723
- a += l & 65535;
1724
- b += l >>> 16;
1725
- c += h & 65535;
1726
- d += h >>> 16;
1727
- b += a >>> 16;
1728
- c += b >>> 16;
1729
- d += c >>> 16;
1730
- hh[4] = ah4 = c & 65535 | d << 16;
1731
- hl[4] = al4 = a & 65535 | b << 16;
1732
- h = ah5;
1733
- l = al5;
1734
- a = l & 65535;
1735
- b = l >>> 16;
1736
- c = h & 65535;
1737
- d = h >>> 16;
1738
- h = hh[5];
1739
- l = hl[5];
1740
- a += l & 65535;
1741
- b += l >>> 16;
1742
- c += h & 65535;
1743
- d += h >>> 16;
1744
- b += a >>> 16;
1745
- c += b >>> 16;
1746
- d += c >>> 16;
1747
- hh[5] = ah5 = c & 65535 | d << 16;
1748
- hl[5] = al5 = a & 65535 | b << 16;
1749
- h = ah6;
1750
- l = al6;
1751
- a = l & 65535;
1752
- b = l >>> 16;
1753
- c = h & 65535;
1754
- d = h >>> 16;
1755
- h = hh[6];
1756
- l = hl[6];
1757
- a += l & 65535;
1758
- b += l >>> 16;
1759
- c += h & 65535;
1760
- d += h >>> 16;
1761
- b += a >>> 16;
1762
- c += b >>> 16;
1763
- d += c >>> 16;
1764
- hh[6] = ah6 = c & 65535 | d << 16;
1765
- hl[6] = al6 = a & 65535 | b << 16;
1766
- h = ah7;
1767
- l = al7;
1768
- a = l & 65535;
1769
- b = l >>> 16;
1770
- c = h & 65535;
1771
- d = h >>> 16;
1772
- h = hh[7];
1773
- l = hl[7];
1774
- a += l & 65535;
1775
- b += l >>> 16;
1776
- c += h & 65535;
1777
- d += h >>> 16;
1778
- b += a >>> 16;
1779
- c += b >>> 16;
1780
- d += c >>> 16;
1781
- hh[7] = ah7 = c & 65535 | d << 16;
1782
- hl[7] = al7 = a & 65535 | b << 16;
1783
- pos += 128;
1784
- n -= 128;
1785
- }
1786
- return n;
1787
- }
1788
- function crypto_hash(out, m, n) {
1789
- var hh = new Int32Array(8), hl = new Int32Array(8), x = new Uint8Array(256), i, b = n;
1790
- hh[0] = 1779033703;
1791
- hh[1] = 3144134277;
1792
- hh[2] = 1013904242;
1793
- hh[3] = 2773480762;
1794
- hh[4] = 1359893119;
1795
- hh[5] = 2600822924;
1796
- hh[6] = 528734635;
1797
- hh[7] = 1541459225;
1798
- hl[0] = 4089235720;
1799
- hl[1] = 2227873595;
1800
- hl[2] = 4271175723;
1801
- hl[3] = 1595750129;
1802
- hl[4] = 2917565137;
1803
- hl[5] = 725511199;
1804
- hl[6] = 4215389547;
1805
- hl[7] = 327033209;
1806
- crypto_hashblocks_hl(hh, hl, m, n);
1807
- n %= 128;
1808
- for (i = 0; i < n; i++) x[i] = m[b - n + i];
1809
- x[n] = 128;
1810
- n = 256 - 128 * (n < 112 ? 1 : 0);
1811
- x[n - 9] = 0;
1812
- ts64(x, n - 8, b / 536870912 | 0, b << 3);
1813
- crypto_hashblocks_hl(hh, hl, x, n);
1814
- for (i = 0; i < 8; i++) ts64(out, 8 * i, hh[i], hl[i]);
1815
- return 0;
1816
- }
1817
- function add(p, q) {
1818
- var a = gf(), b = gf(), c = gf(), d = gf(), e = gf(), f = gf(), g = gf(), h = gf(), t = gf();
1819
- Z(a, p[1], p[0]);
1820
- Z(t, q[1], q[0]);
1821
- M(a, a, t);
1822
- A(b, p[0], p[1]);
1823
- A(t, q[0], q[1]);
1824
- M(b, b, t);
1825
- M(c, p[3], q[3]);
1826
- M(c, c, D2);
1827
- M(d, p[2], q[2]);
1828
- A(d, d, d);
1829
- Z(e, b, a);
1830
- Z(f, d, c);
1831
- A(g, d, c);
1832
- A(h, b, a);
1833
- M(p[0], e, f);
1834
- M(p[1], h, g);
1835
- M(p[2], g, f);
1836
- M(p[3], e, h);
1837
- }
1838
- function cswap(p, q, b) {
1839
- var i;
1840
- for (i = 0; i < 4; i++) {
1841
- sel25519(p[i], q[i], b);
1842
- }
1843
- }
1844
- function pack(r, p) {
1845
- var tx = gf(), ty = gf(), zi = gf();
1846
- inv25519(zi, p[2]);
1847
- M(tx, p[0], zi);
1848
- M(ty, p[1], zi);
1849
- pack25519(r, ty);
1850
- r[31] ^= par25519(tx) << 7;
1851
- }
1852
- function scalarmult(p, q, s) {
1853
- var b, i;
1854
- set25519(p[0], gf0);
1855
- set25519(p[1], gf1);
1856
- set25519(p[2], gf1);
1857
- set25519(p[3], gf0);
1858
- for (i = 255; i >= 0; --i) {
1859
- b = s[i / 8 | 0] >> (i & 7) & 1;
1860
- cswap(p, q, b);
1861
- add(q, p);
1862
- add(p, p);
1863
- cswap(p, q, b);
1864
- }
1865
- }
1866
- function scalarbase(p, s) {
1867
- var q = [gf(), gf(), gf(), gf()];
1868
- set25519(q[0], X);
1869
- set25519(q[1], Y);
1870
- set25519(q[2], gf1);
1871
- M(q[3], X, Y);
1872
- scalarmult(p, q, s);
1873
- }
1874
- function crypto_sign_keypair(pk, sk, seeded) {
1875
- var d = new Uint8Array(64);
1876
- var p = [gf(), gf(), gf(), gf()];
1877
- var i;
1878
- if (!seeded) randombytes(sk, 32);
1879
- crypto_hash(d, sk, 32);
1880
- d[0] &= 248;
1881
- d[31] &= 127;
1882
- d[31] |= 64;
1883
- scalarbase(p, d);
1884
- pack(pk, p);
1885
- for (i = 0; i < 32; i++) sk[i + 32] = pk[i];
1886
- return 0;
1887
- }
1888
- 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]);
1889
- function modL(r, x) {
1890
- var carry, i, j, k;
1891
- for (i = 63; i >= 32; --i) {
1892
- carry = 0;
1893
- for (j = i - 32, k = i - 12; j < k; ++j) {
1894
- x[j] += carry - 16 * x[i] * L[j - (i - 32)];
1895
- carry = Math.floor((x[j] + 128) / 256);
1896
- x[j] -= carry * 256;
1897
- }
1898
- x[j] += carry;
1899
- x[i] = 0;
1900
- }
1901
- carry = 0;
1902
- for (j = 0; j < 32; j++) {
1903
- x[j] += carry - (x[31] >> 4) * L[j];
1904
- carry = x[j] >> 8;
1905
- x[j] &= 255;
1906
- }
1907
- for (j = 0; j < 32; j++) x[j] -= carry * L[j];
1908
- for (i = 0; i < 32; i++) {
1909
- x[i + 1] += x[i] >> 8;
1910
- r[i] = x[i] & 255;
1911
- }
1912
- }
1913
- function reduce(r) {
1914
- var x = new Float64Array(64), i;
1915
- for (i = 0; i < 64; i++) x[i] = r[i];
1916
- for (i = 0; i < 64; i++) r[i] = 0;
1917
- modL(r, x);
1918
- }
1919
- function crypto_sign(sm, m, n, sk) {
1920
- var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64);
1921
- var i, j, x = new Float64Array(64);
1922
- var p = [gf(), gf(), gf(), gf()];
1923
- crypto_hash(d, sk, 32);
1924
- d[0] &= 248;
1925
- d[31] &= 127;
1926
- d[31] |= 64;
1927
- var smlen = n + 64;
1928
- for (i = 0; i < n; i++) sm[64 + i] = m[i];
1929
- for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i];
1930
- crypto_hash(r, sm.subarray(32), n + 32);
1931
- reduce(r);
1932
- scalarbase(p, r);
1933
- pack(sm, p);
1934
- for (i = 32; i < 64; i++) sm[i] = sk[i];
1935
- crypto_hash(h, sm, n + 64);
1936
- reduce(h);
1937
- for (i = 0; i < 64; i++) x[i] = 0;
1938
- for (i = 0; i < 32; i++) x[i] = r[i];
1939
- for (i = 0; i < 32; i++) {
1940
- for (j = 0; j < 32; j++) {
1941
- x[i + j] += h[i] * d[j];
1942
- }
1943
- }
1944
- modL(sm.subarray(32), x);
1945
- return smlen;
1946
- }
1947
- function unpackneg(r, p) {
1948
- var t = gf(), chk = gf(), num = gf(), den = gf(), den2 = gf(), den4 = gf(), den6 = gf();
1949
- set25519(r[2], gf1);
1950
- unpack25519(r[1], p);
1951
- S(num, r[1]);
1952
- M(den, num, D);
1953
- Z(num, num, r[2]);
1954
- A(den, r[2], den);
1955
- S(den2, den);
1956
- S(den4, den2);
1957
- M(den6, den4, den2);
1958
- M(t, den6, num);
1959
- M(t, t, den);
1960
- pow2523(t, t);
1961
- M(t, t, num);
1962
- M(t, t, den);
1963
- M(t, t, den);
1964
- M(r[0], t, den);
1965
- S(chk, r[0]);
1966
- M(chk, chk, den);
1967
- if (neq25519(chk, num)) M(r[0], r[0], I);
1968
- S(chk, r[0]);
1969
- M(chk, chk, den);
1970
- if (neq25519(chk, num)) return -1;
1971
- if (par25519(r[0]) === p[31] >> 7) Z(r[0], gf0, r[0]);
1972
- M(r[3], r[0], r[1]);
1973
- return 0;
1974
- }
1975
- function crypto_sign_open(m, sm, n, pk) {
1976
- var i;
1977
- var t = new Uint8Array(32), h = new Uint8Array(64);
1978
- var p = [gf(), gf(), gf(), gf()], q = [gf(), gf(), gf(), gf()];
1979
- if (n < 64) return -1;
1980
- if (unpackneg(q, pk)) return -1;
1981
- for (i = 0; i < n; i++) m[i] = sm[i];
1982
- for (i = 0; i < 32; i++) m[i + 32] = pk[i];
1983
- crypto_hash(h, m, n);
1984
- reduce(h);
1985
- scalarmult(p, q, h);
1986
- scalarbase(q, sm.subarray(32));
1987
- add(p, q);
1988
- pack(t, p);
1989
- n -= 64;
1990
- if (crypto_verify_32(sm, 0, t, 0)) {
1991
- for (i = 0; i < n; i++) m[i] = 0;
1992
- return -1;
1993
- }
1994
- for (i = 0; i < n; i++) m[i] = sm[i + 64];
1995
- return n;
1996
- }
1997
- 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;
1998
- nacl2.lowlevel = {
1999
- crypto_core_hsalsa20,
2000
- crypto_stream_xor,
2001
- crypto_stream,
2002
- crypto_stream_salsa20_xor,
2003
- crypto_stream_salsa20,
2004
- crypto_onetimeauth,
2005
- crypto_onetimeauth_verify,
2006
- crypto_verify_16,
2007
- crypto_verify_32,
2008
- crypto_secretbox,
2009
- crypto_secretbox_open,
2010
- crypto_scalarmult,
2011
- crypto_scalarmult_base,
2012
- crypto_box_beforenm,
2013
- crypto_box_afternm,
2014
- crypto_box,
2015
- crypto_box_open,
2016
- crypto_box_keypair,
2017
- crypto_hash,
2018
- crypto_sign,
2019
- crypto_sign_keypair,
2020
- crypto_sign_open,
2021
- crypto_secretbox_KEYBYTES,
2022
- crypto_secretbox_NONCEBYTES,
2023
- crypto_secretbox_ZEROBYTES,
2024
- crypto_secretbox_BOXZEROBYTES,
2025
- crypto_scalarmult_BYTES,
2026
- crypto_scalarmult_SCALARBYTES,
2027
- crypto_box_PUBLICKEYBYTES,
2028
- crypto_box_SECRETKEYBYTES,
2029
- crypto_box_BEFORENMBYTES,
2030
- crypto_box_NONCEBYTES,
2031
- crypto_box_ZEROBYTES,
2032
- crypto_box_BOXZEROBYTES,
2033
- crypto_sign_BYTES,
2034
- crypto_sign_PUBLICKEYBYTES,
2035
- crypto_sign_SECRETKEYBYTES,
2036
- crypto_sign_SEEDBYTES,
2037
- crypto_hash_BYTES,
2038
- gf,
2039
- D,
2040
- L,
2041
- pack25519,
2042
- unpack25519,
2043
- M,
2044
- A,
2045
- S,
2046
- Z,
2047
- pow2523,
2048
- add,
2049
- set25519,
2050
- modL,
2051
- scalarmult,
2052
- scalarbase
2053
- };
2054
- function checkLengths(k, n) {
2055
- if (k.length !== crypto_secretbox_KEYBYTES) throw new Error("bad key size");
2056
- if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error("bad nonce size");
2057
- }
2058
- function checkBoxLengths(pk, sk) {
2059
- if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error("bad public key size");
2060
- if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error("bad secret key size");
2061
- }
2062
- function checkArrayTypes() {
2063
- for (var i = 0; i < arguments.length; i++) {
2064
- if (!(arguments[i] instanceof Uint8Array))
2065
- throw new TypeError("unexpected type, use Uint8Array");
2066
- }
2067
- }
2068
- function cleanup(arr) {
2069
- for (var i = 0; i < arr.length; i++) arr[i] = 0;
2070
- }
2071
- nacl2.randomBytes = function(n) {
2072
- var b = new Uint8Array(n);
2073
- randombytes(b, n);
2074
- return b;
2075
- };
2076
- nacl2.secretbox = function(msg, nonce, key) {
2077
- checkArrayTypes(msg, nonce, key);
2078
- checkLengths(key, nonce);
2079
- var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length);
2080
- var c = new Uint8Array(m.length);
2081
- for (var i = 0; i < msg.length; i++) m[i + crypto_secretbox_ZEROBYTES] = msg[i];
2082
- crypto_secretbox(c, m, m.length, nonce, key);
2083
- return c.subarray(crypto_secretbox_BOXZEROBYTES);
2084
- };
2085
- nacl2.secretbox.open = function(box, nonce, key) {
2086
- checkArrayTypes(box, nonce, key);
2087
- checkLengths(key, nonce);
2088
- var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length);
2089
- var m = new Uint8Array(c.length);
2090
- for (var i = 0; i < box.length; i++) c[i + crypto_secretbox_BOXZEROBYTES] = box[i];
2091
- if (c.length < 32) return null;
2092
- if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null;
2093
- return m.subarray(crypto_secretbox_ZEROBYTES);
2094
- };
2095
- nacl2.secretbox.keyLength = crypto_secretbox_KEYBYTES;
2096
- nacl2.secretbox.nonceLength = crypto_secretbox_NONCEBYTES;
2097
- nacl2.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES;
2098
- nacl2.scalarMult = function(n, p) {
2099
- checkArrayTypes(n, p);
2100
- if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error("bad n size");
2101
- if (p.length !== crypto_scalarmult_BYTES) throw new Error("bad p size");
2102
- var q = new Uint8Array(crypto_scalarmult_BYTES);
2103
- crypto_scalarmult(q, n, p);
2104
- return q;
2105
- };
2106
- nacl2.scalarMult.base = function(n) {
2107
- checkArrayTypes(n);
2108
- if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error("bad n size");
2109
- var q = new Uint8Array(crypto_scalarmult_BYTES);
2110
- crypto_scalarmult_base(q, n);
2111
- return q;
2112
- };
2113
- nacl2.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES;
2114
- nacl2.scalarMult.groupElementLength = crypto_scalarmult_BYTES;
2115
- nacl2.box = function(msg, nonce, publicKey, secretKey) {
2116
- var k = nacl2.box.before(publicKey, secretKey);
2117
- return nacl2.secretbox(msg, nonce, k);
2118
- };
2119
- nacl2.box.before = function(publicKey, secretKey) {
2120
- checkArrayTypes(publicKey, secretKey);
2121
- checkBoxLengths(publicKey, secretKey);
2122
- var k = new Uint8Array(crypto_box_BEFORENMBYTES);
2123
- crypto_box_beforenm(k, publicKey, secretKey);
2124
- return k;
2125
- };
2126
- nacl2.box.after = nacl2.secretbox;
2127
- nacl2.box.open = function(msg, nonce, publicKey, secretKey) {
2128
- var k = nacl2.box.before(publicKey, secretKey);
2129
- return nacl2.secretbox.open(msg, nonce, k);
2130
- };
2131
- nacl2.box.open.after = nacl2.secretbox.open;
2132
- nacl2.box.keyPair = function() {
2133
- var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
2134
- var sk = new Uint8Array(crypto_box_SECRETKEYBYTES);
2135
- crypto_box_keypair(pk, sk);
2136
- return { publicKey: pk, secretKey: sk };
2137
- };
2138
- nacl2.box.keyPair.fromSecretKey = function(secretKey) {
2139
- checkArrayTypes(secretKey);
2140
- if (secretKey.length !== crypto_box_SECRETKEYBYTES)
2141
- throw new Error("bad secret key size");
2142
- var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
2143
- crypto_scalarmult_base(pk, secretKey);
2144
- return { publicKey: pk, secretKey: new Uint8Array(secretKey) };
2145
- };
2146
- nacl2.box.publicKeyLength = crypto_box_PUBLICKEYBYTES;
2147
- nacl2.box.secretKeyLength = crypto_box_SECRETKEYBYTES;
2148
- nacl2.box.sharedKeyLength = crypto_box_BEFORENMBYTES;
2149
- nacl2.box.nonceLength = crypto_box_NONCEBYTES;
2150
- nacl2.box.overheadLength = nacl2.secretbox.overheadLength;
2151
- nacl2.sign = function(msg, secretKey) {
2152
- checkArrayTypes(msg, secretKey);
2153
- if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
2154
- throw new Error("bad secret key size");
2155
- var signedMsg = new Uint8Array(crypto_sign_BYTES + msg.length);
2156
- crypto_sign(signedMsg, msg, msg.length, secretKey);
2157
- return signedMsg;
2158
- };
2159
- nacl2.sign.open = function(signedMsg, publicKey) {
2160
- checkArrayTypes(signedMsg, publicKey);
2161
- if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
2162
- throw new Error("bad public key size");
2163
- var tmp = new Uint8Array(signedMsg.length);
2164
- var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey);
2165
- if (mlen < 0) return null;
2166
- var m = new Uint8Array(mlen);
2167
- for (var i = 0; i < m.length; i++) m[i] = tmp[i];
2168
- return m;
2169
- };
2170
- nacl2.sign.detached = function(msg, secretKey) {
2171
- var signedMsg = nacl2.sign(msg, secretKey);
2172
- var sig = new Uint8Array(crypto_sign_BYTES);
2173
- for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i];
2174
- return sig;
2175
- };
2176
- nacl2.sign.detached.verify = function(msg, sig, publicKey) {
2177
- checkArrayTypes(msg, sig, publicKey);
2178
- if (sig.length !== crypto_sign_BYTES)
2179
- throw new Error("bad signature size");
2180
- if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
2181
- throw new Error("bad public key size");
2182
- var sm = new Uint8Array(crypto_sign_BYTES + msg.length);
2183
- var m = new Uint8Array(crypto_sign_BYTES + msg.length);
2184
- var i;
2185
- for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i];
2186
- for (i = 0; i < msg.length; i++) sm[i + crypto_sign_BYTES] = msg[i];
2187
- return crypto_sign_open(m, sm, sm.length, publicKey) >= 0;
2188
- };
2189
- nacl2.sign.keyPair = function() {
2190
- var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
2191
- var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
2192
- crypto_sign_keypair(pk, sk);
2193
- return { publicKey: pk, secretKey: sk };
2194
- };
2195
- nacl2.sign.keyPair.fromSecretKey = function(secretKey) {
2196
- checkArrayTypes(secretKey);
2197
- if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
2198
- throw new Error("bad secret key size");
2199
- var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
2200
- for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32 + i];
2201
- return { publicKey: pk, secretKey: new Uint8Array(secretKey) };
2202
- };
2203
- nacl2.sign.keyPair.fromSeed = function(seed) {
2204
- checkArrayTypes(seed);
2205
- if (seed.length !== crypto_sign_SEEDBYTES)
2206
- throw new Error("bad seed size");
2207
- var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
2208
- var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
2209
- for (var i = 0; i < 32; i++) sk[i] = seed[i];
2210
- crypto_sign_keypair(pk, sk, true);
2211
- return { publicKey: pk, secretKey: sk };
2212
- };
2213
- nacl2.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES;
2214
- nacl2.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES;
2215
- nacl2.sign.seedLength = crypto_sign_SEEDBYTES;
2216
- nacl2.sign.signatureLength = crypto_sign_BYTES;
2217
- nacl2.hash = function(msg) {
2218
- checkArrayTypes(msg);
2219
- var h = new Uint8Array(crypto_hash_BYTES);
2220
- crypto_hash(h, msg, msg.length);
2221
- return h;
2222
- };
2223
- nacl2.hash.hashLength = crypto_hash_BYTES;
2224
- nacl2.verify = function(x, y) {
2225
- checkArrayTypes(x, y);
2226
- if (x.length === 0 || y.length === 0) return false;
2227
- if (x.length !== y.length) return false;
2228
- return vn(x, 0, y, 0, x.length) === 0 ? true : false;
2229
- };
2230
- nacl2.setPRNG = function(fn) {
2231
- randombytes = fn;
2232
- };
2233
- (function() {
2234
- var crypto2 = typeof self !== "undefined" ? self.crypto || self.msCrypto : null;
2235
- if (crypto2 && crypto2.getRandomValues) {
2236
- var QUOTA = 65536;
2237
- nacl2.setPRNG(function(x, n) {
2238
- var i, v = new Uint8Array(n);
2239
- for (i = 0; i < n; i += QUOTA) {
2240
- crypto2.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
2241
- }
2242
- for (i = 0; i < n; i++) x[i] = v[i];
2243
- cleanup(v);
2244
- });
2245
- } else if (typeof __require !== "undefined") {
2246
- crypto2 = __require("crypto");
2247
- if (crypto2 && crypto2.randomBytes) {
2248
- nacl2.setPRNG(function(x, n) {
2249
- var i, v = crypto2.randomBytes(n);
2250
- for (i = 0; i < n; i++) x[i] = v[i];
2251
- cleanup(v);
2252
- });
2253
- }
2254
- }
2255
- })();
2256
- })(typeof module !== "undefined" && module.exports ? module.exports : self.nacl = self.nacl || {});
2257
- }
2258
- });
3
+ import {
4
+ callTool,
5
+ clearCredentials,
6
+ createTool,
7
+ defineToolSchema,
8
+ getConfigOrDefault,
9
+ login,
10
+ messageSign,
11
+ resolveBaseUrl,
12
+ schemas_default,
13
+ transactionSign,
14
+ walletCreate,
15
+ walletDelete,
16
+ walletImport,
17
+ walletList,
18
+ walletRetrieve
19
+ } from "./chunk-SQTD2GMD.js";
2259
20
 
2260
21
  // src/index.ts
2261
22
  import { createRequire } from "module";
2262
23
  import { Command } from "commander";
2263
24
 
2264
- // src/auth.ts
2265
- import { spawn } from "child_process";
2266
- import * as crypto from "crypto";
2267
- import * as fs from "fs";
2268
- import * as http from "http";
2269
- import * as os from "os";
2270
- import * as path from "path";
2271
- function escapeHtml(str) {
2272
- return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
2273
- }
2274
- function generateCodeVerifier() {
2275
- return crypto.randomBytes(32).toString("base64url");
2276
- }
2277
- function generateCodeChallenge(verifier) {
2278
- return crypto.createHash("sha256").update(verifier).digest("base64url");
2279
- }
2280
- var CONFIG_DIR = path.join(os.homedir(), ".config", "moonpay");
2281
- var CONFIG_PATH = path.join(CONFIG_DIR, "config.json");
2282
- var CREDENTIALS_PATH = path.join(CONFIG_DIR, "credentials.json");
2283
- var LOCK_PATH = path.join(CONFIG_DIR, ".credentials.lock");
2284
- var CALLBACK_PORT = 3847;
2285
- var CALLBACK_URL = `http://localhost:${CALLBACK_PORT}/callback`;
2286
- var DEFAULT_CONFIG = {
2287
- baseUrl: "https://agents.moonpay.com",
2288
- clientId: "mooniq_zin3s5jz3olzkdfxpmbeaogv"
2289
- };
2290
- function ensureConfigDir() {
2291
- if (!fs.existsSync(CONFIG_DIR)) {
2292
- fs.mkdirSync(CONFIG_DIR, { recursive: true, mode: 448 });
2293
- }
2294
- }
2295
- function atomicWriteFileSync(filePath, data, mode) {
2296
- const tmp = filePath + `.tmp.${process.pid}`;
2297
- fs.writeFileSync(tmp, data, { encoding: "utf-8", mode });
2298
- fs.renameSync(tmp, filePath);
2299
- }
2300
- var LOCK_STALE_MS = 3e4;
2301
- function acquireLock() {
2302
- ensureConfigDir();
2303
- try {
2304
- const fd = fs.openSync(LOCK_PATH, fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_WRONLY, 384);
2305
- fs.writeSync(fd, JSON.stringify({ pid: process.pid, ts: Date.now() }));
2306
- fs.closeSync(fd);
2307
- } catch (err) {
2308
- if (err.code !== "EEXIST") throw err;
2309
- try {
2310
- const lockData = JSON.parse(fs.readFileSync(LOCK_PATH, "utf-8"));
2311
- if (Date.now() - lockData.ts < LOCK_STALE_MS) {
2312
- return null;
2313
- }
2314
- } catch {
2315
- }
2316
- try {
2317
- fs.unlinkSync(LOCK_PATH);
2318
- } catch {
2319
- }
2320
- try {
2321
- const fd = fs.openSync(LOCK_PATH, fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_WRONLY, 384);
2322
- fs.writeSync(fd, JSON.stringify({ pid: process.pid, ts: Date.now() }));
2323
- fs.closeSync(fd);
2324
- } catch {
2325
- return null;
2326
- }
2327
- }
2328
- return () => {
2329
- try {
2330
- fs.unlinkSync(LOCK_PATH);
2331
- } catch {
2332
- }
2333
- };
2334
- }
2335
- function getConfig() {
2336
- if (!fs.existsSync(CONFIG_PATH)) {
2337
- return null;
2338
- }
2339
- try {
2340
- const data = JSON.parse(fs.readFileSync(CONFIG_PATH, "utf-8"));
2341
- if (!data.baseUrl || !data.clientId) {
2342
- return null;
2343
- }
2344
- return data;
2345
- } catch {
2346
- return null;
2347
- }
2348
- }
2349
- function getConfigOrDefault() {
2350
- const fromFile = getConfig();
2351
- if (fromFile) return fromFile;
2352
- saveConfig(DEFAULT_CONFIG);
2353
- return DEFAULT_CONFIG;
2354
- }
2355
- function getCredentials() {
2356
- if (!fs.existsSync(CREDENTIALS_PATH)) {
2357
- return null;
2358
- }
2359
- try {
2360
- const data = JSON.parse(fs.readFileSync(CREDENTIALS_PATH, "utf-8"));
2361
- if (!data.accessToken || !data.baseUrl) {
2362
- return null;
2363
- }
2364
- return data;
2365
- } catch {
2366
- return null;
2367
- }
2368
- }
2369
- function saveCredentials(creds) {
2370
- ensureConfigDir();
2371
- atomicWriteFileSync(CREDENTIALS_PATH, JSON.stringify(creds, null, 2), 384);
2372
- }
2373
- function saveConfig(config) {
2374
- ensureConfigDir();
2375
- atomicWriteFileSync(CONFIG_PATH, JSON.stringify(config, null, 2), 384);
2376
- }
2377
- function clearCredentials() {
2378
- if (fs.existsSync(CREDENTIALS_PATH)) {
2379
- fs.unlinkSync(CREDENTIALS_PATH);
2380
- }
2381
- }
2382
- function openBrowser(url) {
2383
- const platform = process.platform;
2384
- const cmd = platform === "darwin" ? "open" : platform === "win32" ? "cmd" : "xdg-open";
2385
- const args = platform === "win32" ? ["/c", "start", "", url] : [url];
2386
- spawn(cmd, args, { stdio: "ignore", detached: true }).unref();
2387
- }
2388
- async function login(config) {
2389
- const state = crypto.randomUUID();
2390
- const usePkce = !config.clientSecret;
2391
- let codeVerifier;
2392
- if (usePkce) {
2393
- codeVerifier = generateCodeVerifier();
2394
- }
2395
- let resolveCallback;
2396
- const codePromise = new Promise((resolve) => {
2397
- resolveCallback = resolve;
2398
- });
2399
- const sockets = /* @__PURE__ */ new Set();
2400
- const server = http.createServer((req, res) => {
2401
- const url = new URL(req.url ?? "/", `http://localhost:${CALLBACK_PORT}`);
2402
- if (url.pathname === "/callback") {
2403
- const code2 = url.searchParams.get("code");
2404
- const returnedState = url.searchParams.get("state");
2405
- const error = url.searchParams.get("error");
2406
- const errorDesc = url.searchParams.get("error_description");
2407
- if (returnedState !== state) {
2408
- res.writeHead(200, { "Content-Type": "text/html" });
2409
- res.end(
2410
- `<!DOCTYPE html><html><head><meta charset="utf-8"><title>OAuth Error</title></head><body style="font-family:system-ui,sans-serif;display:flex;flex-direction:column;align-items:center;justify-content:center;min-height:100vh;margin:0;padding:2rem;text-align:center;background:#fef2f2"><h1 style="color:#b91c1c;margin:0 0 1rem">OAuth Error</h1><p style="color:#991b1b;margin:0">State mismatch \u2014 possible CSRF attack. Please try logging in again.</p></body></html>`
2411
- );
2412
- resolveCallback("");
2413
- setTimeout(() => server.close(), 2e3);
2414
- } else if (error) {
2415
- const safeError = escapeHtml(error);
2416
- const safeDesc = escapeHtml(errorDesc ?? "Unknown error");
2417
- res.writeHead(200, { "Content-Type": "text/html" });
2418
- res.end(
2419
- `<!DOCTYPE html><html><head><meta charset="utf-8"><title>OAuth Error</title></head><body style="font-family:system-ui,sans-serif;display:flex;flex-direction:column;align-items:center;justify-content:center;min-height:100vh;margin:0;padding:2rem;text-align:center;background:#fef2f2"><h1 style="color:#b91c1c;margin:0 0 1rem">OAuth Error</h1><p style="color:#991b1b;margin:0">${safeError}: ${safeDesc}</p></body></html>`
2420
- );
2421
- resolveCallback("");
2422
- setTimeout(() => server.close(), 2e3);
2423
- } else if (code2) {
2424
- res.writeHead(200, { "Content-Type": "text/html" });
2425
- res.end(
2426
- `<!DOCTYPE html><html><head><meta charset="utf-8"><title>MoonPay Agents</title></head><body style="font-family:system-ui,-apple-system,sans-serif;display:flex;flex-direction:column;align-items:center;justify-content:center;min-height:100vh;margin:0;padding:2rem;text-align:center;background:#0a0a0a;color:#fafafa"><img src="https://agents.moonpay.com/logos/moonpay.jpg" alt="MoonPay" style="width:64px;height:64px;border-radius:16px;margin-bottom:1.5rem" /><h1 style="margin:0 0 0.5rem;font-size:1.5rem;font-weight:600">Your agent has money now.</h1><p style="color:#a1a1aa;margin:0;font-size:1rem">You can close this tab and return to the terminal.</p></body></html>`
2427
- );
2428
- resolveCallback(code2);
2429
- } else {
2430
- res.writeHead(200, { "Content-Type": "text/html" });
2431
- res.end(
2432
- `<!DOCTYPE html><html><head><meta charset="utf-8"><title>Error</title></head><body style="font-family:system-ui,sans-serif;display:flex;flex-direction:column;align-items:center;justify-content:center;min-height:100vh;margin:0;padding:2rem;text-align:center;background:#fef2f2"><h1 style="color:#b91c1c;margin:0 0 1rem">Error</h1><p style="color:#991b1b;margin:0">No authorization code received.</p></body></html>`
2433
- );
2434
- resolveCallback("");
2435
- setTimeout(() => server.close(), 2e3);
2436
- }
2437
- } else {
2438
- res.writeHead(204);
2439
- res.end();
2440
- }
2441
- });
2442
- await new Promise((resolve, reject) => {
2443
- server.on("error", (err) => {
2444
- if (err.code === "EADDRINUSE") {
2445
- reject(
2446
- new Error(
2447
- `Port ${CALLBACK_PORT} is in use. Close the other process or run: lsof -i :${CALLBACK_PORT}`
2448
- )
2449
- );
2450
- } else {
2451
- reject(err);
2452
- }
2453
- });
2454
- server.on("connection", (socket) => {
2455
- sockets.add(socket);
2456
- socket.on("close", () => sockets.delete(socket));
2457
- });
2458
- server.listen(CALLBACK_PORT, "127.0.0.1", () => resolve());
2459
- });
2460
- console.log(
2461
- `Waiting for callback at http://localhost:${CALLBACK_PORT}/callback`
2462
- );
2463
- const authorizeParams = new URLSearchParams({
2464
- client_id: config.clientId,
2465
- redirect_uri: CALLBACK_URL,
2466
- response_type: "code",
2467
- scope: "profile email",
2468
- state
2469
- });
2470
- if (usePkce && codeVerifier) {
2471
- authorizeParams.set("code_challenge", generateCodeChallenge(codeVerifier));
2472
- authorizeParams.set("code_challenge_method", "S256");
2473
- }
2474
- const authorizeUrl = `${config.baseUrl}/authorize?${authorizeParams.toString()}`;
2475
- console.log("Opening browser for authorization...");
2476
- console.log("(Make sure you're logged in to MoonPay in your browser)\n");
2477
- openBrowser(authorizeUrl);
2478
- const code = await codePromise;
2479
- if (!code) {
2480
- throw new Error("No authorization code received");
2481
- }
2482
- const tokenParams = {
2483
- grant_type: "authorization_code",
2484
- code,
2485
- client_id: config.clientId,
2486
- redirect_uri: CALLBACK_URL
2487
- };
2488
- if (config.clientSecret) {
2489
- tokenParams.client_secret = config.clientSecret;
2490
- }
2491
- if (usePkce && codeVerifier) {
2492
- tokenParams.code_verifier = codeVerifier;
2493
- }
2494
- const tokenResponse = await fetch(`${config.baseUrl}/api/oauth/token`, {
2495
- method: "POST",
2496
- headers: { "Content-Type": "application/x-www-form-urlencoded" },
2497
- body: new URLSearchParams(tokenParams)
2498
- });
2499
- if (!tokenResponse.ok) {
2500
- const err = await tokenResponse.json().catch(() => ({}));
2501
- const msg = err.error_description ?? err.error ?? tokenResponse.statusText;
2502
- throw new Error(`Token exchange failed: ${msg}`);
2503
- }
2504
- const tokens = await tokenResponse.json();
2505
- const expiresAt = Date.now() + (tokens.expires_in ?? 3600) * 1e3;
2506
- const creds = {
2507
- accessToken: tokens.access_token,
2508
- refreshToken: tokens.refresh_token ?? null,
2509
- expiresAt,
2510
- baseUrl: config.baseUrl
2511
- };
2512
- saveCredentials(creds);
2513
- await new Promise((resolve) => setTimeout(resolve, 1e3));
2514
- server.close();
2515
- for (const socket of sockets) {
2516
- if ("destroy" in socket && typeof socket.destroy === "function") {
2517
- socket.destroy();
2518
- }
2519
- }
2520
- sockets.clear();
2521
- return creds;
2522
- }
2523
- async function refreshCredentials(creds, config) {
2524
- if (!creds.refreshToken) {
2525
- throw new Error("No refresh token available");
2526
- }
2527
- const unlock = acquireLock();
2528
- if (!unlock) {
2529
- await new Promise((r) => setTimeout(r, 2e3));
2530
- const fresh = getCredentials();
2531
- if (fresh && fresh.expiresAt > Date.now()) {
2532
- return fresh;
2533
- }
2534
- throw new Error("Token refresh failed (concurrent refresh in progress)");
2535
- }
2536
- try {
2537
- const latest = getCredentials();
2538
- if (latest && latest.expiresAt > Date.now() + 6e4) {
2539
- return latest;
2540
- }
2541
- const refreshParams = {
2542
- grant_type: "refresh_token",
2543
- refresh_token: creds.refreshToken,
2544
- client_id: config.clientId
2545
- };
2546
- if (config.clientSecret) {
2547
- refreshParams.client_secret = config.clientSecret;
2548
- }
2549
- const tokenResponse = await fetch(`${config.baseUrl}/api/oauth/token`, {
2550
- method: "POST",
2551
- headers: { "Content-Type": "application/x-www-form-urlencoded" },
2552
- body: new URLSearchParams(refreshParams)
2553
- });
2554
- if (!tokenResponse.ok) {
2555
- throw new Error("Token refresh failed");
2556
- }
2557
- const tokens = await tokenResponse.json();
2558
- const expiresAt = Date.now() + (tokens.expires_in ?? 3600) * 1e3;
2559
- const newCreds = {
2560
- accessToken: tokens.access_token,
2561
- refreshToken: tokens.refresh_token ?? creds.refreshToken,
2562
- expiresAt,
2563
- baseUrl: config.baseUrl
2564
- };
2565
- saveCredentials(newCreds);
2566
- return newCreds;
2567
- } finally {
2568
- unlock();
2569
- }
2570
- }
2571
- var TOKEN_EXPIRY_BUFFER_MS = 5 * 60 * 1e3;
2572
- async function getValidToken() {
2573
- const creds = getCredentials();
2574
- if (!creds) return null;
2575
- const config = getConfig();
2576
- if (!config || config.baseUrl !== creds.baseUrl) return null;
2577
- if (Date.now() >= creds.expiresAt - TOKEN_EXPIRY_BUFFER_MS) {
2578
- if (creds.refreshToken) {
2579
- try {
2580
- const newCreds = await refreshCredentials(creds, config);
2581
- return newCreds.accessToken;
2582
- } catch {
2583
- return null;
2584
- }
2585
- }
2586
- return null;
2587
- }
2588
- return creds.accessToken;
2589
- }
2590
-
2591
- // src/client.ts
2592
- async function callTool(baseUrl, toolName, params) {
2593
- const token = await getValidToken();
2594
- const headers = {
2595
- "Content-Type": "application/json"
2596
- };
2597
- if (token) {
2598
- headers["Authorization"] = `Bearer ${token}`;
2599
- }
2600
- let res = await fetch(`${baseUrl}/api/tools/${toolName}`, {
2601
- method: "POST",
2602
- headers,
2603
- body: JSON.stringify(params)
2604
- });
2605
- if (res.status === 401 && token) {
2606
- const creds = getCredentials();
2607
- const config = getConfig();
2608
- if (creds?.refreshToken && config && config.baseUrl === creds.baseUrl) {
2609
- try {
2610
- const newCreds = await refreshCredentials(creds, config);
2611
- res = await fetch(`${baseUrl}/api/tools/${toolName}`, {
2612
- method: "POST",
2613
- headers: {
2614
- "Content-Type": "application/json",
2615
- Authorization: `Bearer ${newCreds.accessToken}`
2616
- },
2617
- body: JSON.stringify(params)
2618
- });
2619
- } catch {
2620
- }
2621
- }
2622
- }
2623
- const data = await res.json();
2624
- if (res.status === 401) {
2625
- throw new Error("This command requires a MoonPay Agents account. Run `moonpay login` first.");
2626
- }
2627
- if (res.status < 200 || res.status >= 300) {
2628
- const err = data;
2629
- throw new Error(err?.error ?? `Tool call failed (${res.status})`);
2630
- }
2631
- return data;
2632
- }
2633
-
2634
25
  // src/format.ts
2635
26
  var useColor = !process.env.NO_COLOR && process.stdout.isTTY === true;
2636
27
  function ansi(code) {
@@ -2702,16 +93,16 @@ function formatOutput(result, format) {
2702
93
  }
2703
94
 
2704
95
  // src/version-check.ts
2705
- import { readFileSync as readFileSync2, writeFileSync as writeFileSync2, mkdirSync as mkdirSync2 } from "fs";
2706
- import { join as join2 } from "path";
2707
- import { homedir as homedir2 } from "os";
2708
- var CACHE_DIR = join2(homedir2(), ".config", "moonpay");
2709
- var CACHE_FILE = join2(CACHE_DIR, "update-check.json");
96
+ import { readFileSync, writeFileSync, mkdirSync } from "fs";
97
+ import { join } from "path";
98
+ import { homedir } from "os";
99
+ var CACHE_DIR = join(homedir(), ".config", "moonpay");
100
+ var CACHE_FILE = join(CACHE_DIR, "update-check.json");
2710
101
  var ONE_DAY_MS = 24 * 60 * 60 * 1e3;
2711
102
  var FETCH_TIMEOUT_MS = 3e3;
2712
103
  function readCache() {
2713
104
  try {
2714
- const raw = readFileSync2(CACHE_FILE, "utf-8");
105
+ const raw = readFileSync(CACHE_FILE, "utf-8");
2715
106
  return JSON.parse(raw);
2716
107
  } catch {
2717
108
  return null;
@@ -2719,8 +110,8 @@ function readCache() {
2719
110
  }
2720
111
  function writeCache(data) {
2721
112
  try {
2722
- mkdirSync2(CACHE_DIR, { recursive: true });
2723
- writeFileSync2(CACHE_FILE, JSON.stringify(data));
113
+ mkdirSync(CACHE_DIR, { recursive: true });
114
+ writeFileSync(CACHE_FILE, JSON.stringify(data));
2724
115
  } catch {
2725
116
  }
2726
117
  }
@@ -2767,1608 +158,24 @@ function startVersionCheck(currentVersion) {
2767
158
  return () => notice;
2768
159
  }
2769
160
 
2770
- // src/generated/schemas.json
2771
- var schemas_default = [
2772
- {
2773
- name: "buy",
2774
- description: "Buy crypto with fiat via MoonPay. Returns a checkout URL to complete the purchase.",
2775
- inputSchema: {
2776
- $ref: "#/definitions/buy_input",
2777
- definitions: {
2778
- buy_input: {
2779
- type: "object",
2780
- properties: {
2781
- token: {
2782
- type: "string",
2783
- enum: [
2784
- "sol",
2785
- "usdc",
2786
- "usdc_arbitrum",
2787
- "usdc_base",
2788
- "usdc_optimism",
2789
- "usdc_sol",
2790
- "usdc_polygon",
2791
- "eth",
2792
- "eth_polygon",
2793
- "eth_optimism",
2794
- "eth_base",
2795
- "eth_arbitrum"
2796
- ],
2797
- description: "MoonPay currency code: sol (Solana), usdc_sol (USDC on Solana), eth (Ethereum), usdc (USDC on Ethereum), usdc_base (USDC on Base), etc."
2798
- },
2799
- amount: {
2800
- type: "number",
2801
- description: "Amount of token to buy (e.g. 1.5 for 1.5 SOL)"
2802
- },
2803
- wallet: {
2804
- type: "string",
2805
- description: "Destination wallet address to receive the tokens"
2806
- },
2807
- email: {
2808
- type: [
2809
- "string",
2810
- "null"
2811
- ],
2812
- description: "Buyer email to pre-fill on the checkout page"
2813
- }
2814
- },
2815
- required: [
2816
- "token",
2817
- "amount",
2818
- "wallet",
2819
- "email"
2820
- ],
2821
- additionalProperties: false
2822
- }
2823
- },
2824
- $schema: "http://json-schema.org/draft-07/schema#"
2825
- }
2826
- },
2827
- {
2828
- name: "token_balance_list",
2829
- description: "List all token balances held in a wallet, including amount owned, current value in USD, and token details. Shows the complete token portfolio.",
2830
- inputSchema: {
2831
- $ref: "#/definitions/token_balance_list_input",
2832
- definitions: {
2833
- token_balance_list_input: {
2834
- type: "object",
2835
- properties: {
2836
- wallet: {
2837
- type: "string",
2838
- description: "Wallet address to check token balances for"
2839
- },
2840
- chain: {
2841
- type: "string",
2842
- enum: [
2843
- "solana",
2844
- "ethereum",
2845
- "base",
2846
- "polygon",
2847
- "arbitrum",
2848
- "optimism"
2849
- ],
2850
- description: "Blockchain to check balances on (e.g. 'solana', 'ethereum', 'base')"
2851
- }
2852
- },
2853
- required: [
2854
- "wallet",
2855
- "chain"
2856
- ],
2857
- additionalProperties: false
2858
- }
2859
- },
2860
- $schema: "http://json-schema.org/draft-07/schema#"
2861
- }
2862
- },
2863
- {
2864
- name: "token_retrieve",
2865
- description: "Get detailed token information including market data, price changes, volume, trades, and holder statistics by token address",
2866
- inputSchema: {
2867
- $ref: "#/definitions/token_retrieve_input",
2868
- definitions: {
2869
- token_retrieve_input: {
2870
- type: "object",
2871
- properties: {
2872
- token: {
2873
- type: "string",
2874
- description: "Address of the token to retrieve"
2875
- },
2876
- chain: {
2877
- type: "string",
2878
- enum: [
2879
- "solana",
2880
- "ethereum",
2881
- "base",
2882
- "polygon",
2883
- "arbitrum",
2884
- "optimism"
2885
- ],
2886
- description: "Blockchain network where the token exists"
2887
- }
2888
- },
2889
- required: [
2890
- "token",
2891
- "chain"
2892
- ],
2893
- additionalProperties: false
2894
- }
2895
- },
2896
- $schema: "http://json-schema.org/draft-07/schema#"
2897
- }
2898
- },
2899
- {
2900
- name: "token_search",
2901
- description: "Search for tokens by name, symbol, or address. Returns matching tokens with their market data including price, volume, and liquidity.",
2902
- inputSchema: {
2903
- $ref: "#/definitions/token_search_input",
2904
- definitions: {
2905
- token_search_input: {
2906
- type: "object",
2907
- properties: {
2908
- query: {
2909
- type: "string",
2910
- description: "Search term - can be token name (e.g. 'Bitcoin'), symbol (e.g. 'BTC'), or partial match"
2911
- },
2912
- chain: {
2913
- type: "string",
2914
- enum: [
2915
- "solana",
2916
- "ethereum",
2917
- "base",
2918
- "polygon",
2919
- "arbitrum",
2920
- "optimism"
2921
- ],
2922
- description: "Blockchain to search on (e.g. 'solana', 'ethereum', 'base')"
2923
- },
2924
- limit: {
2925
- type: [
2926
- "number",
2927
- "null"
2928
- ],
2929
- description: "Maximum number of results to return (optional, defaults to 5)"
2930
- }
2931
- },
2932
- required: [
2933
- "query",
2934
- "chain",
2935
- "limit"
2936
- ],
2937
- additionalProperties: false
2938
- }
2939
- },
2940
- $schema: "http://json-schema.org/draft-07/schema#"
2941
- }
2942
- },
2943
- {
2944
- name: "token_swap_build",
2945
- description: "Build an unsigned swap transaction. Returns a base64-encoded transaction ready for signing.",
2946
- inputSchema: {
2947
- $ref: "#/definitions/token_swap_build_input",
2948
- definitions: {
2949
- token_swap_build_input: {
2950
- type: "object",
2951
- properties: {
2952
- input: {
2953
- type: "string",
2954
- description: "Mint address of the input token"
2955
- },
2956
- output: {
2957
- type: "string",
2958
- description: "Mint address of the output token"
2959
- },
2960
- amount: {
2961
- type: "number",
2962
- description: "Amount of the input token to swap"
2963
- },
2964
- wallet: {
2965
- type: "string",
2966
- description: "Wallet address that will execute the swap"
2967
- }
2968
- },
2969
- required: [
2970
- "input",
2971
- "output",
2972
- "amount",
2973
- "wallet"
2974
- ],
2975
- additionalProperties: false
2976
- }
2977
- },
2978
- $schema: "http://json-schema.org/draft-07/schema#"
2979
- }
2980
- },
2981
- {
2982
- name: "token_swap_execute",
2983
- description: "Execute a signed swap transaction. Pass the signed transaction and requestId from token_swap_build.",
2984
- inputSchema: {
2985
- $ref: "#/definitions/token_swap_execute_input",
2986
- definitions: {
2987
- token_swap_execute_input: {
2988
- type: "object",
2989
- properties: {
2990
- transaction: {
2991
- type: "string",
2992
- description: "Base64-encoded signed transaction"
2993
- },
2994
- requestId: {
2995
- type: "string",
2996
- description: "Request ID from token_swap_build"
2997
- }
2998
- },
2999
- required: [
3000
- "transaction",
3001
- "requestId"
3002
- ],
3003
- additionalProperties: false
3004
- }
3005
- },
3006
- $schema: "http://json-schema.org/draft-07/schema#"
3007
- }
3008
- },
3009
- {
3010
- name: "token_trending_list",
3011
- description: "Get currently trending tokens on a blockchain. Perfect for discovering what's hot right now.",
3012
- inputSchema: {
3013
- $ref: "#/definitions/token_trending_list_input",
3014
- definitions: {
3015
- token_trending_list_input: {
3016
- type: "object",
3017
- properties: {
3018
- chain: {
3019
- type: "string",
3020
- enum: [
3021
- "solana",
3022
- "ethereum",
3023
- "base",
3024
- "polygon",
3025
- "arbitrum",
3026
- "optimism"
3027
- ],
3028
- description: "Blockchain to get trending tokens from (e.g. 'solana', 'ethereum', 'base')"
3029
- },
3030
- limit: {
3031
- type: "number",
3032
- description: "Number of results per page"
3033
- },
3034
- page: {
3035
- type: "number",
3036
- description: "The page number of results"
3037
- }
3038
- },
3039
- required: [
3040
- "chain",
3041
- "limit",
3042
- "page"
3043
- ],
3044
- additionalProperties: false
3045
- }
3046
- },
3047
- $schema: "http://json-schema.org/draft-07/schema#"
3048
- }
3049
- },
3050
- {
3051
- name: "transaction_send",
3052
- description: "Broadcast a signed transaction to Solana. Simulates first, then sends and confirms.",
3053
- inputSchema: {
3054
- $ref: "#/definitions/transaction_send_input",
3055
- definitions: {
3056
- transaction_send_input: {
3057
- type: "object",
3058
- properties: {
3059
- transaction: {
3060
- type: "string",
3061
- description: "Base64-encoded signed transaction"
3062
- },
3063
- message: {
3064
- type: "string",
3065
- description: "Human-readable message describing the transaction"
3066
- }
3067
- },
3068
- required: [
3069
- "transaction",
3070
- "message"
3071
- ],
3072
- additionalProperties: false
3073
- }
3074
- },
3075
- $schema: "http://json-schema.org/draft-07/schema#"
3076
- }
3077
- },
3078
- {
3079
- name: "user_retrieve",
3080
- description: "Get the currently authenticated user",
3081
- inputSchema: {
3082
- $ref: "#/definitions/user_retrieve_input",
3083
- definitions: {
3084
- user_retrieve_input: {
3085
- type: "object",
3086
- properties: {},
3087
- additionalProperties: false
3088
- }
3089
- },
3090
- $schema: "http://json-schema.org/draft-07/schema#"
3091
- }
3092
- },
3093
- {
3094
- name: "virtual-account_bank-account_delete",
3095
- description: "Delete a bank account",
3096
- inputSchema: {
3097
- $ref: "#/definitions/virtual-account_bank-account_delete_input",
3098
- definitions: {
3099
- "virtual-account_bank-account_delete_input": {
3100
- type: "object",
3101
- properties: {
3102
- bankAccountId: {
3103
- type: "string",
3104
- format: "uuid",
3105
- description: "The ID of the bank account to delete"
3106
- }
3107
- },
3108
- required: [
3109
- "bankAccountId"
3110
- ],
3111
- additionalProperties: false
3112
- }
3113
- },
3114
- $schema: "http://json-schema.org/draft-07/schema#"
3115
- }
3116
- },
3117
- {
3118
- name: "virtual-account_bank-account_eur_register",
3119
- description: "Register a EUR bank account for offramp payouts",
3120
- inputSchema: {
3121
- $ref: "#/definitions/virtual-account_bank-account_eur_register_input",
3122
- definitions: {
3123
- "virtual-account_bank-account_eur_register_input": {
3124
- type: "object",
3125
- properties: {
3126
- iban: {
3127
- type: "string",
3128
- description: "IBAN for SEPA bank account"
3129
- },
3130
- address: {
3131
- type: "object",
3132
- properties: {
3133
- street: {
3134
- type: "string",
3135
- description: "Street address"
3136
- },
3137
- city: {
3138
- type: "string",
3139
- description: "City"
3140
- },
3141
- state: {
3142
- type: "string",
3143
- description: "State or province"
3144
- },
3145
- country: {
3146
- type: "string",
3147
- enum: [
3148
- "US",
3149
- "GB",
3150
- "CA",
3151
- "AU",
3152
- "DE",
3153
- "FR",
3154
- "IT",
3155
- "ES",
3156
- "NL",
3157
- "BE",
3158
- "AT",
3159
- "CH",
3160
- "SE",
3161
- "NO",
3162
- "DK",
3163
- "FI",
3164
- "IE",
3165
- "PT",
3166
- "PL",
3167
- "CZ",
3168
- "GR",
3169
- "JP",
3170
- "KR",
3171
- "CN",
3172
- "IN",
3173
- "BR",
3174
- "MX",
3175
- "AR",
3176
- "ZA",
3177
- "NZ",
3178
- "SG",
3179
- "HK",
3180
- "AE"
3181
- ],
3182
- description: "ISO 3166-1 Alpha-2 country code"
3183
- },
3184
- postalCode: {
3185
- type: "string",
3186
- description: "Postal or ZIP code"
3187
- }
3188
- },
3189
- required: [
3190
- "street",
3191
- "city",
3192
- "state",
3193
- "country",
3194
- "postalCode"
3195
- ],
3196
- additionalProperties: false,
3197
- description: "Address of the user that owns the bank account"
3198
- },
3199
- email: {
3200
- type: "string",
3201
- description: "Email address of the user that owns the bank account"
3202
- },
3203
- phoneNumber: {
3204
- type: "string",
3205
- description: "Phone number of the user"
3206
- },
3207
- providerCountry: {
3208
- type: "string",
3209
- enum: [
3210
- "US",
3211
- "GB",
3212
- "CA",
3213
- "AU",
3214
- "DE",
3215
- "FR",
3216
- "IT",
3217
- "ES",
3218
- "NL",
3219
- "BE",
3220
- "AT",
3221
- "CH",
3222
- "SE",
3223
- "NO",
3224
- "DK",
3225
- "FI",
3226
- "IE",
3227
- "PT",
3228
- "PL",
3229
- "CZ",
3230
- "GR",
3231
- "JP",
3232
- "KR",
3233
- "CN",
3234
- "IN",
3235
- "BR",
3236
- "MX",
3237
- "AR",
3238
- "ZA",
3239
- "NZ",
3240
- "SG",
3241
- "HK",
3242
- "AE"
3243
- ],
3244
- description: "ISO 3166-1 Alpha-2 country code where the bank is located"
3245
- },
3246
- providerName: {
3247
- type: "string",
3248
- description: "Name of the bank"
3249
- },
3250
- givenName: {
3251
- type: "string",
3252
- description: "First/given name of the account holder"
3253
- },
3254
- familyName: {
3255
- type: "string",
3256
- description: "Last/family name of the account holder"
3257
- }
3258
- },
3259
- required: [
3260
- "iban",
3261
- "address",
3262
- "email",
3263
- "phoneNumber",
3264
- "providerCountry",
3265
- "providerName",
3266
- "givenName",
3267
- "familyName"
3268
- ],
3269
- additionalProperties: false
3270
- }
3271
- },
3272
- $schema: "http://json-schema.org/draft-07/schema#"
3273
- }
3274
- },
3275
- {
3276
- name: "virtual-account_bank-account_list",
3277
- description: "List registered bank accounts",
3278
- inputSchema: {
3279
- $ref: "#/definitions/virtual-account_bank-account_list_input",
3280
- definitions: {
3281
- "virtual-account_bank-account_list_input": {
3282
- type: "object",
3283
- properties: {},
3284
- additionalProperties: false
3285
- }
3286
- },
3287
- $schema: "http://json-schema.org/draft-07/schema#"
3288
- }
3289
- },
3290
- {
3291
- name: "virtual-account_bank-account_retrieve",
3292
- description: "Get a bank account by currency",
3293
- inputSchema: {
3294
- $ref: "#/definitions/virtual-account_bank-account_retrieve_input",
3295
- definitions: {
3296
- "virtual-account_bank-account_retrieve_input": {
3297
- type: "object",
3298
- properties: {
3299
- currency: {
3300
- type: "string",
3301
- enum: [
3302
- "USD",
3303
- "EUR"
3304
- ],
3305
- description: "The fiat currency code (USD or EUR)"
3306
- }
3307
- },
3308
- required: [
3309
- "currency"
3310
- ],
3311
- additionalProperties: false
3312
- }
3313
- },
3314
- $schema: "http://json-schema.org/draft-07/schema#"
3315
- }
3316
- },
3317
- {
3318
- name: "virtual-account_bank-account_usd_register",
3319
- description: "Register a USD bank account for offramp payouts",
3320
- inputSchema: {
3321
- $ref: "#/definitions/virtual-account_bank-account_usd_register_input",
3322
- definitions: {
3323
- "virtual-account_bank-account_usd_register_input": {
3324
- type: "object",
3325
- properties: {
3326
- type: {
3327
- type: "string",
3328
- enum: [
3329
- "ACH",
3330
- "Wire"
3331
- ],
3332
- description: "Type of bank account (ACH or Wire)"
3333
- },
3334
- accountNumber: {
3335
- type: "string",
3336
- description: "Account number"
3337
- },
3338
- routingNumber: {
3339
- type: "string",
3340
- description: "Routing number"
3341
- },
3342
- address: {
3343
- type: "object",
3344
- properties: {
3345
- street: {
3346
- type: "string",
3347
- description: "Street address"
3348
- },
3349
- city: {
3350
- type: "string",
3351
- description: "City"
3352
- },
3353
- state: {
3354
- type: "string",
3355
- description: "State or province"
3356
- },
3357
- country: {
3358
- type: "string",
3359
- enum: [
3360
- "US",
3361
- "GB",
3362
- "CA",
3363
- "AU",
3364
- "DE",
3365
- "FR",
3366
- "IT",
3367
- "ES",
3368
- "NL",
3369
- "BE",
3370
- "AT",
3371
- "CH",
3372
- "SE",
3373
- "NO",
3374
- "DK",
3375
- "FI",
3376
- "IE",
3377
- "PT",
3378
- "PL",
3379
- "CZ",
3380
- "GR",
3381
- "JP",
3382
- "KR",
3383
- "CN",
3384
- "IN",
3385
- "BR",
3386
- "MX",
3387
- "AR",
3388
- "ZA",
3389
- "NZ",
3390
- "SG",
3391
- "HK",
3392
- "AE"
3393
- ],
3394
- description: "ISO 3166-1 Alpha-2 country code"
3395
- },
3396
- postalCode: {
3397
- type: "string",
3398
- description: "Postal or ZIP code"
3399
- }
3400
- },
3401
- required: [
3402
- "street",
3403
- "city",
3404
- "state",
3405
- "country",
3406
- "postalCode"
3407
- ],
3408
- additionalProperties: false,
3409
- description: "Address of the user that owns the bank account"
3410
- },
3411
- email: {
3412
- type: "string",
3413
- description: "Email address of the user that owns the bank account"
3414
- },
3415
- phoneNumber: {
3416
- type: "string",
3417
- description: "Phone number of the user"
3418
- },
3419
- providerCountry: {
3420
- type: "string",
3421
- enum: [
3422
- "US",
3423
- "GB",
3424
- "CA",
3425
- "AU",
3426
- "DE",
3427
- "FR",
3428
- "IT",
3429
- "ES",
3430
- "NL",
3431
- "BE",
3432
- "AT",
3433
- "CH",
3434
- "SE",
3435
- "NO",
3436
- "DK",
3437
- "FI",
3438
- "IE",
3439
- "PT",
3440
- "PL",
3441
- "CZ",
3442
- "GR",
3443
- "JP",
3444
- "KR",
3445
- "CN",
3446
- "IN",
3447
- "BR",
3448
- "MX",
3449
- "AR",
3450
- "ZA",
3451
- "NZ",
3452
- "SG",
3453
- "HK",
3454
- "AE"
3455
- ],
3456
- description: "ISO 3166-1 Alpha-2 country code where the bank is located"
3457
- },
3458
- providerName: {
3459
- type: "string",
3460
- description: "Name of the bank"
3461
- },
3462
- givenName: {
3463
- type: "string",
3464
- description: "First/given name of the account holder"
3465
- },
3466
- familyName: {
3467
- type: "string",
3468
- description: "Last/family name of the account holder"
3469
- }
3470
- },
3471
- required: [
3472
- "type",
3473
- "accountNumber",
3474
- "routingNumber",
3475
- "address",
3476
- "email",
3477
- "phoneNumber",
3478
- "providerCountry",
3479
- "providerName",
3480
- "givenName",
3481
- "familyName"
3482
- ],
3483
- additionalProperties: false
3484
- }
3485
- },
3486
- $schema: "http://json-schema.org/draft-07/schema#"
3487
- }
3488
- },
3489
- {
3490
- name: "virtual-account_create",
3491
- description: "Create a virtual account and start KYC verification",
3492
- inputSchema: {
3493
- $ref: "#/definitions/virtual-account_create_input",
3494
- definitions: {
3495
- "virtual-account_create_input": {
3496
- type: "object",
3497
- properties: {},
3498
- additionalProperties: false
3499
- }
3500
- },
3501
- $schema: "http://json-schema.org/draft-07/schema#"
3502
- }
3503
- },
3504
- {
3505
- name: "virtual-account_delete",
3506
- description: "Delete your virtual account",
3507
- inputSchema: {
3508
- $ref: "#/definitions/virtual-account_delete_input",
3509
- definitions: {
3510
- "virtual-account_delete_input": {
3511
- type: "object",
3512
- properties: {},
3513
- additionalProperties: false
3514
- }
3515
- },
3516
- $schema: "http://json-schema.org/draft-07/schema#"
3517
- }
3518
- },
3519
- {
3520
- name: "virtual-account_identification_create",
3521
- description: "Create a KYC verification link to complete identity verification",
3522
- inputSchema: {
3523
- $ref: "#/definitions/virtual-account_identification_create_input",
3524
- definitions: {
3525
- "virtual-account_identification_create_input": {
3526
- type: "object",
3527
- properties: {},
3528
- additionalProperties: false
3529
- }
3530
- },
3531
- $schema: "http://json-schema.org/draft-07/schema#"
3532
- }
3533
- },
3534
- {
3535
- name: "virtual-account_identification_list",
3536
- description: "List all KYC identifications",
3537
- inputSchema: {
3538
- $ref: "#/definitions/virtual-account_identification_list_input",
3539
- definitions: {
3540
- "virtual-account_identification_list_input": {
3541
- type: "object",
3542
- properties: {},
3543
- additionalProperties: false
3544
- }
3545
- },
3546
- $schema: "http://json-schema.org/draft-07/schema#"
3547
- }
3548
- },
3549
- {
3550
- name: "virtual-account_identification_retrieve",
3551
- description: "Get the status of a KYC identification",
3552
- inputSchema: {
3553
- $ref: "#/definitions/virtual-account_identification_retrieve_input",
3554
- definitions: {
3555
- "virtual-account_identification_retrieve_input": {
3556
- type: "object",
3557
- properties: {},
3558
- additionalProperties: false
3559
- }
3560
- },
3561
- $schema: "http://json-schema.org/draft-07/schema#"
3562
- }
3563
- },
3564
- {
3565
- name: "virtual-account_offramp_create",
3566
- description: "Create an offramp to convert stablecoin to fiat",
3567
- inputSchema: {
3568
- $ref: "#/definitions/virtual-account_offramp_create_input",
3569
- definitions: {
3570
- "virtual-account_offramp_create_input": {
3571
- type: "object",
3572
- properties: {
3573
- name: {
3574
- type: "string",
3575
- description: "The name of the offramp"
3576
- },
3577
- fiat: {
3578
- type: "string",
3579
- enum: [
3580
- "USD",
3581
- "EUR"
3582
- ],
3583
- description: "The fiat currency to convert to"
3584
- },
3585
- stablecoin: {
3586
- type: "string",
3587
- enum: [
3588
- "USDC",
3589
- "USDT",
3590
- "EURC"
3591
- ],
3592
- description: "The stablecoin token to convert from"
3593
- }
3594
- },
3595
- required: [
3596
- "name",
3597
- "fiat",
3598
- "stablecoin"
3599
- ],
3600
- additionalProperties: false
3601
- }
3602
- },
3603
- $schema: "http://json-schema.org/draft-07/schema#"
3604
- }
3605
- },
3606
- {
3607
- name: "virtual-account_offramp_delete",
3608
- description: "Cancel an offramp",
3609
- inputSchema: {
3610
- $ref: "#/definitions/virtual-account_offramp_delete_input",
3611
- definitions: {
3612
- "virtual-account_offramp_delete_input": {
3613
- type: "object",
3614
- properties: {
3615
- offrampId: {
3616
- type: "string",
3617
- format: "uuid",
3618
- description: "The ID of the offramp to cancel"
3619
- }
3620
- },
3621
- required: [
3622
- "offrampId"
3623
- ],
3624
- additionalProperties: false
3625
- }
3626
- },
3627
- $schema: "http://json-schema.org/draft-07/schema#"
3628
- }
3629
- },
3630
- {
3631
- name: "virtual-account_offramp_initiate",
3632
- description: "Build an unsigned transaction to send stablecoin to an offramp deposit address",
3633
- inputSchema: {
3634
- $ref: "#/definitions/virtual-account_offramp_initiate_input",
3635
- definitions: {
3636
- "virtual-account_offramp_initiate_input": {
3637
- type: "object",
3638
- properties: {
3639
- wallet: {
3640
- type: "string",
3641
- description: "The wallet address to send from"
3642
- },
3643
- offrampId: {
3644
- type: "string",
3645
- description: "The ID of the offramp to initiate"
3646
- },
3647
- amount: {
3648
- type: "number",
3649
- minimum: 0,
3650
- description: "The amount of stablecoin to send (in human-readable units, e.g., 100.5)"
3651
- }
3652
- },
3653
- required: [
3654
- "wallet",
3655
- "offrampId",
3656
- "amount"
3657
- ],
3658
- additionalProperties: false
3659
- }
3660
- },
3661
- $schema: "http://json-schema.org/draft-07/schema#"
3662
- }
3663
- },
3664
- {
3665
- name: "virtual-account_offramp_list",
3666
- description: "List all offramps",
3667
- inputSchema: {
3668
- $ref: "#/definitions/virtual-account_offramp_list_input",
3669
- definitions: {
3670
- "virtual-account_offramp_list_input": {
3671
- type: "object",
3672
- properties: {},
3673
- additionalProperties: false
3674
- }
3675
- },
3676
- $schema: "http://json-schema.org/draft-07/schema#"
3677
- }
3678
- },
3679
- {
3680
- name: "virtual-account_offramp_retrieve",
3681
- description: "Get offramp details",
3682
- inputSchema: {
3683
- $ref: "#/definitions/virtual-account_offramp_retrieve_input",
3684
- definitions: {
3685
- "virtual-account_offramp_retrieve_input": {
3686
- type: "object",
3687
- properties: {
3688
- offrampId: {
3689
- type: "string",
3690
- format: "uuid",
3691
- description: "The ID of the offramp to retrieve"
3692
- }
3693
- },
3694
- required: [
3695
- "offrampId"
3696
- ],
3697
- additionalProperties: false
3698
- }
3699
- },
3700
- $schema: "http://json-schema.org/draft-07/schema#"
3701
- }
3702
- },
3703
- {
3704
- name: "virtual-account_onramp_create",
3705
- description: "Create an onramp to convert fiat to stablecoin",
3706
- inputSchema: {
3707
- $ref: "#/definitions/virtual-account_onramp_create_input",
3708
- definitions: {
3709
- "virtual-account_onramp_create_input": {
3710
- type: "object",
3711
- properties: {
3712
- name: {
3713
- type: "string",
3714
- description: "The name of the onramp"
3715
- },
3716
- fiat: {
3717
- type: "string",
3718
- enum: [
3719
- "USD",
3720
- "EUR"
3721
- ],
3722
- description: "The fiat currency to convert from"
3723
- },
3724
- stablecoin: {
3725
- type: "string",
3726
- enum: [
3727
- "USDC",
3728
- "USDT",
3729
- "EURC"
3730
- ],
3731
- description: "The stablecoin token to convert to"
3732
- }
3733
- },
3734
- required: [
3735
- "name",
3736
- "fiat",
3737
- "stablecoin"
3738
- ],
3739
- additionalProperties: false
3740
- }
3741
- },
3742
- $schema: "http://json-schema.org/draft-07/schema#"
3743
- }
3744
- },
3745
- {
3746
- name: "virtual-account_onramp_delete",
3747
- description: "Cancel an onramp",
3748
- inputSchema: {
3749
- $ref: "#/definitions/virtual-account_onramp_delete_input",
3750
- definitions: {
3751
- "virtual-account_onramp_delete_input": {
3752
- type: "object",
3753
- properties: {
3754
- onrampId: {
3755
- type: "string",
3756
- format: "uuid",
3757
- description: "The ID of the onramp to cancel"
3758
- }
3759
- },
3760
- required: [
3761
- "onrampId"
3762
- ],
3763
- additionalProperties: false
3764
- }
3765
- },
3766
- $schema: "http://json-schema.org/draft-07/schema#"
3767
- }
3768
- },
3769
- {
3770
- name: "virtual-account_onramp_list",
3771
- description: "List all onramps",
3772
- inputSchema: {
3773
- $ref: "#/definitions/virtual-account_onramp_list_input",
3774
- definitions: {
3775
- "virtual-account_onramp_list_input": {
3776
- type: "object",
3777
- properties: {
3778
- status: {
3779
- type: "string",
3780
- enum: [
3781
- "Created",
3782
- "Authorized",
3783
- "DepositAccountAdded",
3784
- "Approved",
3785
- "Rejected",
3786
- "Cancelled"
3787
- ],
3788
- description: "Status of the onramps to get"
3789
- }
3790
- },
3791
- required: [
3792
- "status"
3793
- ],
3794
- additionalProperties: false
3795
- }
3796
- },
3797
- $schema: "http://json-schema.org/draft-07/schema#"
3798
- }
3799
- },
3800
- {
3801
- name: "virtual-account_onramp_payment_create",
3802
- description: "Create an open banking payment link for an onramp",
3803
- inputSchema: {
3804
- $ref: "#/definitions/virtual-account_onramp_payment_create_input",
3805
- definitions: {
3806
- "virtual-account_onramp_payment_create_input": {
3807
- type: "object",
3808
- properties: {
3809
- onrampId: {
3810
- type: "string",
3811
- format: "uuid",
3812
- description: "The ID of the onramp"
3813
- },
3814
- amount: {
3815
- type: "string",
3816
- description: "The amount to pay"
3817
- },
3818
- fiat: {
3819
- type: "string",
3820
- enum: [
3821
- "USD",
3822
- "EUR"
3823
- ],
3824
- description: "The fiat currency (USD or EUR)"
3825
- }
3826
- },
3827
- required: [
3828
- "onrampId",
3829
- "amount",
3830
- "fiat"
3831
- ],
3832
- additionalProperties: false
3833
- }
3834
- },
3835
- $schema: "http://json-schema.org/draft-07/schema#"
3836
- }
3837
- },
3838
- {
3839
- name: "virtual-account_onramp_payment_retrieve",
3840
- description: "Get the status of an open banking payment",
3841
- inputSchema: {
3842
- $ref: "#/definitions/virtual-account_onramp_payment_retrieve_input",
3843
- definitions: {
3844
- "virtual-account_onramp_payment_retrieve_input": {
3845
- type: "object",
3846
- properties: {
3847
- onrampId: {
3848
- type: "string",
3849
- format: "uuid",
3850
- description: "The ID of the onramp this payment belongs to"
3851
- },
3852
- paymentId: {
3853
- type: "string",
3854
- format: "uuid",
3855
- description: "The ID of the payment to retrieve"
3856
- }
3857
- },
3858
- required: [
3859
- "onrampId",
3860
- "paymentId"
3861
- ],
3862
- additionalProperties: false
3863
- }
3864
- },
3865
- $schema: "http://json-schema.org/draft-07/schema#"
3866
- }
3867
- },
3868
- {
3869
- name: "virtual-account_onramp_retrieve",
3870
- description: "Get onramp details and banking info",
3871
- inputSchema: {
3872
- $ref: "#/definitions/virtual-account_onramp_retrieve_input",
3873
- definitions: {
3874
- "virtual-account_onramp_retrieve_input": {
3875
- type: "object",
3876
- properties: {
3877
- onrampId: {
3878
- type: "string",
3879
- format: "uuid",
3880
- description: "The ID of the onramp to retrieve"
3881
- }
3882
- },
3883
- required: [
3884
- "onrampId"
3885
- ],
3886
- additionalProperties: false
3887
- }
3888
- },
3889
- $schema: "http://json-schema.org/draft-07/schema#"
3890
- }
3891
- },
3892
- {
3893
- name: "virtual-account_retrieve",
3894
- description: "Get your virtual account status",
3895
- inputSchema: {
3896
- $ref: "#/definitions/virtual-account_retrieve_input",
3897
- definitions: {
3898
- "virtual-account_retrieve_input": {
3899
- type: "object",
3900
- properties: {},
3901
- additionalProperties: false
3902
- }
3903
- },
3904
- $schema: "http://json-schema.org/draft-07/schema#"
3905
- }
3906
- },
3907
- {
3908
- name: "virtual-account_signing_create",
3909
- description: "Sign a required document for your virtual account",
3910
- inputSchema: {
3911
- $ref: "#/definitions/virtual-account_signing_create_input",
3912
- definitions: {
3913
- "virtual-account_signing_create_input": {
3914
- type: "object",
3915
- properties: {
3916
- contentId: {
3917
- type: "string",
3918
- description: "The unique ID of the content to sign"
3919
- }
3920
- },
3921
- required: [
3922
- "contentId"
3923
- ],
3924
- additionalProperties: false
3925
- }
3926
- },
3927
- $schema: "http://json-schema.org/draft-07/schema#"
3928
- }
3929
- },
3930
- {
3931
- name: "virtual-account_signing_list",
3932
- description: "List all signed documents",
3933
- inputSchema: {
3934
- $ref: "#/definitions/virtual-account_signing_list_input",
3935
- definitions: {
3936
- "virtual-account_signing_list_input": {
3937
- type: "object",
3938
- properties: {},
3939
- additionalProperties: false
3940
- }
3941
- },
3942
- $schema: "http://json-schema.org/draft-07/schema#"
3943
- }
3944
- },
3945
- {
3946
- name: "virtual-account_signing_required_list",
3947
- description: "List documents that require your signature",
3948
- inputSchema: {
3949
- $ref: "#/definitions/virtual-account_signing_required_list_input",
3950
- definitions: {
3951
- "virtual-account_signing_required_list_input": {
3952
- type: "object",
3953
- properties: {},
3954
- additionalProperties: false
3955
- }
3956
- },
3957
- $schema: "http://json-schema.org/draft-07/schema#"
3958
- }
3959
- },
3960
- {
3961
- name: "virtual-account_transaction_list",
3962
- description: "List virtual account transactions",
3963
- inputSchema: {
3964
- $ref: "#/definitions/virtual-account_transaction_list_input",
3965
- definitions: {
3966
- "virtual-account_transaction_list_input": {
3967
- type: "object",
3968
- properties: {},
3969
- additionalProperties: false
3970
- }
3971
- },
3972
- $schema: "http://json-schema.org/draft-07/schema#"
3973
- }
3974
- },
3975
- {
3976
- name: "virtual-account_wallet_list",
3977
- description: "List registered wallets",
3978
- inputSchema: {
3979
- $ref: "#/definitions/virtual-account_wallet_list_input",
3980
- definitions: {
3981
- "virtual-account_wallet_list_input": {
3982
- type: "object",
3983
- properties: {},
3984
- additionalProperties: false
3985
- }
3986
- },
3987
- $schema: "http://json-schema.org/draft-07/schema#"
3988
- }
3989
- },
3990
- {
3991
- name: "virtual-account_wallet_register",
3992
- description: "Register a wallet using a signed verification message",
3993
- inputSchema: {
3994
- $ref: "#/definitions/virtual-account_wallet_register_input",
3995
- definitions: {
3996
- "virtual-account_wallet_register_input": {
3997
- type: "object",
3998
- properties: {
3999
- wallet: {
4000
- type: "string",
4001
- description: "The wallet address to register"
4002
- },
4003
- message: {
4004
- type: "string",
4005
- description: "The verification message (from virtual-account_wallet_registration-message_create)"
4006
- },
4007
- signature: {
4008
- type: "string",
4009
- description: "Base58-encoded signature of the message"
4010
- }
4011
- },
4012
- required: [
4013
- "wallet",
4014
- "message",
4015
- "signature"
4016
- ],
4017
- additionalProperties: false
4018
- }
4019
- },
4020
- $schema: "http://json-schema.org/draft-07/schema#"
4021
- }
4022
- },
4023
- {
4024
- name: "virtual-account_wallet_registration-message_create",
4025
- description: "Create the verification message to register a wallet",
4026
- inputSchema: {
4027
- $ref: "#/definitions/virtual-account_wallet_registration-message_create_input",
4028
- definitions: {
4029
- "virtual-account_wallet_registration-message_create_input": {
4030
- type: "object",
4031
- properties: {
4032
- wallet: {
4033
- type: "string",
4034
- description: "The wallet address to register"
4035
- }
4036
- },
4037
- required: [
4038
- "wallet"
4039
- ],
4040
- additionalProperties: false
4041
- }
4042
- },
4043
- $schema: "http://json-schema.org/draft-07/schema#"
4044
- }
4045
- }
4046
- ];
4047
-
4048
- // src/tools/wallet/create/tool.ts
4049
- import { Keypair } from "@solana/web3.js";
4050
- import bs58 from "bs58";
4051
-
4052
- // src/tools/shared.ts
4053
- var defineToolSchema = (config) => config;
4054
- var createTool = (schema, handler) => ({
4055
- schema,
4056
- handler: async (params) => {
4057
- const parsedInput = schema.input.parse(params);
4058
- const result = await handler(parsedInput);
4059
- return schema.output.parse(result);
4060
- }
4061
- });
4062
-
4063
- // src/tools/wallet/server.ts
4064
- import {
4065
- readFileSync as readFileSync3,
4066
- readdirSync,
4067
- writeFileSync as writeFileSync3,
4068
- mkdirSync as mkdirSync3,
4069
- existsSync as existsSync2,
4070
- renameSync as renameSync2
4071
- } from "fs";
4072
- import { join as join3 } from "path";
4073
- import { homedir as homedir3 } from "os";
4074
- import { randomBytes as randomBytes2 } from "crypto";
4075
- var CONFIG_DIR2 = join3(homedir3(), ".config", "moonpay");
4076
- var WALLETS_DIR = join3(CONFIG_DIR2, "wallets");
4077
- function ensureWalletsDir() {
4078
- mkdirSync3(WALLETS_DIR, { recursive: true, mode: 448 });
4079
- }
4080
- function getWalletPath(name) {
4081
- return join3(WALLETS_DIR, `${name}.json`);
4082
- }
4083
- function getWalletsDir() {
4084
- return WALLETS_DIR;
4085
- }
4086
- function saveWallet(wallet) {
4087
- ensureWalletsDir();
4088
- const filePath = getWalletPath(wallet.name);
4089
- if (existsSync2(filePath)) {
4090
- throw new Error(`Wallet "${wallet.name}" already exists`);
4091
- }
4092
- const tmpPath = join3(
4093
- WALLETS_DIR,
4094
- `.${wallet.name}.${randomBytes2(4).toString("hex")}.tmp`
4095
- );
4096
- writeFileSync3(tmpPath, JSON.stringify(wallet, null, 2), { mode: 384 });
4097
- renameSync2(tmpPath, filePath);
4098
- }
4099
- function loadWallet(nameOrAddress) {
4100
- ensureWalletsDir();
4101
- const files = readdirSync(WALLETS_DIR).filter((f) => f.endsWith(".json"));
4102
- for (const file of files) {
4103
- const wallet = JSON.parse(
4104
- readFileSync3(join3(WALLETS_DIR, file), "utf-8")
4105
- );
4106
- if (wallet.name === nameOrAddress || wallet.address === nameOrAddress)
4107
- return wallet;
4108
- }
4109
- throw new Error(`Wallet "${nameOrAddress}" not found`);
4110
- }
4111
-
4112
- // src/tools/wallet/create/schema.ts
4113
- import { z } from "zod";
4114
- var walletCreateSchema = defineToolSchema({
4115
- name: "wallet_create",
4116
- description: "Generate a new Solana keypair and store it locally",
4117
- input: z.object({
4118
- name: z.string().describe("Wallet name")
4119
- }),
4120
- output: z.object({
4121
- name: z.string().describe("Wallet name"),
4122
- address: z.string().describe("Solana wallet address (base58)")
4123
- })
4124
- });
4125
-
4126
- // src/tools/wallet/create/tool.ts
4127
- var walletCreate = createTool(walletCreateSchema, async (params) => {
4128
- const keypair = Keypair.generate();
4129
- const wallet = {
4130
- name: params.name,
4131
- address: keypair.publicKey.toBase58(),
4132
- secretKey: bs58.encode(keypair.secretKey),
4133
- chain: "solana",
4134
- createdAt: (/* @__PURE__ */ new Date()).toISOString()
4135
- };
4136
- saveWallet(wallet);
4137
- return { name: wallet.name, address: wallet.address };
4138
- });
4139
-
4140
- // src/tools/wallet/import/tool.ts
4141
- import { Keypair as Keypair2 } from "@solana/web3.js";
4142
- import bs582 from "bs58";
4143
- import { createInterface } from "readline";
4144
-
4145
- // src/tools/wallet/import/schema.ts
4146
- import { z as z2 } from "zod";
4147
- var walletImportSchema = defineToolSchema({
4148
- name: "wallet_import",
4149
- description: "Import a Solana wallet from a base58 private key",
4150
- input: z2.object({
4151
- name: z2.string().describe("Wallet name"),
4152
- key: z2.string().nullable().describe("Base58-encoded private key (prompted interactively if not provided)")
4153
- }),
4154
- output: z2.object({
4155
- name: z2.string().describe("Wallet name"),
4156
- address: z2.string().describe("Solana wallet address (base58)")
4157
- })
4158
- });
4159
-
4160
- // src/tools/wallet/import/tool.ts
4161
- async function promptSecret(prompt) {
4162
- const rl = createInterface({ input: process.stdin, output: process.stderr });
4163
- return new Promise((resolve) => {
4164
- rl.question(prompt, (answer) => {
4165
- rl.close();
4166
- resolve(answer.trim());
4167
- });
4168
- });
4169
- }
4170
- var walletImport = createTool(walletImportSchema, async (params) => {
4171
- const secretKeyBase58 = params.key !== null ? params.key : await promptSecret("Enter private key (base58): ");
4172
- let keypair;
4173
- try {
4174
- const secretKeyBytes = bs582.decode(secretKeyBase58);
4175
- keypair = Keypair2.fromSecretKey(secretKeyBytes);
4176
- } catch {
4177
- throw new Error(
4178
- "Invalid private key. Expected a base58-encoded Solana secret key."
4179
- );
4180
- }
4181
- const wallet = {
4182
- name: params.name,
4183
- address: keypair.publicKey.toBase58(),
4184
- secretKey: secretKeyBase58,
4185
- chain: "solana",
4186
- createdAt: (/* @__PURE__ */ new Date()).toISOString()
4187
- };
4188
- saveWallet(wallet);
4189
- return { name: wallet.name, address: wallet.address };
4190
- });
4191
-
4192
- // src/tools/wallet/list/tool.ts
4193
- import { readFileSync as readFileSync4, readdirSync as readdirSync2 } from "fs";
4194
- import { join as join4 } from "path";
4195
-
4196
- // src/tools/wallet/list/schema.ts
4197
- import { z as z4 } from "zod";
4198
-
4199
- // src/tools/wallet/models.ts
4200
- import { z as z3 } from "zod";
4201
- var walletSchema = z3.object({
4202
- name: z3.string(),
4203
- address: z3.string(),
4204
- secretKey: z3.string(),
4205
- chain: z3.literal("solana"),
4206
- createdAt: z3.string()
4207
- });
4208
- var walletInfoSchema = walletSchema.omit({ secretKey: true });
4209
-
4210
- // src/tools/wallet/list/schema.ts
4211
- var walletListSchema = defineToolSchema({
4212
- name: "wallet_list",
4213
- description: "List all local wallets",
4214
- input: z4.object({}),
4215
- output: z4.array(walletInfoSchema)
4216
- });
4217
-
4218
- // src/tools/wallet/list/tool.ts
4219
- var walletList = createTool(walletListSchema, async () => {
4220
- ensureWalletsDir();
4221
- const dir = getWalletsDir();
4222
- const files = readdirSync2(dir).filter(
4223
- (f) => f.endsWith(".json") && !f.startsWith(".")
4224
- );
4225
- return files.map((f) => {
4226
- const wallet = JSON.parse(readFileSync4(join4(dir, f), "utf-8"));
4227
- return {
4228
- name: wallet.name,
4229
- address: wallet.address,
4230
- chain: wallet.chain,
4231
- createdAt: wallet.createdAt
4232
- };
4233
- });
4234
- });
4235
-
4236
- // src/tools/wallet/retrieve/schema.ts
4237
- import { z as z5 } from "zod";
4238
- var walletRetrieveSchema = defineToolSchema({
4239
- name: "wallet_retrieve",
4240
- description: "Get details of a specific wallet",
4241
- input: z5.object({
4242
- wallet: z5.string().describe("Wallet name or address")
4243
- }),
4244
- output: walletInfoSchema
4245
- });
4246
-
4247
- // src/tools/wallet/retrieve/tool.ts
4248
- var walletRetrieve = createTool(
4249
- walletRetrieveSchema,
4250
- async (params) => {
4251
- const wallet = loadWallet(params.wallet);
4252
- return {
4253
- name: wallet.name,
4254
- address: wallet.address,
4255
- chain: wallet.chain,
4256
- createdAt: wallet.createdAt
4257
- };
4258
- }
4259
- );
4260
-
4261
- // src/tools/wallet/delete/tool.ts
4262
- import { unlinkSync as unlinkSync2 } from "fs";
4263
-
4264
- // src/tools/wallet/delete/schema.ts
4265
- import { z as z6 } from "zod";
4266
- var walletDeleteSchema = defineToolSchema({
4267
- name: "wallet_delete",
4268
- description: "Permanently delete a local wallet. This removes the private key file and cannot be undone.",
4269
- input: z6.object({
4270
- wallet: z6.string().describe("Name or address of the wallet to delete"),
4271
- confirm: z6.boolean().describe("Must be true to confirm deletion")
4272
- }),
4273
- output: z6.object({
4274
- name: z6.string().describe("Name of the deleted wallet"),
4275
- deleted: z6.literal(true)
4276
- })
4277
- });
4278
-
4279
- // src/tools/wallet/delete/tool.ts
4280
- var walletDelete = createTool(walletDeleteSchema, async (params) => {
4281
- if (!params.confirm) {
4282
- throw new Error(
4283
- "Deletion not confirmed. Pass --confirm to permanently delete this wallet."
4284
- );
4285
- }
4286
- const wallet = await walletRetrieve.handler({ wallet: params.wallet });
4287
- unlinkSync2(getWalletPath(wallet.name));
4288
- return { name: wallet.name, deleted: true };
4289
- });
4290
-
4291
- // src/tools/transaction/sign/tool.ts
4292
- import { Keypair as Keypair3, VersionedTransaction } from "@solana/web3.js";
4293
- import bs583 from "bs58";
4294
-
4295
- // src/tools/transaction/sign/schema.ts
4296
- import { z as z7 } from "zod";
4297
- var transactionSignSchema = defineToolSchema({
4298
- name: "transaction_sign",
4299
- description: "Sign a base64-encoded Solana transaction with a local wallet",
4300
- input: z7.object({
4301
- wallet: z7.string().describe("Wallet address"),
4302
- transaction: z7.string().describe("Base64-encoded unsigned transaction")
4303
- }),
4304
- output: z7.object({
4305
- transaction: z7.string().describe("Base64-encoded signed transaction")
4306
- })
4307
- });
4308
-
4309
- // src/tools/transaction/sign/tool.ts
4310
- var transactionSign = createTool(
4311
- transactionSignSchema,
4312
- async (params) => {
4313
- const storedWallet = loadWallet(params.wallet);
4314
- const txBytes = Buffer.from(params.transaction.trim(), "base64");
4315
- const tx = VersionedTransaction.deserialize(txBytes);
4316
- const secretKeyBytes = bs583.decode(storedWallet.secretKey);
4317
- const keypair = Keypair3.fromSecretKey(secretKeyBytes);
4318
- tx.sign([keypair]);
4319
- return {
4320
- transaction: Buffer.from(tx.serialize()).toString("base64")
4321
- };
4322
- }
4323
- );
4324
-
4325
- // src/tools/message/sign/tool.ts
4326
- var import_tweetnacl = __toESM(require_nacl_fast(), 1);
4327
- import { Keypair as Keypair4 } from "@solana/web3.js";
4328
- import bs584 from "bs58";
4329
-
4330
- // src/tools/message/sign/schema.ts
4331
- import { z as z8 } from "zod";
4332
- var messageSignSchema = defineToolSchema({
4333
- name: "message_sign",
4334
- description: "Sign a message with a local wallet. Produces a base58-encoded ed25519 signature compatible with Solana's signMessage.",
4335
- input: z8.object({
4336
- wallet: z8.string().describe("Wallet address to sign with"),
4337
- message: z8.string().describe("Message text to sign")
4338
- }),
4339
- output: z8.object({
4340
- signature: z8.string().describe("Base58-encoded ed25519 signature")
4341
- })
4342
- });
4343
-
4344
- // src/tools/message/sign/tool.ts
4345
- var messageSign = createTool(messageSignSchema, async (params) => {
4346
- const storedWallet = loadWallet(params.wallet);
4347
- const secretKeyBytes = bs584.decode(storedWallet.secretKey);
4348
- const keypair = Keypair4.fromSecretKey(secretKeyBytes);
4349
- const messageBytes = Buffer.from(params.message, "utf8");
4350
- const signatureBytes = import_tweetnacl.default.sign.detached(messageBytes, keypair.secretKey);
4351
- return { signature: bs584.encode(signatureBytes) };
4352
- });
4353
-
4354
161
  // src/tools/skill/server.ts
4355
- import { readdirSync as readdirSync3, readFileSync as readFileSync5, existsSync as existsSync3, mkdirSync as mkdirSync4, cpSync } from "fs";
4356
- import { join as join5, dirname } from "path";
4357
- import { homedir as homedir4 } from "os";
162
+ import { readdirSync, readFileSync as readFileSync2, existsSync, mkdirSync as mkdirSync2, cpSync } from "fs";
163
+ import { join as join2, dirname } from "path";
164
+ import { homedir as homedir2 } from "os";
4358
165
  import { fileURLToPath } from "url";
4359
166
  function getSkillsDir() {
4360
167
  const __filename = fileURLToPath(import.meta.url);
4361
168
  const distDir = dirname(__filename);
4362
- return join5(distDir, "..", "skills");
169
+ return join2(distDir, "..", "skills");
4363
170
  }
4364
171
  function getClaudeSkillsDir() {
4365
- return join5(homedir4(), ".claude", "skills");
172
+ return join2(homedir2(), ".claude", "skills");
4366
173
  }
4367
174
  function listBundledSkills() {
4368
175
  const dir = getSkillsDir();
4369
- if (!existsSync3(dir)) return [];
4370
- return readdirSync3(dir, { withFileTypes: true }).filter((e) => e.isDirectory() && e.name.startsWith("moonpay-")).map((e) => {
4371
- const md = readFileSync5(join5(dir, e.name, "SKILL.md"), "utf-8");
176
+ if (!existsSync(dir)) return [];
177
+ return readdirSync(dir, { withFileTypes: true }).filter((e) => e.isDirectory() && e.name.startsWith("moonpay-")).map((e) => {
178
+ const md = readFileSync2(join2(dir, e.name, "SKILL.md"), "utf-8");
4372
179
  const descMatch = md.match(/^description:\s*(.+)$/m);
4373
180
  return {
4374
181
  name: e.name,
@@ -4377,37 +184,37 @@ function listBundledSkills() {
4377
184
  }).sort((a, b) => a.name.localeCompare(b.name));
4378
185
  }
4379
186
  function readSkill(name) {
4380
- const skillPath = join5(getSkillsDir(), name, "SKILL.md");
4381
- if (!existsSync3(skillPath)) {
187
+ const skillPath = join2(getSkillsDir(), name, "SKILL.md");
188
+ if (!existsSync(skillPath)) {
4382
189
  throw new Error(`Skill "${name}" not found. Run \`mp skill list\` to see available skills.`);
4383
190
  }
4384
- return readFileSync5(skillPath, "utf-8");
191
+ return readFileSync2(skillPath, "utf-8");
4385
192
  }
4386
193
  function installSkills(force) {
4387
194
  const srcDir = getSkillsDir();
4388
195
  const destDir = getClaudeSkillsDir();
4389
196
  const skills = listBundledSkills();
4390
- mkdirSync4(destDir, { recursive: true });
197
+ mkdirSync2(destDir, { recursive: true });
4391
198
  return skills.map((s) => {
4392
- const dest = join5(destDir, s.name);
4393
- if (existsSync3(dest) && !force) {
199
+ const dest = join2(destDir, s.name);
200
+ if (existsSync(dest) && !force) {
4394
201
  return { name: s.name, installed: false };
4395
202
  }
4396
- cpSync(join5(srcDir, s.name), dest, { recursive: true, force: true });
203
+ cpSync(join2(srcDir, s.name), dest, { recursive: true, force: true });
4397
204
  return { name: s.name, installed: true };
4398
205
  });
4399
206
  }
4400
207
 
4401
208
  // src/tools/skill/list/schema.ts
4402
- import { z as z9 } from "zod";
209
+ import { z } from "zod";
4403
210
  var skillListSchema = defineToolSchema({
4404
211
  name: "skill_list",
4405
212
  description: "List available AI skills for Claude Code and other agents",
4406
- input: z9.object({}),
4407
- output: z9.array(
4408
- z9.object({
4409
- name: z9.string(),
4410
- description: z9.string()
213
+ input: z.object({}),
214
+ output: z.array(
215
+ z.object({
216
+ name: z.string(),
217
+ description: z.string()
4411
218
  })
4412
219
  )
4413
220
  });
@@ -4418,16 +225,16 @@ var skillList = createTool(skillListSchema, async () => {
4418
225
  });
4419
226
 
4420
227
  // src/tools/skill/retrieve/schema.ts
4421
- import { z as z10 } from "zod";
228
+ import { z as z2 } from "zod";
4422
229
  var skillRetrieveSchema = defineToolSchema({
4423
230
  name: "skill_retrieve",
4424
231
  description: "Get the full instructions for a specific skill",
4425
- input: z10.object({
4426
- name: z10.string().describe("Skill name (e.g. moonpay-swap-tokens)")
232
+ input: z2.object({
233
+ name: z2.string().describe("Skill name (e.g. moonpay-swap-tokens)")
4427
234
  }),
4428
- output: z10.object({
4429
- name: z10.string(),
4430
- content: z10.string()
235
+ output: z2.object({
236
+ name: z2.string(),
237
+ content: z2.string()
4431
238
  })
4432
239
  });
4433
240
 
@@ -4440,17 +247,17 @@ var skillRetrieve = createTool(skillRetrieveSchema, async (params) => {
4440
247
  });
4441
248
 
4442
249
  // src/tools/skill/install/schema.ts
4443
- import { z as z11 } from "zod";
250
+ import { z as z3 } from "zod";
4444
251
  var skillInstallSchema = defineToolSchema({
4445
252
  name: "skill_install",
4446
253
  description: "Install AI skills to ~/.claude/skills/ for Claude Code",
4447
- input: z11.object({
4448
- force: z11.boolean().describe("Overwrite existing skills")
254
+ input: z3.object({
255
+ force: z3.boolean().describe("Overwrite existing skills")
4449
256
  }),
4450
- output: z11.array(
4451
- z11.object({
4452
- name: z11.string(),
4453
- installed: z11.boolean()
257
+ output: z3.array(
258
+ z3.object({
259
+ name: z3.string(),
260
+ installed: z3.boolean()
4454
261
  })
4455
262
  )
4456
263
  });
@@ -4476,7 +283,6 @@ var LOCAL_TOOLS = [
4476
283
  var require2 = createRequire(import.meta.url);
4477
284
  var { version } = require2("../package.json");
4478
285
  var getUpdateNotice = startVersionCheck(version);
4479
- var DEFAULT_BASE_URL = "https://agents.moonpay.com";
4480
286
  var program = new Command();
4481
287
  program.name("moonpay").description("MoonPay CLI \u2014 non-custodial crypto tools\n\n Run `mp skill install` to install AI skills for Claude Code.").version(version).option("-f, --format <type>", "Output format: json, compact, or table", "json");
4482
288
  function getFormat() {
@@ -4491,11 +297,6 @@ function printUpdateNotice() {
4491
297
  const notice = getUpdateNotice();
4492
298
  if (notice) process.stderr.write(notice);
4493
299
  }
4494
- function resolveBaseUrl() {
4495
- const config = getConfig();
4496
- const creds = getCredentials();
4497
- return config?.baseUrl ?? creds?.baseUrl ?? DEFAULT_BASE_URL;
4498
- }
4499
300
  program.command("login").description("Log in to MoonPay via OAuth (required for authenticated tools)").action(async () => {
4500
301
  const config = getConfigOrDefault();
4501
302
  try {
@@ -4510,6 +311,10 @@ program.command("logout").description("Log out and clear stored credentials").ac
4510
311
  clearCredentials();
4511
312
  console.log("Logged out.");
4512
313
  });
314
+ program.command("mcp").description("Start MCP server over stdio (for Claude Desktop, Claude Code, etc.)").action(async () => {
315
+ const { startMcpServer } = await import("./mcp-R3YBYDRT.js");
316
+ await startMcpServer();
317
+ });
4513
318
  function getOrCreateGroup(parent, segments) {
4514
319
  let current = parent;
4515
320
  for (const segment of segments) {