UNPKG

@privy-io/js-sdk-core

Version:

Vanilla JS client for the Privy Auth API

2 lines (1 loc) 2.58 kB
import{SiweUnlink as e,SiweLink as t,SiweAuthenticate as i,SiweInit as n}from"@privy-io/public-api";import{maybeCreateWalletOnLogin as s}from"./maybeCreateWalletOnLogin.mjs";import"../../utils/getUserEmbeddedEthereumWallet.mjs";import"../../utils/getAllUserEmbeddedEthereumWallets.mjs";import"../../utils/getUserEmbeddedSolanaWallet.mjs";import"../../utils/getAllUserEmbeddedSolanaWallets.mjs";import"../../utils/shouldCreateEmbeddedEthWallet.mjs";import"../../utils/shouldCreateEmbeddedSolWallet.mjs";class a{async unlinkWallet(t){await this._privyInternal.fetch(e,{body:{address:t}});let i=await this._privyInternal.refreshSession();return{user:i.user,identity_token:i.identity_token}}async linkWithSiwe(e,i,n){let s=i||this._wallet,a=n||this._preparedMessage;if(!s)throw Error("A wallet must be provided in the init step or as an argument to linkWithSiwe");if(!a)throw Error("A message must be generated and signed before being used to link a wallet to privy");await this._privyInternal.fetch(t,{body:{message:a,signature:e,chainId:s.chainId,walletClientType:s.walletClientType,connectorType:s.connectorType}});let r=await this._privyInternal.refreshSession();return{user:r.user,identity_token:r.identity_token}}async loginWithSiwe(e,t,n,a,r){let o=t||this._wallet,l=n||this._preparedMessage;if(!o)throw Error("A wallet must be provided in the init step or as an argument to loginWithSiwe");if(!l)throw Error("A message must be generated and signed before being used to login to privy with a wallet");let d=await this._privyInternal.fetch(i,{body:{signature:e,message:l,chainId:o.chainId,walletClientType:o.walletClientType,connectorType:o.connectorType,mode:a}});await this._privyInternal.session.updateWithTokensResponse(d);let h=await s(this._embedded,d,r?.embedded);return this._privyInternal.callbacks?.setUser?.(h.user),h}async init(e,t,i){var s;this._wallet=e;let{nonce:a}=await this._privyInternal.fetch(n,{body:{address:e.address}}),r=`${(s={chainId:e.chainId.toString().replace("eip155:",""),address:e.address,issuedAt:(new Date).toISOString(),statement:"By signing, you are proving you own this wallet and logging in. This does not initiate a transaction or cost any fees.",domain:t,nonce:a,uri:i}).domain} wants you to sign in with your Ethereum account:\n${s.address}\n\n${s.statement}\n\nURI: ${s.uri}\nVersion: 1\nChain ID: ${s.chainId}\nNonce: ${s.nonce}\nIssued At: ${s.issuedAt}\nResources:\n- https://privy.io`;return this._preparedMessage=r,{nonce:a,message:r}}constructor(e,t){this._wallet=void 0,this._privyInternal=e,this._embedded=t}}export{a as default};