Skip to content

Commit 735902c

Browse files
authored
Merge pull request #27 from kaleido-io/kv3-wallet
Add filesystem listener interface to KeystoreV3 signer, and move to `pkg`
2 parents b846fbb + 8b6cfe4 commit 735902c

22 files changed

+1148
-613
lines changed

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
"ffsigner",
1717
"fftypes",
1818
"filewallet",
19+
"fsnotify",
20+
"fswallet",
1921
"GJSON",
2022
"httpserver",
2123
"hyperledger",

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ clean:
4444
$(VGO) clean
4545
deps:
4646
$(VGO) get ./ffsigner
47-
docs:
47+
reference:
4848
$(VGO) test ./cmd -timeout=10s -tags docs
4949
docker:
5050
docker build --build-arg BUILD_VERSION=${BUILD_VERSION} ${DOCKER_ARGS} -t hyperledger/firefly-signer .

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,17 @@ A set of Ethereum transaction signing utilities designed for use across projects
1919
- EIP-155
2020
- EIP-1559
2121
- See `pkg/ethsigner` [go doc](https://pkg.go.dev/github.com/hyperledger/firefly-signer/pkg/ethsigner)
22-
- Keystore V3 wallet implementation
22+
- Keystore V3 key file implementation
2323
- Scrypt - read/write
2424
- pbkdf2 - read
2525
- See `pkg/keystorev3` [go doc](https://pkg.go.dev/github.com/hyperledger/firefly-signer/pkg/keystorev3)
26+
- Filesystem wallet
27+
- Configurable caching for in-memory keys
28+
- Files in directory with a given extension matching `{{ADDRESS}}.key`/`{{ADDRESS}}.toml` or arbitrary regex
29+
- Files can be TOML/YAML/JSON metadata pointing to Keystore V3 files + password files
30+
- Files can be Keystore V3 files directly, with accompanying `{{ADDRESS}}.pass` files
31+
- Detects newly added files automatically
32+
- See `pkg/fswallet` [go doc](https://pkg.go.dev/github.com/hyperledger/firefly-signer/pkg/fswallet)
2633

2734
## JSON/RPC proxy server
2835

@@ -40,12 +47,6 @@ calls through unchanged.
4047
- Queries Chain ID via `net_version` on startup
4148
- `eth_accounts` JSON/RPC method support
4249
- Trivial nonce management built-in (calls `eth_getTransactionCount` for each request)
43-
- File based wallet
44-
- Configurable caching for in-memory keys
45-
- Files in directory with a given extension matching `{{ADDRESS}}.key`/`{{ADDRESS}}.toml`
46-
- Customizable extension, and optional `0x` prefix to filename
47-
- Files can be TOML/YAML/JSON metadata pointing to Keystore V3 files + password files
48-
- Files can be Keystore V3 files directly, with accompanying `{{ADDRESS}}.pass` files
4950

5051
## JSON/RPC proxy server configuration
5152

cmd/ffsigner.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ import (
2626
"github.com/hyperledger/firefly-common/pkg/config"
2727
"github.com/hyperledger/firefly-common/pkg/i18n"
2828
"github.com/hyperledger/firefly-common/pkg/log"
29-
"github.com/hyperledger/firefly-signer/internal/filewallet"
3029
"github.com/hyperledger/firefly-signer/internal/rpcserver"
3130
"github.com/hyperledger/firefly-signer/internal/signerconfig"
3231
"github.com/hyperledger/firefly-signer/internal/signermsgs"
32+
"github.com/hyperledger/firefly-signer/pkg/fswallet"
3333
"github.com/sirupsen/logrus"
3434
"github.com/spf13/cobra"
3535
)
@@ -92,7 +92,7 @@ func run() error {
9292
if !config.GetBool(signerconfig.FileWalletEnabled) {
9393
return i18n.NewError(ctx, signermsgs.MsgNoWalletEnabled)
9494
}
95-
fileWallet, err := filewallet.NewFileWallet(ctx)
95+
fileWallet, err := fswallet.NewFilesystemWallet(ctx, fswallet.ReadConfig(signerconfig.FileWalletConfig))
9696
if err != nil {
9797
return err
9898
}

config.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ nav_order: 2
2121

2222
|Key|Description|Type|Default Value|
2323
|---|-----------|----|-------------|
24-
|chainId|Optionally set the Chain ID of the blockchain. Otherwise the Network ID will be queried, and used as the Chain ID in signind|number|`-1`
24+
|chainId|Optionally set the Chain ID of the blockchain. Otherwise the Network ID will be queried, and used as the Chain ID in signing|number|`-1`
2525
|connectionTimeout|The maximum amount of time that a connection is allowed to remain with no data transmitted|[`time.Duration`](https://pkg.go.dev/time#Duration)|`30s`
2626
|expectContinueTimeout|See [ExpectContinueTimeout in the Go docs](https://pkg.go.dev/net/http#Transport)|[`time.Duration`](https://pkg.go.dev/time#Duration)|`1s`
2727
|headers|Adds custom headers to HTTP requests|`map[string]string`|`<nil>`
@@ -80,6 +80,7 @@ nav_order: 2
8080
|Key|Description|Type|Default Value|
8181
|---|-----------|----|-------------|
8282
|defaultPasswordFile|Optional default password file to use, if one is not specified individually for the key (via metadata, or file extension)|string|`<nil>`
83+
|disableListener|Disable the filesystem listener that automatically detects the creation of new keystore files|boolean|`<nil>`
8384
|enabled|Whether the Keystore V3 filesystem wallet is enabled|boolean|`true`
8485
|path|Path on the filesystem where the metadata files (and/or key files) are located|string|`<nil>`
8586
|signerCacheSize|Maximum of signing keys to hold in memory|number|`250`
@@ -90,8 +91,11 @@ nav_order: 2
9091
|Key|Description|Type|Default Value|
9192
|---|-----------|----|-------------|
9293
|passwordExt|Optional to use to look up password files, that sit next to the key files directly. Alternative to metadata when you have a password per keystore|string|`<nil>`
93-
|primaryExt|Extension for the primary file to look up for an address string (can be key file directly, or metadata file)|string|`<nil>`
94-
|with0xPrefix|When true filenames will be resolved with an 0x prefix|boolean|`<nil>`
94+
|passwordPath|Optional directory in which to look for the password files, when passwordExt is configured. Default is the wallet directory|string|`<nil>`
95+
|passwordTrimSpace|Whether to trim leading/trailing whitespace (such as a newline) from the password when loaded from file|boolean|`true`
96+
|primaryExt|Extension for key/metadata files named by <ADDRESS>.<EXT>|string|`<nil>`
97+
|primaryMatchRegex|Regular expression run against key/metadata filenames to extract the address (takes precedence over primaryExt)|regexp|`<nil>`
98+
|with0xPrefix|When true and passwordExt is used, password filenames will be generated with an 0x prefix|boolean|`<nil>`
9599

96100
## fileWallet.metadata
97101

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.17
44

55
require (
66
github.com/btcsuite/btcd/btcec/v2 v2.1.3
7+
github.com/fsnotify/fsnotify v1.5.4
78
github.com/go-resty/resty/v2 v2.7.0
89
github.com/gorilla/mux v1.8.0
910
github.com/hyperledger/firefly-common v0.1.13
@@ -24,7 +25,6 @@ require (
2425
github.com/davecgh/go-spew v1.1.1 // indirect
2526
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
2627
github.com/docker/go-units v0.4.0 // indirect
27-
github.com/fsnotify/fsnotify v1.5.4 // indirect
2828
github.com/google/uuid v1.3.0 // indirect
2929
github.com/gorilla/websocket v1.5.0 // indirect
3030
github.com/hashicorp/hcl v1.0.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r
7878
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
7979
github.com/btcsuite/btcd/btcec/v2 v2.1.3 h1:xM/n3yIhHAhHy04z4i43C8p4ehixJZMsnrVJkgl+MTE=
8080
github.com/btcsuite/btcd/btcec/v2 v2.1.3/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE=
81+
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0 h1:MSskdM4/xJYcFzy0altH/C/xHopifpWzHUi1JeVI34Q=
8182
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
8283
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
8384
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
@@ -104,6 +105,7 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
104105
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
105106
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
106107
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
108+
github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0=
107109
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
108110
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1m5sE92cU+pd5Mcc=
109111
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs=

0 commit comments

Comments
 (0)