Files
ark/pkg/client-sdk/wasm/browser/exports.go
Louis Singer ff96524f22 Ark Notes (#379)
* ark credits

* rename "ecash" --> "ark credit"

* rework note_test.go

* NewFromString

* create several notes

* note repo: rename "push" to "add"

* RegisterInputsForNextRoundRequest: move "notes" to field #3

* use uint64 as note ID

* rename to voucher

* add nostr notification

* nostr notification test and fixes

* bump badger to 4.3

* allow npub to be registered

* rename poolTxID

* add default relays

* Update server/internal/config/config.go

Co-authored-by: Marco Argentieri <3596602+tiero@users.noreply.github.com>

* fix RedeemVouchers test

* notification = voucher

* WASM wrappers

* fix arkd voucher cmd

* test_utils.go ignore gosec rule G101

* fix permissions

* rename ALL to notes

* add URI prefix

* note.go : fix signature encoding

* fix decode note.Data

* Update server/internal/infrastructure/notifier/nostr/nostr.go

Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com>

* Update pkg/client-sdk/wasm/browser/wrappers.go

Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com>

* Update server/internal/infrastructure/notifier/nostr/nostr.go

Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com>

* rework note and entity db + sqlite implementations

* NOTIFICATION_PREFIX -> NOTE_URI_PREFIX

* validate NOTE_URI_PREFIX

* Update defaults to convenant-less mainnet (#2)

* config: defaults to convenant-less tx builder

* Drop env var for blockchain scanner

---------

Co-authored-by: altafan <18440657+altafan@users.noreply.github.com>

* add // before URI prefix

* add URI prefix in admin CreateNote

* Fixes

* rework nonces encoding (#4)

* rework nonces encoding

* add a check in Musig2Nonce decode function

* musig2_test: increase number of signers to 20

* musig2.json: add a test case with a 35 leaves tree

* GetEventStream REST rework

* fix round phases time intervals

* [SDK] Use server-side streams in rest client

* Fix history

* make the URI optional

* Updates

* Fix settled txs in history

* fix e2e test

* go work sync in sdk unit test

* fix signMessage in btc and liquid sdk wallets

---------

Co-authored-by: Marco Argentieri <3596602+tiero@users.noreply.github.com>
Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com>
2024-11-15 19:07:33 +01:00

144 lines
4.0 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/types"
"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
store types.Store
)
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("sendAsync", SendAsyncWrapper())
js.Global().Set("settle", SettleWrapper())
js.Global().Set("unilateralRedeem", UnilateralRedeemWrapper())
js.Global().Set("collaborativeRedeem", CollaborativeRedeemWrapper())
js.Global().Set("getTransactionHistory", GetTransactionHistoryWrapper())
js.Global().Set("log", LogWrapper())
js.Global().Set("dump", DumpWrapper())
js.Global().Set("redeemNotes", RedeemNotesWrapper())
js.Global().Set("setNostrNotificationRecipient", SetNostrNotificationRecipientWrapper())
js.Global().Set("listVtxos", ListVtxosWrapper())
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("getDust", GetDustWrapper())
}
func NewCovenantClient(
ctx context.Context, storeSvc types.Store,
) error {
var err error
data, err := storeSvc.ConfigStore().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.ConfigStore(), 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
}
store = storeSvc
select {}
}
func NewCovenantlessClient(
ctx context.Context, storeSvc types.Store,
) error {
var err error
data, err := storeSvc.ConfigStore().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.ConfigStore(), 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
}
store = 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 types.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)
}