Files
ark/pkg/client-sdk/wasm/browser/exports.go
Louis Singer 4da76ec88b New boarding protocol (#279)
* [domain] add reverse boarding inputs in Payment struct

* [tx-builder] support reverse boarding script

* [wallet] add GetTransaction

* [api-spec][application] add reverse boarding support in covenantless

* [config] add reverse boarding config

* [api-spec] add ReverseBoardingAddress RPC

* [domain][application] support empty forfeits txs in EndFinalization events

* [tx-builder] optional connector output in round tx

* [btc-embedded] fix getTx and taproot finalizer

* whitelist ReverseBoardingAddress RPC

* [test] add reverse boarding integration test

* [client] support reverse boarding

* [sdk] support reverse boarding

* [e2e] add sleep time after faucet

* [test] run using bitcoin-core RPC

* [tx-builder] fix GetSweepInput

* [application][tx-builder] support reverse onboarding in covenant

* [cli] support reverse onboarding in covenant CLI

* [test] rework integration tests

* [sdk] remove onchain wallet, replace by onboarding address

* remove old onboarding protocols

* [sdk] Fix RegisterPayment

* [e2e] add more funds to covenant ASP

* [e2e] add sleeping time

* several fixes

* descriptor boarding

* remove boarding delay from info

* [sdk] implement descriptor boarding

* go mod tidy

* fixes and revert error msgs

* move descriptor pkg to common

* add replace in go.mod

* [sdk] fix unit tests

* rename DescriptorInput --> BoardingInput

* genrest in SDK

* remove boarding input from domain

* remove all "reverse boarding"

* rename "onboarding" ==> "boarding"

* remove outdate payment unit test

* use tmpfs docker volument for compose testing files

* several fixes
2024-09-04 19:21:26 +02:00

137 lines
3.6 KiB
Go

//go:build js && wasm
// +build js,wasm
package browser
import (
"context"
"fmt"
"strings"
"syscall/js"
arksdk "github.com/ark-network/ark/pkg/client-sdk"
"github.com/ark-network/ark/pkg/client-sdk/store"
"github.com/ark-network/ark/pkg/client-sdk/wallet"
singlekeywallet "github.com/ark-network/ark/pkg/client-sdk/wallet/singlekey"
walletstore "github.com/ark-network/ark/pkg/client-sdk/wallet/singlekey/store"
)
var (
arkSdkClient arksdk.ArkClient
configStore store.ConfigStore
)
func init() {
js.Global().Set("init", InitWrapper())
js.Global().Set("unlock", UnlockWrapper())
js.Global().Set("lock", LockWrapper())
js.Global().Set("locked", IsLockedWrapper())
js.Global().Set("balance", BalanceWrapper())
js.Global().Set("receive", ReceiveWrapper())
js.Global().Set("sendOnChain", SendOnChainWrapper())
js.Global().Set("sendOffChain", SendOffChainWrapper())
js.Global().Set("unilateralRedeem", UnilateralRedeemWrapper())
js.Global().Set("collaborativeRedeem", CollaborativeRedeemWrapper())
js.Global().Set("log", LogWrapper())
js.Global().Set("getAspUrl", GetAspUrlWrapper())
js.Global().Set("getAspPubKeyHex", GetAspPubkeyWrapper())
js.Global().Set("getWalletType", GetWalletTypeWrapper())
js.Global().Set("getClientType", GetClientTypeWrapper())
js.Global().Set("getNetwork", GetNetworkWrapper())
js.Global().Set("getRoundLifetime", GetRoundLifetimeWrapper())
js.Global().Set("getUnilateralExitDelay", GetUnilateralExitDelayWrapper())
js.Global().Set("getMinRelayFee", GetMinRelayFeeWrapper())
}
func NewCovenantClient(
ctx context.Context, storeSvc store.ConfigStore,
) error {
var err error
data, err := storeSvc.GetData(ctx)
if err != nil {
return err
}
if data == nil {
arkSdkClient, err = arksdk.NewCovenantClient(storeSvc)
} else {
var walletSvc wallet.WalletService
switch data.WalletType {
case arksdk.SingleKeyWallet:
walletSvc, err = getSingleKeyWallet(storeSvc, data.Network.Name)
if err != nil {
return err
}
// TODO: Support HD wallet
default:
return fmt.Errorf("unknown wallet type")
}
arkSdkClient, err = arksdk.LoadCovenantClientWithWallet(storeSvc, walletSvc)
}
if err != nil {
js.Global().Get("console").Call("error", err.Error())
return err
}
configStore = storeSvc
select {}
}
func NewCovenantlessClient(
ctx context.Context, storeSvc store.ConfigStore,
) error {
var err error
data, err := storeSvc.GetData(ctx)
if err != nil {
return err
}
if data == nil {
arkSdkClient, err = arksdk.NewCovenantlessClient(storeSvc)
} else {
var walletSvc wallet.WalletService
switch data.WalletType {
case arksdk.SingleKeyWallet:
walletSvc, err = getSingleKeyWallet(storeSvc, data.Network.Name)
if err != nil {
return err
}
// TODO: Support HD wallet
default:
return fmt.Errorf("unknown wallet type")
}
arkSdkClient, err = arksdk.LoadCovenantlessClientWithWallet(storeSvc, walletSvc)
}
if err != nil {
js.Global().Get("console").Call("error", err.Error())
return err
}
configStore = storeSvc
select {}
}
func getWalletStore(storeType string) (walletstore.WalletStore, error) {
if storeType == LocalStorageStore {
return NewLocalStorageWalletStore()
}
// TODO: Support IndexDB store
return nil, fmt.Errorf("unknown wallet store type")
}
func getSingleKeyWallet(
configStore store.ConfigStore, network string,
) (wallet.WalletService, error) {
walletStore, err := getWalletStore(configStore.GetType())
if err != nil {
return nil, err
}
if strings.Contains(network, "liquid") {
return singlekeywallet.NewLiquidWallet(configStore, walletStore)
}
return singlekeywallet.NewBitcoinWallet(configStore, walletStore)
}