20 lines
129 KiB
JavaScript
20 lines
129 KiB
JavaScript
|
var Ta=Object.defineProperty;var Na=(Ke,L,Te)=>L in Ke?Ta(Ke,L,{enumerable:!0,configurable:!0,writable:!0,value:Te}):Ke[L]=Te;var x=(Ke,L,Te)=>(Na(Ke,typeof L!="symbol"?L+"":L,Te),Te);(function(){"use strict";var So,Ao,Bo,Io,Oo;const Ke='*,:before,:after{box-sizing:border-box;border-width:0;border-style:solid;border-color:#e5e7eb}:before,:after{--tw-content: ""}html,:host{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji";font-feature-settings:normal;font-variation-settings:normal;-webkit-tap-highlight-color:transparent}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-feature-settings:normal;font-variation-settings:normal;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-feature-settings:inherit;font-variation-settings:inherit;font-size:100%;font-weight:inherit;line-height:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}button,[type=button],[type=reset],[type=submit]{-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dl,dd,h1,h2,h3,h4,h5,h6,hr,figure,p,pre{margin:0}fieldset{margin:0;padding:0}legend{padding:0}ol,ul,menu{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}button,[role=button]{cursor:pointer}:disabled{cursor:default}img,svg,video,canvas,audio,iframe,embed,object{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]{display:none}*,:before,:after{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(59 130 246 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }::backdrop{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figur
|
||
|
you can drop in any page that already uses NIP-07 and make it also
|
||
|
work with NIP-46 automatically when the user doesn't have an
|
||
|
extension installed.
|
||
|
<br/>
|
||
|
It adds a small floating button on the side of the window that users
|
||
|
can use to create Nostr accuonts or connect to their NIP-46 bunkers.</p> <p class="mt-4">This tool is opensource, get the code from the <a target="_blank" class="underline" href="https://github.com/fiatjaf/window.nostr.js">project's page</a>.</p> <p class="mt-4">You don't know what Nostr is?
|
||
|
<a target="_blank" class="underline" href="https://www.nostr.com">Learn more</a>.</p>`,v(e,"class","text-center text-lg"),v(r,"class","text-base leading-5")},m(o,i){q(o,e,i),q(o,n,i),q(o,r,i)},p:L,i:L,o:L,d(o){o&&(R(e),R(n),R(r))}}}function Kc(t){let e,n,r,o,i,s,c=new URL(t[15]).host+"",a,l,f,u,g,h,b,d,p,y;return{c(){e=N("div"),n=N("div"),n.textContent="An action requires your confirmation",r=$(),o=N("div"),i=j("Now you a new window will bring you to "),s=N("strong"),a=j(c),l=j(" where you can approve the current action. If nothing happens check that if your browser is blocking popups, pleaase."),f=N("br"),u=j(`
|
||
|
After that you will be returned to this page.`),g=$(),h=N("button"),b=j("Confirm action »"),v(n,"class","text-center text-lg"),v(o,"class","mt-4 text-center text-sm leading-4"),v(h,"class",d="mt-4 block w-full cursor-pointer rounded border-0 px-2 py-1 text-lg text-white disabled:cursor-default disabled:bg-neutral-400 disabled:text-neutral-200 bg-"+t[0]+"-900 hover:bg-"+t[0]+"-950"),v(e,"class","m-auto w-full")},m(w,E){q(w,e,E),k(e,n),k(e,r),k(e,o),k(o,i),k(o,s),k(s,a),k(o,l),k(o,f),k(o,u),k(e,g),k(e,h),k(h,b),p||(y=J(h,"click",t[48]),p=!0)},p(w,E){E[0]&32768&&c!==(c=new URL(w[15]).host+"")&&Pe(a,c),E[0]&1&&d!==(d="mt-4 block w-full cursor-pointer rounded border-0 px-2 py-1 text-lg text-white disabled:cursor-default disabled:bg-neutral-400 disabled:text-neutral-200 bg-"+w[0]+"-900 hover:bg-"+w[0]+"-950")&&v(h,"class",d)},i:L,o:L,d(w){w&&R(e),p=!1,y()}}}function Dc(t){let e,n,r,o,i,s,c=new URL(t[14]).host+"",a,l,f,u,g,h,b,d,p,y;return{c(){e=N("div"),n=N("div"),n.textContent="Login into a Nostr account",r=$(),o=N("div"),i=j("Now you a new window will bring you to "),s=N("strong"),a=j(c),l=j(" where you can login and approve the permissions. If nothing happens check that if your browser is blocking popups, pleaase."),f=N("br"),u=j(`
|
||
|
After that you will be returned to this page.`),g=$(),h=N("button"),b=j("Login now »"),v(n,"class","text-center text-lg"),v(o,"class","mt-4 text-center text-sm leading-4"),v(h,"class",d="mt-4 block w-full cursor-pointer rounded border-0 px-2 py-1 text-lg text-white disabled:cursor-default disabled:bg-neutral-400 disabled:text-neutral-200 bg-"+t[0]+"-900 hover:bg-"+t[0]+"-950"),v(e,"class","m-auto w-full")},m(w,E){q(w,e,E),k(e,n),k(e,r),k(e,o),k(o,i),k(o,s),k(s,a),k(o,l),k(o,f),k(o,u),k(e,g),k(e,h),k(h,b),p||(y=J(h,"click",t[47]),p=!0)},p(w,E){E[0]&16384&&c!==(c=new URL(w[14]).host+"")&&Pe(a,c),E[0]&1&&d!==(d="mt-4 block w-full cursor-pointer rounded border-0 px-2 py-1 text-lg text-white disabled:cursor-default disabled:bg-neutral-400 disabled:text-neutral-200 bg-"+w[0]+"-900 hover:bg-"+w[0]+"-950")&&v(h,"class",d)},i:L,o:L,d(w){w&&R(e),p=!1,y()}}}function Wc(t){let e,n,r,o,i,s,c=new URL(t[13]).host+"",a,l,f,u,g,h,b,d,p,y;return{c(){e=N("div"),n=N("div"),n.textContent="Create a Nostr account",r=$(),o=N("div"),i=j("Now you a new window will bring you to "),s=N("strong"),a=j(c),l=j(" where the account creation will take place. If nothing happens check that if your browser is blocking popups, pleaase."),f=N("br"),u=j(`
|
||
|
After that you will be returned to this page.`),g=$(),h=N("button"),b=j("Start account creation »"),v(n,"class","text-center text-lg"),v(o,"class","mt-4 text-center text-sm leading-4"),v(h,"class",d="mt-4 block w-full cursor-pointer rounded border-0 px-2 py-1 text-lg text-white disabled:cursor-default disabled:bg-neutral-400 disabled:text-neutral-200 bg-"+t[0]+"-900 hover:bg-"+t[0]+"-950"),v(e,"class","m-auto w-full")},m(w,E){q(w,e,E),k(e,n),k(e,r),k(e,o),k(o,i),k(o,s),k(s,a),k(o,l),k(o,f),k(o,u),k(e,g),k(e,h),k(h,b),p||(y=J(h,"click",t[46]),p=!0)},p(w,E){E[0]&8192&&c!==(c=new URL(w[13]).host+"")&&Pe(a,c),E[0]&1&&d!==(d="mt-4 block w-full cursor-pointer rounded border-0 px-2 py-1 text-lg text-white disabled:cursor-default disabled:bg-neutral-400 disabled:text-neutral-200 bg-"+w[0]+"-900 hover:bg-"+w[0]+"-950")&&v(h,"class",d)},i:L,o:L,d(w){w&&R(e),p=!1,y()}}}function ho(t){let e,n,r=t[21].picture&&go(t),o=t[21].name&&po(t);return{c(){e=N("div"),r&&r.c(),n=$(),o&&o.c(),v(e,"class","mb-2 flex items-center justify-center gap-2")},m(i,s){q(i,e,s),r&&r.m(e,null),k(e,n),o&&o.m(e,null)},p(i,s){i[21].picture?r?r.p(i,s):(r=go(i),r.c(),r.m(e,n)):r&&(r.d(1),r=null),i[21].name?o?o.p(i,s):(o=po(i),o.c(),o.m(e,null)):o&&(o.d(1),o=null)},d(i){i&&R(e),r&&r.d(),o&&o.d()}}}function go(t){let e,n,r;return{c(){e=N("img"),Xe(e.src,n=t[21].picture)||v(e,"src",n),v(e,"alt",""),v(e,"class",r="h-10 w-10 rounded-full border-2 border-solid border-transparent group-hover:border-"+t[0]+"-100")},m(o,i){q(o,e,i)},p(o,i){i[0]&2097152&&!Xe(e.src,n=o[21].picture)&&v(e,"src",n),i[0]&1&&r!==(r="h-10 w-10 rounded-full border-2 border-solid border-transparent group-hover:border-"+o[0]+"-100")&&v(e,"class",r)},d(o){o&&R(e)}}}function po(t){let e,n=t[21].name+"",r;return{c(){e=N("div"),r=j(n),v(e,"class","text-3xl decoration-2 underline-offset-4 group-hover:underline")},m(o,i){q(o,e,i),k(e,r)},p(o,i){i[0]&2097152&&n!==(n=o[21].name+"")&&Pe(r,n)},d(o){o&&R(e)}}}function bo(t){let e,n;return{c(){e=N("div"),n=j(t[19]),v(e,"class","my-2 rounded bg-yellow-100 p-2 text-center text-sm leading-4 text-red-400")},m(r,o){q(r,e,o),k(e,n)},p(r,o){o[0]&524288&&Pe(n,r[19])},d(r){r&&R(e)}}}function Vc(t){let e;return{c(){e=j("Connect »")},m(n,r){q(n,e,r)},i:L,o:L,d(n){n&&R(e)}}}function Gc(t){let e,n,r;return n=new lo({}),{c(){e=j(`Connecting to bunker
|
||
|
`),Yn(n.$$.fragment)},m(o,i){q(o,e,i),Yt(n,o,i),r=!0},i(o){r||(de(n.$$.fragment,o),r=!0)},o(o){be(n.$$.fragment,o),r=!1},d(o){o&&R(e),Ft(n,o)}}}function wo(t){let e,n,r,o,i;return{c(){e=N("div"),n=j(`Waiting too much?
|
||
|
`),r=N("button"),r.textContent="Cancel the connection",v(r,"class","cursor-pointer border-0 bg-transparent text-sm text-white underline"),v(e,"class","mt-6 text-center text-sm leading-3")},m(s,c){q(s,e,c),k(e,n),k(e,r),o||(i=J(r,"click",t[39]),o=!0)},p:L,d(s){s&&R(e),o=!1,i()}}}function yo(t){let e,n,r,o,i,s,c;return{c(){e=N("div"),n=j("Do you need a Nostr account?"),r=N("br"),o=$(),i=N("button"),i.textContent="Sign up now",v(i,"class","cursor-pointer border-0 bg-transparent text-sm text-white underline"),v(e,"class","mt-6 text-center text-sm leading-3")},m(a,l){q(a,e,l),k(e,n),k(e,r),k(e,o),k(e,i),s||(c=J(i,"click",t[35]),s=!0)},p:L,d(a){a&&R(e),s=!1,c()}}}function mo(t){let e,n,r;return{c(){e=N("option"),v(e,"label",n=t[78].domain),e.__value=r=t[78],et(e,e.__value),v(e,"class","px-2 py-1 text-lg")},m(o,i){q(o,e,i)},p(o,i){i[0]&4194304&&n!==(n=o[78].domain)&&v(e,"label",n),i[0]&4194304&&r!==(r=o[78])&&(e.__value=r,et(e,e.__value))},d(o){o&&R(e)}}}function Zc(t){let e,n;return{c(){e=N("img"),Xe(e.src,n=t[21].picture)||v(e,"src",n),v(e,"alt",""),v(e,"class","h-6 w-6 rounded-full")},m(r,o){q(r,e,o)},p(r,o){o[0]&2097152&&!Xe(e.src,n=r[21].picture)&&v(e,"src",n)},i:L,o:L,d(r){r&&R(e)}}}function Yc(t){let e,n,r,o=(t[21].name||t[21].npub.slice(0,7)+"…"+t[21].npub.slice(-4))+"",i;function s(l,f){return l[21].picture?ea:Xc}let c=s(t),a=c(t);return{c(){e=N("div"),a.c(),n=$(),r=N("div"),i=j(o),v(r,"class","max-w-56 overflow-hidden whitespace-nowrap overflow-ellipsis inline-block"),v(e,"class","flex px-2 items-center")},m(l,f){q(l,e,f),a.m(e,null),k(e,n),k(e,r),k(r,i)},p(l,f){c===(c=s(l))&&a?a.p(l,f):(a.d(1),a=c(l),a&&(a.c(),a.m(e,n))),f[0]&2097152&&o!==(o=(l[21].name||l[21].npub.slice(0,7)+"…"+l[21].npub.slice(-4))+"")&&Pe(i,o)},i:L,o:L,d(l){l&&R(e),a.d()}}}function Fc(t){let e;return{c(){e=N("div"),e.textContent="N",v(e,"class","w-6 text-center")},m(n,r){q(n,e,r)},p:L,i:L,o:L,d(n){n&&R(e)}}}function Jc(t){let e;return{c(){e=N("div"),e.textContent="Connect with Nostr",v(e,"class","flex px-2 items-center")},m(n,r){q(n,e,r)},p:L,i:L,o:L,d(n){n&&R(e)}}}function Qc(t){let e,n,r,o;return r=new lo({}),{c(){e=N("div"),n=j(`Connecting to bunker
|
||
|
`),Yn(r.$$.fragment),v(e,"class","flex px-2 items-center")},m(i,s){q(i,e,s),k(e,n),Yt(r,e,null),o=!0},p:L,i(i){o||(de(r.$$.fragment,i),o=!0)},o(i){be(r.$$.fragment,i),o=!1},d(i){i&&R(e),Ft(r)}}}function Xc(t){let e;return{c(){e=j("☉")},m(n,r){q(n,e,r)},p:L,d(n){n&&R(e)}}}function ea(t){let e,n;return{c(){e=N("img"),Xe(e.src,n=t[21].picture)||v(e,"src",n),v(e,"alt",""),v(e,"class","mr-2 h-5 w-5 rounded-full")},m(r,o){q(r,e,o)},p(r,o){o[0]&2097152&&!Xe(e.src,n=r[21].picture)&&v(e,"src",n)},d(r){r&&R(e)}}}function ta(t){let e,n,r,o,i,s,c;const a=[qc,Hc,Rc],l=[];function f(u,g){return!u[25]&&!u[21]&&u[1]?0:u[25]?2:1}return n=f(t),r=l[n]=a[n](t),{c(){e=N("div"),r.c(),v(e,"class","draggable animate-fadein font-sans text-white"),v(e,"style",o="position: fixed; "+(t[25]&&t[5]?"width: 100vw;":"")+"; right: "+(t[25]&&t[5]?"0":t[3])+"px; user-select: none; "+(t[25]&&t[5]?"bottom: 0px":t[24]+":"+t[23]+"px")),Wn(e,"cursor-pointer",!t[21]&&!t[25])},m(u,g){q(u,e,g),l[n].m(e,null),t[54](e),i=!0,s||(c=[J(Rn,"click",t[29]),J(Rn,"mouseup",t[42]),J(Rn,"mousemove",t[41]),J(e,"mousedown",t[40])],s=!0)},p(u,g){let h=n;n=f(u),n===h?l[n].p(u,g):(At(),be(l[h],1,1,()=>{l[h]=null}),Bt(),r=l[n],r?r.p(u,g):(r=l[n]=a[n](u),r.c()),de(r,1),r.m(e,null)),(!i||g[0]&58720296&&o!==(o="position: fixed; "+(u[25]&&u[5]?"width: 100vw;":"")+"; right: "+(u[25]&&u[5]?"0":u[3])+"px; user-select: none; "+(u[25]&&u[5]?"bottom: 0px":u[24]+":"+u[23]+"px")))&&v(e,"style",o),(!i||g[0]&35651584)&&Wn(e,"cursor-pointer",!u[21]&&!u[25])},i(u){i||(de(r),i=!0)},o(u){be(r),i=!1},d(u){u&&R(e),l[n].d(),t[54](null),s=!1,Ne(c)}}}const vo="We could not connect to a NIP-46 bunker with that url, are you sure it is set up correctly?",xo="We were not able to connect using this address. For it to work it has to come from a NIP-46 provider.",ze=20;function Hn(t){return window.open(t,"window.nostr","width=600,height=800,popup=yes")}function na(t,e,n){let r,o,i,s,c,a;const l=Lc("only screen and (max-width: 640px)");Uo(t,l,I=>n(5,a=I));const f={ORIGIN:"wnj:origin",CLIENT_SECRET:"wnj:clientSecret",Y_POS:"wnj:ypos",CALLBACK_TOKEN:"wnj:callbackToken",BUNKER_POINTER:"wnj:bunkerPointer"};let u,{accent:g}=e,{position:h="top"}=e,{startHidden:b}=e,{compactMode:d}=e;const p=window,y=new As;let w,E,O,P,S,_;const m=localStorage.getItem(f.CLIENT_SECRET);m?_=en(m):(_=cs(),localStorage.setItem(f.CLIENT_SECRET,ne(_)));let A="closed",C,U,G,Z,Y,B,T=null,H=null,z=null,M=!1,K,ee,V,fe=!1,F,he,ge=[],{right:pe=20}=e,Je=!1,ce=!1,Be,Et,Ie;const ie={pool:y,onauth(I){K?n(13,T=I):F?(n(15,z=I),n(25,i=!0)):n(14,H=I)}},Oe=Xn(()=>{switch(A){case"justopened":n(44,A="opened");break;case"justclosed":n(44,A="closed");break}},500);function Qe(){n(44,A="justopened"),Oe()}function $e(){n(44,A="justclosed"),Oe()}function Kt(){if(C&&!B){zn();return}Qe()}Mn();let To={isWnj:!0,async getPublicKey(){return C?C.pubkey:(!Y&&!B&&Qe(),(await Z).bp.pubkey)},async signEvent(I){try{return!Y&&!B&&Kt(),await(await Z).signEvent(I)}finally{n(15,z=null),$e()}},async getRelays(){return!Y&&!B&&Kt(),(await Z).getRelays()},nip04:{async encrypt(I,D){return!Y&&!B&&Kt(),(await Z).nip04Encrypt(I,D)},async decrypt(I,D){return!Y&&!B&&Kt(),(await Z).nip04Decrypt(I,D)}}};function Mn(){$e(),C=null,Z=new Promise((I,D)=>{U=I,G=D}),n(21,F=null),n(12,Y=!1),n(16,M=!1),n(17,K=!1),B=!1,he=null,n(19,V="")}$o(()=>{if(!C){let I=localStorage.getItem(f.BUNKER_POINTER);I&&(C=JSON.parse(I),$n())}if(p.nostr&&!p.nostr.isWnj){p.destroyWnj();return}else Object.defineProperty(window,"nostr",{get(){return To},set(I){To=I,I.isWnj||p.destroyWnj()},configurable:!0});return()=>{he&&he.close()}});function sa(I){Math.abs(o-Et)>6||Date.now()-Ie>600||A==="justopened"||A==="justclosed"||(I.composedPath().find(D=>D.id==="wnj")?Qe():$e())}function ca(I){$e(),n(17,K=!1),n(13,T=null),n(14,H=null),n(15,z=null),I.stopPropagation()}function aa(I){n(20,fe=!0),I.stopPropagation()}function la(I){n(20,fe=!1),I.stopPropagation()}async function ua(I){I.preventDefault();try{if(C=await Sc(w.value),!C){w.value.match($t)?n(19,V=vo):n(19,V=xo);return}w.setCustomValidity(""),n(19,V=""),await zn
|
||
|
html, body {
|
||
|
overflow: auto;
|
||
|
height: 100%;
|
||
|
}
|
||
|
`;ko.innerHTML=ia,document.head.appendChild(ko)}})();
|