UNPKG

scorechain-safetransfer

Version:

A Metamask Snap to protect your crypto transactions

1 lines β€’ 8.67 kB
(()=>{"use strict";var e={d:(t,n)=>{for(var s in n)e.o(n,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:n[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function n(e,t,n){if("string"==typeof e)throw new Error(`An HTML element ("${String(e)}") was used in a Snap component, which is not supported by Snaps UI. Please use one of the supported Snap components.`);if(!e)throw new Error("A JSX fragment was used in a Snap component, which is not supported by Snaps UI. Please use one of the supported Snap components.");return e({...t,key:n})}function s(e,t,s){return n(e,t,s)}function r(e){return Object.fromEntries(Object.entries(e).filter((([,e])=>void 0!==e)))}function a(e){return t=>{const{key:n=null,...s}=t;return{type:e,props:r(s),key:n}}}e.r(t),e.d(t,{onHomePage:()=>M,onInstall:()=>k,onTransaction:()=>U,onUpdate:()=>R});const o=a("Box"),i=a("Heading"),c={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let d;const l=new Uint8Array(16);const u=[];for(let e=0;e<256;++e)u.push((e+256).toString(16).slice(1));function p(e,t=0){return(u[e[t+0]]+u[e[t+1]]+u[e[t+2]]+u[e[t+3]]+"-"+u[e[t+4]]+u[e[t+5]]+"-"+u[e[t+6]]+u[e[t+7]]+"-"+u[e[t+8]]+u[e[t+9]]+"-"+u[e[t+10]]+u[e[t+11]]+u[e[t+12]]+u[e[t+13]]+u[e[t+14]]+u[e[t+15]]).toLowerCase()}const h=function(e,t,n){if(c.randomUUID&&!t&&!e)return c.randomUUID();const s=(e=e||{}).random??e.rng?.()??function(){if(!d){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");d=crypto.getRandomValues.bind(crypto)}return d(l)}();if(s.length<16)throw new Error("Random bytes length must be >= 16");if(s[6]=15&s[6]|64,s[8]=63&s[8]|128,t){if((n=n||0)<0||n+16>t.length)throw new RangeError(`UUID byte range ${n}:${n+15} is out of buffer bounds`);for(let e=0;e<16;++e)t[n+e]=s[e];return t}return p(s)},m=a("Row"),y=a("Text"),f=a("Link"),T=()=>s(o,{children:[n(i,{children:"Welcome to Scorechain SafeTransfer πŸš€"}),n(m,{label:"Why use it?",children:n(y,{children:"Take control of your financial safetyβ€”minimize risk, maximize confidence. Don’t take chances with your crypto transactions!"})}),n(m,{label:"Networks We Support",children:n(y,{children:"We support the following networks to help you manage your transactions securely:"})}),s(o,{children:[n(y,{children:"🌐 AVALANCHE"}),n(y,{children:"🌐 BASE"}),n(y,{children:"🌐 BSC (Binance Smart Chain)"}),n(y,{children:"🌐 ETHEREUM"}),n(y,{children:"🌐 POLYGON"}),n(y,{children:"🌐 ARBITRUM ONE"}),n(y,{children:"🌐 OPTIMISM"}),n(y,{children:"🌐 BLAST"})]}),s(o,{children:[n(y,{children:"Want to learn more?"}),n(f,{href:"https://www.scorechain.com/",children:"Visit Us 🌐"})]})]}),g=a("Address"),w=a("Bold"),A=({to:e,score:t})=>{let r;return r="UNAVAILABLE"===t?{icon:"βšͺ",message:"This address has not interacted with the blockchain yet. No risk level can be determined."}:"CRITICAL"===t?{icon:"πŸ”΄",message:"This address is CRITICAL risk. Do not proceed."}:"HIGH"===t?{icon:"🟠",message:"This address is HIGH risk. Proceed with caution."}:"MEDIUM"===t?{icon:"🟑",message:"This address is MEDIUM risk. Be cautious."}:"LOW"===t?{icon:"🟒",message:"This address is LOW risk. No detected issues."}:{icon:"βœ…",message:"This address has NO risk detected."},s(o,{children:[n(o,{children:n(m,{label:"To",children:e?n(g,{address:e}):s(y,{children:["The score is ",s(w,{children:[t,"%"]})]})})}),n(o,{children:n(m,{label:"Insight",children:s(y,{children:[n(w,{children:r.icon})," Β ",r.message]})})}),s(o,{children:[s(y,{children:[s(w,{children:["Want to know more about this address and create a report ?"," "]})," ","Β "]}),s(y,{children:["Install our ScorechainBot in Telegram for a lite report.",n(f,{href:"https://t.me/scorechainbot",children:" "})]}),s(y,{children:["Go to our website for a full detailed address report.",n(f,{href:"https://www.scorechain.com/kya-know-your-address-metamask",children:" "})]})]})]})},S=({message:e})=>n(o,{children:n(o,{children:n(m,{label:"Oops ! ",children:n(y,{children:e})})})});var I;!function(e){e.ETHEREUM="ETHEREUM",e.BSC="BSC",e.POLYGON="POLYGON",e.AVALANCHE="AVALANCHE",e.BASE="BASE",e.ARBITRUMONE="ARBITRUMONE",e.BLAST="BLAST",e.OPTIMISM="OPTIMISM"}(I||(I={}));var E;!function(e){e.TRANSACTION="TRANSACTION",e.INSTALLATION="INSTALLATION",e.UPDATE="UPDATE",e.BLOCKED="BLOCKED"}(E||(E={}));const O=async e=>{try{var t,n,s;const r=await fetch("https://lite.api.scorechain.com/v1/userKPI",{method:"POST",headers:{"Content-Type":"application/json"},body:e?JSON.stringify(e):null});if(200===r.status)return{success:!0,status:r.status};const a=await(null===(t=r)||void 0===t?void 0:t.json());return{success:!1,message:null===(n=a)||void 0===n?void 0:n.message,error:null===(s=a)||void 0===s?void 0:s.error,status:r.status}}catch(e){return{success:!1,message:String(e),status:e.code||0}}};var v;!function(e){e.ClearState="clear",e.GetState="get",e.UpdateState="update"}(v||(v={}));const b={id:""};async function L(e){return await snap.request({method:"snap_manageState",params:{operation:v.GetState,encrypted:e}})??b}async function N(e,t){await snap.request({method:"snap_manageState",params:{operation:v.UpdateState,newState:e,encrypted:t}})}const U=async({transaction:e,chainId:t})=>{const s=(e=>{if(!e)return null;if(e.startsWith("eip155:")){const t=e.replace("eip155:","");return{1:I.ETHEREUM,11155111:I.ETHEREUM,8453:I.BASE,137:I.POLYGON,56:I.BSC,43114:I.AVALANCHE,42161:I.ARBITRUMONE,421614:I.ARBITRUMONE,81457:I.BLAST,168587773:I.BLAST,10:I.OPTIMISM,11155420:I.OPTIMISM}[t]??null}return null})(t);if(null!==s){let t=await L(!0);if(void 0===t.id||""===t.id){const e=h();await N({id:e},!0),t=await L(!0)}await O({type:E.TRANSACTION,userId:String(t.id)});const a=await(async e=>{try{var t,n,s;const r=await fetch("https://lite.api.scorechain.com/v1/scoringAnalysis",{method:"POST",headers:{"Content-Type":"application/json"},body:e?JSON.stringify(e):null});if(200===r.status)return{success:!0,data:await r.json(),status:r.status};const a=await(null===(t=r)||void 0===t?void 0:t.json());return{success:!1,message:null===(n=a)||void 0===n?void 0:n.message,error:null===(s=a)||void 0===s?void 0:s.error,status:r.status}}catch(e){return{success:!1,message:String(e),status:e.code||0}}})({objectId:e.to,blockchain:s});if(a.success){const{score:t}=a.data;return"UNAVAILABLE"===t?await snap.request({method:"snap_notify",params:{type:"inApp",message:`Hmm... The address ${e.to.slice(0,7)} hasn’t interacted with the blockchain yet. No risk level available. Proceed carefully and verify further!`}}):"CRITICAL"===t?await snap.request({method:"snap_notify",params:{type:"inApp",message:`WARNING! The address ${e.to.slice(0,7)} is CRITICAL risk. It’s best to stay away from this one.`}}):"HIGH"===t?await snap.request({method:"snap_notify",params:{type:"inApp",message:`WARNING! The address ${e.to.slice(0,7)} is HIGH risk. Think twice before proceeding.`}}):"MEDIUM"===t?await snap.request({method:"snap_notify",params:{type:"inApp",message:`Caution! The address ${e.to.slice(0,7)} has MEDIUM risk. Be sure to double-check before continuing.`}}):"LOW"===t?await snap.request({method:"snap_notify",params:{type:"inApp",message:`Looking good! The address ${e.to.slice(0,7)} is LOW risk.`}}):await snap.request({method:"snap_notify",params:{type:"inApp",message:`Great news! The address ${e.to.slice(0,7)} has NO detected risk. All clear to move forward.`}}),{content:n(A,{to:e.to,score:t})}}return 404===a.status?{content:n(S,{message:"Sorry, we have no insight about this address."})}:429===a.status?(await O({type:E.BLOCKED,userId:(null===(r=t)||void 0===r?void 0:r.id)?String(t.id):void 0}),{content:n(S,{message:"Too Many Requests. Please Try Again Later"})}):{content:n(S,{message:"Sorry, action failed. If this continues please contact us at support@scorechain.com."})};var r}return{content:n(S,{message:"Sorry, we don't support this network."})}},M=async()=>({content:n(T,{})}),k=async()=>{const e=h();await N({id:e},!0),await O({type:E.INSTALLATION,userId:e}),await snap.request({method:"snap_dialog",params:{type:"alert",content:n(o,{children:n(i,{children:"Thank you for installing our SafeTransfer Snap."})})}})},R=async()=>{var e;const t=await L(!0);await O({type:E.UPDATE,userId:(null===(e=t)||void 0===e?void 0:e.id)?String(t.id):void 0})};var B=exports;for(var C in t)B[C]=t[C];t.__esModule&&Object.defineProperty(B,"__esModule",{value:!0})})();