├── .eslintrc.json
├── .gitignore
├── .prettierrc
├── .vscode
├── extensions.json
└── settings.json
├── LICENSE
├── README.md
├── components
├── AddBike.tsx
├── BikeSelector.tsx
├── Button.tsx
├── Callouts.tsx
├── Connect.tsx
├── Controls.tsx
├── Footer.tsx
├── Form.tsx
├── Input.tsx
├── Login.tsx
├── Modal.tsx
├── SoundBoard.tsx
├── Spacing.tsx
├── Unsupported.tsx
├── bellsound
│ ├── BellSoundWalkthrough.tsx
│ ├── ConvertStep.tsx
│ ├── SelectFileStep.tsx
│ ├── UploadStep.tsx
│ └── WalkthroughButton.tsx
├── icons
│ ├── MaterialCloseRounded.tsx
│ ├── MaterialMoreVert.tsx
│ └── props.tsx
└── sharing
│ ├── CurrentShares.tsx
│ ├── ShareBike.tsx
│ └── ShareDurationSlider.tsx
├── custom.d.ts
├── lib
├── aes.js
├── api.ts
├── bike.ts
└── queue.ts
├── next-env.d.ts
├── next.config.js
├── package-lock.json
├── package.json
├── pages
├── _app.tsx
├── controls-test.tsx
├── donate.tsx
└── index.tsx
├── public
├── app.webmanifest
├── compressed_logos
│ ├── logo_full.png
│ ├── logo_full.webp
│ ├── logo_full_128.png
│ ├── logo_full_128.webp
│ ├── logo_full_256.png
│ ├── logo_full_256.webp
│ ├── logo_full_512.png
│ ├── logo_full_512.webp
│ ├── logo_full_64.png
│ └── logo_full_64.webp
├── logo_full.png
├── screenshot_dark.png
└── screenshot_light.png
├── styles
└── globals.css
└── tsconfig.json
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "next/core-web-vitals"
3 | }
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # next.js
12 | /.next/
13 | /out/
14 |
15 | # production
16 | /build
17 |
18 | # misc
19 | .DS_Store
20 | *.pem
21 |
22 | # debug
23 | npm-debug.log*
24 | yarn-debug.log*
25 | yarn-error.log*
26 | .pnpm-debug.log*
27 |
28 | # local env files
29 | .env*.local
30 |
31 | # vercel
32 | .vercel
33 |
34 | # typescript
35 | *.tsbuildinfo
36 |
37 | # Ignore auto generated service worker files
38 | public/sw.js
39 | public/sw.js.map
40 | public/workbox-*
41 |
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "semi": false,
3 | "useTabs": true
4 | }
5 |
--------------------------------------------------------------------------------
/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | "recommendations": [
3 | "divlo.vscode-styled-jsx-languageserver",
4 | "Divlo.vscode-styled-jsx-syntax"
5 | ]
6 | }
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "[typescriptreact]": {
3 | "editor.defaultFormatter": "esbenp.prettier-vscode"
4 | },
5 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 2.1, February 1999
3 |
4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc.
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | [This is the first released version of the Lesser GPL. It also counts
10 | as the successor of the GNU Library Public License, version 2, hence
11 | the version number 2.1.]
12 |
13 | Preamble
14 |
15 | The licenses for most software are designed to take away your
16 | freedom to share and change it. By contrast, the GNU General Public
17 | Licenses are intended to guarantee your freedom to share and change
18 | free software--to make sure the software is free for all its users.
19 |
20 | This license, the Lesser General Public License, applies to some
21 | specially designated software packages--typically libraries--of the
22 | Free Software Foundation and other authors who decide to use it. You
23 | can use it too, but we suggest you first think carefully about whether
24 | this license or the ordinary General Public License is the better
25 | strategy to use in any particular case, based on the explanations below.
26 |
27 | When we speak of free software, we are referring to freedom of use,
28 | not price. Our General Public Licenses are designed to make sure that
29 | you have the freedom to distribute copies of free software (and charge
30 | for this service if you wish); that you receive source code or can get
31 | it if you want it; that you can change the software and use pieces of
32 | it in new free programs; and that you are informed that you can do
33 | these things.
34 |
35 | To protect your rights, we need to make restrictions that forbid
36 | distributors to deny you these rights or to ask you to surrender these
37 | rights. These restrictions translate to certain responsibilities for
38 | you if you distribute copies of the library or if you modify it.
39 |
40 | For example, if you distribute copies of the library, whether gratis
41 | or for a fee, you must give the recipients all the rights that we gave
42 | you. You must make sure that they, too, receive or can get the source
43 | code. If you link other code with the library, you must provide
44 | complete object files to the recipients, so that they can relink them
45 | with the library after making changes to the library and recompiling
46 | it. And you must show them these terms so they know their rights.
47 |
48 | We protect your rights with a two-step method: (1) we copyright the
49 | library, and (2) we offer you this license, which gives you legal
50 | permission to copy, distribute and/or modify the library.
51 |
52 | To protect each distributor, we want to make it very clear that
53 | there is no warranty for the free library. Also, if the library is
54 | modified by someone else and passed on, the recipients should know
55 | that what they have is not the original version, so that the original
56 | author's reputation will not be affected by problems that might be
57 | introduced by others.
58 |
59 | Finally, software patents pose a constant threat to the existence of
60 | any free program. We wish to make sure that a company cannot
61 | effectively restrict the users of a free program by obtaining a
62 | restrictive license from a patent holder. Therefore, we insist that
63 | any patent license obtained for a version of the library must be
64 | consistent with the full freedom of use specified in this license.
65 |
66 | Most GNU software, including some libraries, is covered by the
67 | ordinary GNU General Public License. This license, the GNU Lesser
68 | General Public License, applies to certain designated libraries, and
69 | is quite different from the ordinary General Public License. We use
70 | this license for certain libraries in order to permit linking those
71 | libraries into non-free programs.
72 |
73 | When a program is linked with a library, whether statically or using
74 | a shared library, the combination of the two is legally speaking a
75 | combined work, a derivative of the original library. The ordinary
76 | General Public License therefore permits such linking only if the
77 | entire combination fits its criteria of freedom. The Lesser General
78 | Public License permits more lax criteria for linking other code with
79 | the library.
80 |
81 | We call this license the "Lesser" General Public License because it
82 | does Less to protect the user's freedom than the ordinary General
83 | Public License. It also provides other free software developers Less
84 | of an advantage over competing non-free programs. These disadvantages
85 | are the reason we use the ordinary General Public License for many
86 | libraries. However, the Lesser license provides advantages in certain
87 | special circumstances.
88 |
89 | For example, on rare occasions, there may be a special need to
90 | encourage the widest possible use of a certain library, so that it becomes
91 | a de-facto standard. To achieve this, non-free programs must be
92 | allowed to use the library. A more frequent case is that a free
93 | library does the same job as widely used non-free libraries. In this
94 | case, there is little to gain by limiting the free library to free
95 | software only, so we use the Lesser General Public License.
96 |
97 | In other cases, permission to use a particular library in non-free
98 | programs enables a greater number of people to use a large body of
99 | free software. For example, permission to use the GNU C Library in
100 | non-free programs enables many more people to use the whole GNU
101 | operating system, as well as its variant, the GNU/Linux operating
102 | system.
103 |
104 | Although the Lesser General Public License is Less protective of the
105 | users' freedom, it does ensure that the user of a program that is
106 | linked with the Library has the freedom and the wherewithal to run
107 | that program using a modified version of the Library.
108 |
109 | The precise terms and conditions for copying, distribution and
110 | modification follow. Pay close attention to the difference between a
111 | "work based on the library" and a "work that uses the library". The
112 | former contains code derived from the library, whereas the latter must
113 | be combined with the library in order to run.
114 |
115 | GNU LESSER GENERAL PUBLIC LICENSE
116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
117 |
118 | 0. This License Agreement applies to any software library or other
119 | program which contains a notice placed by the copyright holder or
120 | other authorized party saying it may be distributed under the terms of
121 | this Lesser General Public License (also called "this License").
122 | Each licensee is addressed as "you".
123 |
124 | A "library" means a collection of software functions and/or data
125 | prepared so as to be conveniently linked with application programs
126 | (which use some of those functions and data) to form executables.
127 |
128 | The "Library", below, refers to any such software library or work
129 | which has been distributed under these terms. A "work based on the
130 | Library" means either the Library or any derivative work under
131 | copyright law: that is to say, a work containing the Library or a
132 | portion of it, either verbatim or with modifications and/or translated
133 | straightforwardly into another language. (Hereinafter, translation is
134 | included without limitation in the term "modification".)
135 |
136 | "Source code" for a work means the preferred form of the work for
137 | making modifications to it. For a library, complete source code means
138 | all the source code for all modules it contains, plus any associated
139 | interface definition files, plus the scripts used to control compilation
140 | and installation of the library.
141 |
142 | Activities other than copying, distribution and modification are not
143 | covered by this License; they are outside its scope. The act of
144 | running a program using the Library is not restricted, and output from
145 | such a program is covered only if its contents constitute a work based
146 | on the Library (independent of the use of the Library in a tool for
147 | writing it). Whether that is true depends on what the Library does
148 | and what the program that uses the Library does.
149 |
150 | 1. You may copy and distribute verbatim copies of the Library's
151 | complete source code as you receive it, in any medium, provided that
152 | you conspicuously and appropriately publish on each copy an
153 | appropriate copyright notice and disclaimer of warranty; keep intact
154 | all the notices that refer to this License and to the absence of any
155 | warranty; and distribute a copy of this License along with the
156 | Library.
157 |
158 | You may charge a fee for the physical act of transferring a copy,
159 | and you may at your option offer warranty protection in exchange for a
160 | fee.
161 |
162 | 2. You may modify your copy or copies of the Library or any portion
163 | of it, thus forming a work based on the Library, and copy and
164 | distribute such modifications or work under the terms of Section 1
165 | above, provided that you also meet all of these conditions:
166 |
167 | a) The modified work must itself be a software library.
168 |
169 | b) You must cause the files modified to carry prominent notices
170 | stating that you changed the files and the date of any change.
171 |
172 | c) You must cause the whole of the work to be licensed at no
173 | charge to all third parties under the terms of this License.
174 |
175 | d) If a facility in the modified Library refers to a function or a
176 | table of data to be supplied by an application program that uses
177 | the facility, other than as an argument passed when the facility
178 | is invoked, then you must make a good faith effort to ensure that,
179 | in the event an application does not supply such function or
180 | table, the facility still operates, and performs whatever part of
181 | its purpose remains meaningful.
182 |
183 | (For example, a function in a library to compute square roots has
184 | a purpose that is entirely well-defined independent of the
185 | application. Therefore, Subsection 2d requires that any
186 | application-supplied function or table used by this function must
187 | be optional: if the application does not supply it, the square
188 | root function must still compute square roots.)
189 |
190 | These requirements apply to the modified work as a whole. If
191 | identifiable sections of that work are not derived from the Library,
192 | and can be reasonably considered independent and separate works in
193 | themselves, then this License, and its terms, do not apply to those
194 | sections when you distribute them as separate works. But when you
195 | distribute the same sections as part of a whole which is a work based
196 | on the Library, the distribution of the whole must be on the terms of
197 | this License, whose permissions for other licensees extend to the
198 | entire whole, and thus to each and every part regardless of who wrote
199 | it.
200 |
201 | Thus, it is not the intent of this section to claim rights or contest
202 | your rights to work written entirely by you; rather, the intent is to
203 | exercise the right to control the distribution of derivative or
204 | collective works based on the Library.
205 |
206 | In addition, mere aggregation of another work not based on the Library
207 | with the Library (or with a work based on the Library) on a volume of
208 | a storage or distribution medium does not bring the other work under
209 | the scope of this License.
210 |
211 | 3. You may opt to apply the terms of the ordinary GNU General Public
212 | License instead of this License to a given copy of the Library. To do
213 | this, you must alter all the notices that refer to this License, so
214 | that they refer to the ordinary GNU General Public License, version 2,
215 | instead of to this License. (If a newer version than version 2 of the
216 | ordinary GNU General Public License has appeared, then you can specify
217 | that version instead if you wish.) Do not make any other change in
218 | these notices.
219 |
220 | Once this change is made in a given copy, it is irreversible for
221 | that copy, so the ordinary GNU General Public License applies to all
222 | subsequent copies and derivative works made from that copy.
223 |
224 | This option is useful when you wish to copy part of the code of
225 | the Library into a program that is not a library.
226 |
227 | 4. You may copy and distribute the Library (or a portion or
228 | derivative of it, under Section 2) in object code or executable form
229 | under the terms of Sections 1 and 2 above provided that you accompany
230 | it with the complete corresponding machine-readable source code, which
231 | must be distributed under the terms of Sections 1 and 2 above on a
232 | medium customarily used for software interchange.
233 |
234 | If distribution of object code is made by offering access to copy
235 | from a designated place, then offering equivalent access to copy the
236 | source code from the same place satisfies the requirement to
237 | distribute the source code, even though third parties are not
238 | compelled to copy the source along with the object code.
239 |
240 | 5. A program that contains no derivative of any portion of the
241 | Library, but is designed to work with the Library by being compiled or
242 | linked with it, is called a "work that uses the Library". Such a
243 | work, in isolation, is not a derivative work of the Library, and
244 | therefore falls outside the scope of this License.
245 |
246 | However, linking a "work that uses the Library" with the Library
247 | creates an executable that is a derivative of the Library (because it
248 | contains portions of the Library), rather than a "work that uses the
249 | library". The executable is therefore covered by this License.
250 | Section 6 states terms for distribution of such executables.
251 |
252 | When a "work that uses the Library" uses material from a header file
253 | that is part of the Library, the object code for the work may be a
254 | derivative work of the Library even though the source code is not.
255 | Whether this is true is especially significant if the work can be
256 | linked without the Library, or if the work is itself a library. The
257 | threshold for this to be true is not precisely defined by law.
258 |
259 | If such an object file uses only numerical parameters, data
260 | structure layouts and accessors, and small macros and small inline
261 | functions (ten lines or less in length), then the use of the object
262 | file is unrestricted, regardless of whether it is legally a derivative
263 | work. (Executables containing this object code plus portions of the
264 | Library will still fall under Section 6.)
265 |
266 | Otherwise, if the work is a derivative of the Library, you may
267 | distribute the object code for the work under the terms of Section 6.
268 | Any executables containing that work also fall under Section 6,
269 | whether or not they are linked directly with the Library itself.
270 |
271 | 6. As an exception to the Sections above, you may also combine or
272 | link a "work that uses the Library" with the Library to produce a
273 | work containing portions of the Library, and distribute that work
274 | under terms of your choice, provided that the terms permit
275 | modification of the work for the customer's own use and reverse
276 | engineering for debugging such modifications.
277 |
278 | You must give prominent notice with each copy of the work that the
279 | Library is used in it and that the Library and its use are covered by
280 | this License. You must supply a copy of this License. If the work
281 | during execution displays copyright notices, you must include the
282 | copyright notice for the Library among them, as well as a reference
283 | directing the user to the copy of this License. Also, you must do one
284 | of these things:
285 |
286 | a) Accompany the work with the complete corresponding
287 | machine-readable source code for the Library including whatever
288 | changes were used in the work (which must be distributed under
289 | Sections 1 and 2 above); and, if the work is an executable linked
290 | with the Library, with the complete machine-readable "work that
291 | uses the Library", as object code and/or source code, so that the
292 | user can modify the Library and then relink to produce a modified
293 | executable containing the modified Library. (It is understood
294 | that the user who changes the contents of definitions files in the
295 | Library will not necessarily be able to recompile the application
296 | to use the modified definitions.)
297 |
298 | b) Use a suitable shared library mechanism for linking with the
299 | Library. A suitable mechanism is one that (1) uses at run time a
300 | copy of the library already present on the user's computer system,
301 | rather than copying library functions into the executable, and (2)
302 | will operate properly with a modified version of the library, if
303 | the user installs one, as long as the modified version is
304 | interface-compatible with the version that the work was made with.
305 |
306 | c) Accompany the work with a written offer, valid for at
307 | least three years, to give the same user the materials
308 | specified in Subsection 6a, above, for a charge no more
309 | than the cost of performing this distribution.
310 |
311 | d) If distribution of the work is made by offering access to copy
312 | from a designated place, offer equivalent access to copy the above
313 | specified materials from the same place.
314 |
315 | e) Verify that the user has already received a copy of these
316 | materials or that you have already sent this user a copy.
317 |
318 | For an executable, the required form of the "work that uses the
319 | Library" must include any data and utility programs needed for
320 | reproducing the executable from it. However, as a special exception,
321 | the materials to be distributed need not include anything that is
322 | normally distributed (in either source or binary form) with the major
323 | components (compiler, kernel, and so on) of the operating system on
324 | which the executable runs, unless that component itself accompanies
325 | the executable.
326 |
327 | It may happen that this requirement contradicts the license
328 | restrictions of other proprietary libraries that do not normally
329 | accompany the operating system. Such a contradiction means you cannot
330 | use both them and the Library together in an executable that you
331 | distribute.
332 |
333 | 7. You may place library facilities that are a work based on the
334 | Library side-by-side in a single library together with other library
335 | facilities not covered by this License, and distribute such a combined
336 | library, provided that the separate distribution of the work based on
337 | the Library and of the other library facilities is otherwise
338 | permitted, and provided that you do these two things:
339 |
340 | a) Accompany the combined library with a copy of the same work
341 | based on the Library, uncombined with any other library
342 | facilities. This must be distributed under the terms of the
343 | Sections above.
344 |
345 | b) Give prominent notice with the combined library of the fact
346 | that part of it is a work based on the Library, and explaining
347 | where to find the accompanying uncombined form of the same work.
348 |
349 | 8. You may not copy, modify, sublicense, link with, or distribute
350 | the Library except as expressly provided under this License. Any
351 | attempt otherwise to copy, modify, sublicense, link with, or
352 | distribute the Library is void, and will automatically terminate your
353 | rights under this License. However, parties who have received copies,
354 | or rights, from you under this License will not have their licenses
355 | terminated so long as such parties remain in full compliance.
356 |
357 | 9. You are not required to accept this License, since you have not
358 | signed it. However, nothing else grants you permission to modify or
359 | distribute the Library or its derivative works. These actions are
360 | prohibited by law if you do not accept this License. Therefore, by
361 | modifying or distributing the Library (or any work based on the
362 | Library), you indicate your acceptance of this License to do so, and
363 | all its terms and conditions for copying, distributing or modifying
364 | the Library or works based on it.
365 |
366 | 10. Each time you redistribute the Library (or any work based on the
367 | Library), the recipient automatically receives a license from the
368 | original licensor to copy, distribute, link with or modify the Library
369 | subject to these terms and conditions. You may not impose any further
370 | restrictions on the recipients' exercise of the rights granted herein.
371 | You are not responsible for enforcing compliance by third parties with
372 | this License.
373 |
374 | 11. If, as a consequence of a court judgment or allegation of patent
375 | infringement or for any other reason (not limited to patent issues),
376 | conditions are imposed on you (whether by court order, agreement or
377 | otherwise) that contradict the conditions of this License, they do not
378 | excuse you from the conditions of this License. If you cannot
379 | distribute so as to satisfy simultaneously your obligations under this
380 | License and any other pertinent obligations, then as a consequence you
381 | may not distribute the Library at all. For example, if a patent
382 | license would not permit royalty-free redistribution of the Library by
383 | all those who receive copies directly or indirectly through you, then
384 | the only way you could satisfy both it and this License would be to
385 | refrain entirely from distribution of the Library.
386 |
387 | If any portion of this section is held invalid or unenforceable under any
388 | particular circumstance, the balance of the section is intended to apply,
389 | and the section as a whole is intended to apply in other circumstances.
390 |
391 | It is not the purpose of this section to induce you to infringe any
392 | patents or other property right claims or to contest validity of any
393 | such claims; this section has the sole purpose of protecting the
394 | integrity of the free software distribution system which is
395 | implemented by public license practices. Many people have made
396 | generous contributions to the wide range of software distributed
397 | through that system in reliance on consistent application of that
398 | system; it is up to the author/donor to decide if he or she is willing
399 | to distribute software through any other system and a licensee cannot
400 | impose that choice.
401 |
402 | This section is intended to make thoroughly clear what is believed to
403 | be a consequence of the rest of this License.
404 |
405 | 12. If the distribution and/or use of the Library is restricted in
406 | certain countries either by patents or by copyrighted interfaces, the
407 | original copyright holder who places the Library under this License may add
408 | an explicit geographical distribution limitation excluding those countries,
409 | so that distribution is permitted only in or among countries not thus
410 | excluded. In such case, this License incorporates the limitation as if
411 | written in the body of this License.
412 |
413 | 13. The Free Software Foundation may publish revised and/or new
414 | versions of the Lesser General Public License from time to time.
415 | Such new versions will be similar in spirit to the present version,
416 | but may differ in detail to address new problems or concerns.
417 |
418 | Each version is given a distinguishing version number. If the Library
419 | specifies a version number of this License which applies to it and
420 | "any later version", you have the option of following the terms and
421 | conditions either of that version or of any later version published by
422 | the Free Software Foundation. If the Library does not specify a
423 | license version number, you may choose any version ever published by
424 | the Free Software Foundation.
425 |
426 | 14. If you wish to incorporate parts of the Library into other free
427 | programs whose distribution conditions are incompatible with these,
428 | write to the author to ask for permission. For software which is
429 | copyrighted by the Free Software Foundation, write to the Free
430 | Software Foundation; we sometimes make exceptions for this. Our
431 | decision will be guided by the two goals of preserving the free status
432 | of all derivatives of our free software and of promoting the sharing
433 | and reuse of software generally.
434 |
435 | NO WARRANTY
436 |
437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
446 |
447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
456 | DAMAGES.
457 |
458 | END OF TERMS AND CONDITIONS
459 |
460 | How to Apply These Terms to Your New Libraries
461 |
462 | If you develop a new library, and you want it to be of the greatest
463 | possible use to the public, we recommend making it free software that
464 | everyone can redistribute and change. You can do so by permitting
465 | redistribution under these terms (or, alternatively, under the terms of the
466 | ordinary General Public License).
467 |
468 | To apply these terms, attach the following notices to the library. It is
469 | safest to attach them to the start of each source file to most effectively
470 | convey the exclusion of warranty; and each file should have at least the
471 | "copyright" line and a pointer to where the full notice is found.
472 |
473 |
474 | Copyright (C)
475 |
476 | This library is free software; you can redistribute it and/or
477 | modify it under the terms of the GNU Lesser General Public
478 | License as published by the Free Software Foundation; either
479 | version 2.1 of the License, or (at your option) any later version.
480 |
481 | This library is distributed in the hope that it will be useful,
482 | but WITHOUT ANY WARRANTY; without even the implied warranty of
483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
484 | Lesser General Public License for more details.
485 |
486 | You should have received a copy of the GNU Lesser General Public
487 | License along with this library; if not, write to the Free Software
488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
489 | USA
490 |
491 | Also add information on how to contact you by electronic and paper mail.
492 |
493 | You should also get your employer (if you work as a programmer) or your
494 | school, if any, to sign a "copyright disclaimer" for the library, if
495 | necessary. Here is a sample; alter the names:
496 |
497 | Yoyodyne, Inc., hereby disclaims all copyright interest in the
498 | library `Frob' (a library for tweaking knobs) written by James Random
499 | Hacker.
500 |
501 | , 1 April 1990
502 | Ty Coon, President of Vice
503 |
504 | That's all there is to it!
505 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## [Mooovy](https://mooovy.app/)
2 |
3 | A web app for changing the speed limit of your VanMoof S3 and X3.
4 |
5 | **NOT** an offical VanMoof service/product!
6 |
7 | 
8 |
9 | - **[Web app: mooovy.app](https://mooovy.app/)**
10 | - [Discord server](https://discord.gg/gQFC2n7Tc9)
11 |
12 | ### Current features
13 |
14 | - Change your speed limit to JP (24 km/h), EU (25 km/h), US (32 km/h) or 😎 (37 km/h).
15 | - Set your power level, this also unlocks a new power level 5.
16 | - A sound board with the following sounds:
17 |
18 | | Short | 🔘 Click | 🧨 Error | 👍 Pling | 🤔 Cling clong | 🔔 Bell | 🔔 Normal bike bell | 🎉 Bell Tada | 😚 Whistle | 🚢 BOAT | ⚡️ Wuup | 🫤 Success but error |
19 | | ----- | ------------------- | -------- | ---------------- | -------------- | ------------- | ------------------- | -------------------- | ---------- | ------- | -------- | ------------------- |
20 | | Long | 🔋 Charding noise.. | 🚨 Alarm | 🚨 Alarm stage 2 | 🔋 Charging.. | 🆕 Updating.. | 🎉 Update complete | 💥 Make wired noises |
21 |
22 | - Share your bike to someone using their email.
23 | - Show a list of people you are currently sharing your bike with and a button to stop sharing.
24 | - Set your bell tone (Bell, Submarine, Sonar, Party & Foghorn)
25 | - Upload your own custom bell (will replace the Foghorn/Ping bell)
26 |
27 | ### Want to help?
28 |
29 | Here are some things you can do to help!
30 |
31 | - [Confirm v1.8.**2** still works](https://github.com/mjarkk/vanmoof-web-controller/issues/22) (v1.8.**1** has been confirmed to work already!)
32 | - Help reverse engineer how the refresh token works for the VanMoof API
33 | - Hackin support for older/newer bikes
34 | - Help with finding out what is send from / to the bike over bluetooth and having a good workflow for doing this
35 |
36 | ### Development
37 |
38 | This project is build using [NextJS (a React framework)](https://nextjs.org) and deployed on [vercel](https://vercel.com)
39 |
40 | **Install**
41 |
42 | ```sh
43 | npm i
44 | ```
45 |
46 | **Run**
47 |
48 | ```sh
49 | npm run dev
50 | ```
51 |
52 | **Compress logos**
53 |
54 | ```sh
55 | cd public
56 | npx @squoosh/cli --max-optimizer-rounds 10 --quant '{numColors:8}' --output-dir compressed_logos --webp auto --oxipng auto logo_full.png
57 | npx @squoosh/cli --max-optimizer-rounds 10 --resize '{width:512,height:512}' --quant '{numColors:8}' --output-dir compressed_logos --webp auto --oxipng auto --suffix _512 logo_full.png
58 | npx @squoosh/cli --max-optimizer-rounds 10 --resize '{width:256,height:256}' --quant '{numColors:8}' --output-dir compressed_logos --webp auto --oxipng auto --suffix _256 logo_full.png
59 | npx @squoosh/cli --max-optimizer-rounds 10 --resize '{width:128,height:128}' --quant '{numColors:8}' --output-dir compressed_logos --webp auto --oxipng auto --suffix _128 logo_full.png
60 | npx @squoosh/cli --max-optimizer-rounds 10 --resize '{width:64,height:64}' --quant '{numColors:8}' --output-dir compressed_logos --webp auto --oxipng auto --suffix _64 logo_full.png
61 | ```
62 |
--------------------------------------------------------------------------------
/components/AddBike.tsx:
--------------------------------------------------------------------------------
1 | import { FormEvent, useMemo, useState } from "react"
2 | import { Button } from "./Button"
3 | import { Input } from "./Input"
4 | import { BikeCredentials } from "../lib/bike"
5 | import { Modal, ModalConfirmOrDecline } from "./Modal"
6 |
7 | interface AddBikeProps {
8 | updated: (credentials: Array) => void
9 | }
10 |
11 | export function AddBike({ updated }: AddBikeProps) {
12 | const [name, setName] = useState("")
13 | const [mac, setMac] = useState("")
14 | const [encryptionKey, setEncryptionKey] = useState("")
15 | const [userKeyId, setUserKeyId] = useState("1")
16 | const [showAddBike, setShowAddBike] = useState(false)
17 |
18 | const invalidMac = useMemo(() => {
19 | if (mac.length === 0) {
20 | return true
21 | }
22 |
23 | const hexParts = mac.split(":")
24 |
25 | if (hexParts.length < 4) {
26 | return true
27 | }
28 | if (
29 | hexParts.some((part) => part.length !== 2 || !/^[0-9A-F]{2}$/.test(part))
30 | ) {
31 | return true
32 | }
33 |
34 | return false
35 | }, [mac])
36 |
37 | const invalidUserKeyId = useMemo(() => {
38 | if (userKeyId.length === 0) {
39 | return true
40 | }
41 |
42 | const parsed = Number(userKeyId)
43 | if (!Number.isFinite(parsed)) {
44 | return true
45 | }
46 | if (!Number.isInteger(parsed)) {
47 | return true
48 | }
49 | if (parsed < 0 || parsed > 256) {
50 | return true
51 | }
52 |
53 | return false
54 | }, [userKeyId])
55 |
56 | const canSubmit =
57 | !invalidMac &&
58 | encryptionKey.length > 0 &&
59 | name.length > 0 &&
60 | !invalidUserKeyId
61 |
62 | const addCreds = (e: FormEvent) => {
63 | e.preventDefault()
64 |
65 | if (!canSubmit) {
66 | return
67 | }
68 |
69 | let bikes = []
70 | try {
71 | const rawBikeCredentials = localStorage.getItem("vm-bike-credentials")
72 | bikes = JSON.parse(rawBikeCredentials ?? "[]")
73 | if (!Array.isArray(bikes)) bikes = []
74 | } catch (e) {
75 | // Ignore
76 | }
77 |
78 | const newBike: BikeCredentials = {
79 | mac,
80 | encryptionKey,
81 | userKeyId: Number(userKeyId),
82 | name,
83 | modelColor: null,
84 | links: null,
85 | }
86 | bikes.push(newBike)
87 |
88 | setName("")
89 | setMac("")
90 | setEncryptionKey("")
91 | setShowAddBike(false)
92 |
93 | localStorage.setItem("vm-bike-credentials", JSON.stringify(bikes))
94 | updated(bikes)
95 | }
96 |
97 | return (
98 |
99 |
setShowAddBike(false)}
102 | title="Add a new bike"
103 | >
104 |
150 |
151 |
152 | setShowAddBike(true)}>Add a bike
153 |
154 |
177 |
178 | )
179 | }
180 |
--------------------------------------------------------------------------------
/components/BikeSelector.tsx:
--------------------------------------------------------------------------------
1 | import { MouseEventHandler, useState } from 'react'
2 | import { BikeCredentials } from '../lib/bike'
3 | import { Button } from './Button'
4 | import { MaterialMoreVert } from './icons/MaterialMoreVert'
5 | import { Modal, ModalConfirmOrDecline } from './Modal'
6 |
7 | interface BikeSelectorProps {
8 | options: Array
9 | onSelect: (option: BikeCredentials, idx: number) => void
10 | onDelete: (idx: number) => void
11 | }
12 |
13 | export function BikeSelector({ options, onSelect, onDelete }: BikeSelectorProps) {
14 | return (
15 |
16 |
Select a bike to connect with
17 |
18 | {options.map((bike, idx) =>
19 |
onSelect(bike, idx)}
23 | onDelete={() => onDelete(idx)}
24 | />
25 | )}
26 | {options.length === 0 && No bikes found
}
27 |
28 |
49 |
50 | )
51 | }
52 |
53 | export interface BikeProps {
54 | bike: BikeCredentials
55 | onSelect: () => void
56 | onDelete: () => void
57 | }
58 |
59 | function Bike({ bike, onSelect, onDelete }: BikeProps) {
60 | const [showOptions, setShowOptions] = useState(false)
61 |
62 | const clickOptions: MouseEventHandler = (e) => {
63 | e.preventDefault()
64 | e.stopPropagation()
65 | setShowOptions(true)
66 | }
67 |
68 | const onDeleteProxy = () => {
69 | setShowOptions(false)
70 | onDelete()
71 | }
72 |
73 | return <>
74 | onSelect()}
77 | >
78 | {bike.links ?
79 |
83 | : undefined}
84 |
85 |
86 |
{bike.name}
87 | {bike.ownerName &&
{bike.ownerName}
}
88 |
89 | {bike.id &&
90 |
id {bike.id}
91 | }
92 |
mac {bike.mac}
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
139 |
140 | setShowOptions(false)} title={`Bike ${bike.name} options`}>
141 |
142 |
143 | >
144 | }
145 |
146 | interface BikeOptionsProps {
147 | onDelete: () => void
148 | }
149 |
150 | function BikeOptions({ onDelete }: BikeOptionsProps) {
151 | const [showDelete, setShowDelete] = useState(false)
152 |
153 | return
154 | setShowDelete(true)}>Delete bike
155 |
156 | setShowDelete(false)} title='Delete bike'>
157 | Are you sure?
158 | setShowDelete(false)}
160 | onConfirm={() => {
161 | onDelete()
162 | setShowDelete(false)
163 | }}
164 | confirmText="Yes"
165 | />
166 |
167 |
172 |
173 | }
--------------------------------------------------------------------------------
/components/Button.tsx:
--------------------------------------------------------------------------------
1 | import type { ReactNode, CSSProperties, MouseEventHandler } from "react"
2 |
3 | interface ButtonProps {
4 | children?: ReactNode
5 | onClick?: MouseEventHandler
6 | disabled?: boolean
7 | positive?: boolean
8 | secondary?: boolean
9 | style?: CSSProperties
10 | type?: 'submit' | 'reset' | 'button'
11 | }
12 |
13 | export function Button({ children, onClick, disabled, positive, secondary, style, type }: ButtonProps) {
14 | const classNames = [
15 | positive ? 'postive' : undefined,
16 | secondary ? 'secondary' : undefined,
17 | ]
18 |
19 | return
26 | {children}
27 |
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/components/Callouts.tsx:
--------------------------------------------------------------------------------
1 | import type { ReactNode } from "react"
2 |
3 | export enum CalloutKind {
4 | Warning,
5 | Error,
6 | }
7 |
8 | interface CalloutProps {
9 | children?: ReactNode
10 | kind: CalloutKind
11 | }
12 |
13 | export function Callout({ children, kind }: CalloutProps) {
14 | const [icon, name] = kind == CalloutKind.Warning
15 | ? ['⚠️', 'warning']
16 | : ['🧨', 'error']
17 |
18 | return (
19 |
20 |
21 | {children}
22 |
23 |
38 |
39 | )
40 | }
41 |
--------------------------------------------------------------------------------
/components/Connect.tsx:
--------------------------------------------------------------------------------
1 | import { useState, useEffect } from 'react'
2 | import type { Bike, BikeCredentials } from '../lib/bike'
3 | import { Button } from './Button'
4 | import { FormError, FormHint } from './Form'
5 | import { P } from './Spacing'
6 | import { BikeSelector } from './BikeSelector'
7 | import { AddBike } from './AddBike'
8 |
9 | interface BluetoothConnectArgs {
10 | bikeCredentials: Array
11 | updateBikeCredentials: (credentials: Array) => void
12 | backToLogin: () => void
13 | setBikeInstance: (bike: Bike) => void,
14 | }
15 |
16 | export default function BluetoothConnect({ bikeCredentials, updateBikeCredentials, setBikeInstance, backToLogin }: BluetoothConnectArgs) {
17 | const [loading, setLoading] = useState(false)
18 | const [error, setError] = useState(undefined)
19 | const [showWakeupMessage, setShowWakeupMessage] = useState(false)
20 |
21 | const clickConnect = async (credentials: BikeCredentials) => {
22 | let reachedAuth = false
23 | try {
24 | setLoading(true)
25 | setError(undefined)
26 |
27 | // Start pre-loading the bike controls
28 | const controlsPannelPreload = import('./Controls')
29 |
30 | const { connectToBike } = await import('../lib/bike')
31 | const bike = await connectToBike(credentials)
32 | reachedAuth = true
33 | await bike.authenticate()
34 |
35 | await controlsPannelPreload
36 |
37 | setBikeInstance(bike)
38 | } catch (e) {
39 | const eStr = `${e}`
40 | // eStr = 2 if you cancled the bluetooth connection screen on the Bluefy browser
41 | if (eStr != '2' && !/permission|cancelled/.test(eStr)) setError(eStr)
42 | if (reachedAuth) setShowWakeupMessage(true)
43 | } finally {
44 | setLoading(false)
45 | }
46 | }
47 |
48 | const deleteBike = (idx: number) => {
49 | const newBikes = bikeCredentials.filter((_, i) => i !== idx)
50 | localStorage.setItem('vm-bike-credentials', JSON.stringify(newBikes))
51 | updateBikeCredentials(newBikes)
52 | }
53 |
54 | useEffect(() => {
55 | if (bikeCredentials.length === 1)
56 | clickConnect(bikeCredentials[0])
57 | }, [])
58 |
59 | return (
60 | <>
61 |
62 | {loading
63 | ? loading
64 | : clickConnect(credentials)}
67 | onDelete={(idx) => deleteBike(idx)}
68 | />
69 | }
70 |
71 |
72 |
73 |
74 |
75 |
79 | Back to login
80 |
81 |
82 | >
83 | )
84 | }
85 |
--------------------------------------------------------------------------------
/components/Controls.tsx:
--------------------------------------------------------------------------------
1 | import { useEffect, useState } from 'react'
2 | import { BikeContext, Bike, PowerLevel as PowerLevelEnum, SpeedLimit as SpeedLimitEnum, BellTone as BellToneEnum } from '../lib/bike'
3 | import { SoundBoard } from './SoundBoard'
4 | import { ShareBike } from './sharing/ShareBike'
5 | import { Button } from './Button'
6 | import { Api, ApiContext } from '../lib/api'
7 | import { CurrentShares } from './sharing/CurrentShares'
8 | import { compareVersions } from 'compare-versions'
9 | import BellSoundWalkthrough from "./bellsound/BellSoundWalkthrough"
10 |
11 | export interface BikeControlsArgs {
12 | bike: Bike
13 | api: Api | undefined
14 | disconnect: () => void
15 | }
16 |
17 | export default function BikeControls({ bike, api, disconnect }: BikeControlsArgs) {
18 | return (
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | {api && bike.id && <>
27 |
28 |
29 | >}
30 |
31 | Disconnect bike
32 |
33 |
34 |
35 | )
36 | }
37 |
38 | function BikeStats({ bike }: { bike: Bike }) {
39 | const [info, setInfo] = useState<{
40 | version?: string
41 | distance?: number
42 | batteryPercentage?: number
43 | }>({})
44 |
45 | const loadInfo = async () => {
46 | setInfo({
47 | version: await bike.bikeFirmwareVersion(),
48 | distance: await bike.bikeDistance(),
49 | batteryPercentage: await bike.batteryChargingLevel()
50 | })
51 | }
52 |
53 | useEffect(() => {
54 | loadInfo()
55 | }, [])
56 |
57 | return (
58 | <>
59 | Bike info
60 |
61 |
Version: {info.version ?? 'loading..'}
62 |
Battery percentage: {info.batteryPercentage ? info.batteryPercentage + '%' : 'Loading...'}
63 |
Distance driven: {info.distance ? info.distance + ' KM' : 'loading..'}
64 |
Mac: {bike.mac}
65 |
76 |
77 | >
78 | )
79 | }
80 |
81 | interface SpeedLimitFirmwareVersionState {
82 | version: string
83 | supportsDebugSettings: boolean
84 | }
85 |
86 | function SpeedLimit({ bike }: { bike: Bike }) {
87 | const [currentSpeedLimit, setCurrentSpeedLimit] = useState(undefined)
88 | const [currentFirmwareVersion, setCurrentFirmwareVersion] = useState()
89 |
90 | const obtainSpeedLimitFromBike = () => bike.getSpeedLimit().then(setCurrentSpeedLimit)
91 | const obtainFirmwareVersionFromBike = async () => {
92 | const version = await bike.bikeFirmwareVersion()
93 | setCurrentFirmwareVersion({
94 | version,
95 | supportsDebugSettings: compareVersions('1.7.6', version) >= 0
96 | })
97 | }
98 |
99 | useEffect(() => {
100 | obtainSpeedLimitFromBike()
101 | obtainFirmwareVersionFromBike()
102 | }, [])
103 |
104 | const newLimit = async (id: SpeedLimitEnum) => {
105 | setCurrentSpeedLimit(id)
106 | setCurrentSpeedLimit(await bike.setSpeedLimit(id))
107 | }
108 |
109 | const options: Array<[string, number, SpeedLimitEnum]> = [
110 | ['🇯🇵', 24, SpeedLimitEnum.JP],
111 | ['🇪🇺', 25, SpeedLimitEnum.EU],
112 | ['🇺🇸', 32, SpeedLimitEnum.US],
113 | ]
114 | if (currentFirmwareVersion?.supportsDebugSettings) {
115 | options.push(['😎', 37, SpeedLimitEnum.NO_LIMIT])
116 | }
117 |
118 | return (
119 | <>
120 | Speed limit
121 |
122 | {options.map(([countryFlag, maxSpeed, id]) =>
123 | newLimit(id)}
129 | />
130 | )}
131 |
132 | >
133 | )
134 | }
135 |
136 | interface SetSpeedLimitButtonArgs {
137 | country: string
138 | maxSpeed: number
139 | selected: boolean
140 | select(): void
141 | }
142 |
143 | function SetSpeedLimitButton({ country, maxSpeed, selected, select }: SetSpeedLimitButtonArgs) {
144 | return (
145 |
154 | {country}
155 | {maxSpeed} km/h
156 |
157 | )
158 | }
159 |
160 | function BellTone({ bike }: { bike: Bike }) {
161 | const [currentTone, setCurrentTone] = useState(undefined)
162 | const [showBellSoundWalkthrough, setShowBellSoundWalkthrough] = useState(false)
163 |
164 | useEffect(() => { bike.getBellTone().then(setCurrentTone) }, [])
165 |
166 | var tones: Array<[string, string, BellToneEnum]> = [
167 | ['🔔', 'Bell', BellToneEnum.Bell],
168 | ['⚓️', 'Sonar', BellToneEnum.Sonar],
169 | ['🎉', 'Party', BellToneEnum.Party],
170 | ['🛳', 'Foghorn', BellToneEnum.Foghorn],
171 | ]
172 |
173 | const setNewTone = async (tone: number) => {
174 | setCurrentTone(await bike.setBellTone(tone))
175 | }
176 |
177 | const toggleBellSoundWalkthrough = () => setShowBellSoundWalkthrough(!showBellSoundWalkthrough)
178 |
179 | const bellSoundWalkthrough = showBellSoundWalkthrough ? (
180 |
183 | ) : null
184 |
185 | return (
186 | <>
187 | {bellSoundWalkthrough}
188 |
189 |
Bell tone
190 |
191 | {tones.map(([icon, label, id]) =>
192 | setNewTone(id)}
198 | />
199 | )}
200 | toggleBellSoundWalkthrough()}
205 | />
206 |
207 |
208 |
209 |
242 | >
243 | )
244 | }
245 |
246 | function PowerLevel({ bike }: { bike: Bike }) {
247 | const [currentLevel, setCurrentLevel] = useState(undefined)
248 | const [currentFirmwareVersion, setCurrentFirmwareVersion] = useState(undefined)
249 |
250 | const obtainFromBike = () => bike.getPowerLvl().then(setCurrentLevel)
251 | const obtainFirmwareVersionFromBike = () => bike.bikeFirmwareVersion().then(setCurrentFirmwareVersion)
252 | useEffect(() => {
253 | obtainFromBike()
254 | obtainFirmwareVersionFromBike()
255 | }, [])
256 |
257 | const setNewLevel = async (id: PowerLevelEnum) => {
258 | setCurrentLevel(id)
259 | setCurrentLevel(await bike.setPowerLvl(id))
260 | }
261 |
262 | const levels: Array<[string, PowerLevelEnum, string?]> = [
263 | ['0', PowerLevelEnum.Off],
264 | ['1', PowerLevelEnum.First],
265 | ['2', PowerLevelEnum.Second],
266 | ['3', PowerLevelEnum.Third],
267 | ['4', PowerLevelEnum.Fourth],
268 | ['5', PowerLevelEnum.Max, '1.7.6'],
269 | ]
270 |
271 | const getPossibleSpeedLevels = (): Array<[string, PowerLevelEnum, string?]> => {
272 | return levels.filter(([, , latestSupportedFirmwareVersion]) => {
273 | if (latestSupportedFirmwareVersion == undefined || currentFirmwareVersion == undefined) return true
274 | const firmwareTooNew: Boolean = compareVersions(latestSupportedFirmwareVersion, currentFirmwareVersion) < 1
275 | return !firmwareTooNew;
276 | })
277 | }
278 |
279 | return (
280 | <>
281 | Power level
282 |
283 | {getPossibleSpeedLevels().map(([label, id]) =>
284 | setNewLevel(id)}
289 | />
290 | )}
291 |
292 | >
293 | )
294 | }
295 |
296 | interface SetPowerLevelButtonArgs {
297 | level: string
298 | selected: boolean
299 | onSelect(): void
300 | }
301 |
302 | function SetPowerLevelButton({ level, selected, onSelect }: SetPowerLevelButtonArgs) {
303 | return (
304 |
314 | {level}
315 |
316 | )
317 | }
318 |
319 | interface SetBellToneButtonArgs {
320 | icon: string
321 | label: string
322 | selected: boolean
323 | onSelect(): void
324 | }
325 |
326 | function SetBellToneButton({ icon, label, selected, onSelect }: SetBellToneButtonArgs) {
327 | return (
328 |
337 | {icon}
338 | {label}
339 |
340 | )
341 | }
342 |
--------------------------------------------------------------------------------
/components/Footer.tsx:
--------------------------------------------------------------------------------
1 | import Link from 'next/link'
2 |
3 | interface FooterProps {
4 | noDonate?: boolean
5 | }
6 |
7 | export function Footer({ noDonate }: FooterProps) {
8 | return (
9 |
36 | )
37 | }
--------------------------------------------------------------------------------
/components/Form.tsx:
--------------------------------------------------------------------------------
1 | interface FormHintProps {
2 | hint?: string
3 | }
4 |
5 | export function FormHint({ hint }: FormHintProps) {
6 | return hint
7 | ?
8 | Hint: {hint}
9 |
17 |
18 | : <>>
19 | }
20 |
21 |
22 | interface FormErrorProps {
23 | error?: string
24 | }
25 |
26 | export function FormError({ error }: FormErrorProps) {
27 | return error
28 | ?
29 | {error}
30 |
38 |
39 | : <>>
40 | }
41 |
42 | interface FormSuccessProps {
43 | status?: boolean
44 | message?: string
45 | }
46 |
47 | export function FormSuccess({ message }: FormSuccessProps) {
48 | return message
49 | ?
50 | {message}
51 |
60 |
61 | : <>>
62 | }
63 |
--------------------------------------------------------------------------------
/components/Input.tsx:
--------------------------------------------------------------------------------
1 | export interface InputProps {
2 | id: string
3 | label?: string
4 | disabled?: boolean
5 | value?: string
6 | type?: string
7 | onChange?: (value: string) => void
8 | placeholder?: string
9 | error?: string
10 | min?: number
11 | max?: number
12 | }
13 |
14 | export function Input({ id, label, disabled, value, type, onChange, placeholder, error, min, max }: InputProps) {
15 | return
16 | {label &&
17 |
{label}
18 | }
19 |
onChange(e.target.value)) : undefined}
25 | placeholder={placeholder}
26 | min={min}
27 | max={max}
28 | />
29 | {error &&
30 |
{error}
31 | }
32 |
71 |
72 | }
--------------------------------------------------------------------------------
/components/Login.tsx:
--------------------------------------------------------------------------------
1 | import { useState, FormEvent, MouseEventHandler } from 'react'
2 | import type { BikeCredentials } from '../lib/bike'
3 | import { Api, API_KEY } from '../lib/api'
4 | import { Callout, CalloutKind } from './Callouts'
5 | import { Button } from './Button'
6 | import { FormError } from './Form'
7 | import { P } from './Spacing'
8 | import { Input } from './Input'
9 |
10 | export interface BikeAndApiCredentials {
11 | api: Api | undefined,
12 | bikes: Array,
13 | }
14 |
15 | export interface LoginArgs {
16 | setCredentials: (creds: BikeAndApiCredentials) => void
17 | }
18 |
19 | export default function Login({ setCredentials }: LoginArgs) {
20 | const [loading, setLoading] = useState(false)
21 | const [error, setError] = useState(undefined)
22 | const [login, setLogin] = useState({
23 | email: '',
24 | password: '',
25 | })
26 |
27 | const onSubmit = async (event: FormEvent) => {
28 | event.preventDefault()
29 | try {
30 | setLoading(true)
31 | let req = await fetch('/api/my_vanmoof_com/authenticate', {
32 | method: 'POST',
33 | headers: {
34 | 'Api-Key': API_KEY,
35 | 'Authorization': 'Basic ' + btoa(login.email + ':' + login.password),
36 | },
37 | })
38 |
39 | if (req.status >= 400)
40 | throw await req.text()
41 |
42 | const credentials = await req.json()
43 | const api = new Api(credentials)
44 | const bikes = await api.getBikeCredentials()
45 |
46 | api.storeCredentialsInLocalStorage()
47 | localStorage.setItem('vm-bike-credentials', JSON.stringify(bikes))
48 |
49 | setCredentials({ bikes, api })
50 | } catch (e) {
51 | setError(`${e}`)
52 | } finally {
53 | setLoading(false)
54 | }
55 | }
56 |
57 | const loginWithoutAccount: MouseEventHandler = (event) => {
58 | event.preventDefault()
59 |
60 | let bikes = []
61 | try {
62 | const storedCredentials = localStorage.getItem('vm-bike-credentials') ?? ''
63 | const prevCredentials = JSON.parse(storedCredentials)
64 | if (Array.isArray(prevCredentials)) {
65 | bikes = prevCredentials
66 | }
67 | } catch (e) {
68 | // Ignore
69 | }
70 |
71 | localStorage.setItem('vm-bike-credentials', JSON.stringify(bikes))
72 |
73 | setCredentials({ bikes, api: undefined })
74 | }
75 |
76 | return (
77 |
105 |
106 |
146 |
147 | )
148 | }
149 |
--------------------------------------------------------------------------------
/components/Modal.tsx:
--------------------------------------------------------------------------------
1 | import { createPortal } from "react-dom";
2 | import { MaterialCloseRounded } from "./icons/MaterialCloseRounded";
3 | import { ReactNode } from "react";
4 | import { Button } from "./Button";
5 |
6 | export interface ModalProps {
7 | open: boolean
8 | onClose: () => void
9 | title?: string
10 | children?: ReactNode
11 | }
12 |
13 | export function Modal({ open, onClose, title, children }: ModalProps) {
14 | if (!open) return null
15 |
16 | return createPortal(
17 |
18 |
19 |
{title}
20 |
21 |
22 |
23 |
24 |
25 | {children}
26 |
27 |
28 |
73 |
, document.querySelector('#modals')!)
74 | }
75 |
76 | export interface ModalConfirmOrDecline {
77 | onCancel: () => void
78 | onConfirm?: () => void
79 | confirmIsSubmit?: boolean
80 | disableConfirm?: boolean
81 | confirmText: string
82 | }
83 |
84 | export function ModalConfirmOrDecline({ onCancel, onConfirm, confirmIsSubmit, disableConfirm, confirmText }: ModalConfirmOrDecline) {
85 | const styleOpts = { width: 'auto', flex: '1' }
86 |
87 | return
88 | Cancel
89 | {confirmText}
90 |
98 |
99 | }
--------------------------------------------------------------------------------
/components/SoundBoard.tsx:
--------------------------------------------------------------------------------
1 | import { BikeContext } from '../lib/bike'
2 | import { Button } from './Button'
3 |
4 | export function SoundBoard() {
5 | return (
6 |
7 |
Sound board
8 |
Short
9 |
10 | 🔘 Click
11 | 🧨 Error
12 | 👍 Pling
13 | 🤔 Cling clong
14 | 🔔 Bell
15 | 🔔 Normal bike bell
16 | 🎉 Bell Tada
17 | 😚 Whistle
18 | 🚢 BOAT
19 | ⚡️ Wuup
20 | 🫤 Success but error
21 |
22 |
Long
23 |
24 | 🔋 Charding noise..
25 | 🚨 Alarm
26 | 🚨 Alarm stage 2
27 | 🔋 Charging..
28 | 🆕 Updating..
29 | 🎉 Update complete
30 | 💥 Make wired noises
31 | {/* TODO add more bell sounds */}
32 |
33 |
72 |
73 | )
74 | }
75 |
76 | function SoundBtn({ children, id }: { children: string, id: number }) {
77 | return (
78 | {bike =>
79 | bike.playSound(id)}
81 | style={{
82 | margin: 0,
83 | width: '120px',
84 | minHeight: '60px',
85 | display: 'block',
86 | }}
87 | >
88 | {children}
89 |
90 | }
91 | )
92 | }
93 |
--------------------------------------------------------------------------------
/components/Spacing.tsx:
--------------------------------------------------------------------------------
1 | import type { CSSProperties } from 'react'
2 |
3 | interface PDefaultProps {
4 | children?: React.ReactNode
5 | block?: boolean
6 | all?: number | string
7 | vertical?: number | string
8 | top?: number | string
9 | bottom?: number | string
10 | horizontal?: number | string
11 | left?: number | string
12 | right?: number | string
13 | style?: CSSProperties
14 | }
15 |
16 | function addunit(n: number | string | undefined): undefined | string {
17 | return typeof n === 'number'
18 | ? n + 'px'
19 | : n
20 | }
21 |
22 | export function P({
23 | children,
24 | block,
25 | all,
26 | vertical,
27 | top,
28 | bottom,
29 | horizontal,
30 | left,
31 | right,
32 | style,
33 | }: PDefaultProps) {
34 | const divStyle: CSSProperties = {
35 | paddingTop: addunit(top ?? vertical ?? all),
36 | paddingRight: addunit(right ?? horizontal ?? all),
37 | paddingBottom: addunit(bottom ?? vertical ?? all),
38 | paddingLeft: addunit(left ?? horizontal ?? all),
39 | display: block ? 'block' : 'inline-block',
40 | ...(style ?? {}),
41 | }
42 | return {children}
43 | }
44 |
--------------------------------------------------------------------------------
/components/Unsupported.tsx:
--------------------------------------------------------------------------------
1 | import type { CSSProperties } from 'react'
2 | import { Callout, CalloutKind } from './Callouts'
3 | import UAParser from 'ua-parser-js'
4 | import { useEffect, useState, ReactNode } from 'react'
5 |
6 | const boldA: CSSProperties = { fontWeight: 'bold' }
7 |
8 | export default function Unsupported() {
9 | const [sugestion, setSugestion] = useState('')
10 |
11 | useEffect(() => {
12 | setSugestion(getSugestion())
13 | }, [])
14 |
15 | return (
16 |
17 | This browser does not support Web Bluetooth .
18 | we need that to communicate with your bike
19 | {sugestion}
20 |
21 | )
22 | }
23 |
24 | function getSugestion(): ReactNode {
25 | const parser = new UAParser()
26 |
27 | const os = parser.getOS().name?.toLowerCase()
28 | const browser = parser.getBrowser().name?.toLowerCase()
29 |
30 | if (os == 'ios') return <>On IOS You might want to try Bluefy – Web BLE Browser >
31 | if (browser == 'chrome') return undefined
32 | if (os == 'windows') return <>You might want to use Chrome or Edge>
33 |
34 | return <>You might want to use Chrome>
35 | }
36 |
--------------------------------------------------------------------------------
/components/bellsound/BellSoundWalkthrough.tsx:
--------------------------------------------------------------------------------
1 | import { useState } from "react"
2 | import { Bike } from "../../lib/bike"
3 | import SelectFileStep from "./SelectFileStep"
4 | import UploadStep from "./UploadStep"
5 | import { Callout, CalloutKind } from "../Callouts"
6 | import WalkthroughButton from "./WalkthroughButton"
7 | import dynamic from "next/dynamic"
8 |
9 | const ConvertStep = dynamic(() => import("./ConvertStep"), { ssr: false })
10 |
11 | export type CommonProps = {
12 | onDismiss: () => void
13 | }
14 |
15 | enum WalkthroughStep {
16 | SelectFile,
17 | Convert,
18 | Upload,
19 | Done
20 | }
21 |
22 | export default function BellSoundWalkthrough({ bike, onDismiss }: CommonProps & { bike: Bike }) {
23 | const [currentStep, setCurrentStep] = useState(WalkthroughStep.SelectFile)
24 | const [selectedFile, setSelectedFile] = useState(null)
25 | const [convertedFile, setConvertedFile] = useState(null)
26 | const [error, setError] = useState(null)
27 |
28 | const goToStep = (step: WalkthroughStep) => {
29 | setError(null)
30 | setCurrentStep(step)
31 | }
32 |
33 | const onFileSelected = (file: File) => {
34 | setSelectedFile(file)
35 | goToStep(WalkthroughStep.Convert)
36 | }
37 |
38 | const onConversionCompleted = (file: Uint8Array) => {
39 | setConvertedFile(file)
40 | goToStep(WalkthroughStep.Upload)
41 | }
42 |
43 | const onConversionError = (error: string) => {
44 | goToStep(WalkthroughStep.SelectFile)
45 | setError(error)
46 | }
47 |
48 | const onUploadCompleted = () => {
49 | goToStep(WalkthroughStep.Done)
50 | }
51 |
52 | const stepComponent = (() => {
53 | switch (currentStep) {
54 | case WalkthroughStep.SelectFile:
55 | return
58 | case WalkthroughStep.Convert:
59 | return
64 | case WalkthroughStep.Upload:
65 | return
70 | case WalkthroughStep.Done:
71 | return
72 | default:
73 | return Unknown step
74 | }
75 | })()
76 |
77 | return (
78 | <>
79 |
80 |
81 |
Custom Bell Sound
82 | {error ? {error} : null}
83 | {stepComponent}
84 |
85 |
86 |
87 |
127 | >
128 | )
129 | }
130 |
131 | function DoneStep({ onDismiss }: CommonProps) {
132 | return (
133 | <>
134 | 🎉 All done! Enjoy your new bell sound.
135 | Close
136 | >
137 | )
138 | }
--------------------------------------------------------------------------------
/components/bellsound/ConvertStep.tsx:
--------------------------------------------------------------------------------
1 | "use client"
2 |
3 | import { useEffect, useRef, useState } from "react"
4 | import { CommonProps } from "./BellSoundWalkthrough"
5 | import { FFmpeg } from "@ffmpeg/ffmpeg"
6 | import { fetchFile, toBlobURL } from "@ffmpeg/util"
7 | import WalkthroughButton from "./WalkthroughButton"
8 |
9 | const globalFfmpeg = new FFmpeg()
10 |
11 | export default function ConvertStep({ onDismiss, selectedFile, onConversionCompleted, onError }: CommonProps & {
12 | selectedFile: File,
13 | onConversionCompleted: (convertedFile: Uint8Array) => void,
14 | onError: (error: string) => void,
15 | }) {
16 | const [ffmpegLog, setFfmpegLog] = useState("")
17 | const [showLog, setShowLog] = useState(false)
18 | const [converting, setConverting] = useState(false)
19 |
20 | useEffect(() => {
21 | startConversion()
22 | }, [])
23 |
24 | const log = (message: string) => {
25 | console.log(`[ConvertStep] ${message}`)
26 | setFfmpegLog((prev) => prev + message + "\n")
27 | }
28 |
29 | const loadFfmpeg = async () => {
30 | const baseURL = "https://unpkg.com/@ffmpeg/core@0.12.2/dist/umd"
31 | const ffmpeg = globalFfmpeg
32 | if (ffmpeg.loaded) return
33 |
34 | ffmpeg.on("log", ({ message }) => {
35 | log(message)
36 | })
37 |
38 | log("Loading ffmpeg...")
39 |
40 | await ffmpeg.load({
41 | coreURL: await toBlobURL(
42 | `${baseURL}/ffmpeg-core.js`,
43 | "text/javascript",
44 | ),
45 | wasmURL: await toBlobURL(
46 | `${baseURL}/ffmpeg-core.wasm`,
47 | "application/wasm",
48 | ),
49 | })
50 | }
51 |
52 | const fromHexString = (hexString: string) =>
53 | Uint8Array.from(hexString.match(/.{1,2}/g)!.map((byte: string) => parseInt(byte, 16)))
54 |
55 | const applyHeader = (file: Uint8Array): Uint8Array => {
56 | const headerStart = fromHexString("564D5F534F554E44FFFFFFFF015858585800585858585858")
57 | const fileWithHeader = new Uint8Array(headerStart.length + file.length + 4)
58 |
59 | fileWithHeader.set(headerStart, 0)
60 |
61 | const fileSize = file.byteLength
62 | fileWithHeader.set([fileSize & 0xFF, (fileSize >> 8) & 0xFF, (fileSize >> 16) & 0xFF, (fileSize >> 24) & 0xFF], headerStart.length)
63 |
64 | fileWithHeader.set(file, headerStart.length + 4)
65 | return fileWithHeader
66 | }
67 |
68 | const getBestSampleRate = (lengthInSeconds: number, currentSampleRate: number): number => {
69 | const maxFileSize = 400_000
70 |
71 | const projectedCurrentSize = currentSampleRate * 2 * lengthInSeconds
72 | if (projectedCurrentSize < maxFileSize) return currentSampleRate
73 |
74 | const possibleSampleRates = [
75 | 44100,
76 | 22050,
77 | 16000,
78 | 11025,
79 | 8000,
80 | 6000
81 | ]
82 |
83 | for (const sampleRate of possibleSampleRates) {
84 | const projectedSize = sampleRate * 2 * lengthInSeconds
85 | if (projectedSize < maxFileSize) return sampleRate
86 | }
87 |
88 | return 6000
89 | }
90 |
91 | const startConversion = async () => {
92 | if (converting) return
93 | setConverting(true)
94 |
95 | log("Choosing appropriate sample rate...")
96 | const audioContext = new AudioContext()
97 | const audioBuffer = await audioContext.decodeAudioData(await selectedFile.arrayBuffer())
98 | const duration = audioBuffer.duration
99 |
100 | const bestSampleRate = getBestSampleRate(duration, audioBuffer.sampleRate)
101 |
102 | log(`Choosing sample rate of ${bestSampleRate} Hz based on file duration of ${duration} seconds`)
103 |
104 | await loadFfmpeg()
105 | const ffmpeg = globalFfmpeg
106 |
107 | log("Loading file into memory...")
108 | await ffmpeg.writeFile(selectedFile.name, await fetchFile(selectedFile))
109 |
110 | log("Converting file...")
111 | const ffmpegArgs = `-acodec pcm_s16le -ac 1 -ar ${bestSampleRate} -map_metadata -1 -fflags +bitexact`.split(" ")
112 | const exitCode = await ffmpeg.exec(["-i", selectedFile.name, ...ffmpegArgs, "output.wav"])
113 |
114 | if (exitCode !== 0) {
115 | onError("There was an error converting your file. Please select a different one. Standard formats like MP3 or WAV work best.")
116 | setConverting(false)
117 | return
118 | }
119 |
120 | const convertedFile = await ffmpeg.readFile("output.wav", "binary") as Uint8Array
121 |
122 | log("Applying VanMoof sound header...")
123 | const fileWithHeader = applyHeader(convertedFile)
124 |
125 | if (fileWithHeader.byteLength > 400_000) {
126 | onError("The converted file is too large. Please select a shorter sound.")
127 | setConverting(false)
128 | return
129 | }
130 |
131 | onConversionCompleted(fileWithHeader)
132 |
133 | log("Done!")
134 | setConverting(false)
135 | }
136 |
137 | return (
138 | <>
139 | Selected file: {selectedFile.name}
140 | Converting to VanMoof bell format...
141 |
142 | {showLog ? : null}
143 |
144 | {!showLog ? setShowLog(true)}>Show Log : null}
145 | Cancel
146 |
147 |
159 | >
160 | )
161 | }
--------------------------------------------------------------------------------
/components/bellsound/SelectFileStep.tsx:
--------------------------------------------------------------------------------
1 | import { useRef } from "react"
2 | import { CommonProps } from "./BellSoundWalkthrough"
3 | import WalkthroughButton from "./WalkthroughButton"
4 |
5 | export default function SelectFileStep({ onDismiss, onFileSelected }: CommonProps & { onFileSelected: (file: File) => void }) {
6 | const fileInput = useRef(null)
7 |
8 | const selectFile = () => fileInput.current?.click()
9 |
10 | const fileInputChanged = async (e: React.ChangeEvent) => {
11 | if (!e.target.files || e.target.files.length === 0) return
12 | onFileSelected(e.target.files[0])
13 | }
14 |
15 | return (
16 | <>
17 | Things to know:
18 |
19 | Your custom sound will replace the Foghorn or Ping bell sound
20 | The sound should be 10 seconds or less for the best quality
21 | Keep this device close to your bike for the duration of the upload
22 |
23 |
24 |
25 | Select Sound File
26 | Cancel
27 |
28 |
37 | >
38 | )
39 | }
--------------------------------------------------------------------------------
/components/bellsound/UploadStep.tsx:
--------------------------------------------------------------------------------
1 | import { useState } from "react"
2 | import { CommonProps } from "./BellSoundWalkthrough"
3 | import WalkthroughButton from "./WalkthroughButton"
4 | import { BellTone, Bike } from "../../lib/bike"
5 |
6 | export default function UploadStep({ bike, onDismiss, convertedFile, onUploadCompleted }: CommonProps & {
7 | bike: Bike,
8 | convertedFile: Uint8Array,
9 | onUploadCompleted: () => void,
10 | }) {
11 | const [uploading, setUploading] = useState(false)
12 | const [uploadProgress, setUploadProgress] = useState(0)
13 |
14 | const startUpload = async () => {
15 | setUploading(true)
16 | setUploadProgress(0)
17 |
18 | await bike.initiateBellSoundTransfer(convertedFile)
19 |
20 | const chunkSize = 240
21 | for (let i = 0; i < convertedFile.byteLength; i += chunkSize) {
22 | const chunk = convertedFile.slice(i, i + chunkSize)
23 | await bike.sendBellSoundChunk(chunk)
24 | setUploadProgress(i / convertedFile.byteLength)
25 | }
26 |
27 | await bike.setBellTone(BellTone.Foghorn)
28 |
29 | onUploadCompleted()
30 | setUploading(false)
31 | }
32 |
33 | return (
34 | <>
35 | Your sound has been converted to the VanMoof bell sound format, and is now ready to upload.
36 | Press Upload to continue, and keep this device close to your bike.
37 | {uploading ? Uploading... {Math.round(uploadProgress * 100)}%
: null}
38 |
39 | Upload!
40 | Cancel
41 |
42 |
54 | >
55 | )
56 | }
--------------------------------------------------------------------------------
/components/bellsound/WalkthroughButton.tsx:
--------------------------------------------------------------------------------
1 | export default function WalkthroughButton({ onClick, disabled, isPrimary, children }: {
2 | onClick: () => void,
3 | disabled?: boolean,
4 | isPrimary?: boolean,
5 | children: React.ReactNode
6 | }) {
7 | return (
8 | <>
9 | {children}
13 |
14 |
32 | >
33 | )
34 | }
--------------------------------------------------------------------------------
/components/icons/MaterialCloseRounded.tsx:
--------------------------------------------------------------------------------
1 | import { IconProps } from "./props";
2 |
3 | export function MaterialCloseRounded({ size, onClick }: IconProps) {
4 | return
5 | }
--------------------------------------------------------------------------------
/components/icons/MaterialMoreVert.tsx:
--------------------------------------------------------------------------------
1 | import { IconProps } from "./props";
2 |
3 | export function MaterialMoreVert({ size, onClick }: IconProps) {
4 | return
5 | }
--------------------------------------------------------------------------------
/components/icons/props.tsx:
--------------------------------------------------------------------------------
1 | import { MouseEventHandler } from "react"
2 |
3 | export interface IconProps {
4 | size?: number
5 | onClick?: MouseEventHandler
6 | }
--------------------------------------------------------------------------------
/components/sharing/CurrentShares.tsx:
--------------------------------------------------------------------------------
1 | import type { Api, BikeShareEntry } from '../../lib/api'
2 | import { useState, FormEvent } from 'react'
3 | import { FormError } from '../Form'
4 | import { Button } from '../Button'
5 |
6 | export function CurrentShares({ bikeId, api }: { bikeId: string | number, api: Api }) {
7 | const [shares, setShares] = useState>()
8 | const [error, setError] = useState(undefined)
9 |
10 | const loadInvites = async () => {
11 | try {
12 | setError(undefined)
13 | setShares(undefined)
14 | const shares = await api.getCurrentShares(bikeId)
15 | setShares(shares)
16 | } catch (e) {
17 | setError(`${e}`)
18 | }
19 | }
20 |
21 | const removeInvite = async (event: FormEvent, guid: string) => {
22 | event.preventDefault()
23 | try {
24 | setError(undefined)
25 | setShares(undefined)
26 | await api.removeShareHolder(guid)
27 | const shares = await api.getCurrentShares(bikeId)
28 | setShares(shares)
29 | } catch (e) {
30 | setError(`${e}`)
31 | }
32 | }
33 |
34 | return (
35 |
36 |
Currently shared with
37 |
38 | {shares !== undefined
39 | ?
40 | {shares.length == 0
41 | ?
You have not shared your bike
42 | : shares.map((d, idx) =>
43 |
61 | )
62 | }
63 |
64 | :
Click on the button below to obtain your share holders list.
65 | }
66 |
67 |
68 | Get shared list
73 |
74 |
75 |
76 |
77 |
122 |
123 | )
124 | }
125 |
--------------------------------------------------------------------------------
/components/sharing/ShareBike.tsx:
--------------------------------------------------------------------------------
1 | import { Bike } from '../../lib/bike'
2 | import { Button } from '../Button'
3 | import { useState, FormEvent } from 'react'
4 | import { FormError, FormSuccess } from '../Form'
5 | import { Api } from '../../lib/api'
6 | import { ShareDurationSlider } from './ShareDurationSlider'
7 | import { P } from '../Spacing'
8 |
9 | export function ShareBike({ bike, api }: { bike: Bike, api: Api }) {
10 | const [shareSuccessfull, setShareSuccessfull] = useState(false)
11 | const [error, setError] = useState()
12 | const [shareinfo, setShareinfo] = useState({
13 | email: '',
14 | duration: undefined as undefined | number,
15 | })
16 |
17 | const onSubmit = async (event: FormEvent) => {
18 | event.preventDefault()
19 | try {
20 | setError(undefined)
21 | setShareSuccessfull(false)
22 | await api.createBikeSharingInvitation(bike, shareinfo.email, shareinfo.duration)
23 | setShareSuccessfull(true)
24 | } catch (e) {
25 | setError(`${e}`)
26 | }
27 | }
28 |
29 | return (
30 |
31 |
Share bike
32 |
33 |
65 |
66 |
120 |
121 | )
122 | }
123 |
--------------------------------------------------------------------------------
/components/sharing/ShareDurationSlider.tsx:
--------------------------------------------------------------------------------
1 | import { useState, useEffect, useRef } from 'react'
2 |
3 | const minute = 1
4 | const hour = minute * 60
5 | const day = hour * 24
6 | const week = day * 7
7 |
8 | interface ShareDurationSliderProps {
9 | onChangeMinutes?: (minutes: number | undefined) => void
10 | }
11 |
12 | export function ShareDurationSlider({ onChangeMinutes }: ShareDurationSliderProps) {
13 | const [optionIdx, setOptionIdx] = useState(4)
14 | const lastOnChangeValue = useRef()
15 |
16 | const options = [
17 | { value: hour / 2, label: '30 minutes' },
18 | { value: hour, label: '1 hour', showLabel: true },
19 | { value: hour * 2, label: '2 hours' },
20 | { value: hour * 6, label: '6 hours' },
21 | { value: day / 2, label: '12 hours' },
22 | { value: day, label: '1 day', showLabel: true },
23 | { value: day * 2, label: '2 days' },
24 | { value: day * 3, label: '3 days' },
25 | { value: week, label: '1 week', showLabel: true },
26 | { value: week * 2, label: '2 weeks' },
27 | { value: undefined, label: 'Unlimited' }
28 | ]
29 | const selectedOption = options[optionIdx]
30 |
31 | useEffect(() => {
32 | const newValue = onChangeMinutes ? selectedOption.value : undefined
33 | if (onChangeMinutes && lastOnChangeValue.current !== newValue) {
34 | onChangeMinutes(newValue)
35 | }
36 | lastOnChangeValue.current = newValue
37 |
38 | }, [selectedOption, onChangeMinutes])
39 |
40 | return (
41 |
42 |
Share bike for {selectedOption.label}
43 |
44 |
setOptionIdx(Number(e.target.value))}
51 | />
52 |
53 | {options.map((option, idx) =>
54 |
55 | {option.showLabel
56 | ?
{option.label}
57 | : undefined
58 | }
59 |
60 | )}
61 |
62 |
91 |
92 | )
93 | }
94 |
--------------------------------------------------------------------------------
/custom.d.ts:
--------------------------------------------------------------------------------
1 | import 'react'
2 |
3 | declare module 'react' {
4 | interface StyleHTMLAttributes extends React.HTMLAttributes {
5 | jsx?: boolean;
6 | global?: boolean;
7 | }
8 | }
--------------------------------------------------------------------------------
/lib/aes.js:
--------------------------------------------------------------------------------
1 | /*! MIT License. Copyright 2015-2018 Richard Moore . See LICENSE.txt. */
2 |
3 | "use strict";
4 |
5 | function checkInt(value) {
6 | return (parseInt(value) === value);
7 | }
8 |
9 | function checkInts(arrayish) {
10 | if (!checkInt(arrayish.length)) { return false; }
11 |
12 | for (var i = 0; i < arrayish.length; i++) {
13 | if (!checkInt(arrayish[i]) || arrayish[i] < 0 || arrayish[i] > 255) {
14 | return false;
15 | }
16 | }
17 |
18 | return true;
19 | }
20 |
21 | function coerceArray(arg, copy) {
22 |
23 | // ArrayBuffer view
24 | if (arg.buffer && arg.name === 'Uint8Array') {
25 |
26 | if (copy) {
27 | if (arg.slice) {
28 | arg = arg.slice();
29 | } else {
30 | arg = Array.prototype.slice.call(arg);
31 | }
32 | }
33 |
34 | return arg;
35 | }
36 |
37 | // It's an array; check it is a valid representation of a byte
38 | if (Array.isArray(arg)) {
39 | if (!checkInts(arg)) {
40 | throw new Error('Array contains invalid value: ' + arg);
41 | }
42 |
43 | return new Uint8Array(arg);
44 | }
45 |
46 | // Something else, but behaves like an array (maybe a Buffer? Arguments?)
47 | if (checkInt(arg.length) && checkInts(arg)) {
48 | return new Uint8Array(arg);
49 | }
50 |
51 | throw new Error('unsupported array-like object');
52 | }
53 |
54 | function createArray(length) {
55 | return new Uint8Array(length);
56 | }
57 |
58 | function copyArray(sourceArray, targetArray, targetStart, sourceStart, sourceEnd) {
59 | if (sourceStart != null || sourceEnd != null) {
60 | if (sourceArray.slice) {
61 | sourceArray = sourceArray.slice(sourceStart, sourceEnd);
62 | } else {
63 | sourceArray = Array.prototype.slice.call(sourceArray, sourceStart, sourceEnd);
64 | }
65 | }
66 | targetArray.set(sourceArray, targetStart);
67 | }
68 |
69 |
70 | // Number of rounds by keysize
71 | var numberOfRounds = { 16: 10, 24: 12, 32: 14 }
72 |
73 | // Round constant words
74 | var rcon = [0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91];
75 |
76 | // S-box and Inverse S-box (S is for Substitution)
77 | var S = [0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16];
78 | var Si = [0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e, 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84, 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73, 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4, 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61, 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d];
79 |
80 | // Transformations for encryption
81 | var T1 = [0xc66363a5, 0xf87c7c84, 0xee777799, 0xf67b7b8d, 0xfff2f20d, 0xd66b6bbd, 0xde6f6fb1, 0x91c5c554, 0x60303050, 0x02010103, 0xce6767a9, 0x562b2b7d, 0xe7fefe19, 0xb5d7d762, 0x4dababe6, 0xec76769a, 0x8fcaca45, 0x1f82829d, 0x89c9c940, 0xfa7d7d87, 0xeffafa15, 0xb25959eb, 0x8e4747c9, 0xfbf0f00b, 0x41adadec, 0xb3d4d467, 0x5fa2a2fd, 0x45afafea, 0x239c9cbf, 0x53a4a4f7, 0xe4727296, 0x9bc0c05b, 0x75b7b7c2, 0xe1fdfd1c, 0x3d9393ae, 0x4c26266a, 0x6c36365a, 0x7e3f3f41, 0xf5f7f702, 0x83cccc4f, 0x6834345c, 0x51a5a5f4, 0xd1e5e534, 0xf9f1f108, 0xe2717193, 0xabd8d873, 0x62313153, 0x2a15153f, 0x0804040c, 0x95c7c752, 0x46232365, 0x9dc3c35e, 0x30181828, 0x379696a1, 0x0a05050f, 0x2f9a9ab5, 0x0e070709, 0x24121236, 0x1b80809b, 0xdfe2e23d, 0xcdebeb26, 0x4e272769, 0x7fb2b2cd, 0xea75759f, 0x1209091b, 0x1d83839e, 0x582c2c74, 0x341a1a2e, 0x361b1b2d, 0xdc6e6eb2, 0xb45a5aee, 0x5ba0a0fb, 0xa45252f6, 0x763b3b4d, 0xb7d6d661, 0x7db3b3ce, 0x5229297b, 0xdde3e33e, 0x5e2f2f71, 0x13848497, 0xa65353f5, 0xb9d1d168, 0x00000000, 0xc1eded2c, 0x40202060, 0xe3fcfc1f, 0x79b1b1c8, 0xb65b5bed, 0xd46a6abe, 0x8dcbcb46, 0x67bebed9, 0x7239394b, 0x944a4ade, 0x984c4cd4, 0xb05858e8, 0x85cfcf4a, 0xbbd0d06b, 0xc5efef2a, 0x4faaaae5, 0xedfbfb16, 0x864343c5, 0x9a4d4dd7, 0x66333355, 0x11858594, 0x8a4545cf, 0xe9f9f910, 0x04020206, 0xfe7f7f81, 0xa05050f0, 0x783c3c44, 0x259f9fba, 0x4ba8a8e3, 0xa25151f3, 0x5da3a3fe, 0x804040c0, 0x058f8f8a, 0x3f9292ad, 0x219d9dbc, 0x70383848, 0xf1f5f504, 0x63bcbcdf, 0x77b6b6c1, 0xafdada75, 0x42212163, 0x20101030, 0xe5ffff1a, 0xfdf3f30e, 0xbfd2d26d, 0x81cdcd4c, 0x180c0c14, 0x26131335, 0xc3ecec2f, 0xbe5f5fe1, 0x359797a2, 0x884444cc, 0x2e171739, 0x93c4c457, 0x55a7a7f2, 0xfc7e7e82, 0x7a3d3d47, 0xc86464ac, 0xba5d5de7, 0x3219192b, 0xe6737395, 0xc06060a0, 0x19818198, 0x9e4f4fd1, 0xa3dcdc7f, 0x44222266, 0x542a2a7e, 0x3b9090ab, 0x0b888883, 0x8c4646ca, 0xc7eeee29, 0x6bb8b8d3, 0x2814143c, 0xa7dede79, 0xbc5e5ee2, 0x160b0b1d, 0xaddbdb76, 0xdbe0e03b, 0x64323256, 0x743a3a4e, 0x140a0a1e, 0x924949db, 0x0c06060a, 0x4824246c, 0xb85c5ce4, 0x9fc2c25d, 0xbdd3d36e, 0x43acacef, 0xc46262a6, 0x399191a8, 0x319595a4, 0xd3e4e437, 0xf279798b, 0xd5e7e732, 0x8bc8c843, 0x6e373759, 0xda6d6db7, 0x018d8d8c, 0xb1d5d564, 0x9c4e4ed2, 0x49a9a9e0, 0xd86c6cb4, 0xac5656fa, 0xf3f4f407, 0xcfeaea25, 0xca6565af, 0xf47a7a8e, 0x47aeaee9, 0x10080818, 0x6fbabad5, 0xf0787888, 0x4a25256f, 0x5c2e2e72, 0x381c1c24, 0x57a6a6f1, 0x73b4b4c7, 0x97c6c651, 0xcbe8e823, 0xa1dddd7c, 0xe874749c, 0x3e1f1f21, 0x964b4bdd, 0x61bdbddc, 0x0d8b8b86, 0x0f8a8a85, 0xe0707090, 0x7c3e3e42, 0x71b5b5c4, 0xcc6666aa, 0x904848d8, 0x06030305, 0xf7f6f601, 0x1c0e0e12, 0xc26161a3, 0x6a35355f, 0xae5757f9, 0x69b9b9d0, 0x17868691, 0x99c1c158, 0x3a1d1d27, 0x279e9eb9, 0xd9e1e138, 0xebf8f813, 0x2b9898b3, 0x22111133, 0xd26969bb, 0xa9d9d970, 0x078e8e89, 0x339494a7, 0x2d9b9bb6, 0x3c1e1e22, 0x15878792, 0xc9e9e920, 0x87cece49, 0xaa5555ff, 0x50282878, 0xa5dfdf7a, 0x038c8c8f, 0x59a1a1f8, 0x09898980, 0x1a0d0d17, 0x65bfbfda, 0xd7e6e631, 0x844242c6, 0xd06868b8, 0x824141c3, 0x299999b0, 0x5a2d2d77, 0x1e0f0f11, 0x7bb0b0cb, 0xa85454fc, 0x6dbbbbd6, 0x2c16163a];
82 | var T2 = [0xa5c66363, 0x84f87c7c, 0x99ee7777, 0x8df67b7b, 0x0dfff2f2, 0xbdd66b6b, 0xb1de6f6f, 0x5491c5c5, 0x50603030, 0x03020101, 0xa9ce6767, 0x7d562b2b, 0x19e7fefe, 0x62b5d7d7, 0xe64dabab, 0x9aec7676, 0x458fcaca, 0x9d1f8282, 0x4089c9c9, 0x87fa7d7d, 0x15effafa, 0xebb25959, 0xc98e4747, 0x0bfbf0f0, 0xec41adad, 0x67b3d4d4, 0xfd5fa2a2, 0xea45afaf, 0xbf239c9c, 0xf753a4a4, 0x96e47272, 0x5b9bc0c0, 0xc275b7b7, 0x1ce1fdfd, 0xae3d9393, 0x6a4c2626, 0x5a6c3636, 0x417e3f3f, 0x02f5f7f7, 0x4f83cccc, 0x5c683434, 0xf451a5a5, 0x34d1e5e5, 0x08f9f1f1, 0x93e27171, 0x73abd8d8, 0x53623131, 0x3f2a1515, 0x0c080404, 0x5295c7c7, 0x65462323, 0x5e9dc3c3, 0x28301818, 0xa1379696, 0x0f0a0505, 0xb52f9a9a, 0x090e0707, 0x36241212, 0x9b1b8080, 0x3ddfe2e2, 0x26cdebeb, 0x694e2727, 0xcd7fb2b2, 0x9fea7575, 0x1b120909, 0x9e1d8383, 0x74582c2c, 0x2e341a1a, 0x2d361b1b, 0xb2dc6e6e, 0xeeb45a5a, 0xfb5ba0a0, 0xf6a45252, 0x4d763b3b, 0x61b7d6d6, 0xce7db3b3, 0x7b522929, 0x3edde3e3, 0x715e2f2f, 0x97138484, 0xf5a65353, 0x68b9d1d1, 0x00000000, 0x2cc1eded, 0x60402020, 0x1fe3fcfc, 0xc879b1b1, 0xedb65b5b, 0xbed46a6a, 0x468dcbcb, 0xd967bebe, 0x4b723939, 0xde944a4a, 0xd4984c4c, 0xe8b05858, 0x4a85cfcf, 0x6bbbd0d0, 0x2ac5efef, 0xe54faaaa, 0x16edfbfb, 0xc5864343, 0xd79a4d4d, 0x55663333, 0x94118585, 0xcf8a4545, 0x10e9f9f9, 0x06040202, 0x81fe7f7f, 0xf0a05050, 0x44783c3c, 0xba259f9f, 0xe34ba8a8, 0xf3a25151, 0xfe5da3a3, 0xc0804040, 0x8a058f8f, 0xad3f9292, 0xbc219d9d, 0x48703838, 0x04f1f5f5, 0xdf63bcbc, 0xc177b6b6, 0x75afdada, 0x63422121, 0x30201010, 0x1ae5ffff, 0x0efdf3f3, 0x6dbfd2d2, 0x4c81cdcd, 0x14180c0c, 0x35261313, 0x2fc3ecec, 0xe1be5f5f, 0xa2359797, 0xcc884444, 0x392e1717, 0x5793c4c4, 0xf255a7a7, 0x82fc7e7e, 0x477a3d3d, 0xacc86464, 0xe7ba5d5d, 0x2b321919, 0x95e67373, 0xa0c06060, 0x98198181, 0xd19e4f4f, 0x7fa3dcdc, 0x66442222, 0x7e542a2a, 0xab3b9090, 0x830b8888, 0xca8c4646, 0x29c7eeee, 0xd36bb8b8, 0x3c281414, 0x79a7dede, 0xe2bc5e5e, 0x1d160b0b, 0x76addbdb, 0x3bdbe0e0, 0x56643232, 0x4e743a3a, 0x1e140a0a, 0xdb924949, 0x0a0c0606, 0x6c482424, 0xe4b85c5c, 0x5d9fc2c2, 0x6ebdd3d3, 0xef43acac, 0xa6c46262, 0xa8399191, 0xa4319595, 0x37d3e4e4, 0x8bf27979, 0x32d5e7e7, 0x438bc8c8, 0x596e3737, 0xb7da6d6d, 0x8c018d8d, 0x64b1d5d5, 0xd29c4e4e, 0xe049a9a9, 0xb4d86c6c, 0xfaac5656, 0x07f3f4f4, 0x25cfeaea, 0xafca6565, 0x8ef47a7a, 0xe947aeae, 0x18100808, 0xd56fbaba, 0x88f07878, 0x6f4a2525, 0x725c2e2e, 0x24381c1c, 0xf157a6a6, 0xc773b4b4, 0x5197c6c6, 0x23cbe8e8, 0x7ca1dddd, 0x9ce87474, 0x213e1f1f, 0xdd964b4b, 0xdc61bdbd, 0x860d8b8b, 0x850f8a8a, 0x90e07070, 0x427c3e3e, 0xc471b5b5, 0xaacc6666, 0xd8904848, 0x05060303, 0x01f7f6f6, 0x121c0e0e, 0xa3c26161, 0x5f6a3535, 0xf9ae5757, 0xd069b9b9, 0x91178686, 0x5899c1c1, 0x273a1d1d, 0xb9279e9e, 0x38d9e1e1, 0x13ebf8f8, 0xb32b9898, 0x33221111, 0xbbd26969, 0x70a9d9d9, 0x89078e8e, 0xa7339494, 0xb62d9b9b, 0x223c1e1e, 0x92158787, 0x20c9e9e9, 0x4987cece, 0xffaa5555, 0x78502828, 0x7aa5dfdf, 0x8f038c8c, 0xf859a1a1, 0x80098989, 0x171a0d0d, 0xda65bfbf, 0x31d7e6e6, 0xc6844242, 0xb8d06868, 0xc3824141, 0xb0299999, 0x775a2d2d, 0x111e0f0f, 0xcb7bb0b0, 0xfca85454, 0xd66dbbbb, 0x3a2c1616];
83 | var T3 = [0x63a5c663, 0x7c84f87c, 0x7799ee77, 0x7b8df67b, 0xf20dfff2, 0x6bbdd66b, 0x6fb1de6f, 0xc55491c5, 0x30506030, 0x01030201, 0x67a9ce67, 0x2b7d562b, 0xfe19e7fe, 0xd762b5d7, 0xabe64dab, 0x769aec76, 0xca458fca, 0x829d1f82, 0xc94089c9, 0x7d87fa7d, 0xfa15effa, 0x59ebb259, 0x47c98e47, 0xf00bfbf0, 0xadec41ad, 0xd467b3d4, 0xa2fd5fa2, 0xafea45af, 0x9cbf239c, 0xa4f753a4, 0x7296e472, 0xc05b9bc0, 0xb7c275b7, 0xfd1ce1fd, 0x93ae3d93, 0x266a4c26, 0x365a6c36, 0x3f417e3f, 0xf702f5f7, 0xcc4f83cc, 0x345c6834, 0xa5f451a5, 0xe534d1e5, 0xf108f9f1, 0x7193e271, 0xd873abd8, 0x31536231, 0x153f2a15, 0x040c0804, 0xc75295c7, 0x23654623, 0xc35e9dc3, 0x18283018, 0x96a13796, 0x050f0a05, 0x9ab52f9a, 0x07090e07, 0x12362412, 0x809b1b80, 0xe23ddfe2, 0xeb26cdeb, 0x27694e27, 0xb2cd7fb2, 0x759fea75, 0x091b1209, 0x839e1d83, 0x2c74582c, 0x1a2e341a, 0x1b2d361b, 0x6eb2dc6e, 0x5aeeb45a, 0xa0fb5ba0, 0x52f6a452, 0x3b4d763b, 0xd661b7d6, 0xb3ce7db3, 0x297b5229, 0xe33edde3, 0x2f715e2f, 0x84971384, 0x53f5a653, 0xd168b9d1, 0x00000000, 0xed2cc1ed, 0x20604020, 0xfc1fe3fc, 0xb1c879b1, 0x5bedb65b, 0x6abed46a, 0xcb468dcb, 0xbed967be, 0x394b7239, 0x4ade944a, 0x4cd4984c, 0x58e8b058, 0xcf4a85cf, 0xd06bbbd0, 0xef2ac5ef, 0xaae54faa, 0xfb16edfb, 0x43c58643, 0x4dd79a4d, 0x33556633, 0x85941185, 0x45cf8a45, 0xf910e9f9, 0x02060402, 0x7f81fe7f, 0x50f0a050, 0x3c44783c, 0x9fba259f, 0xa8e34ba8, 0x51f3a251, 0xa3fe5da3, 0x40c08040, 0x8f8a058f, 0x92ad3f92, 0x9dbc219d, 0x38487038, 0xf504f1f5, 0xbcdf63bc, 0xb6c177b6, 0xda75afda, 0x21634221, 0x10302010, 0xff1ae5ff, 0xf30efdf3, 0xd26dbfd2, 0xcd4c81cd, 0x0c14180c, 0x13352613, 0xec2fc3ec, 0x5fe1be5f, 0x97a23597, 0x44cc8844, 0x17392e17, 0xc45793c4, 0xa7f255a7, 0x7e82fc7e, 0x3d477a3d, 0x64acc864, 0x5de7ba5d, 0x192b3219, 0x7395e673, 0x60a0c060, 0x81981981, 0x4fd19e4f, 0xdc7fa3dc, 0x22664422, 0x2a7e542a, 0x90ab3b90, 0x88830b88, 0x46ca8c46, 0xee29c7ee, 0xb8d36bb8, 0x143c2814, 0xde79a7de, 0x5ee2bc5e, 0x0b1d160b, 0xdb76addb, 0xe03bdbe0, 0x32566432, 0x3a4e743a, 0x0a1e140a, 0x49db9249, 0x060a0c06, 0x246c4824, 0x5ce4b85c, 0xc25d9fc2, 0xd36ebdd3, 0xacef43ac, 0x62a6c462, 0x91a83991, 0x95a43195, 0xe437d3e4, 0x798bf279, 0xe732d5e7, 0xc8438bc8, 0x37596e37, 0x6db7da6d, 0x8d8c018d, 0xd564b1d5, 0x4ed29c4e, 0xa9e049a9, 0x6cb4d86c, 0x56faac56, 0xf407f3f4, 0xea25cfea, 0x65afca65, 0x7a8ef47a, 0xaee947ae, 0x08181008, 0xbad56fba, 0x7888f078, 0x256f4a25, 0x2e725c2e, 0x1c24381c, 0xa6f157a6, 0xb4c773b4, 0xc65197c6, 0xe823cbe8, 0xdd7ca1dd, 0x749ce874, 0x1f213e1f, 0x4bdd964b, 0xbddc61bd, 0x8b860d8b, 0x8a850f8a, 0x7090e070, 0x3e427c3e, 0xb5c471b5, 0x66aacc66, 0x48d89048, 0x03050603, 0xf601f7f6, 0x0e121c0e, 0x61a3c261, 0x355f6a35, 0x57f9ae57, 0xb9d069b9, 0x86911786, 0xc15899c1, 0x1d273a1d, 0x9eb9279e, 0xe138d9e1, 0xf813ebf8, 0x98b32b98, 0x11332211, 0x69bbd269, 0xd970a9d9, 0x8e89078e, 0x94a73394, 0x9bb62d9b, 0x1e223c1e, 0x87921587, 0xe920c9e9, 0xce4987ce, 0x55ffaa55, 0x28785028, 0xdf7aa5df, 0x8c8f038c, 0xa1f859a1, 0x89800989, 0x0d171a0d, 0xbfda65bf, 0xe631d7e6, 0x42c68442, 0x68b8d068, 0x41c38241, 0x99b02999, 0x2d775a2d, 0x0f111e0f, 0xb0cb7bb0, 0x54fca854, 0xbbd66dbb, 0x163a2c16];
84 | var T4 = [0x6363a5c6, 0x7c7c84f8, 0x777799ee, 0x7b7b8df6, 0xf2f20dff, 0x6b6bbdd6, 0x6f6fb1de, 0xc5c55491, 0x30305060, 0x01010302, 0x6767a9ce, 0x2b2b7d56, 0xfefe19e7, 0xd7d762b5, 0xababe64d, 0x76769aec, 0xcaca458f, 0x82829d1f, 0xc9c94089, 0x7d7d87fa, 0xfafa15ef, 0x5959ebb2, 0x4747c98e, 0xf0f00bfb, 0xadadec41, 0xd4d467b3, 0xa2a2fd5f, 0xafafea45, 0x9c9cbf23, 0xa4a4f753, 0x727296e4, 0xc0c05b9b, 0xb7b7c275, 0xfdfd1ce1, 0x9393ae3d, 0x26266a4c, 0x36365a6c, 0x3f3f417e, 0xf7f702f5, 0xcccc4f83, 0x34345c68, 0xa5a5f451, 0xe5e534d1, 0xf1f108f9, 0x717193e2, 0xd8d873ab, 0x31315362, 0x15153f2a, 0x04040c08, 0xc7c75295, 0x23236546, 0xc3c35e9d, 0x18182830, 0x9696a137, 0x05050f0a, 0x9a9ab52f, 0x0707090e, 0x12123624, 0x80809b1b, 0xe2e23ddf, 0xebeb26cd, 0x2727694e, 0xb2b2cd7f, 0x75759fea, 0x09091b12, 0x83839e1d, 0x2c2c7458, 0x1a1a2e34, 0x1b1b2d36, 0x6e6eb2dc, 0x5a5aeeb4, 0xa0a0fb5b, 0x5252f6a4, 0x3b3b4d76, 0xd6d661b7, 0xb3b3ce7d, 0x29297b52, 0xe3e33edd, 0x2f2f715e, 0x84849713, 0x5353f5a6, 0xd1d168b9, 0x00000000, 0xeded2cc1, 0x20206040, 0xfcfc1fe3, 0xb1b1c879, 0x5b5bedb6, 0x6a6abed4, 0xcbcb468d, 0xbebed967, 0x39394b72, 0x4a4ade94, 0x4c4cd498, 0x5858e8b0, 0xcfcf4a85, 0xd0d06bbb, 0xefef2ac5, 0xaaaae54f, 0xfbfb16ed, 0x4343c586, 0x4d4dd79a, 0x33335566, 0x85859411, 0x4545cf8a, 0xf9f910e9, 0x02020604, 0x7f7f81fe, 0x5050f0a0, 0x3c3c4478, 0x9f9fba25, 0xa8a8e34b, 0x5151f3a2, 0xa3a3fe5d, 0x4040c080, 0x8f8f8a05, 0x9292ad3f, 0x9d9dbc21, 0x38384870, 0xf5f504f1, 0xbcbcdf63, 0xb6b6c177, 0xdada75af, 0x21216342, 0x10103020, 0xffff1ae5, 0xf3f30efd, 0xd2d26dbf, 0xcdcd4c81, 0x0c0c1418, 0x13133526, 0xecec2fc3, 0x5f5fe1be, 0x9797a235, 0x4444cc88, 0x1717392e, 0xc4c45793, 0xa7a7f255, 0x7e7e82fc, 0x3d3d477a, 0x6464acc8, 0x5d5de7ba, 0x19192b32, 0x737395e6, 0x6060a0c0, 0x81819819, 0x4f4fd19e, 0xdcdc7fa3, 0x22226644, 0x2a2a7e54, 0x9090ab3b, 0x8888830b, 0x4646ca8c, 0xeeee29c7, 0xb8b8d36b, 0x14143c28, 0xdede79a7, 0x5e5ee2bc, 0x0b0b1d16, 0xdbdb76ad, 0xe0e03bdb, 0x32325664, 0x3a3a4e74, 0x0a0a1e14, 0x4949db92, 0x06060a0c, 0x24246c48, 0x5c5ce4b8, 0xc2c25d9f, 0xd3d36ebd, 0xacacef43, 0x6262a6c4, 0x9191a839, 0x9595a431, 0xe4e437d3, 0x79798bf2, 0xe7e732d5, 0xc8c8438b, 0x3737596e, 0x6d6db7da, 0x8d8d8c01, 0xd5d564b1, 0x4e4ed29c, 0xa9a9e049, 0x6c6cb4d8, 0x5656faac, 0xf4f407f3, 0xeaea25cf, 0x6565afca, 0x7a7a8ef4, 0xaeaee947, 0x08081810, 0xbabad56f, 0x787888f0, 0x25256f4a, 0x2e2e725c, 0x1c1c2438, 0xa6a6f157, 0xb4b4c773, 0xc6c65197, 0xe8e823cb, 0xdddd7ca1, 0x74749ce8, 0x1f1f213e, 0x4b4bdd96, 0xbdbddc61, 0x8b8b860d, 0x8a8a850f, 0x707090e0, 0x3e3e427c, 0xb5b5c471, 0x6666aacc, 0x4848d890, 0x03030506, 0xf6f601f7, 0x0e0e121c, 0x6161a3c2, 0x35355f6a, 0x5757f9ae, 0xb9b9d069, 0x86869117, 0xc1c15899, 0x1d1d273a, 0x9e9eb927, 0xe1e138d9, 0xf8f813eb, 0x9898b32b, 0x11113322, 0x6969bbd2, 0xd9d970a9, 0x8e8e8907, 0x9494a733, 0x9b9bb62d, 0x1e1e223c, 0x87879215, 0xe9e920c9, 0xcece4987, 0x5555ffaa, 0x28287850, 0xdfdf7aa5, 0x8c8c8f03, 0xa1a1f859, 0x89898009, 0x0d0d171a, 0xbfbfda65, 0xe6e631d7, 0x4242c684, 0x6868b8d0, 0x4141c382, 0x9999b029, 0x2d2d775a, 0x0f0f111e, 0xb0b0cb7b, 0x5454fca8, 0xbbbbd66d, 0x16163a2c];
85 |
86 | // Transformations for decryption
87 | var T5 = [0x51f4a750, 0x7e416553, 0x1a17a4c3, 0x3a275e96, 0x3bab6bcb, 0x1f9d45f1, 0xacfa58ab, 0x4be30393, 0x2030fa55, 0xad766df6, 0x88cc7691, 0xf5024c25, 0x4fe5d7fc, 0xc52acbd7, 0x26354480, 0xb562a38f, 0xdeb15a49, 0x25ba1b67, 0x45ea0e98, 0x5dfec0e1, 0xc32f7502, 0x814cf012, 0x8d4697a3, 0x6bd3f9c6, 0x038f5fe7, 0x15929c95, 0xbf6d7aeb, 0x955259da, 0xd4be832d, 0x587421d3, 0x49e06929, 0x8ec9c844, 0x75c2896a, 0xf48e7978, 0x99583e6b, 0x27b971dd, 0xbee14fb6, 0xf088ad17, 0xc920ac66, 0x7dce3ab4, 0x63df4a18, 0xe51a3182, 0x97513360, 0x62537f45, 0xb16477e0, 0xbb6bae84, 0xfe81a01c, 0xf9082b94, 0x70486858, 0x8f45fd19, 0x94de6c87, 0x527bf8b7, 0xab73d323, 0x724b02e2, 0xe31f8f57, 0x6655ab2a, 0xb2eb2807, 0x2fb5c203, 0x86c57b9a, 0xd33708a5, 0x302887f2, 0x23bfa5b2, 0x02036aba, 0xed16825c, 0x8acf1c2b, 0xa779b492, 0xf307f2f0, 0x4e69e2a1, 0x65daf4cd, 0x0605bed5, 0xd134621f, 0xc4a6fe8a, 0x342e539d, 0xa2f355a0, 0x058ae132, 0xa4f6eb75, 0x0b83ec39, 0x4060efaa, 0x5e719f06, 0xbd6e1051, 0x3e218af9, 0x96dd063d, 0xdd3e05ae, 0x4de6bd46, 0x91548db5, 0x71c45d05, 0x0406d46f, 0x605015ff, 0x1998fb24, 0xd6bde997, 0x894043cc, 0x67d99e77, 0xb0e842bd, 0x07898b88, 0xe7195b38, 0x79c8eedb, 0xa17c0a47, 0x7c420fe9, 0xf8841ec9, 0x00000000, 0x09808683, 0x322bed48, 0x1e1170ac, 0x6c5a724e, 0xfd0efffb, 0x0f853856, 0x3daed51e, 0x362d3927, 0x0a0fd964, 0x685ca621, 0x9b5b54d1, 0x24362e3a, 0x0c0a67b1, 0x9357e70f, 0xb4ee96d2, 0x1b9b919e, 0x80c0c54f, 0x61dc20a2, 0x5a774b69, 0x1c121a16, 0xe293ba0a, 0xc0a02ae5, 0x3c22e043, 0x121b171d, 0x0e090d0b, 0xf28bc7ad, 0x2db6a8b9, 0x141ea9c8, 0x57f11985, 0xaf75074c, 0xee99ddbb, 0xa37f60fd, 0xf701269f, 0x5c72f5bc, 0x44663bc5, 0x5bfb7e34, 0x8b432976, 0xcb23c6dc, 0xb6edfc68, 0xb8e4f163, 0xd731dcca, 0x42638510, 0x13972240, 0x84c61120, 0x854a247d, 0xd2bb3df8, 0xaef93211, 0xc729a16d, 0x1d9e2f4b, 0xdcb230f3, 0x0d8652ec, 0x77c1e3d0, 0x2bb3166c, 0xa970b999, 0x119448fa, 0x47e96422, 0xa8fc8cc4, 0xa0f03f1a, 0x567d2cd8, 0x223390ef, 0x87494ec7, 0xd938d1c1, 0x8ccaa2fe, 0x98d40b36, 0xa6f581cf, 0xa57ade28, 0xdab78e26, 0x3fadbfa4, 0x2c3a9de4, 0x5078920d, 0x6a5fcc9b, 0x547e4662, 0xf68d13c2, 0x90d8b8e8, 0x2e39f75e, 0x82c3aff5, 0x9f5d80be, 0x69d0937c, 0x6fd52da9, 0xcf2512b3, 0xc8ac993b, 0x10187da7, 0xe89c636e, 0xdb3bbb7b, 0xcd267809, 0x6e5918f4, 0xec9ab701, 0x834f9aa8, 0xe6956e65, 0xaaffe67e, 0x21bccf08, 0xef15e8e6, 0xbae79bd9, 0x4a6f36ce, 0xea9f09d4, 0x29b07cd6, 0x31a4b2af, 0x2a3f2331, 0xc6a59430, 0x35a266c0, 0x744ebc37, 0xfc82caa6, 0xe090d0b0, 0x33a7d815, 0xf104984a, 0x41ecdaf7, 0x7fcd500e, 0x1791f62f, 0x764dd68d, 0x43efb04d, 0xccaa4d54, 0xe49604df, 0x9ed1b5e3, 0x4c6a881b, 0xc12c1fb8, 0x4665517f, 0x9d5eea04, 0x018c355d, 0xfa877473, 0xfb0b412e, 0xb3671d5a, 0x92dbd252, 0xe9105633, 0x6dd64713, 0x9ad7618c, 0x37a10c7a, 0x59f8148e, 0xeb133c89, 0xcea927ee, 0xb761c935, 0xe11ce5ed, 0x7a47b13c, 0x9cd2df59, 0x55f2733f, 0x1814ce79, 0x73c737bf, 0x53f7cdea, 0x5ffdaa5b, 0xdf3d6f14, 0x7844db86, 0xcaaff381, 0xb968c43e, 0x3824342c, 0xc2a3405f, 0x161dc372, 0xbce2250c, 0x283c498b, 0xff0d9541, 0x39a80171, 0x080cb3de, 0xd8b4e49c, 0x6456c190, 0x7bcb8461, 0xd532b670, 0x486c5c74, 0xd0b85742];
88 | var T6 = [0x5051f4a7, 0x537e4165, 0xc31a17a4, 0x963a275e, 0xcb3bab6b, 0xf11f9d45, 0xabacfa58, 0x934be303, 0x552030fa, 0xf6ad766d, 0x9188cc76, 0x25f5024c, 0xfc4fe5d7, 0xd7c52acb, 0x80263544, 0x8fb562a3, 0x49deb15a, 0x6725ba1b, 0x9845ea0e, 0xe15dfec0, 0x02c32f75, 0x12814cf0, 0xa38d4697, 0xc66bd3f9, 0xe7038f5f, 0x9515929c, 0xebbf6d7a, 0xda955259, 0x2dd4be83, 0xd3587421, 0x2949e069, 0x448ec9c8, 0x6a75c289, 0x78f48e79, 0x6b99583e, 0xdd27b971, 0xb6bee14f, 0x17f088ad, 0x66c920ac, 0xb47dce3a, 0x1863df4a, 0x82e51a31, 0x60975133, 0x4562537f, 0xe0b16477, 0x84bb6bae, 0x1cfe81a0, 0x94f9082b, 0x58704868, 0x198f45fd, 0x8794de6c, 0xb7527bf8, 0x23ab73d3, 0xe2724b02, 0x57e31f8f, 0x2a6655ab, 0x07b2eb28, 0x032fb5c2, 0x9a86c57b, 0xa5d33708, 0xf2302887, 0xb223bfa5, 0xba02036a, 0x5ced1682, 0x2b8acf1c, 0x92a779b4, 0xf0f307f2, 0xa14e69e2, 0xcd65daf4, 0xd50605be, 0x1fd13462, 0x8ac4a6fe, 0x9d342e53, 0xa0a2f355, 0x32058ae1, 0x75a4f6eb, 0x390b83ec, 0xaa4060ef, 0x065e719f, 0x51bd6e10, 0xf93e218a, 0x3d96dd06, 0xaedd3e05, 0x464de6bd, 0xb591548d, 0x0571c45d, 0x6f0406d4, 0xff605015, 0x241998fb, 0x97d6bde9, 0xcc894043, 0x7767d99e, 0xbdb0e842, 0x8807898b, 0x38e7195b, 0xdb79c8ee, 0x47a17c0a, 0xe97c420f, 0xc9f8841e, 0x00000000, 0x83098086, 0x48322bed, 0xac1e1170, 0x4e6c5a72, 0xfbfd0eff, 0x560f8538, 0x1e3daed5, 0x27362d39, 0x640a0fd9, 0x21685ca6, 0xd19b5b54, 0x3a24362e, 0xb10c0a67, 0x0f9357e7, 0xd2b4ee96, 0x9e1b9b91, 0x4f80c0c5, 0xa261dc20, 0x695a774b, 0x161c121a, 0x0ae293ba, 0xe5c0a02a, 0x433c22e0, 0x1d121b17, 0x0b0e090d, 0xadf28bc7, 0xb92db6a8, 0xc8141ea9, 0x8557f119, 0x4caf7507, 0xbbee99dd, 0xfda37f60, 0x9ff70126, 0xbc5c72f5, 0xc544663b, 0x345bfb7e, 0x768b4329, 0xdccb23c6, 0x68b6edfc, 0x63b8e4f1, 0xcad731dc, 0x10426385, 0x40139722, 0x2084c611, 0x7d854a24, 0xf8d2bb3d, 0x11aef932, 0x6dc729a1, 0x4b1d9e2f, 0xf3dcb230, 0xec0d8652, 0xd077c1e3, 0x6c2bb316, 0x99a970b9, 0xfa119448, 0x2247e964, 0xc4a8fc8c, 0x1aa0f03f, 0xd8567d2c, 0xef223390, 0xc787494e, 0xc1d938d1, 0xfe8ccaa2, 0x3698d40b, 0xcfa6f581, 0x28a57ade, 0x26dab78e, 0xa43fadbf, 0xe42c3a9d, 0x0d507892, 0x9b6a5fcc, 0x62547e46, 0xc2f68d13, 0xe890d8b8, 0x5e2e39f7, 0xf582c3af, 0xbe9f5d80, 0x7c69d093, 0xa96fd52d, 0xb3cf2512, 0x3bc8ac99, 0xa710187d, 0x6ee89c63, 0x7bdb3bbb, 0x09cd2678, 0xf46e5918, 0x01ec9ab7, 0xa8834f9a, 0x65e6956e, 0x7eaaffe6, 0x0821bccf, 0xe6ef15e8, 0xd9bae79b, 0xce4a6f36, 0xd4ea9f09, 0xd629b07c, 0xaf31a4b2, 0x312a3f23, 0x30c6a594, 0xc035a266, 0x37744ebc, 0xa6fc82ca, 0xb0e090d0, 0x1533a7d8, 0x4af10498, 0xf741ecda, 0x0e7fcd50, 0x2f1791f6, 0x8d764dd6, 0x4d43efb0, 0x54ccaa4d, 0xdfe49604, 0xe39ed1b5, 0x1b4c6a88, 0xb8c12c1f, 0x7f466551, 0x049d5eea, 0x5d018c35, 0x73fa8774, 0x2efb0b41, 0x5ab3671d, 0x5292dbd2, 0x33e91056, 0x136dd647, 0x8c9ad761, 0x7a37a10c, 0x8e59f814, 0x89eb133c, 0xeecea927, 0x35b761c9, 0xede11ce5, 0x3c7a47b1, 0x599cd2df, 0x3f55f273, 0x791814ce, 0xbf73c737, 0xea53f7cd, 0x5b5ffdaa, 0x14df3d6f, 0x867844db, 0x81caaff3, 0x3eb968c4, 0x2c382434, 0x5fc2a340, 0x72161dc3, 0x0cbce225, 0x8b283c49, 0x41ff0d95, 0x7139a801, 0xde080cb3, 0x9cd8b4e4, 0x906456c1, 0x617bcb84, 0x70d532b6, 0x74486c5c, 0x42d0b857];
89 | var T7 = [0xa75051f4, 0x65537e41, 0xa4c31a17, 0x5e963a27, 0x6bcb3bab, 0x45f11f9d, 0x58abacfa, 0x03934be3, 0xfa552030, 0x6df6ad76, 0x769188cc, 0x4c25f502, 0xd7fc4fe5, 0xcbd7c52a, 0x44802635, 0xa38fb562, 0x5a49deb1, 0x1b6725ba, 0x0e9845ea, 0xc0e15dfe, 0x7502c32f, 0xf012814c, 0x97a38d46, 0xf9c66bd3, 0x5fe7038f, 0x9c951592, 0x7aebbf6d, 0x59da9552, 0x832dd4be, 0x21d35874, 0x692949e0, 0xc8448ec9, 0x896a75c2, 0x7978f48e, 0x3e6b9958, 0x71dd27b9, 0x4fb6bee1, 0xad17f088, 0xac66c920, 0x3ab47dce, 0x4a1863df, 0x3182e51a, 0x33609751, 0x7f456253, 0x77e0b164, 0xae84bb6b, 0xa01cfe81, 0x2b94f908, 0x68587048, 0xfd198f45, 0x6c8794de, 0xf8b7527b, 0xd323ab73, 0x02e2724b, 0x8f57e31f, 0xab2a6655, 0x2807b2eb, 0xc2032fb5, 0x7b9a86c5, 0x08a5d337, 0x87f23028, 0xa5b223bf, 0x6aba0203, 0x825ced16, 0x1c2b8acf, 0xb492a779, 0xf2f0f307, 0xe2a14e69, 0xf4cd65da, 0xbed50605, 0x621fd134, 0xfe8ac4a6, 0x539d342e, 0x55a0a2f3, 0xe132058a, 0xeb75a4f6, 0xec390b83, 0xefaa4060, 0x9f065e71, 0x1051bd6e, 0x8af93e21, 0x063d96dd, 0x05aedd3e, 0xbd464de6, 0x8db59154, 0x5d0571c4, 0xd46f0406, 0x15ff6050, 0xfb241998, 0xe997d6bd, 0x43cc8940, 0x9e7767d9, 0x42bdb0e8, 0x8b880789, 0x5b38e719, 0xeedb79c8, 0x0a47a17c, 0x0fe97c42, 0x1ec9f884, 0x00000000, 0x86830980, 0xed48322b, 0x70ac1e11, 0x724e6c5a, 0xfffbfd0e, 0x38560f85, 0xd51e3dae, 0x3927362d, 0xd9640a0f, 0xa621685c, 0x54d19b5b, 0x2e3a2436, 0x67b10c0a, 0xe70f9357, 0x96d2b4ee, 0x919e1b9b, 0xc54f80c0, 0x20a261dc, 0x4b695a77, 0x1a161c12, 0xba0ae293, 0x2ae5c0a0, 0xe0433c22, 0x171d121b, 0x0d0b0e09, 0xc7adf28b, 0xa8b92db6, 0xa9c8141e, 0x198557f1, 0x074caf75, 0xddbbee99, 0x60fda37f, 0x269ff701, 0xf5bc5c72, 0x3bc54466, 0x7e345bfb, 0x29768b43, 0xc6dccb23, 0xfc68b6ed, 0xf163b8e4, 0xdccad731, 0x85104263, 0x22401397, 0x112084c6, 0x247d854a, 0x3df8d2bb, 0x3211aef9, 0xa16dc729, 0x2f4b1d9e, 0x30f3dcb2, 0x52ec0d86, 0xe3d077c1, 0x166c2bb3, 0xb999a970, 0x48fa1194, 0x642247e9, 0x8cc4a8fc, 0x3f1aa0f0, 0x2cd8567d, 0x90ef2233, 0x4ec78749, 0xd1c1d938, 0xa2fe8cca, 0x0b3698d4, 0x81cfa6f5, 0xde28a57a, 0x8e26dab7, 0xbfa43fad, 0x9de42c3a, 0x920d5078, 0xcc9b6a5f, 0x4662547e, 0x13c2f68d, 0xb8e890d8, 0xf75e2e39, 0xaff582c3, 0x80be9f5d, 0x937c69d0, 0x2da96fd5, 0x12b3cf25, 0x993bc8ac, 0x7da71018, 0x636ee89c, 0xbb7bdb3b, 0x7809cd26, 0x18f46e59, 0xb701ec9a, 0x9aa8834f, 0x6e65e695, 0xe67eaaff, 0xcf0821bc, 0xe8e6ef15, 0x9bd9bae7, 0x36ce4a6f, 0x09d4ea9f, 0x7cd629b0, 0xb2af31a4, 0x23312a3f, 0x9430c6a5, 0x66c035a2, 0xbc37744e, 0xcaa6fc82, 0xd0b0e090, 0xd81533a7, 0x984af104, 0xdaf741ec, 0x500e7fcd, 0xf62f1791, 0xd68d764d, 0xb04d43ef, 0x4d54ccaa, 0x04dfe496, 0xb5e39ed1, 0x881b4c6a, 0x1fb8c12c, 0x517f4665, 0xea049d5e, 0x355d018c, 0x7473fa87, 0x412efb0b, 0x1d5ab367, 0xd25292db, 0x5633e910, 0x47136dd6, 0x618c9ad7, 0x0c7a37a1, 0x148e59f8, 0x3c89eb13, 0x27eecea9, 0xc935b761, 0xe5ede11c, 0xb13c7a47, 0xdf599cd2, 0x733f55f2, 0xce791814, 0x37bf73c7, 0xcdea53f7, 0xaa5b5ffd, 0x6f14df3d, 0xdb867844, 0xf381caaf, 0xc43eb968, 0x342c3824, 0x405fc2a3, 0xc372161d, 0x250cbce2, 0x498b283c, 0x9541ff0d, 0x017139a8, 0xb3de080c, 0xe49cd8b4, 0xc1906456, 0x84617bcb, 0xb670d532, 0x5c74486c, 0x5742d0b8];
90 | var T8 = [0xf4a75051, 0x4165537e, 0x17a4c31a, 0x275e963a, 0xab6bcb3b, 0x9d45f11f, 0xfa58abac, 0xe303934b, 0x30fa5520, 0x766df6ad, 0xcc769188, 0x024c25f5, 0xe5d7fc4f, 0x2acbd7c5, 0x35448026, 0x62a38fb5, 0xb15a49de, 0xba1b6725, 0xea0e9845, 0xfec0e15d, 0x2f7502c3, 0x4cf01281, 0x4697a38d, 0xd3f9c66b, 0x8f5fe703, 0x929c9515, 0x6d7aebbf, 0x5259da95, 0xbe832dd4, 0x7421d358, 0xe0692949, 0xc9c8448e, 0xc2896a75, 0x8e7978f4, 0x583e6b99, 0xb971dd27, 0xe14fb6be, 0x88ad17f0, 0x20ac66c9, 0xce3ab47d, 0xdf4a1863, 0x1a3182e5, 0x51336097, 0x537f4562, 0x6477e0b1, 0x6bae84bb, 0x81a01cfe, 0x082b94f9, 0x48685870, 0x45fd198f, 0xde6c8794, 0x7bf8b752, 0x73d323ab, 0x4b02e272, 0x1f8f57e3, 0x55ab2a66, 0xeb2807b2, 0xb5c2032f, 0xc57b9a86, 0x3708a5d3, 0x2887f230, 0xbfa5b223, 0x036aba02, 0x16825ced, 0xcf1c2b8a, 0x79b492a7, 0x07f2f0f3, 0x69e2a14e, 0xdaf4cd65, 0x05bed506, 0x34621fd1, 0xa6fe8ac4, 0x2e539d34, 0xf355a0a2, 0x8ae13205, 0xf6eb75a4, 0x83ec390b, 0x60efaa40, 0x719f065e, 0x6e1051bd, 0x218af93e, 0xdd063d96, 0x3e05aedd, 0xe6bd464d, 0x548db591, 0xc45d0571, 0x06d46f04, 0x5015ff60, 0x98fb2419, 0xbde997d6, 0x4043cc89, 0xd99e7767, 0xe842bdb0, 0x898b8807, 0x195b38e7, 0xc8eedb79, 0x7c0a47a1, 0x420fe97c, 0x841ec9f8, 0x00000000, 0x80868309, 0x2bed4832, 0x1170ac1e, 0x5a724e6c, 0x0efffbfd, 0x8538560f, 0xaed51e3d, 0x2d392736, 0x0fd9640a, 0x5ca62168, 0x5b54d19b, 0x362e3a24, 0x0a67b10c, 0x57e70f93, 0xee96d2b4, 0x9b919e1b, 0xc0c54f80, 0xdc20a261, 0x774b695a, 0x121a161c, 0x93ba0ae2, 0xa02ae5c0, 0x22e0433c, 0x1b171d12, 0x090d0b0e, 0x8bc7adf2, 0xb6a8b92d, 0x1ea9c814, 0xf1198557, 0x75074caf, 0x99ddbbee, 0x7f60fda3, 0x01269ff7, 0x72f5bc5c, 0x663bc544, 0xfb7e345b, 0x4329768b, 0x23c6dccb, 0xedfc68b6, 0xe4f163b8, 0x31dccad7, 0x63851042, 0x97224013, 0xc6112084, 0x4a247d85, 0xbb3df8d2, 0xf93211ae, 0x29a16dc7, 0x9e2f4b1d, 0xb230f3dc, 0x8652ec0d, 0xc1e3d077, 0xb3166c2b, 0x70b999a9, 0x9448fa11, 0xe9642247, 0xfc8cc4a8, 0xf03f1aa0, 0x7d2cd856, 0x3390ef22, 0x494ec787, 0x38d1c1d9, 0xcaa2fe8c, 0xd40b3698, 0xf581cfa6, 0x7ade28a5, 0xb78e26da, 0xadbfa43f, 0x3a9de42c, 0x78920d50, 0x5fcc9b6a, 0x7e466254, 0x8d13c2f6, 0xd8b8e890, 0x39f75e2e, 0xc3aff582, 0x5d80be9f, 0xd0937c69, 0xd52da96f, 0x2512b3cf, 0xac993bc8, 0x187da710, 0x9c636ee8, 0x3bbb7bdb, 0x267809cd, 0x5918f46e, 0x9ab701ec, 0x4f9aa883, 0x956e65e6, 0xffe67eaa, 0xbccf0821, 0x15e8e6ef, 0xe79bd9ba, 0x6f36ce4a, 0x9f09d4ea, 0xb07cd629, 0xa4b2af31, 0x3f23312a, 0xa59430c6, 0xa266c035, 0x4ebc3774, 0x82caa6fc, 0x90d0b0e0, 0xa7d81533, 0x04984af1, 0xecdaf741, 0xcd500e7f, 0x91f62f17, 0x4dd68d76, 0xefb04d43, 0xaa4d54cc, 0x9604dfe4, 0xd1b5e39e, 0x6a881b4c, 0x2c1fb8c1, 0x65517f46, 0x5eea049d, 0x8c355d01, 0x877473fa, 0x0b412efb, 0x671d5ab3, 0xdbd25292, 0x105633e9, 0xd647136d, 0xd7618c9a, 0xa10c7a37, 0xf8148e59, 0x133c89eb, 0xa927eece, 0x61c935b7, 0x1ce5ede1, 0x47b13c7a, 0xd2df599c, 0xf2733f55, 0x14ce7918, 0xc737bf73, 0xf7cdea53, 0xfdaa5b5f, 0x3d6f14df, 0x44db8678, 0xaff381ca, 0x68c43eb9, 0x24342c38, 0xa3405fc2, 0x1dc37216, 0xe2250cbc, 0x3c498b28, 0x0d9541ff, 0xa8017139, 0x0cb3de08, 0xb4e49cd8, 0x56c19064, 0xcb84617b, 0x32b670d5, 0x6c5c7448, 0xb85742d0];
91 |
92 | // Transformations for decryption key expansion
93 | var U1 = [0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927, 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45, 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb, 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381, 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf, 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66, 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28, 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012, 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec, 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e, 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd, 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7, 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89, 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b, 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815, 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f, 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa, 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8, 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36, 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c, 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742, 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea, 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4, 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e, 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360, 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502, 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87, 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd, 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3, 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621, 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f, 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55, 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26, 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844, 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba, 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480, 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce, 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67, 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929, 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713, 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed, 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f, 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3];
94 | var U2 = [0x00000000, 0x0b0e090d, 0x161c121a, 0x1d121b17, 0x2c382434, 0x27362d39, 0x3a24362e, 0x312a3f23, 0x58704868, 0x537e4165, 0x4e6c5a72, 0x4562537f, 0x74486c5c, 0x7f466551, 0x62547e46, 0x695a774b, 0xb0e090d0, 0xbbee99dd, 0xa6fc82ca, 0xadf28bc7, 0x9cd8b4e4, 0x97d6bde9, 0x8ac4a6fe, 0x81caaff3, 0xe890d8b8, 0xe39ed1b5, 0xfe8ccaa2, 0xf582c3af, 0xc4a8fc8c, 0xcfa6f581, 0xd2b4ee96, 0xd9bae79b, 0x7bdb3bbb, 0x70d532b6, 0x6dc729a1, 0x66c920ac, 0x57e31f8f, 0x5ced1682, 0x41ff0d95, 0x4af10498, 0x23ab73d3, 0x28a57ade, 0x35b761c9, 0x3eb968c4, 0x0f9357e7, 0x049d5eea, 0x198f45fd, 0x12814cf0, 0xcb3bab6b, 0xc035a266, 0xdd27b971, 0xd629b07c, 0xe7038f5f, 0xec0d8652, 0xf11f9d45, 0xfa119448, 0x934be303, 0x9845ea0e, 0x8557f119, 0x8e59f814, 0xbf73c737, 0xb47dce3a, 0xa96fd52d, 0xa261dc20, 0xf6ad766d, 0xfda37f60, 0xe0b16477, 0xebbf6d7a, 0xda955259, 0xd19b5b54, 0xcc894043, 0xc787494e, 0xaedd3e05, 0xa5d33708, 0xb8c12c1f, 0xb3cf2512, 0x82e51a31, 0x89eb133c, 0x94f9082b, 0x9ff70126, 0x464de6bd, 0x4d43efb0, 0x5051f4a7, 0x5b5ffdaa, 0x6a75c289, 0x617bcb84, 0x7c69d093, 0x7767d99e, 0x1e3daed5, 0x1533a7d8, 0x0821bccf, 0x032fb5c2, 0x32058ae1, 0x390b83ec, 0x241998fb, 0x2f1791f6, 0x8d764dd6, 0x867844db, 0x9b6a5fcc, 0x906456c1, 0xa14e69e2, 0xaa4060ef, 0xb7527bf8, 0xbc5c72f5, 0xd50605be, 0xde080cb3, 0xc31a17a4, 0xc8141ea9, 0xf93e218a, 0xf2302887, 0xef223390, 0xe42c3a9d, 0x3d96dd06, 0x3698d40b, 0x2b8acf1c, 0x2084c611, 0x11aef932, 0x1aa0f03f, 0x07b2eb28, 0x0cbce225, 0x65e6956e, 0x6ee89c63, 0x73fa8774, 0x78f48e79, 0x49deb15a, 0x42d0b857, 0x5fc2a340, 0x54ccaa4d, 0xf741ecda, 0xfc4fe5d7, 0xe15dfec0, 0xea53f7cd, 0xdb79c8ee, 0xd077c1e3, 0xcd65daf4, 0xc66bd3f9, 0xaf31a4b2, 0xa43fadbf, 0xb92db6a8, 0xb223bfa5, 0x83098086, 0x8807898b, 0x9515929c, 0x9e1b9b91, 0x47a17c0a, 0x4caf7507, 0x51bd6e10, 0x5ab3671d, 0x6b99583e, 0x60975133, 0x7d854a24, 0x768b4329, 0x1fd13462, 0x14df3d6f, 0x09cd2678, 0x02c32f75, 0x33e91056, 0x38e7195b, 0x25f5024c, 0x2efb0b41, 0x8c9ad761, 0x8794de6c, 0x9a86c57b, 0x9188cc76, 0xa0a2f355, 0xabacfa58, 0xb6bee14f, 0xbdb0e842, 0xd4ea9f09, 0xdfe49604, 0xc2f68d13, 0xc9f8841e, 0xf8d2bb3d, 0xf3dcb230, 0xeecea927, 0xe5c0a02a, 0x3c7a47b1, 0x37744ebc, 0x2a6655ab, 0x21685ca6, 0x10426385, 0x1b4c6a88, 0x065e719f, 0x0d507892, 0x640a0fd9, 0x6f0406d4, 0x72161dc3, 0x791814ce, 0x48322bed, 0x433c22e0, 0x5e2e39f7, 0x552030fa, 0x01ec9ab7, 0x0ae293ba, 0x17f088ad, 0x1cfe81a0, 0x2dd4be83, 0x26dab78e, 0x3bc8ac99, 0x30c6a594, 0x599cd2df, 0x5292dbd2, 0x4f80c0c5, 0x448ec9c8, 0x75a4f6eb, 0x7eaaffe6, 0x63b8e4f1, 0x68b6edfc, 0xb10c0a67, 0xba02036a, 0xa710187d, 0xac1e1170, 0x9d342e53, 0x963a275e, 0x8b283c49, 0x80263544, 0xe97c420f, 0xe2724b02, 0xff605015, 0xf46e5918, 0xc544663b, 0xce4a6f36, 0xd3587421, 0xd8567d2c, 0x7a37a10c, 0x7139a801, 0x6c2bb316, 0x6725ba1b, 0x560f8538, 0x5d018c35, 0x40139722, 0x4b1d9e2f, 0x2247e964, 0x2949e069, 0x345bfb7e, 0x3f55f273, 0x0e7fcd50, 0x0571c45d, 0x1863df4a, 0x136dd647, 0xcad731dc, 0xc1d938d1, 0xdccb23c6, 0xd7c52acb, 0xe6ef15e8, 0xede11ce5, 0xf0f307f2, 0xfbfd0eff, 0x92a779b4, 0x99a970b9, 0x84bb6bae, 0x8fb562a3, 0xbe9f5d80, 0xb591548d, 0xa8834f9a, 0xa38d4697];
95 | var U3 = [0x00000000, 0x0d0b0e09, 0x1a161c12, 0x171d121b, 0x342c3824, 0x3927362d, 0x2e3a2436, 0x23312a3f, 0x68587048, 0x65537e41, 0x724e6c5a, 0x7f456253, 0x5c74486c, 0x517f4665, 0x4662547e, 0x4b695a77, 0xd0b0e090, 0xddbbee99, 0xcaa6fc82, 0xc7adf28b, 0xe49cd8b4, 0xe997d6bd, 0xfe8ac4a6, 0xf381caaf, 0xb8e890d8, 0xb5e39ed1, 0xa2fe8cca, 0xaff582c3, 0x8cc4a8fc, 0x81cfa6f5, 0x96d2b4ee, 0x9bd9bae7, 0xbb7bdb3b, 0xb670d532, 0xa16dc729, 0xac66c920, 0x8f57e31f, 0x825ced16, 0x9541ff0d, 0x984af104, 0xd323ab73, 0xde28a57a, 0xc935b761, 0xc43eb968, 0xe70f9357, 0xea049d5e, 0xfd198f45, 0xf012814c, 0x6bcb3bab, 0x66c035a2, 0x71dd27b9, 0x7cd629b0, 0x5fe7038f, 0x52ec0d86, 0x45f11f9d, 0x48fa1194, 0x03934be3, 0x0e9845ea, 0x198557f1, 0x148e59f8, 0x37bf73c7, 0x3ab47dce, 0x2da96fd5, 0x20a261dc, 0x6df6ad76, 0x60fda37f, 0x77e0b164, 0x7aebbf6d, 0x59da9552, 0x54d19b5b, 0x43cc8940, 0x4ec78749, 0x05aedd3e, 0x08a5d337, 0x1fb8c12c, 0x12b3cf25, 0x3182e51a, 0x3c89eb13, 0x2b94f908, 0x269ff701, 0xbd464de6, 0xb04d43ef, 0xa75051f4, 0xaa5b5ffd, 0x896a75c2, 0x84617bcb, 0x937c69d0, 0x9e7767d9, 0xd51e3dae, 0xd81533a7, 0xcf0821bc, 0xc2032fb5, 0xe132058a, 0xec390b83, 0xfb241998, 0xf62f1791, 0xd68d764d, 0xdb867844, 0xcc9b6a5f, 0xc1906456, 0xe2a14e69, 0xefaa4060, 0xf8b7527b, 0xf5bc5c72, 0xbed50605, 0xb3de080c, 0xa4c31a17, 0xa9c8141e, 0x8af93e21, 0x87f23028, 0x90ef2233, 0x9de42c3a, 0x063d96dd, 0x0b3698d4, 0x1c2b8acf, 0x112084c6, 0x3211aef9, 0x3f1aa0f0, 0x2807b2eb, 0x250cbce2, 0x6e65e695, 0x636ee89c, 0x7473fa87, 0x7978f48e, 0x5a49deb1, 0x5742d0b8, 0x405fc2a3, 0x4d54ccaa, 0xdaf741ec, 0xd7fc4fe5, 0xc0e15dfe, 0xcdea53f7, 0xeedb79c8, 0xe3d077c1, 0xf4cd65da, 0xf9c66bd3, 0xb2af31a4, 0xbfa43fad, 0xa8b92db6, 0xa5b223bf, 0x86830980, 0x8b880789, 0x9c951592, 0x919e1b9b, 0x0a47a17c, 0x074caf75, 0x1051bd6e, 0x1d5ab367, 0x3e6b9958, 0x33609751, 0x247d854a, 0x29768b43, 0x621fd134, 0x6f14df3d, 0x7809cd26, 0x7502c32f, 0x5633e910, 0x5b38e719, 0x4c25f502, 0x412efb0b, 0x618c9ad7, 0x6c8794de, 0x7b9a86c5, 0x769188cc, 0x55a0a2f3, 0x58abacfa, 0x4fb6bee1, 0x42bdb0e8, 0x09d4ea9f, 0x04dfe496, 0x13c2f68d, 0x1ec9f884, 0x3df8d2bb, 0x30f3dcb2, 0x27eecea9, 0x2ae5c0a0, 0xb13c7a47, 0xbc37744e, 0xab2a6655, 0xa621685c, 0x85104263, 0x881b4c6a, 0x9f065e71, 0x920d5078, 0xd9640a0f, 0xd46f0406, 0xc372161d, 0xce791814, 0xed48322b, 0xe0433c22, 0xf75e2e39, 0xfa552030, 0xb701ec9a, 0xba0ae293, 0xad17f088, 0xa01cfe81, 0x832dd4be, 0x8e26dab7, 0x993bc8ac, 0x9430c6a5, 0xdf599cd2, 0xd25292db, 0xc54f80c0, 0xc8448ec9, 0xeb75a4f6, 0xe67eaaff, 0xf163b8e4, 0xfc68b6ed, 0x67b10c0a, 0x6aba0203, 0x7da71018, 0x70ac1e11, 0x539d342e, 0x5e963a27, 0x498b283c, 0x44802635, 0x0fe97c42, 0x02e2724b, 0x15ff6050, 0x18f46e59, 0x3bc54466, 0x36ce4a6f, 0x21d35874, 0x2cd8567d, 0x0c7a37a1, 0x017139a8, 0x166c2bb3, 0x1b6725ba, 0x38560f85, 0x355d018c, 0x22401397, 0x2f4b1d9e, 0x642247e9, 0x692949e0, 0x7e345bfb, 0x733f55f2, 0x500e7fcd, 0x5d0571c4, 0x4a1863df, 0x47136dd6, 0xdccad731, 0xd1c1d938, 0xc6dccb23, 0xcbd7c52a, 0xe8e6ef15, 0xe5ede11c, 0xf2f0f307, 0xfffbfd0e, 0xb492a779, 0xb999a970, 0xae84bb6b, 0xa38fb562, 0x80be9f5d, 0x8db59154, 0x9aa8834f, 0x97a38d46];
96 | var U4 = [0x00000000, 0x090d0b0e, 0x121a161c, 0x1b171d12, 0x24342c38, 0x2d392736, 0x362e3a24, 0x3f23312a, 0x48685870, 0x4165537e, 0x5a724e6c, 0x537f4562, 0x6c5c7448, 0x65517f46, 0x7e466254, 0x774b695a, 0x90d0b0e0, 0x99ddbbee, 0x82caa6fc, 0x8bc7adf2, 0xb4e49cd8, 0xbde997d6, 0xa6fe8ac4, 0xaff381ca, 0xd8b8e890, 0xd1b5e39e, 0xcaa2fe8c, 0xc3aff582, 0xfc8cc4a8, 0xf581cfa6, 0xee96d2b4, 0xe79bd9ba, 0x3bbb7bdb, 0x32b670d5, 0x29a16dc7, 0x20ac66c9, 0x1f8f57e3, 0x16825ced, 0x0d9541ff, 0x04984af1, 0x73d323ab, 0x7ade28a5, 0x61c935b7, 0x68c43eb9, 0x57e70f93, 0x5eea049d, 0x45fd198f, 0x4cf01281, 0xab6bcb3b, 0xa266c035, 0xb971dd27, 0xb07cd629, 0x8f5fe703, 0x8652ec0d, 0x9d45f11f, 0x9448fa11, 0xe303934b, 0xea0e9845, 0xf1198557, 0xf8148e59, 0xc737bf73, 0xce3ab47d, 0xd52da96f, 0xdc20a261, 0x766df6ad, 0x7f60fda3, 0x6477e0b1, 0x6d7aebbf, 0x5259da95, 0x5b54d19b, 0x4043cc89, 0x494ec787, 0x3e05aedd, 0x3708a5d3, 0x2c1fb8c1, 0x2512b3cf, 0x1a3182e5, 0x133c89eb, 0x082b94f9, 0x01269ff7, 0xe6bd464d, 0xefb04d43, 0xf4a75051, 0xfdaa5b5f, 0xc2896a75, 0xcb84617b, 0xd0937c69, 0xd99e7767, 0xaed51e3d, 0xa7d81533, 0xbccf0821, 0xb5c2032f, 0x8ae13205, 0x83ec390b, 0x98fb2419, 0x91f62f17, 0x4dd68d76, 0x44db8678, 0x5fcc9b6a, 0x56c19064, 0x69e2a14e, 0x60efaa40, 0x7bf8b752, 0x72f5bc5c, 0x05bed506, 0x0cb3de08, 0x17a4c31a, 0x1ea9c814, 0x218af93e, 0x2887f230, 0x3390ef22, 0x3a9de42c, 0xdd063d96, 0xd40b3698, 0xcf1c2b8a, 0xc6112084, 0xf93211ae, 0xf03f1aa0, 0xeb2807b2, 0xe2250cbc, 0x956e65e6, 0x9c636ee8, 0x877473fa, 0x8e7978f4, 0xb15a49de, 0xb85742d0, 0xa3405fc2, 0xaa4d54cc, 0xecdaf741, 0xe5d7fc4f, 0xfec0e15d, 0xf7cdea53, 0xc8eedb79, 0xc1e3d077, 0xdaf4cd65, 0xd3f9c66b, 0xa4b2af31, 0xadbfa43f, 0xb6a8b92d, 0xbfa5b223, 0x80868309, 0x898b8807, 0x929c9515, 0x9b919e1b, 0x7c0a47a1, 0x75074caf, 0x6e1051bd, 0x671d5ab3, 0x583e6b99, 0x51336097, 0x4a247d85, 0x4329768b, 0x34621fd1, 0x3d6f14df, 0x267809cd, 0x2f7502c3, 0x105633e9, 0x195b38e7, 0x024c25f5, 0x0b412efb, 0xd7618c9a, 0xde6c8794, 0xc57b9a86, 0xcc769188, 0xf355a0a2, 0xfa58abac, 0xe14fb6be, 0xe842bdb0, 0x9f09d4ea, 0x9604dfe4, 0x8d13c2f6, 0x841ec9f8, 0xbb3df8d2, 0xb230f3dc, 0xa927eece, 0xa02ae5c0, 0x47b13c7a, 0x4ebc3774, 0x55ab2a66, 0x5ca62168, 0x63851042, 0x6a881b4c, 0x719f065e, 0x78920d50, 0x0fd9640a, 0x06d46f04, 0x1dc37216, 0x14ce7918, 0x2bed4832, 0x22e0433c, 0x39f75e2e, 0x30fa5520, 0x9ab701ec, 0x93ba0ae2, 0x88ad17f0, 0x81a01cfe, 0xbe832dd4, 0xb78e26da, 0xac993bc8, 0xa59430c6, 0xd2df599c, 0xdbd25292, 0xc0c54f80, 0xc9c8448e, 0xf6eb75a4, 0xffe67eaa, 0xe4f163b8, 0xedfc68b6, 0x0a67b10c, 0x036aba02, 0x187da710, 0x1170ac1e, 0x2e539d34, 0x275e963a, 0x3c498b28, 0x35448026, 0x420fe97c, 0x4b02e272, 0x5015ff60, 0x5918f46e, 0x663bc544, 0x6f36ce4a, 0x7421d358, 0x7d2cd856, 0xa10c7a37, 0xa8017139, 0xb3166c2b, 0xba1b6725, 0x8538560f, 0x8c355d01, 0x97224013, 0x9e2f4b1d, 0xe9642247, 0xe0692949, 0xfb7e345b, 0xf2733f55, 0xcd500e7f, 0xc45d0571, 0xdf4a1863, 0xd647136d, 0x31dccad7, 0x38d1c1d9, 0x23c6dccb, 0x2acbd7c5, 0x15e8e6ef, 0x1ce5ede1, 0x07f2f0f3, 0x0efffbfd, 0x79b492a7, 0x70b999a9, 0x6bae84bb, 0x62a38fb5, 0x5d80be9f, 0x548db591, 0x4f9aa883, 0x4697a38d];
97 |
98 | function convertToInt32(bytes) {
99 | var result = [];
100 | for (var i = 0; i < bytes.length; i += 4) {
101 | result.push(
102 | (bytes[i] << 24) |
103 | (bytes[i + 1] << 16) |
104 | (bytes[i + 2] << 8) |
105 | bytes[i + 3]
106 | );
107 | }
108 | return result;
109 | }
110 |
111 | var AES = function (key) {
112 | if (!(this instanceof AES)) {
113 | throw Error('AES must be instanitated with `new`');
114 | }
115 |
116 | Object.defineProperty(this, 'key', {
117 | value: coerceArray(key, true)
118 | });
119 |
120 | this._prepare();
121 | }
122 |
123 |
124 | AES.prototype._prepare = function () {
125 |
126 | var rounds = numberOfRounds[this.key.length];
127 | if (rounds == null) {
128 | throw new Error('invalid key size (must be 16, 24 or 32 bytes)');
129 | }
130 |
131 | // encryption round keys
132 | this._Ke = [];
133 |
134 | // decryption round keys
135 | this._Kd = [];
136 |
137 | for (var i = 0; i <= rounds; i++) {
138 | this._Ke.push([0, 0, 0, 0]);
139 | this._Kd.push([0, 0, 0, 0]);
140 | }
141 |
142 | var roundKeyCount = (rounds + 1) * 4;
143 | var KC = this.key.length / 4;
144 |
145 | // convert the key into ints
146 | var tk = convertToInt32(this.key);
147 |
148 | // copy values into round key arrays
149 | var index;
150 | for (var i = 0; i < KC; i++) {
151 | index = i >> 2;
152 | this._Ke[index][i % 4] = tk[i];
153 | this._Kd[rounds - index][i % 4] = tk[i];
154 | }
155 |
156 | // key expansion (fips-197 section 5.2)
157 | var rconpointer = 0;
158 | var t = KC, tt;
159 | while (t < roundKeyCount) {
160 | tt = tk[KC - 1];
161 | tk[0] ^= ((S[(tt >> 16) & 0xFF] << 24) ^
162 | (S[(tt >> 8) & 0xFF] << 16) ^
163 | (S[tt & 0xFF] << 8) ^
164 | S[(tt >> 24) & 0xFF] ^
165 | (rcon[rconpointer] << 24));
166 | rconpointer += 1;
167 |
168 | // key expansion (for non-256 bit)
169 | if (KC != 8) {
170 | for (var i = 1; i < KC; i++) {
171 | tk[i] ^= tk[i - 1];
172 | }
173 |
174 | // key expansion for 256-bit keys is "slightly different" (fips-197)
175 | } else {
176 | for (var i = 1; i < (KC / 2); i++) {
177 | tk[i] ^= tk[i - 1];
178 | }
179 | tt = tk[(KC / 2) - 1];
180 |
181 | tk[KC / 2] ^= (S[tt & 0xFF] ^
182 | (S[(tt >> 8) & 0xFF] << 8) ^
183 | (S[(tt >> 16) & 0xFF] << 16) ^
184 | (S[(tt >> 24) & 0xFF] << 24));
185 |
186 | for (var i = (KC / 2) + 1; i < KC; i++) {
187 | tk[i] ^= tk[i - 1];
188 | }
189 | }
190 |
191 | // copy values into round key arrays
192 | var i = 0, r, c;
193 | while (i < KC && t < roundKeyCount) {
194 | r = t >> 2;
195 | c = t % 4;
196 | this._Ke[r][c] = tk[i];
197 | this._Kd[rounds - r][c] = tk[i++];
198 | t++;
199 | }
200 | }
201 |
202 | // inverse-cipher-ify the decryption round key (fips-197 section 5.3)
203 | for (var r = 1; r < rounds; r++) {
204 | for (var c = 0; c < 4; c++) {
205 | tt = this._Kd[r][c];
206 | this._Kd[r][c] = (U1[(tt >> 24) & 0xFF] ^
207 | U2[(tt >> 16) & 0xFF] ^
208 | U3[(tt >> 8) & 0xFF] ^
209 | U4[tt & 0xFF]);
210 | }
211 | }
212 | }
213 |
214 | AES.prototype.encrypt = function (plaintext) {
215 | if (plaintext.length != 16) {
216 | throw new Error('invalid plaintext size (must be 16 bytes)');
217 | }
218 |
219 | var rounds = this._Ke.length - 1;
220 | var a = [0, 0, 0, 0];
221 |
222 | // convert plaintext to (ints ^ key)
223 | var t = convertToInt32(plaintext);
224 | for (var i = 0; i < 4; i++) {
225 | t[i] ^= this._Ke[0][i];
226 | }
227 |
228 | // apply round transforms
229 | for (var r = 1; r < rounds; r++) {
230 | for (var i = 0; i < 4; i++) {
231 | a[i] = (T1[(t[i] >> 24) & 0xff] ^
232 | T2[(t[(i + 1) % 4] >> 16) & 0xff] ^
233 | T3[(t[(i + 2) % 4] >> 8) & 0xff] ^
234 | T4[t[(i + 3) % 4] & 0xff] ^
235 | this._Ke[r][i]);
236 | }
237 | t = a.slice();
238 | }
239 |
240 | // the last round is special
241 | var result = createArray(16), tt;
242 | for (var i = 0; i < 4; i++) {
243 | tt = this._Ke[rounds][i];
244 | result[4 * i] = (S[(t[i] >> 24) & 0xff] ^ (tt >> 24)) & 0xff;
245 | result[4 * i + 1] = (S[(t[(i + 1) % 4] >> 16) & 0xff] ^ (tt >> 16)) & 0xff;
246 | result[4 * i + 2] = (S[(t[(i + 2) % 4] >> 8) & 0xff] ^ (tt >> 8)) & 0xff;
247 | result[4 * i + 3] = (S[t[(i + 3) % 4] & 0xff] ^ tt) & 0xff;
248 | }
249 |
250 | return result;
251 | }
252 |
253 | AES.prototype.decrypt = function (ciphertext) {
254 | if (ciphertext.length != 16) {
255 | throw new Error('invalid ciphertext size (must be 16 bytes)');
256 | }
257 |
258 | var rounds = this._Kd.length - 1;
259 | var a = [0, 0, 0, 0];
260 |
261 | // convert plaintext to (ints ^ key)
262 | var t = convertToInt32(ciphertext);
263 | for (var i = 0; i < 4; i++) {
264 | t[i] ^= this._Kd[0][i];
265 | }
266 |
267 | // apply round transforms
268 | for (var r = 1; r < rounds; r++) {
269 | for (var i = 0; i < 4; i++) {
270 | a[i] = (T5[(t[i] >> 24) & 0xff] ^
271 | T6[(t[(i + 3) % 4] >> 16) & 0xff] ^
272 | T7[(t[(i + 2) % 4] >> 8) & 0xff] ^
273 | T8[t[(i + 1) % 4] & 0xff] ^
274 | this._Kd[r][i]);
275 | }
276 | t = a.slice();
277 | }
278 |
279 | // the last round is special
280 | var result = createArray(16), tt;
281 | for (var i = 0; i < 4; i++) {
282 | tt = this._Kd[rounds][i];
283 | result[4 * i] = (Si[(t[i] >> 24) & 0xff] ^ (tt >> 24)) & 0xff;
284 | result[4 * i + 1] = (Si[(t[(i + 3) % 4] >> 16) & 0xff] ^ (tt >> 16)) & 0xff;
285 | result[4 * i + 2] = (Si[(t[(i + 2) % 4] >> 8) & 0xff] ^ (tt >> 8)) & 0xff;
286 | result[4 * i + 3] = (Si[t[(i + 1) % 4] & 0xff] ^ tt) & 0xff;
287 | }
288 |
289 | return result;
290 | }
291 |
292 |
293 | /**
294 | * Mode Of Operation - Electonic Codebook (ECB)
295 | */
296 | export var AESECB = function (key) {
297 | if (!(this instanceof AESECB)) {
298 | throw Error('AES must be instanitated with `new`');
299 | }
300 |
301 | this.description = "Electronic Code Block";
302 | this.name = "ecb";
303 |
304 | this._aes = new AES(key);
305 | }
306 |
307 | AESECB.prototype.encrypt = function (plaintext) {
308 | plaintext = coerceArray(plaintext);
309 |
310 | if ((plaintext.length % 16) !== 0) {
311 | throw new Error('invalid plaintext size (must be multiple of 16 bytes)');
312 | }
313 |
314 | var ciphertext = createArray(plaintext.length);
315 | var block = createArray(16);
316 |
317 | for (var i = 0; i < plaintext.length; i += 16) {
318 | copyArray(plaintext, block, 0, i, i + 16);
319 | block = this._aes.encrypt(block);
320 | copyArray(block, ciphertext, i);
321 | }
322 |
323 | return ciphertext;
324 | }
325 |
326 | AESECB.prototype.decrypt = function (ciphertext) {
327 | ciphertext = coerceArray(ciphertext);
328 |
329 | if ((ciphertext.length % 16) !== 0) {
330 | throw new Error('invalid ciphertext size (must be multiple of 16 bytes)');
331 | }
332 |
333 | var plaintext = createArray(ciphertext.length);
334 | var block = createArray(16);
335 |
336 | for (var i = 0; i < ciphertext.length; i += 16) {
337 | copyArray(ciphertext, block, 0, i, i + 16);
338 | block = this._aes.decrypt(block);
339 | copyArray(block, plaintext, i);
340 | }
341 |
342 | return plaintext;
343 | }
344 |
345 |
346 | /**
347 | * Mode Of Operation - Cipher Block Chaining (CBC)
348 | */
349 | export var AESCBC = function (key, iv) {
350 | if (!(this instanceof AESCBC)) {
351 | throw Error('AES must be instanitated with `new`');
352 | }
353 |
354 | this.description = "Cipher Block Chaining";
355 | this.name = "cbc";
356 |
357 | if (!iv) {
358 | iv = createArray(16);
359 |
360 | } else if (iv.length != 16) {
361 | throw new Error('invalid initialation vector size (must be 16 bytes)');
362 | }
363 |
364 | this._lastCipherblock = coerceArray(iv, true);
365 |
366 | this._aes = new AES(key);
367 | }
368 |
369 | AESCBC.prototype.encrypt = function (plaintext) {
370 | plaintext = coerceArray(plaintext);
371 |
372 | if ((plaintext.length % 16) !== 0) {
373 | throw new Error('invalid plaintext size (must be multiple of 16 bytes)');
374 | }
375 |
376 | var ciphertext = createArray(plaintext.length);
377 | var block = createArray(16);
378 |
379 | for (var i = 0; i < plaintext.length; i += 16) {
380 | copyArray(plaintext, block, 0, i, i + 16);
381 |
382 | for (var j = 0; j < 16; j++) {
383 | block[j] ^= this._lastCipherblock[j];
384 | }
385 |
386 | this._lastCipherblock = this._aes.encrypt(block);
387 | copyArray(this._lastCipherblock, ciphertext, i);
388 | }
389 |
390 | return ciphertext;
391 | }
392 |
393 | AESCBC.prototype.decrypt = function (ciphertext) {
394 | ciphertext = coerceArray(ciphertext);
395 |
396 | if ((ciphertext.length % 16) !== 0) {
397 | throw new Error('invalid ciphertext size (must be multiple of 16 bytes)');
398 | }
399 |
400 | var plaintext = createArray(ciphertext.length);
401 | var block = createArray(16);
402 |
403 | for (var i = 0; i < ciphertext.length; i += 16) {
404 | copyArray(ciphertext, block, 0, i, i + 16);
405 | block = this._aes.decrypt(block);
406 |
407 | for (var j = 0; j < 16; j++) {
408 | plaintext[i + j] = block[j] ^ this._lastCipherblock[j];
409 | }
410 |
411 | copyArray(ciphertext, this._lastCipherblock, 0, i, i + 16);
412 | }
413 |
414 | return plaintext;
415 | }
416 |
417 |
418 | /**
419 | * Mode Of Operation - Cipher Feedback (CFB)
420 | */
421 | export var AESCFB = function (key, iv, segmentSize) {
422 | if (!(this instanceof AESCFB)) {
423 | throw Error('AES must be instanitated with `new`');
424 | }
425 |
426 | this.description = "Cipher Feedback";
427 | this.name = "cfb";
428 |
429 | if (!iv) {
430 | iv = createArray(16);
431 |
432 | } else if (iv.length != 16) {
433 | throw new Error('invalid initialation vector size (must be 16 size)');
434 | }
435 |
436 | if (!segmentSize) { segmentSize = 1; }
437 |
438 | this.segmentSize = segmentSize;
439 |
440 | this._shiftRegister = coerceArray(iv, true);
441 |
442 | this._aes = new AES(key);
443 | }
444 |
445 | AESCFB.prototype.encrypt = function (plaintext) {
446 | if ((plaintext.length % this.segmentSize) != 0) {
447 | throw new Error('invalid plaintext size (must be segmentSize bytes)');
448 | }
449 |
450 | var encrypted = coerceArray(plaintext, true);
451 |
452 | var xorSegment;
453 | for (var i = 0; i < encrypted.length; i += this.segmentSize) {
454 | xorSegment = this._aes.encrypt(this._shiftRegister);
455 | for (var j = 0; j < this.segmentSize; j++) {
456 | encrypted[i + j] ^= xorSegment[j];
457 | }
458 |
459 | // Shift the register
460 | copyArray(this._shiftRegister, this._shiftRegister, 0, this.segmentSize);
461 | copyArray(encrypted, this._shiftRegister, 16 - this.segmentSize, i, i + this.segmentSize);
462 | }
463 |
464 | return encrypted;
465 | }
466 |
467 | AESCFB.prototype.decrypt = function (ciphertext) {
468 | if ((ciphertext.length % this.segmentSize) != 0) {
469 | throw new Error('invalid ciphertext size (must be segmentSize bytes)');
470 | }
471 |
472 | var plaintext = coerceArray(ciphertext, true);
473 |
474 | var xorSegment;
475 | for (var i = 0; i < plaintext.length; i += this.segmentSize) {
476 | xorSegment = this._aes.encrypt(this._shiftRegister);
477 |
478 | for (var j = 0; j < this.segmentSize; j++) {
479 | plaintext[i + j] ^= xorSegment[j];
480 | }
481 |
482 | // Shift the register
483 | copyArray(this._shiftRegister, this._shiftRegister, 0, this.segmentSize);
484 | copyArray(ciphertext, this._shiftRegister, 16 - this.segmentSize, i, i + this.segmentSize);
485 | }
486 |
487 | return plaintext;
488 | }
489 |
490 | /**
491 | * Mode Of Operation - Output Feedback (OFB)
492 | */
493 | export var AESOFB = function (key, iv) {
494 | if (!(this instanceof AESOFB)) {
495 | throw Error('AES must be instanitated with `new`');
496 | }
497 |
498 | this.description = "Output Feedback";
499 | this.name = "ofb";
500 |
501 | if (!iv) {
502 | iv = createArray(16);
503 |
504 | } else if (iv.length != 16) {
505 | throw new Error('invalid initialation vector size (must be 16 bytes)');
506 | }
507 |
508 | this._lastPrecipher = coerceArray(iv, true);
509 | this._lastPrecipherIndex = 16;
510 |
511 | this._aes = new AES(key);
512 | }
513 |
514 | AESOFB.prototype.encrypt = function (plaintext) {
515 | var encrypted = coerceArray(plaintext, true);
516 |
517 | for (var i = 0; i < encrypted.length; i++) {
518 | if (this._lastPrecipherIndex === 16) {
519 | this._lastPrecipher = this._aes.encrypt(this._lastPrecipher);
520 | this._lastPrecipherIndex = 0;
521 | }
522 | encrypted[i] ^= this._lastPrecipher[this._lastPrecipherIndex++];
523 | }
524 |
525 | return encrypted;
526 | }
527 |
528 | // Decryption is symetric
529 | AESOFB.prototype.decrypt = AESOFB.prototype.encrypt;
530 |
531 |
532 | /**
533 | * Counter object for CTR common mode of operation
534 | */
535 | var Counter = function (initialValue) {
536 | if (!(this instanceof Counter)) {
537 | throw Error('Counter must be instanitated with `new`');
538 | }
539 |
540 | // We allow 0, but anything false-ish uses the default 1
541 | if (initialValue !== 0 && !initialValue) { initialValue = 1; }
542 |
543 | if (typeof (initialValue) === 'number') {
544 | this._counter = createArray(16);
545 | this.setValue(initialValue);
546 |
547 | } else {
548 | this.setBytes(initialValue);
549 | }
550 | }
551 |
552 | Counter.prototype.setValue = function (value) {
553 | if (typeof (value) !== 'number' || parseInt(value) != value) {
554 | throw new Error('invalid counter value (must be an integer)');
555 | }
556 |
557 | // We cannot safely handle numbers beyond the safe range for integers
558 | if (value > Number.MAX_SAFE_INTEGER) {
559 | throw new Error('integer value out of safe range');
560 | }
561 |
562 | for (var index = 15; index >= 0; --index) {
563 | this._counter[index] = value % 256;
564 | value = parseInt(value / 256);
565 | }
566 | }
567 |
568 | Counter.prototype.setBytes = function (bytes) {
569 | bytes = coerceArray(bytes, true);
570 |
571 | if (bytes.length != 16) {
572 | throw new Error('invalid counter bytes size (must be 16 bytes)');
573 | }
574 |
575 | this._counter = bytes;
576 | };
577 |
578 | Counter.prototype.increment = function () {
579 | for (var i = 15; i >= 0; i--) {
580 | if (this._counter[i] === 255) {
581 | this._counter[i] = 0;
582 | } else {
583 | this._counter[i]++;
584 | break;
585 | }
586 | }
587 | }
588 |
589 |
590 | /**
591 | * Mode Of Operation - Counter (CTR)
592 | */
593 | export var AESCTR = function (key, counter) {
594 | if (!(this instanceof AESCTR)) {
595 | throw Error('AES must be instanitated with `new`');
596 | }
597 |
598 | this.description = "Counter";
599 | this.name = "ctr";
600 |
601 | if (!(counter instanceof Counter)) {
602 | counter = new Counter(counter)
603 | }
604 |
605 | this._counter = counter;
606 |
607 | this._remainingCounter = null;
608 | this._remainingCounterIndex = 16;
609 |
610 | this._aes = new AES(key);
611 | }
612 |
613 | AESCTR.prototype.encrypt = function (plaintext) {
614 | var encrypted = coerceArray(plaintext, true);
615 |
616 | for (var i = 0; i < encrypted.length; i++) {
617 | if (this._remainingCounterIndex === 16) {
618 | this._remainingCounter = this._aes.encrypt(this._counter._counter);
619 | this._remainingCounterIndex = 0;
620 | this._counter.increment();
621 | }
622 | encrypted[i] ^= this._remainingCounter[this._remainingCounterIndex++];
623 | }
624 |
625 | return encrypted;
626 | }
627 |
628 | // Decryption is symetric
629 | AESCTR.prototype.decrypt = AESCTR.prototype.encrypt;
630 |
--------------------------------------------------------------------------------
/lib/api.ts:
--------------------------------------------------------------------------------
1 | import type { Bike, BikeCredentials } from './bike'
2 | import { createContext } from 'react'
3 |
4 | export const API_KEY = 'fcb38d47-f14b-30cf-843b-26283f6a5819'
5 |
6 | export interface ApiCredentials {
7 | token: string
8 | refreshToken: string
9 | }
10 |
11 | export interface BikeShareEntry {
12 | guid: string
13 | expiresAt: string
14 | startsAt: null
15 | endsAt: null
16 | duration: number
17 | role: string
18 | email: string
19 | }
20 |
21 | async function checkErrorAndUnwrap(req: Response): Promise {
22 | const resp = await req.text()
23 |
24 | // Try parse the json or throw the resp
25 | let jsonResp
26 | try {
27 | jsonResp = JSON.parse(resp)
28 | } catch (e) {
29 | throw resp
30 | }
31 |
32 | // Always throw the error if that apears in the responsse
33 | if (jsonResp.error) throw jsonResp.error.toString()
34 |
35 | // Always throw if the response status is above equal or above 400
36 | if (req.status >= 400)
37 | return jsonResp.message.toString() || jsonResp.toString()
38 |
39 | return jsonResp
40 | }
41 |
42 | export class Api {
43 | /*
44 | TODO: Add support for the refresh token
45 | */
46 |
47 | private credentials: ApiCredentials
48 |
49 | constructor(credentials: ApiCredentials) {
50 | this.credentials = credentials
51 | if (!credentials.token || !credentials.refreshToken)
52 | throw 'login failed, missing token or refreshToken'
53 | }
54 |
55 | private get authHeader() {
56 | return {
57 | 'Api-Key': API_KEY,
58 | 'Authorization': 'Bearer ' + this.credentials.token,
59 | }
60 | }
61 |
62 | async getBikeCredentials(): Promise> {
63 | const req = await fetch(`/api/my_vanmoof_com/getCustomerData?includeBikeDetails`, {
64 | headers: this.authHeader,
65 | })
66 | const resp = await checkErrorAndUnwrap(req)
67 |
68 | const bikes = resp.data.bikeDetails
69 | if (bikes.length == 0)
70 | throw 'You don\'t have a bike connected to your account'
71 |
72 | const supportedBikes = bikes.filter((b: any) => b.key && b.key.encryptionKey && b.key.userKeyId)
73 |
74 | return supportedBikes.map((b: any): BikeCredentials => ({
75 | id: b.id,
76 | mac: b.macAddress,
77 | encryptionKey: b.key.encryptionKey,
78 | userKeyId: b.key.userKeyId,
79 |
80 | name: b.name,
81 | ownerName: b.ownerName,
82 |
83 | modelColor: b.modelColor,
84 | links: b.links,
85 | }))
86 | }
87 |
88 | async createBikeSharingInvitation(bike: Bike, email: string, durationInSeconds: undefined | number): Promise {
89 | const body: any = {
90 | email,
91 | bikeId: bike.id,
92 | role: "user",
93 | }
94 | if (durationInSeconds !== undefined)
95 | body['duration'] = durationInSeconds
96 |
97 | let req = await fetch(`/api/api_vanmoof-api_com/createBikeSharingInvitation`, {
98 | method: 'POST',
99 | headers: {
100 | ...this.authHeader,
101 | 'Content-Type': 'application/json'
102 | },
103 | body: JSON.stringify(body)
104 | })
105 |
106 | return await checkErrorAndUnwrap(req)
107 | }
108 |
109 | async getCurrentShares(bikeid: number | string): Promise> {
110 | let req = await fetch(`/api/api_vanmoof-api_com/getBikeSharingInvitationsForBike/${bikeid}`, {
111 | method: 'GET',
112 | headers: {
113 | ...this.authHeader,
114 | 'Content-Type': 'application/json'
115 | }
116 | })
117 | const resp = await checkErrorAndUnwrap(req)
118 | return resp.invitations || []
119 | }
120 |
121 | async removeShareHolder(guid: string): Promise {
122 | let req = await fetch(`/api/api_vanmoof-api_com/revokeBikeSharingInvitation/${guid}`, {
123 | method: 'POST',
124 | headers: {
125 | ...this.authHeader,
126 | 'Content-Type': 'application/json'
127 | }
128 | })
129 | return await checkErrorAndUnwrap(req)
130 | }
131 |
132 | storeCredentialsInLocalStorage() {
133 | localStorage.setItem('vm-api-credentials', JSON.stringify(this.credentials))
134 | }
135 |
136 | }
137 |
138 | export const ApiContext = createContext(undefined)
139 |
--------------------------------------------------------------------------------
/lib/bike.ts:
--------------------------------------------------------------------------------
1 | import { createContext } from 'react'
2 | import CRC32 from 'crc-32'
3 | import { AESECB } from './aes'
4 | import { Queue } from './queue'
5 |
6 | export const BikeContext = createContext({} as Bike)
7 |
8 | export enum PowerLevel {
9 | Off = 0,
10 | First = 1,
11 | Second = 2,
12 | Third = 3,
13 | Fourth = 4,
14 | Max = 5,
15 | }
16 |
17 | export enum BellTone {
18 | Bell = 0x16,
19 | Sonar = 0x0a,
20 | Party = 0x17,
21 | Foghorn = 0x18,
22 | }
23 |
24 | export enum SpeedLimit {
25 | JP = 2,
26 | EU = 0,
27 | US = 1,
28 | NO_LIMIT = 3,
29 | }
30 |
31 | const wait = (timeout: number): Promise =>
32 | new Promise(res => setTimeout(res, timeout))
33 |
34 | export class Bike {
35 | mac: string
36 | id: string | number | undefined
37 | server: BluetoothRemoteGATTServer
38 | encryptionKey: string
39 | userKeyId: number
40 | aesEcb: AESECB
41 | queue: Queue
42 |
43 | constructor(credentials: BikeCredentials, server: BluetoothRemoteGATTServer) {
44 | this.mac = credentials.mac
45 | this.id = credentials.id
46 | this.encryptionKey = credentials.encryptionKey
47 | this.userKeyId = credentials.userKeyId
48 | this.server = server
49 | this.aesEcb = new AESECB(new Uint8Array(Buffer.from(this.encryptionKey, 'hex')))
50 | this.queue = new Queue
51 | }
52 |
53 | private async makeEncryptedPayloadWithoutQueue(data: Uint8Array): Promise {
54 | const nonce = await this.bluetoothReadWithoutQueue(CHALLENGE, false)
55 | const paddLength = 16 - ((nonce.length + data.length) % 16)
56 | const dataToEncrypt = new Uint8Array([
57 | ...nonce,
58 | ...data,
59 | ...new Uint8Array(paddLength),
60 | ])
61 | return this.aesEcb.encrypt(dataToEncrypt)
62 | }
63 |
64 | private decrypt(data: Uint8Array): Uint8Array {
65 | let decryptedValue = this.aesEcb.decrypt(data).reverse()
66 | for (const v of decryptedValue) {
67 | if (v != 0) {
68 | decryptedValue.slice()
69 | break
70 | }
71 | decryptedValue = decryptedValue.slice(1)
72 | }
73 | return decryptedValue.reverse()
74 | }
75 |
76 | private async bluetoothReadWithoutQueue(characteristic: Characteristic, decrypt = true): Promise {
77 | let lastError: any;
78 | for (let retry = 0; retry < 5; retry++) {
79 | if (retry != 0) {
80 | console.log('retrying to read bluetooth value, attempt:', retry)
81 | }
82 |
83 | try {
84 | const bluetoothService = await this.server.getPrimaryService(characteristic.service)
85 | const bluetoothCharacteristic = await bluetoothService.getCharacteristic(characteristic.id)
86 | const buff = await bluetoothCharacteristic.readValue()
87 | const data = new Uint8Array(buff.buffer)
88 | return decrypt ? this.decrypt(data) : data
89 | } catch (e) {
90 | lastError = e
91 | }
92 | }
93 | throw lastError
94 | }
95 |
96 | private async bluetoothRead(characteristic: Characteristic, decrypt = true): Promise {
97 | return await this.queue.push(() => this.bluetoothReadWithoutQueue(characteristic, decrypt))
98 | }
99 |
100 | private async bluetoothWriteWithoutQueue(characteristic: Characteristic, data: Uint8Array, encrypted = true) {
101 | const payload = encrypted ? await this.makeEncryptedPayloadWithoutQueue(data) : data
102 | const bluetoothService = await this.server.getPrimaryService(characteristic.service)
103 | const bluetoothCharacteristic = await bluetoothService.getCharacteristic(characteristic.id)
104 | await bluetoothCharacteristic.writeValue(payload)
105 | }
106 |
107 | private async bluetoothWrite(characteristic: Characteristic, data: Uint8Array, encrypted = true) {
108 | await this.queue.push(() => this.bluetoothWriteWithoutQueue(characteristic, data, encrypted))
109 | }
110 |
111 | private async bluetoothReadWrite(characteristic: Characteristic, data: Uint8Array, { encryptedAndDecrypt = true, timeout = 0 }): Promise {
112 | return await this.queue.push(async () => {
113 | await this.bluetoothWriteWithoutQueue(characteristic, data, encryptedAndDecrypt)
114 | if (timeout != 0) await wait(timeout)
115 | return await this.bluetoothReadWithoutQueue(characteristic, encryptedAndDecrypt)
116 | })
117 | }
118 |
119 | async authenticate(playSuccessSound = true) {
120 | const nonce = await this.bluetoothRead(CHALLENGE, false)
121 | const dataToEncrypt = new Uint8Array(16)
122 | dataToEncrypt.set(nonce)
123 | const encryptedData = this.aesEcb.encrypt(dataToEncrypt)
124 | const data = new Uint8Array([...encryptedData, 0, 0, 0, this.userKeyId])
125 | await this.bluetoothWrite(KEY_INDEX, data, false)
126 | if (playSuccessSound)
127 | await this.playSound(0x1)
128 | }
129 |
130 | async bikeFirmwareVersion(): Promise {
131 | const value = await this.bluetoothRead(BIKE_FIRMWARE_VERSION)
132 | const strValue = new TextDecoder().decode(value)
133 | return strValue.split('.').map(part => part.match(/^0+(.+)/)?.[1] ?? part).join('.')
134 | }
135 |
136 | async batteryChargingLevel(): Promise {
137 | const value = await this.bluetoothRead(MOTOR_BATTERY_LEVEL);
138 | return value[0];
139 | }
140 |
141 | // returns the distance in kilometers
142 | async bikeDistance(): Promise {
143 | const distanceInBytes = await this.bluetoothRead(DISTANCE)
144 | const distance = distanceInBytes.reduce((acc, v, idx) => acc + (v << (idx * 8)), 0)
145 | return distance / 10
146 | }
147 |
148 | // disconnect the bluetooth connection
149 | // this makes the bike also available for other devices again
150 | disconnect() {
151 | this.server.disconnect()
152 | }
153 |
154 | // checkConnection throws if the bike is not connected anymore and is unable to be reconnected with
155 | async checkConnection() {
156 | if (this.server.connected) return
157 | console.log('trying to reconnect..')
158 | await this.server.connect()
159 | // Re-authenticate
160 | await this.authenticate(false)
161 | console.log('success reconnecting..')
162 | }
163 |
164 | async playSound(id: number) {
165 | await this.bluetoothWrite(PLAY_SOUND, new Uint8Array([id, 0x1]))
166 | }
167 |
168 | async getPowerLvl(): Promise {
169 | const result = await this.bluetoothRead(POWER_LEVEL)
170 | return result[0] as PowerLevel
171 | }
172 |
173 | async setPowerLvl(lvl: PowerLevel): Promise {
174 | const result = await this.bluetoothReadWrite(POWER_LEVEL, new Uint8Array([lvl, 0x1]), {})
175 | return result[0] as PowerLevel
176 | }
177 |
178 | async getBellTone(): Promise {
179 | const result = await this.bluetoothRead(BELL_SOUND)
180 | return result[0] as BellTone
181 | }
182 |
183 | async setBellTone(bell: number): Promise {
184 | await this.bluetoothWrite(BELL_SOUND, new Uint8Array([bell, 0x1]))
185 | return bell
186 | }
187 |
188 | async getSpeedLimit(): Promise {
189 | const result = await this.bluetoothRead(SPEED_LIMIT)
190 | return uwnrapSpeedLimit(result)
191 | }
192 |
193 | async setSpeedLimit(limit: SpeedLimit): Promise {
194 | const result = await this.bluetoothReadWrite(SPEED_LIMIT, new Uint8Array([limit, 0x1]), { timeout: 400 })
195 | return uwnrapSpeedLimit(result)
196 | }
197 |
198 | async initiateBellSoundTransfer(buffer: ArrayBuffer): Promise {
199 | const fileHeader = new Uint8Array(9)
200 | fileHeader.set([0x19], 0)
201 |
202 | const fileSize = buffer.byteLength
203 | fileHeader.set([fileSize >> 24, fileSize >> 16, fileSize >> 8, fileSize], 1)
204 |
205 | const crc = CRC32.buf(new Uint8Array(buffer))
206 | fileHeader.set([crc >> 24, crc >> 16, crc >> 8, crc], 5)
207 |
208 | return await this.bluetoothWrite(FIRMWARE_METADATA, new Uint8Array(fileHeader))
209 | }
210 |
211 | async sendBellSoundChunk(chunk: ArrayBuffer): Promise {
212 | return await this.bluetoothWrite(FIRMWARE_BLOCK, new Uint8Array(chunk), false)
213 | }
214 | }
215 |
216 | export interface BikeCredentials {
217 | id?: string
218 | mac: string
219 | encryptionKey: string
220 | userKeyId: number
221 |
222 | name: string
223 | ownerName?: string
224 |
225 | modelColor: null | {
226 | name: 'Dark' | string // TODO find out what other colors this can be
227 | primary: string
228 | secondary: string
229 | }
230 | links: null | {
231 | hash: string
232 | thumbnail: string
233 | }
234 | }
235 |
236 | export async function connectToBike(credentials: BikeCredentials): Promise {
237 | const device = await navigator.bluetooth.requestDevice({
238 | filters: [
239 | { name: 'ES3-' + credentials.mac.replaceAll(':', '').toUpperCase() },
240 | { name: 'EX3-' + credentials.mac.replaceAll(':', '').toUpperCase() }
241 | ],
242 | optionalServices: [SECURITY_SERVICE, DEFENSE_SERVICE, MOVEMENT_SERVICE, BIKE_INFO_SERVICE, BIKE_STATE_SERVICE, SOUND_SERVICE, LIGHT_SERVICE, FIRMWARE_SERVICE]
243 | })
244 |
245 | const gatt = device.gatt
246 | if (!gatt) throw `gatt property not found`
247 | const server = await gatt.connect()
248 | if (!server.connected) throw `device not connected`
249 |
250 | return new Bike(credentials, server)
251 | }
252 |
253 | function uwnrapSpeedLimit(data: Uint8Array): SpeedLimit {
254 | const lvlNr = data[0]
255 | if (lvlNr === undefined) return SpeedLimit.EU
256 | if (lvlNr === 255) return SpeedLimit.NO_LIMIT
257 | return lvlNr as SpeedLimit
258 | }
259 |
260 | export interface Characteristic {
261 | service: string
262 | id: string
263 | }
264 |
265 | function c(service: string, characteristic: string): Characteristic {
266 | return {
267 | service,
268 | id: characteristic,
269 | }
270 | }
271 |
272 | // Security
273 | const SECURITY_SERVICE = "6acc5500-e631-4069-944d-b8ca7598ad50"
274 | export const CHALLENGE = c(SECURITY_SERVICE, "6acc5501-e631-4069-944d-b8ca7598ad50")
275 | export const KEY_INDEX = c(SECURITY_SERVICE, "6acc5502-e631-4069-944d-b8ca7598ad50")
276 | export const BACKUP_CODE = c(SECURITY_SERVICE, "6acc5503-e631-4069-944d-b8ca7598ad50")
277 | export const BIKE_MESSAGE = c(SECURITY_SERVICE, "6acc5505-e631-4069-944d-b8ca7598ad50")
278 |
279 | // Defense
280 | const DEFENSE_SERVICE = "6acc5520-e631-4069-944d-b8ca7598ad50"
281 | export const LOCK_STATE = c(DEFENSE_SERVICE, "6acc5521-e631-4069-944d-b8ca7598ad50")
282 | export const UNLOCK_REQUEST = c(DEFENSE_SERVICE, "6acc5522-e631-4069-944d-b8ca7598ad50")
283 | export const ALARM_STATE = c(DEFENSE_SERVICE, "6acc5523-e631-4069-944d-b8ca7598ad50")
284 | export const ALARM_MODE = c(DEFENSE_SERVICE, "6acc5524-e631-4069-944d-b8ca7598ad50")
285 |
286 | // Movement
287 | const MOVEMENT_SERVICE = "6acc5530-e631-4069-944d-b8ca7598ad50"
288 | export const DISTANCE = c(MOVEMENT_SERVICE, "6acc5531-e631-4069-944d-b8ca7598ad50")
289 | export const SPEED = c(MOVEMENT_SERVICE, "6acc5532-e631-4069-944d-b8ca7598ad50")
290 | export const UNIT_SYSTEM = c(MOVEMENT_SERVICE, "6acc5533-e631-4069-944d-b8ca7598ad50")
291 | export const POWER_LEVEL = c(MOVEMENT_SERVICE, "6acc5534-e631-4069-944d-b8ca7598ad50")
292 | export const SPEED_LIMIT = c(MOVEMENT_SERVICE, "6acc5535-e631-4069-944d-b8ca7598ad50")
293 | export const E_SHIFTER_GEAR = c(MOVEMENT_SERVICE, "6acc5536-e631-4069-944d-b8ca7598ad50")
294 | export const E_SHIFTIG_POINTS = c(MOVEMENT_SERVICE, "6acc5537-e631-4069-944d-b8ca7598ad50")
295 | export const E_SHIFTER_MODE = c(MOVEMENT_SERVICE, "6acc5538-e631-4069-944d-b8ca7598ad50")
296 |
297 | // BikeInfo
298 | const BIKE_INFO_SERVICE = "6acc5540-e631-4069-944d-b8ca7598ad50"
299 | export const MOTOR_BATTERY_LEVEL = c(BIKE_INFO_SERVICE, "6acc5541-e631-4069-944d-b8ca7598ad50")
300 | export const MOTOR_BATTERY_STATE = c(BIKE_INFO_SERVICE, "6acc5542-e631-4069-944d-b8ca7598ad50")
301 | export const MODULE_BATTERY_LEVEL = c(BIKE_INFO_SERVICE, "6acc5543-e631-4069-944d-b8ca7598ad50")
302 | export const MODULE_BATTERY_STATE = c(BIKE_INFO_SERVICE, "6acc5544-e631-4069-944d-b8ca7598ad50")
303 | export const BIKE_FIRMWARE_VERSION = c(BIKE_INFO_SERVICE, "6acc554a-e631-4069-944d-b8ca7598ad50")
304 | export const BLE_CHIP_FIRMWARE_VERSION = c(BIKE_INFO_SERVICE, "6acc554b-e631-4069-944d-b8ca7598ad50")
305 | export const CONTROLLER_FIRMWARE_VERSION = c(BIKE_INFO_SERVICE, "6acc554c-e631-4069-944d-b8ca7598ad50")
306 | export const PCBA_HARDWARE_VERSION = c(BIKE_INFO_SERVICE, "6acc554d-e631-4069-944d-b8ca7598ad50")
307 | export const GSM_FIRMWARE_VERSION = c(BIKE_INFO_SERVICE, "6acc554e-e631-4069-944d-b8ca7598ad50")
308 | export const E_SHIFTER_FIRMWARE_VERSION = c(BIKE_INFO_SERVICE, "6acc554f-e631-4069-944d-b8ca7598ad50")
309 | export const BATTERY_FIRMWARE_VERSION = c(BIKE_INFO_SERVICE, "6acc5550-e631-4069-944d-b8ca7598ad50")
310 | // data returned seems to be firmware version info?
311 | export const _UNKNOWN = c(BIKE_INFO_SERVICE, "6acc5551-e631-4069-944d-b8ca7598ad50")
312 | export const FRAME_NUMBER = c(BIKE_INFO_SERVICE, "6acc5552-e631-4069-944d-b8ca7598ad50")
313 |
314 | // BikeState
315 | const BIKE_STATE_SERVICE = "6acc5560-e631-4069-944d-b8ca7598ad50"
316 | export const MODULE_MODE = c(BIKE_STATE_SERVICE, "6acc5561-e631-4069-944d-b8ca7598ad50")
317 | export const MODULE_STATE = c(BIKE_STATE_SERVICE, "6acc5562-e631-4069-944d-b8ca7598ad50")
318 | export const ERRORS = c(BIKE_STATE_SERVICE, "6acc5563-e631-4069-944d-b8ca7598ad50")
319 | export const WHEEL_SIZE = c(BIKE_STATE_SERVICE, "6acc5564-e631-4069-944d-b8ca7598ad50")
320 | export const CLOCK = c(BIKE_STATE_SERVICE, "6acc5567-e631-4069-944d-b8ca7598ad50")
321 |
322 | // Sound
323 | const SOUND_SERVICE = "6acc5570-e631-4069-944d-b8ca7598ad50"
324 | export const PLAY_SOUND = c(SOUND_SERVICE, "6acc5571-e631-4069-944d-b8ca7598ad50")
325 | export const SOUND_VOLUME = c(SOUND_SERVICE, "6acc5572-e631-4069-944d-b8ca7598ad50")
326 | export const BELL_SOUND = c(SOUND_SERVICE, "6acc5574-e631-4069-944d-b8ca7598ad50")
327 |
328 | // Light
329 | const LIGHT_SERVICE = "6acc5580-e631-4069-944d-b8ca7598ad50"
330 | export const LIGHT_MODE = c(LIGHT_SERVICE, "6acc5581-e631-4069-944d-b8ca7598ad50")
331 | export const SENSOR = c(LIGHT_SERVICE, "6acc5584-e631-4069-944d-b8ca7598ad50")
332 |
333 | // Firmware upload
334 | const FIRMWARE_SERVICE = "6acc5510-e631-4069-944d-b8ca7598ad50"
335 | export const FIRMWARE_METADATA = c(FIRMWARE_SERVICE, "6acc5511-e631-4069-944d-b8ca7598ad50")
336 | export const FIRMWARE_BLOCK = c(FIRMWARE_SERVICE, "6acc5512-e631-4069-944d-b8ca7598ad50")
--------------------------------------------------------------------------------
/lib/queue.ts:
--------------------------------------------------------------------------------
1 | interface APromise {
2 | action(): Promise
3 | res(data: T): any
4 | rej(reason?: any): any
5 | }
6 |
7 | export class Queue {
8 | private queue: Array> = []
9 | private running = false
10 |
11 | public push(action: () => Promise): Promise {
12 | return new Promise((res, rej) => {
13 | this.queue.push({
14 | action,
15 | res,
16 | rej,
17 | })
18 | this.run()
19 | })
20 | }
21 |
22 | private async run() {
23 | if (this.running) { return }
24 | this.running = true
25 |
26 | const entry = this.queue.shift()
27 | if (!entry) {
28 | this.running = false
29 | return
30 | }
31 | const { action, res, rej } = entry
32 |
33 | try {
34 | res(await action())
35 | } catch (error) {
36 | rej(error)
37 | }
38 |
39 | this.running = false
40 | this.run()
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/next-env.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 |
4 | // NOTE: This file should not be edited
5 | // see https://nextjs.org/docs/basic-features/typescript for more information.
6 |
--------------------------------------------------------------------------------
/next.config.js:
--------------------------------------------------------------------------------
1 | const withPWA = require("next-pwa");
2 |
3 | const env = process.env.NODE_ENV;
4 |
5 | /** @type {import('next').NextConfig} */
6 | const nextConfig = {
7 | reactStrictMode: true,
8 | async rewrites() {
9 | return {
10 | beforeFiles: [
11 | {
12 | source: "/api/my_vanmoof_com/:path",
13 | destination: "https://my.vanmoof.com/api/v8/:path",
14 | },
15 | {
16 | source: "/api/api_vanmoof-api_com/:path",
17 | destination: "https://api.vanmoof-api.com/v8/:path",
18 | },
19 | {
20 | source:
21 | "/api/api_vanmoof-api_com/getBikeSharingInvitationsForBike/:path",
22 | destination:
23 | "https://api.vanmoof-api.com/v8/getBikeSharingInvitationsForBike/:path",
24 | },
25 | {
26 | source: "/api/api_vanmoof-api_com/revokeBikeSharingInvitation/:path",
27 | destination:
28 | "https://api.vanmoof-api.com/v8/revokeBikeSharingInvitation/:path",
29 | },
30 | ],
31 | };
32 | },
33 | pwa: {
34 | dest: "public",
35 | },
36 | };
37 |
38 | module.exports = env === "development" ? nextConfig : withPWA(nextConfig);
39 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vanmoof-test",
3 | "version": "0.1.0",
4 | "private": true,
5 | "scripts": {
6 | "dev": "next dev",
7 | "build": "next build",
8 | "start": "next start",
9 | "lint": "next lint"
10 | },
11 | "dependencies": {
12 | "@ffmpeg/ffmpeg": "^0.12.10",
13 | "@ffmpeg/util": "^0.12.1",
14 | "compare-versions": "^5.0.1",
15 | "crc-32": "^1.2.2",
16 | "next": "12.2.0",
17 | "next-pwa": "^5.5.4",
18 | "react": "18.2.0",
19 | "react-dom": "18.2.0",
20 | "ua-parser-js": "^1.0.38"
21 | },
22 | "devDependencies": {
23 | "@types/node": "18.0.1",
24 | "@types/react": "18.0.14",
25 | "@types/react-dom": "18.0.5",
26 | "@types/ua-parser-js": "^0.7.39",
27 | "@types/web-bluetooth": "^0.0.20",
28 | "eslint": "8.19.0",
29 | "eslint-config-next": "12.2.0",
30 | "typescript": "^4.9.5"
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/pages/_app.tsx:
--------------------------------------------------------------------------------
1 | import '../styles/globals.css'
2 | import type { AppProps } from 'next/app'
3 | import Head from 'next/head'
4 |
5 | function MyApp({ Component, pageProps }: AppProps) {
6 | return
7 |
8 |
Mooovy - Change VanMoof S&X 3 speed limit
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | }
19 |
20 | export default MyApp
21 |
--------------------------------------------------------------------------------
/pages/controls-test.tsx:
--------------------------------------------------------------------------------
1 | import BikeControls from '../components/Controls'
2 | import { SpeedLimit, PowerLevel, BellTone, BikeCredentials } from '../lib/bike'
3 | import { Api } from '../lib/api'
4 | import { useEffect, useState } from 'react'
5 | import { BikeSelector } from '../components/BikeSelector'
6 | import type { BikeAndApiCredentials } from '../components/Login'
7 |
8 | class FakeBike {
9 | id: string | undefined
10 | mac: string
11 | private speedLimit = SpeedLimit.EU
12 | private powerLevel = PowerLevel.Fourth
13 | private bellTone = BellTone.Foghorn
14 | private firmwareVersion = '1.8.1'
15 |
16 | constructor(credentials: BikeCredentials) {
17 | this.id = credentials.id
18 | this.mac = credentials.mac
19 | }
20 |
21 | async batteryChargingLevel() {
22 | return 100
23 | }
24 |
25 | async initiateBellSoundTransfer(file: Uint8Array) {
26 | console.log('initiateBellSoundTransfer', file)
27 | }
28 |
29 | async sendBellSoundChunk(chunk: Uint8Array) {
30 | console.log('sendBellSoundChunk', chunk)
31 | }
32 |
33 | async bikeFirmwareVersion() {
34 | return this.firmwareVersion
35 | }
36 |
37 | async bikeDistance() {
38 | return 100
39 | }
40 |
41 | async setSpeedLimit(l: SpeedLimit): Promise {
42 | this.speedLimit = l
43 | return l
44 | }
45 |
46 | async getSpeedLimit(): Promise {
47 | return this.speedLimit
48 | }
49 |
50 | async setPowerLvl(l: PowerLevel): Promise {
51 | this.powerLevel = l
52 | return l
53 | }
54 | async getPowerLvl(): Promise {
55 | return this.powerLevel
56 | }
57 |
58 | async getBellTone(): Promise {
59 | return this.bellTone
60 | }
61 |
62 | async setBellTone(t: BellTone): Promise {
63 | this.bellTone = t
64 | return t
65 | }
66 |
67 | async playSound(id: number) {
68 | console.log('play sound:', id)
69 | }
70 | }
71 |
72 | const dummyBike: BikeCredentials = {
73 | id: '000000',
74 | mac: '00:00:00:00:00:00',
75 | encryptionKey: '00000000000000000000000000000000',
76 | userKeyId: 1,
77 | name: 'Susy testing bike',
78 | ownerName: 'sus',
79 | modelColor: {
80 | name: 'Dark',
81 | primary: '#25282a',
82 | secondary: '#25282a',
83 | },
84 | links: {
85 | "hash": "http://my.vanmoof.com/v8/getBikeDataHash/000000",
86 | "thumbnail": "https://my.vanmoof.com/image/model/75",
87 | }
88 | }
89 |
90 | export default function ControlsTest() {
91 | const [fakeBike, setFakeBike] = useState(undefined) // new FakeBike as unknown as Bike
92 | const [credentials, setCredentials] = useState({
93 | api: new Api({
94 | token: 'dummy',
95 | refreshToken: 'dummy',
96 | }),
97 | bikes: [dummyBike],
98 | })
99 |
100 | useEffect(() => {
101 | try {
102 | const apiCredential = localStorage.getItem('vm-api-credentials')
103 | const rawBikeCredentials = localStorage.getItem('vm-bike-credentials')
104 |
105 | if (!apiCredential || !rawBikeCredentials)
106 | throw 'no cached credentials that can be used, you can login on the root page (/) page to get them'
107 |
108 | const apiCredentials = JSON.parse(apiCredential)
109 | const parsedBikeCredentials = JSON.parse(rawBikeCredentials)
110 |
111 | const parsedApi = new Api(apiCredentials)
112 |
113 | setCredentials({
114 | api: parsedApi,
115 | bikes: [dummyBike, ...parsedBikeCredentials],
116 | })
117 | } catch (e) {
118 | console.log('unable to parse bike/api credentials from local storage, error:', e)
119 | }
120 | }, [])
121 |
122 | const deleteCredentials = (idx: number) =>
123 | setCredentials(v => ({ api: v.api, bikes: credentials.bikes.filter((_, i) => idx !== i) }))
124 |
125 | return (
126 |
127 |
Page for testing the bike controls
128 |
129 | {fakeBike
130 | ? setFakeBike(undefined)}
134 | />
135 | : setFakeBike(new FakeBike(bike))}
138 | onDelete={deleteCredentials}
139 | />
140 | }
141 |
142 |
150 |
151 | )
152 | }
153 |
--------------------------------------------------------------------------------
/pages/donate.tsx:
--------------------------------------------------------------------------------
1 | import { Footer } from '../components/Footer'
2 | import Link from 'next/link'
3 |
4 | export default function DonationPage() {
5 | return (
6 |
7 |
8 | Donate
9 | If you like the website and want to support me you can do so with the following links.
10 |
11 |
12 |
13 |
14 | If there is enough support i can maybe also add support for newer and/or older bikes
15 | Back to homepage
16 |
17 |
18 |
37 |
38 | )
39 | }
40 |
41 | function DonateOption({ name, link }: { name: string, link: string }) {
42 | return (
43 |
44 | {name}
45 | {link}
46 |
67 |
68 | )
69 | }
--------------------------------------------------------------------------------
/pages/index.tsx:
--------------------------------------------------------------------------------
1 | import type { NextPage } from 'next'
2 | import { useEffect, useState } from 'react'
3 | import type { Bike } from '../lib/bike'
4 | import { Api } from '../lib/api'
5 | import type { BikeControlsArgs } from '../components/Controls'
6 | import Login, { BikeAndApiCredentials } from '../components/Login'
7 | import BluetoothConnect from '../components/Connect'
8 | import dynamic from 'next/dynamic'
9 | import Image from 'next/image'
10 | import screenshotLight from '../public/screenshot_light.png'
11 | import screenshotDark from '../public/screenshot_dark.png'
12 | import { Footer } from '../components/Footer'
13 |
14 | const Unsupported = dynamic(() => import('../components/Unsupported'), { ssr: false })
15 | const BikeControls = dynamic(() => import('../components/Controls'))
16 |
17 | const Home: NextPage = () => {
18 | const [browserCompatible, setBrowserCompatible] = useState(true)
19 | const [credentials, setCredentials] = useState(undefined)
20 | const [bikeInstance, setBikeInstance] = useState(undefined)
21 |
22 | const disconnect = () => {
23 | bikeInstance?.disconnect()
24 | setBikeInstance(undefined)
25 | }
26 |
27 | const backToLogin = () => {
28 | disconnect()
29 | setCredentials(undefined)
30 | }
31 |
32 | useEffect(() => {
33 | setBrowserCompatible(!!navigator.bluetooth)
34 |
35 | const rawBikeCredentials = localStorage.getItem('vm-bike-credentials')
36 | if (rawBikeCredentials) {
37 | let api: Api | undefined = undefined
38 | try {
39 | const apiCredential = localStorage.getItem('vm-api-credentials')
40 | api = new Api(JSON.parse(apiCredential ?? ''))
41 | } catch (e) {
42 | // Ignore
43 | }
44 |
45 | try {
46 | const parsedBikeCredentials = JSON.parse(rawBikeCredentials)
47 |
48 | if (!Array.isArray(parsedBikeCredentials))
49 | throw 'old bike credentials format'
50 |
51 | setCredentials({
52 | api,
53 | bikes: parsedBikeCredentials,
54 | })
55 | } catch (e) {
56 | console.log('unable to parse bike/api credentials from local storage, error:', e)
57 | }
58 | }
59 |
60 | import('../lib/bike') // Start importing the bike lib
61 | }, [])
62 |
63 | useEffect(() => {
64 | if (bikeInstance) {
65 | const connectedTimer = setInterval(() => {
66 | bikeInstance.checkConnection()
67 | .catch((_) => setBikeInstance(undefined))
68 | }, 1_000)
69 | return () => clearTimeout(connectedTimer)
70 | }
71 | }, [bikeInstance])
72 |
73 | return (
74 |
75 |
76 | Mooovy
77 | Change VanMoof S&X 3 speed limit
78 |
79 | {!browserCompatible || (!bikeInstance && !credentials) ?
80 | <>
81 |
82 | Using this site you can change the speed limit of your VanMoof S3 and X3
83 |
84 |
85 |
91 |
92 |
93 |
99 |
100 | >
101 | : undefined}
102 |
103 | {!browserCompatible
104 | ?
105 | : credentials
106 | ? bikeInstance
107 | ?
112 | : setCredentials(prev => ({ api: prev?.api, bikes }))}
115 | setBikeInstance={setBikeInstance}
116 | backToLogin={backToLogin}
117 | />
118 | :
119 | }
120 |
121 |
122 |
123 |
124 |
156 |
157 | )
158 | }
159 |
160 |
161 |
162 | export default Home
163 |
--------------------------------------------------------------------------------
/public/app.webmanifest:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://json.schemastore.org/web-manifest-combined.json",
3 | "name": "Mooovy",
4 | "short_name": "Mooovy",
5 | "start_url": ".",
6 | "display": "standalone",
7 | "background_color": "#ff0",
8 | "description": "A webapp for controlling your vanmoof S3 and X3",
9 | "icons": [
10 | {
11 | "src": "/compressed_logos/logo_full.png",
12 | "sizes": "1000x1000",
13 | "type": "image/png"
14 | },
15 | {
16 | "src": "/compressed_logos/logo_full.webp",
17 | "sizes": "1000x1000",
18 | "type": "image/webp"
19 | },
20 | {
21 | "src": "/compressed_logos/logo_full_512.png",
22 | "sizes": "512x512",
23 | "type": "image/png"
24 | },
25 | {
26 | "src": "/compressed_logos/logo_full_512.webp",
27 | "sizes": "512x512",
28 | "type": "image/webp"
29 | },
30 | {
31 | "src": "/compressed_logos/logo_full_256.png",
32 | "sizes": "256x256",
33 | "type": "image/png"
34 | },
35 | {
36 | "src": "/compressed_logos/logo_full_256.webp",
37 | "sizes": "256x256",
38 | "type": "image/webp"
39 | },
40 | {
41 | "src": "/compressed_logos/logo_full_128.png",
42 | "sizes": "128x128",
43 | "type": "image/png"
44 | },
45 | {
46 | "src": "/compressed_logos/logo_full_128.webp",
47 | "sizes": "128x128",
48 | "type": "image/webp"
49 | },
50 | {
51 | "src": "/compressed_logos/logo_full_64.png",
52 | "sizes": "64x64",
53 | "type": "image/png"
54 | },
55 | {
56 | "src": "/compressed_logos/logo_full_64.webp",
57 | "sizes": "64x64",
58 | "type": "image/webp"
59 | }
60 | ]
61 | }
62 |
--------------------------------------------------------------------------------
/public/compressed_logos/logo_full.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mjarkk/vanmoof-web-controller/97a3f959df1fdaa98836ce1dfac0513961e60369/public/compressed_logos/logo_full.png
--------------------------------------------------------------------------------
/public/compressed_logos/logo_full.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mjarkk/vanmoof-web-controller/97a3f959df1fdaa98836ce1dfac0513961e60369/public/compressed_logos/logo_full.webp
--------------------------------------------------------------------------------
/public/compressed_logos/logo_full_128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mjarkk/vanmoof-web-controller/97a3f959df1fdaa98836ce1dfac0513961e60369/public/compressed_logos/logo_full_128.png
--------------------------------------------------------------------------------
/public/compressed_logos/logo_full_128.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mjarkk/vanmoof-web-controller/97a3f959df1fdaa98836ce1dfac0513961e60369/public/compressed_logos/logo_full_128.webp
--------------------------------------------------------------------------------
/public/compressed_logos/logo_full_256.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mjarkk/vanmoof-web-controller/97a3f959df1fdaa98836ce1dfac0513961e60369/public/compressed_logos/logo_full_256.png
--------------------------------------------------------------------------------
/public/compressed_logos/logo_full_256.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mjarkk/vanmoof-web-controller/97a3f959df1fdaa98836ce1dfac0513961e60369/public/compressed_logos/logo_full_256.webp
--------------------------------------------------------------------------------
/public/compressed_logos/logo_full_512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mjarkk/vanmoof-web-controller/97a3f959df1fdaa98836ce1dfac0513961e60369/public/compressed_logos/logo_full_512.png
--------------------------------------------------------------------------------
/public/compressed_logos/logo_full_512.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mjarkk/vanmoof-web-controller/97a3f959df1fdaa98836ce1dfac0513961e60369/public/compressed_logos/logo_full_512.webp
--------------------------------------------------------------------------------
/public/compressed_logos/logo_full_64.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mjarkk/vanmoof-web-controller/97a3f959df1fdaa98836ce1dfac0513961e60369/public/compressed_logos/logo_full_64.png
--------------------------------------------------------------------------------
/public/compressed_logos/logo_full_64.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mjarkk/vanmoof-web-controller/97a3f959df1fdaa98836ce1dfac0513961e60369/public/compressed_logos/logo_full_64.webp
--------------------------------------------------------------------------------
/public/logo_full.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mjarkk/vanmoof-web-controller/97a3f959df1fdaa98836ce1dfac0513961e60369/public/logo_full.png
--------------------------------------------------------------------------------
/public/screenshot_dark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mjarkk/vanmoof-web-controller/97a3f959df1fdaa98836ce1dfac0513961e60369/public/screenshot_dark.png
--------------------------------------------------------------------------------
/public/screenshot_light.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mjarkk/vanmoof-web-controller/97a3f959df1fdaa98836ce1dfac0513961e60369/public/screenshot_light.png
--------------------------------------------------------------------------------
/styles/globals.css:
--------------------------------------------------------------------------------
1 | /* Light theme */
2 | :root {
3 | --main-bg-color: white;
4 | --text-color: black;
5 | --label-color: rgba(0, 0, 0, 0.7);
6 | --disabled-text-color: rgba(0, 0, 0, 0.5);
7 | --border-color: black;
8 | --secondary-border-color: rgba(0, 0, 0, 0.6);
9 | --divider-color: #eaeaea;
10 | --error-box-bg-color: #ffccbc;
11 | --warning-box-bg-color: #ffecb3;
12 | --positive-box-bg-color: #c8e6c9;
13 | --active-color: #1976d2;
14 | --active-button-bg-color: #7fbbf7;
15 | --active-title-color: #1976d2;
16 | --error-text-color: darkred;
17 | }
18 |
19 | @media (prefers-color-scheme: dark) {
20 |
21 | /* Dark theme */
22 | :root {
23 | --main-bg-color: #121212;
24 | --text-color: white;
25 | --label-color: rgba(255, 255, 255, 0.75);
26 | --disabled-text-color: rgba(255, 255, 255, 0.55);
27 | --border-color: white;
28 | --secondary-border-color: rgba(255, 255, 255, 0.75);
29 | --divider-color: #404040;
30 | --error-box-bg-color: #741818;
31 | --warning-box-bg-color: #5d4037;
32 | --positive-box-bg-color: #004d40;
33 | --active-color: #42a5f5;
34 | --active-button-bg-color: #254f71;
35 | --active-title-color: #92c9ff;
36 | --error-text-color: #f57979;
37 | }
38 | }
39 |
40 | html,
41 | body {
42 | padding: 0;
43 | margin: 0;
44 | }
45 |
46 | body {
47 | font-size: 18px;
48 | font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
49 | Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
50 | background-color: var(--main-bg-color);
51 | color: var(--text-color);
52 | }
53 |
54 | a {
55 | color: var(--active-color);
56 | text-decoration: none;
57 | }
58 |
59 | a:hover {
60 | text-decoration: underline;
61 | }
62 |
63 | * {
64 | box-sizing: border-box;
65 | }
66 |
67 | button {
68 | cursor: pointer;
69 | color: var(--text-color);
70 | }
71 |
72 | button[disabled] {
73 | cursor: default;
74 | color: var(--disabled-text-color);
75 | border-color: var(--disabled-text-color);
76 | }
77 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es5",
4 | "lib": ["dom", "dom.iterable", "esnext"],
5 | "allowJs": true,
6 | "skipLibCheck": true,
7 | "strict": true,
8 | "forceConsistentCasingInFileNames": true,
9 | "noEmit": true,
10 | "esModuleInterop": true,
11 | "module": "esnext",
12 | "moduleResolution": "node",
13 | "resolveJsonModule": true,
14 | "isolatedModules": true,
15 | "jsx": "preserve",
16 | "incremental": true,
17 | "downlevelIteration": true
18 | },
19 | "include": ["node_modules/@types/web-bluetooth/index.d.ts", "next-env.d.ts", "**/*.ts", "**/*.tsx"],
20 | "exclude": ["node_modules"]
21 | }
22 |
--------------------------------------------------------------------------------