File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 11import { JsonRpcProvider } from "@near-js/providers" ;
2+ import bitcoin from "bitcoinjs-lib" ;
23import bs58 from "bs58" ;
34import TronWeb from "tronweb" ;
45import {
@@ -181,6 +182,7 @@ export const getSigner = async (chainId: string) => {
181182
182183 let domainId : number | undefined ;
183184 switch ( vmType ) {
185+ case "bitcoin-vm" :
184186 case "ethereum-vm" :
185187 case "hyperliquid-vm" :
186188 case "tron-vm" : {
@@ -217,6 +219,29 @@ export const getSigner = async (chainId: string) => {
217219
218220 const [ , publicKey ] = result ! . toString ( ) . split ( ":" ) ;
219221 switch ( vmType ) {
222+ case "bitcoin-vm" : {
223+ const raw = Buffer . from ( bs58 . decode ( publicKey ) ) ;
224+
225+ const x = raw . subarray ( 0 , 32 ) ;
226+ const y = raw . subarray ( 32 , 64 ) ;
227+ const yIsEven = ( y [ 31 ] & 1 ) === 0 ;
228+ const prefix = yIsEven ? 0x02 : 0x03 ;
229+ const pubKeyCompressed = Buffer . concat ( [
230+ Buffer . from ( [ prefix ] ) ,
231+ Buffer . from ( x ) ,
232+ ] ) ;
233+
234+ _getSignerCache . set (
235+ chainId ,
236+ bitcoin . payments . p2pkh ( {
237+ network : bitcoin . networks . bitcoin ,
238+ pubkey : pubKeyCompressed ,
239+ } ) . address ! ,
240+ ) ;
241+
242+ break ;
243+ }
244+
220245 case "ethereum-vm" :
221246 case "hyperliquid-vm" :
222247 case "tron-vm" : {
You can’t perform that action at this time.
0 commit comments