{"version":3,"file":"VerID_button.DaLoAEKy.mjs","names":["OAuth2Client","_Fragment"],"sources":["https:/framerusercontent.com/modules/UMfnL98ilarT66qS6JY4/3yvqzYbXz92lncpE5rW9/VerID_button.js"],"sourcesContent":["import{jsx as _jsx,Fragment as _Fragment}from\"react/jsx-runtime\";import{addPropertyControls,ControlType}from\"framer\";import{OAuth2Client}from\"@badgateway/oauth2-client\";import{useEffect}from\"react\";const issuer=new URL(\"https://oauth.ssi.ver.id\");// GENERATING CODE VERIFIER\nfunction dec2hex(dec){return(\"0\"+dec.toString(16)).substr(-2);}function generateCodeVerifier(){var array=new Uint32Array(56/2);window.crypto.getRandomValues(array);return Array.from(array,dec2hex).join(\"\");}function generateRandomString(){var array=new Uint32Array(28);window.crypto.getRandomValues(array);return Array.from(array,dec=>(\"0\"+dec.toString(16)).substr(-2)).join(\"\");}async function request(clientId,scope,redirect_uri){// Part of PCKE\nconst codeVerifier=await generateCodeVerifier();const state=await generateRandomString();sessionStorage.setItem(state,codeVerifier);sessionStorage.setItem(\"clientId\",clientId);sessionStorage.setItem(\"redirect_uri\",redirect_uri);const client=new OAuth2Client({server:issuer.toString(),clientId:clientId});// In a browser this might work as follows:\ndocument.location=await client.authorizationCode.getAuthorizeUri({redirectUri:redirect_uri,state:state,codeVerifier,scope:[scope]});}function openFlow(){}export default function VeriDButton(props){const scope=props.scope||\"disclosure\";let keydown=0;useEffect(()=>{const handleKey=event=>{if(event.key===\"Alt\"){keydown=!keydown;}};window.addEventListener(\"keydown\",handleKey);window.addEventListener(\"keyup\",handleKey);return()=>{window.removeEventListener(\"keydown\",handleKey);window.removeEventListener(\"keyup\",handleKey);};},[]);const handleClick=e=>{let clientId=props.client_id;if(keydown)clientId=props.alternate_client_id;console.log(\"client id\",clientId);if(clientId&&clientId!=\"\")request(clientId,scope,window.location.origin+props.redirect);return;};// wait 0,5 second and continue to next page\n// if (RenderTarget.current() !== RenderTarget.canvas) {\n//     setTimeout(() => {\n//         handleClick(null)\n//     }, 3000)\n// }\nreturn /*#__PURE__*/_jsx(_Fragment,{children:/*#__PURE__*/_jsx(\"div\",{style:containerStyle,onClick:handleClick,children:props.text})});}VeriDButton.defaultProps={text:\"button text\"};addPropertyControls(VeriDButton,{text:{title:\"Text\",type:ControlType.String},client_id:{title:\"ClientID\",type:ControlType.String},alternate_client_id:{title:\"Alternative ClientID\",type:ControlType.String},scope:{title:\"Scope\",type:ControlType.String},redirect:{title:\"Result page\",type:ControlType.Link},secret_kid:{title:\"Secret Key ID\",type:ControlType.String},secret_key:{title:\"Secret Key\",type:ControlType.String}});const containerStyle={width:\"380px\",height:\"40px\",padding:\"12px\",display:\"table-cell\",fontFace:\"Inter\",fontWeight:\"medium\",fontSize:\"16px\",color:\"#ffffff\",justifyContent:\"center\",alignItems:\"center\",overflow:\"hidden\",cursor:\"pointer\",textAlign:\"center\",verticalAlign:\"middle\"};\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"VeriDButton\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./VerID_button.map"],"mappings":"0OACA,SAAS,EAAQ,EAAI,CAAC,OAAO,IAAI,EAAI,SAAS,GAAG,EAAE,OAAO,GAAG,CAAE,SAAS,GAAsB,CAAC,IAAI,EAAM,IAAI,YAAY,GAAG,EAAE,CAAsC,OAArC,EAAO,OAAO,gBAAgB,EAAM,CAAQ,MAAM,KAAK,EAAM,EAAQ,CAAC,KAAK,GAAG,CAAE,SAAS,GAAsB,CAAC,IAAI,EAAM,IAAI,YAAY,GAAG,CAAsC,OAArC,EAAO,OAAO,gBAAgB,EAAM,CAAQ,MAAM,KAAK,EAAM,IAAM,IAAI,EAAI,SAAS,GAAG,EAAE,OAAO,GAAG,CAAC,CAAC,KAAK,GAAG,CAAE,eAAe,EAAQ,EAAS,EAAM,EAAa,CAC/a,IAAM,EAAa,MAAM,GAAsB,CAAO,EAAM,M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