-
Notifications
You must be signed in to change notification settings - Fork 2
/
bech32-js.min.js
1 lines (1 loc) · 929 Bytes
/
bech32-js.min.js
1
for(var ALPHABET="qpzry9x8gf2tvdw0s3jn54khce6mua7l",ALPHABET_MAP={},z=0;z<ALPHABET.length;z++){var x=ALPHABET.charAt(z);ALPHABET_MAP[x]=z}function polymodStep(r){var e=r>>25;return(33554431&r)<<5^996825010&-(e>>0&1)^642813549&-(e>>1&1)^513874426&-(e>>2&1)^1027748829&-(e>>3&1)^705979059&-(e>>4&1)}function prefixChk(r){for(var e=1,t=0;t<r.length;++t){var n=r.charCodeAt(t);if(n<33||126<n)return"KO";e=polymodStep(e)^n>>5}for(e=polymodStep(e),t=0;t<r.length;++t){var o=r.charCodeAt(t);e=polymodStep(e)^31&o}return e}function checkbech32(r){if(r.length<8)return"KO";if(90<r.length)return"KO";var e=r.lastIndexOf("1");if(-1===e)return"KO";if(0===e)return"KO";var t=r.slice(0,e),n=r.slice(e+1);if(n.length<6)return"KO";var o=prefixChk(t);if("string"==typeof o)return"KO";for(var f=[],A=0;A<n.length;++A){var h=n.charAt(A),a=ALPHABET_MAP[h];if(void 0===a)return"KO";o=polymodStep(o)^a,A+6>=n.length||f.push(a)}return 1!==o?"KO":"OK"}