-
Notifications
You must be signed in to change notification settings - Fork 19
/
ed2curve.min.js
1 lines (1 loc) · 2.76 KB
/
ed2curve.min.js
1
!function(r,n){"use strict";"undefined"!=typeof module&&module.exports?module.exports=n(require("tweetnacl")):r.ed2curve=n(r.nacl)}(this,function(e){"use strict";if(!e)throw new Error("tweetnacl not loaded");var l=function(r){var n,o=new Float64Array(16);if(r)for(n=0;n<r.length;n++)o[n]=r[n];return o},y=l(),w=l([1]),s=l([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),d=l([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function i(r){var n,o;for(o=0;o<16;o++)r[o]+=65536,n=Math.floor(r[o]/65536),r[(o+1)*(o<15?1:0)]+=n-1+37*(n-1)*(15===o?1:0),r[o]-=65536*n}function c(r,n,o){for(var t,e=~(o-1),f=0;f<16;f++)t=e&(r[f]^n[f]),r[f]^=t,n[f]^=t}function A(r,n,o){var t;for(t=0;t<16;t++)r[t]=n[t]+o[t]|0}function K(r,n,o){var t;for(t=0;t<16;t++)r[t]=n[t]-o[t]|0}function h(r,n,o){var t,e,f=new Float64Array(31);for(t=0;t<31;t++)f[t]=0;for(t=0;t<16;t++)for(e=0;e<16;e++)f[t+e]+=n[t]*o[e];for(t=0;t<15;t++)f[t]+=38*f[t+16];for(t=0;t<16;t++)r[t]=f[t];i(r),i(r)}function p(r,n){h(r,n,n)}function U(r,n){var o,t,e,f=l(),u=l();for(o=0;o<16;o++)u[o]=n[o];for(i(u),i(u),i(u),t=0;t<2;t++){for(f[0]=u[0]-65517,o=1;o<15;o++)f[o]=u[o]-65535-(f[o-1]>>16&1),f[o-1]&=65535;f[15]=u[15]-32767-(f[14]>>16&1),e=f[15]>>16&1,f[14]&=65535,c(u,f,1-e)}for(o=0;o<16;o++)r[2*o]=255&u[o],r[2*o+1]=u[o]>>8}function f(r,n,o,t){return function(r,n,o,t,e){var f,u=0;for(f=0;f<e;f++)u|=r[n+f]^o[t+f];return(1&u-1>>>8)-1}(r,n,o,t,32)}function b(r,n){var o=new Uint8Array(32),t=new Uint8Array(32);return U(o,r),U(t,n),f(o,0,t,0)}function u(r,n){var o,t,e=l(),f=l(),u=l(),i=l(),c=l(),a=l(),v=l();if(!function(r,n){var o;for(o=0;o<16;o++)r[o]=0|n[o]}(r[2],w),function(r,n){var o;for(o=0;o<16;o++)r[o]=n[2*o]+(n[2*o+1]<<8);r[15]&=32767}(r[1],n),p(u,r[1]),h(i,u,s),K(u,u,r[2]),A(i,r[2],i),p(c,i),p(a,c),h(v,a,c),h(e,v,u),h(e,e,i),function(r,n){var o,t=l();for(o=0;o<16;o++)t[o]=n[o];for(o=250;0<=o;o--)p(t,t),1!==o&&h(t,t,n);for(o=0;o<16;o++)r[o]=t[o]}(e,e),h(e,e,u),h(e,e,i),h(e,e,i),h(r[0],e,i),p(f,r[0]),h(f,f,i),b(f,u)&&h(r[0],r[0],d),p(f,r[0]),h(f,f,i),b(f,u))return 1;o=r[0],U(t=new Uint8Array(32),o),(1&t[0])==n[31]>>7&&K(r[0],y,r[0]),h(r[3],r[0],r[1])}function o(r){var n=new Uint8Array(32),o=[l(),l(),l(),l()],t=l(),e=l();if(u(o,r))return null;var f=o[1];return A(t,w,f),K(e,w,f),function(r,n){var o,t=l();for(o=0;o<16;o++)t[o]=n[o];for(o=253;0<=o;o--)p(t,t),2!==o&&4!==o&&h(t,t,n);for(o=0;o<16;o++)r[o]=t[o]}(e,e),h(t,t,e),U(n,t),n}function t(r){var n,o=new Uint8Array(64),t=new Uint8Array(32);for(e.lowlevel.crypto_hash(o,r,32),o[0]&=248,o[31]&=127,o[31]|=64,n=0;n<32;n++)t[n]=o[n];for(n=0;n<64;n++)o[n]=0;return t}return{convertPublicKey:o,convertSecretKey:t,convertKeyPair:function(r){var n=o(r.publicKey);return n?{publicKey:n,secretKey:t(r.secretKey)}:null}}});