UNPKG

@privy-io/cross-app-connect

Version:

Privy cross app wallet connectors for wagmi and RainbowKit

3 lines (2 loc) 1.25 kB
import{secp256k1 as e}from"@noble/curves/secp256k1";import{base64 as t}from"@scure/base";import{Buffer as r}from"buffer";import{unzlibSync as o,zlibSync as n}from"fflate";import{encoding as a}from"@privy-io/encoding";function i(){let r=e.utils.randomPrivateKey(),o=e.getPublicKey(r);return{privateKey:t.encode(r),publicKey:t.encode(o)}}function y({privateKey:r,publicKey:o}){let n=e.getSharedSecret(t.decode(r),t.decode(o)).slice(1);return t.encode(n)}async function c(e,t){let r=JSON.stringify(e),o=n(a.utf8.toBytes(r)),i=a.base64.toBytes(t),y=await crypto.subtle.importKey("raw",i,{name:"AES-GCM"},!0,["encrypt"]),c=crypto.getRandomValues(new Uint8Array(12)),s=await crypto.subtle.encrypt({name:"AES-GCM",iv:c},y,new Uint8Array(o));return{iv:a.base64.fromBytes(c),encryptedRequest:a.base64.fromBytes(new Uint8Array(s))}}async function s({encryptedResult:e,iv:t,sharedSecret:n}){let i=a.base64.toBytes(n),y=a.base64.toBytes(t),c=await crypto.subtle.importKey("raw",i,{name:"AES-GCM"},!0,["decrypt"]),s=a.base64.toBytes(e),p=await crypto.subtle.decrypt({name:"AES-GCM",iv:y},c,s),u=o(r.from(p));return a.utf8.fromBytes(u)}export{s as decryptResult,c as encryptRequest,i as generateKeyPair,y as recoverSharedSecret}; //# sourceMappingURL=crypto.mjs.map