This repository has been archived by the owner on Mar 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlib.min.js
89 lines (81 loc) · 8.17 KB
/
lib.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// The MIT License (MIT)
//
// Copyright (c) 2013 Artem S Vybornov
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// The MIT License (MIT)
// Copyright base-x contributors (c) 2016
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// https://github.com/cryptocoinjs/base-x/blob/master/index.js
// base-x encoding
// Forked from https://github.com/cryptocoinjs/bs58
// Originally written by Mike Hearn for BitcoinJ
// Copyright (c) 2011 Google Inc
// Ported to JavaScript by Stefan Thomas
// Merged Buffer refactorings from base58-native by Stephen Pair
// Copyright (c) 2013 BitPay Inc
// Copyright (c) 2017 Pieter Wuille
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// ISC License
// Copyright (c) 2013-2016 The btcsuite developers
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
const CHARSET="qpzry9x8gf2tvdw0s3jn54khce6mua7l",CHARSET_MAP={q:0,p:1,z:2,r:3,y:4,9:5,x:6,8:7,g:8,f:9,2:10,t:11,v:12,d:13,w:14,0:15,s:16,3:17,j:18,n:19,5:20,4:21,k:22,h:23,c:24,e:25,6:26,m:27,u:28,a:29,7:30,l:31},ALPHABET="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",ALPHABET_MAP={1:0,2:1,3:2,4:3,5:4,6:5,7:6,8:7,9:8,A:9,B:10,C:11,D:12,E:13,F:14,G:15,H:16,J:17,K:18,L:19,M:20,N:21,P:22,Q:23,R:24,S:25,T:26,U:27,V:28,W:29,X:30,Y:31,Z:32,a:33,b:34,c:35,d:36,e:37,f:38,g:39,h:40,i:41,j:42,k:43,m:44,n:45,o:46,p:47,q:48,r:49,s:50,t:51,u:52,v:53,w:54,x:55,y:56,z:57};function parseAndConvertCashAddress(r,e){for(var t=new Array(e.length),n=0;n<e.length;n++){if(void 0===CHARSET_MAP[e[n]])throw"Unexpected character!";t[n]=CHARSET_MAP[e[n]]}var o=0,c=0;if("bitcoincash"==r){o=246,c=1775070485;var a=!0}else{o=136,c=603865313;a=!1}var s=polyMod(t,o,c);if(0!==s[0]||0!==s[1]){for(var d=0;d<polymodInput.length;d++)for(var f=1;f<32;f++){polymodInput[d]^=f;var h=polyMod(polymodInput);if(0===h[0]&&0===h[1])return correctedAddress=rebuildAddress(polymodInput),document.getElementById("correctedButton").style="","";polymodInput[d]^=f}throw"Can't correct errors!"}var i=convertBits(t.slice(0,-8),5,8,!1);return craftOldAddress(i[0]>>3,i.slice(1,21),a)}function craftOldAddress(r,e,t){return CheckEncodeBase58(e,t?0==r?0:5:0==r?111:196)}function CheckEncodeBase58(r,e){var t=[e].concat(r),n=sha256(sha256(Uint8Array.from(t)));return EncodeBase58Simplified(t=t.concat(Array.from(n).slice(0,4)))}function EncodeBase58Simplified(r){for(var e=[0],t=0;t<r.length;t++){for(var n=0,o=r[t];n<e.length;n++)o+=e[n]<<8,e[n]=o%58,o=o/58|0;for(;o>0;)e.push(o%58),o=o/58|0}var c="";for(t=0;t<r.length&&0===r[t];t++)c=c.concat("1");for(var a=e.length-1;a>=0;a--)c=c.concat(ALPHABET[e[a]]);return c}function parseAndConvertOldAddress(r){for(var e=[0],t=0;t<r.length;t++){var n=ALPHABET_MAP[r[t]];if(void 0===n)throw"Unexpected character!";for(var o=0;o<e.length;o++)n+=58*e[o],e[o]=255&n,n>>=8;for(;n>0;)e.push(255&n),n>>=8}for(t=0;t<r.length&&"1"===r[t];t++)e.push(0);var c=(e=e.reverse())[0],a=sha256(Uint8Array.from(e.slice(0,-4))),s=sha256(a);if(s[0]!=e[e.length-4]||s[1]!=e[e.length-3]||s[2]!=e[e.length-2]||s[3]!=e[e.length-1])throw"Address checksum doesn't match! Did you type it wrong?";var d=e.slice(1,e.length-4);if(0==c)return craftCashAddress(0,d,!0);if(5==c)return craftCashAddress(1,d,!0);if(111==c)return craftCashAddress(0,d,!1);if(196==c)return craftCashAddress(1,d,!1);if(28==c)return craftCashAddress(0,d,!0);if(40==c)return craftCashAddress(1,d,!0);throw"Unknown version byte"}function convertBits(r,e,t,n){for(var o=0,c=0,a=[],s=(1<<t)-1,d=(1<<e+t-1)-1,f=0;f<r.length;f++){var h=r[f];if(h<0||h>>>e!=0)throw"convertBits error!";for(o=(o<<e|h)&d,c+=e;c>=t;)c-=t,a.push(o>>>c&s)}if(n)c>0&&a.push(o<<t-c&s);else if(c>=e||0!=(o<<t-c&s))throw"convertBits error!";return a}function craftCashAddress(r,e,t){var n=convertBits([r<<3].concat(e),8,5,!0),o=0,c=0;1==t?(o=246,c=1775070485):(o=136,c=603865313);for(var a=polyMod(n.concat([0,0,0,0,0,0,0,0]),o,c),s=a[0],d=a[1],f=new Array(8),h=7;h>5;h--)f[h]=31&d,d>>>=5,d|=(31&s)<<27,s>>>=5;for(;h>0;h--)f[h]=31&d,d>>>=5;f[0]=d;var i=n.concat(f);if(1==t)var l="bitcoincash:";else l="bchtest:";for(h=0;h<i.length;h++)l=l.concat(CHARSET[i[h]]);if(54==l.length||50==l.length)return l;throw"Unexpected converted address length!"}function polyMod(r,e,t){for(var n=0,o=0;o<r.length;o++)n=e>>>3,e=(e&=7)<<5|t>>>27,t&=134217727,t<<=5,t^=r[o],1&n&&(e^=152,t^=4072443489),2&n&&(e^=121,t^=3077413346),4&n&&(e^=243,t^=1046459332),8&n&&(e^=174,t^=783016616),16&n&&(e^=30,t^=1329849456);return[e,1^t]}function rebuildAddress(r){for(var e="",t=0;0!=r[t]&&t<r.length;)e=e.concat(String.fromCharCode(96+r[t])),t++;for(e=e.concat(":"),t++;t<r.length;t++)e=e.concat(CHARSET[r[t]]);return e}