UNPKG

@privy-io/js-sdk-core

Version:

Vanilla JS client for the Privy Auth API

2 lines (1 loc) 1.59 kB
"use strict";var e=require("../Error.js");exports.EmbeddedBitcoinWalletProvider=class{async sign({message:e}){return await this.request({method:"sign",params:{message:new TextDecoder("utf8").decode(e)}})}async signTransaction({psbt:e}){return await this.request({method:"signTransaction",params:{psbt:e}})}async request(r){if(!await this._privyInternal.getAccessToken())throw new e.PrivyClientError({error:"Missing access token",code:"attempted_rpc_call_before_logged_in"});return this.handleIFrameRpc(r)}async handleIFrameRpc(r){try{let e=await this._privyInternal.getAccessToken();if(!e)throw Error("Missing access token. User must be authenticated.");return this._privyInternal.createAnalyticsEvent("embedded_wallet_sdk_rpc_started",{method:r.method,address:this._account.address}),(await this._proxy.rpcWallet({accessToken:e,request:r,entropyId:this._entropyId,entropyIdVerifier:this._entropyIdVerifier,hdWalletIndex:this._account.wallet_index,chainType:this._account.chain_type})).response.data}catch(t){console.error(t);let s=t instanceof Error?t.message:"Unable to make wallet request";throw this._privyInternal.createAnalyticsEvent("embedded_wallet_sdk_rpc_failed",{method:r.method,address:this._account.address,error:s}),new e.PrivyClientError({code:"embedded_wallet_request_error",error:s})}}toJSON(){return`PrivyEmbeddedBitcoinProvider { address: '${this._account.address}', request: [Function] }`}constructor({proxy:e,privyInternal:r,account:t,entropyId:s,entropyIdVerifier:a}){this._proxy=e,this._privyInternal=r,this._account=t,this._entropyId=s,this._entropyIdVerifier=a}};