UNPKG

@privy-io/server-auth

Version:

Server-side client for the Privy API

2 lines (1 loc) 1.74 kB
"use strict";var e=require("ethers"),r=require("./errors.js"),t=require("./utils-D9BZ7JAH.js");require("node-fetch-native"),require("ts-case-convert");let a=e=>{let t=2;if(void 0!==e.type)if(0===e.type)t=0;else if(1===e.type)t=1;else{if(2!==e.type)throw new r.PrivyClientError("EIP4844 and EIP7702 transaction types are not yet supported.");t=2}else e.gasPrice&&!e.maxFeePerGas&&(t=0);return{to:e.to?e.to.toString():void 0,nonce:void 0!==e.nonce?Number(e.nonce):void 0,chainId:void 0!==e.chainId?Number(e.chainId):void 0,data:e.data?e.data.toString():void 0,value:e.value?i(e.value):void 0,type:t,gasLimit:e.gasLimit?i(e.gasLimit):void 0,gasPrice:e.gasPrice?i(e.gasPrice):void 0,maxFeePerGas:e.maxFeePerGas?i(e.maxFeePerGas):void 0,maxPriorityFeePerGas:e.maxPriorityFeePerGas?i(e.maxPriorityFeePerGas):void 0}},i=r=>{if(null!=r)return e.ethers.toBeHex(r)},s=e=>e;exports.createEthersSigner=n=>{let{walletId:o,address:d,privyClient:c,provider:l}=n;class u extends e.ethers.AbstractSigner{connect(e){return new u(e)}async getAddress(){return d}async signTransaction(e){let r=a(e),{signedTransaction:t}=await c.walletApi.ethereum.signTransaction({address:d,chainType:"ethereum",transaction:r});return t}async signMessage(e){let r=s(e),{signature:t}=await c.walletApi.ethereum.signMessage({address:d,chainType:"ethereum",message:r});return t}async signTypedData(e,a,s){let n=t.replaceBigInts(e,i),d=t.replaceBigInts(s,i),l=Object.keys(a).find((e=>"EIP712Domain"!==e))||"";if(!l)throw new r.PrivyClientError("Could not determine primaryType from types");let{signature:u}=await c.walletApi.ethereum.signTypedData({walletId:o,typedData:{domain:n,types:a,message:d,primaryType:l}});return u}constructor(e){super(e),this.address=d}}return new u(l)};