From b5fd9151626494612bdeb2f3221061b449cff769 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Tue, 27 Apr 2021 09:09:18 +0200 Subject: [PATCH 1/2] internal/prompt: allow compilation in js/wasm environment The wallet loader has a dependency to the internal/prompt package for prompting the user for certain inputs (e.g. wallet password or new seed). This makes it impossible for projects that use the wallet as a dependency and always provide those inputs as parameters to compile for JavaScript/WebAssembly targets because the prompt code uses some terminal functionality that is not available in JS syscalls. By providing a JS specific implementation that just returns an error we can compile the dependent projects. Adding acutal support for prompting the user in the browser is currently not planned as that can easily be circumvented by providing all inputs as parameters. --- internal/prompt/prompt.go | 2 ++ internal/prompt/prompt_js.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 internal/prompt/prompt_js.go diff --git a/internal/prompt/prompt.go b/internal/prompt/prompt.go index b967803..88730bf 100644 --- a/internal/prompt/prompt.go +++ b/internal/prompt/prompt.go @@ -2,6 +2,8 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. +// +build !js + package prompt import ( diff --git a/internal/prompt/prompt_js.go b/internal/prompt/prompt_js.go new file mode 100644 index 0000000..674119d --- /dev/null +++ b/internal/prompt/prompt_js.go @@ -0,0 +1,32 @@ +// Copyright (c) 2015-2021 The btcsuite developers +// Use of this source code is governed by an ISC +// license that can be found in the LICENSE file. + +package prompt + +import ( + "bufio" + "fmt" + + "github.com/btcsuite/btcwallet/internal/legacy/keystore" +) + +func ProvideSeed() ([]byte, error) { + return nil, fmt.Errorf("prompt not supported in WebAssembly") +} + +func ProvidePrivPassphrase() ([]byte, error) { + return nil, fmt.Errorf("prompt not supported in WebAssembly") +} + +func PrivatePass(_ *bufio.Reader, _ *keystore.Store) ([]byte, error) { + return nil, fmt.Errorf("prompt not supported in WebAssembly") +} + +func PublicPass(_ *bufio.Reader, _, _, _ []byte) ([]byte, error) { + return nil, fmt.Errorf("prompt not supported in WebAssembly") +} + +func Seed(_ *bufio.Reader) ([]byte, error) { + return nil, fmt.Errorf("prompt not supported in WebAssembly") +} From 825ff779a11586d607883096178c7563aa4ed7b7 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Tue, 18 May 2021 13:26:45 +0200 Subject: [PATCH 2/2] make: increase test timeout to 20 minutes --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e732545..b09ca72 100644 --- a/Makefile +++ b/Makefile @@ -81,7 +81,7 @@ check: unit unit: @$(call print, "Running unit tests.") - $(GOLIST) | $(XARGS) env $(GOTEST) + $(GOLIST) | $(XARGS) env $(GOTEST) -test.timeout=20m unit-cover: $(GOACC_BIN) @$(call print, "Running unit coverage tests.") @@ -89,7 +89,7 @@ unit-cover: $(GOACC_BIN) unit-race: @$(call print, "Running unit race tests.") - env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOLIST) | $(XARGS) env $(GOTEST) -race + env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOLIST) | $(XARGS) env $(GOTEST) -race -test.timeout=20m # ========= # UTILITIES