-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add crypto-providers ADR implementation POC
- Loading branch information
Showing
79 changed files
with
1,695 additions
and
3,369 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
.idea | ||
.idea | ||
.vscode | ||
build/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,18 @@ | ||
# Variables | ||
PKG := ./... | ||
GOFILES := $(shell find . -name '*.go' | grep -v _test.go) | ||
TESTFILES := $(shell find . -name '*_test.go') | ||
GOLANGCI_VERSION := v1.59.0 | ||
WALLET_BIN := build/wallet | ||
|
||
all: build | ||
.PHONY: demo run clean | ||
|
||
build: | ||
@if [ -z "$(TAGS)" ]; then \ | ||
echo "Building..."; \ | ||
else \ | ||
echo "Building with tags: $(TAGS)"; \ | ||
fi | ||
@go build -tags "$(TAGS)" $(PKG) | ||
.DEFAULT_GOAL := build | ||
|
||
# Run tests | ||
test: | ||
@if [ -z "$(TAGS)" ]; then \ | ||
echo "Running tests..."; \ | ||
else \ | ||
echo "Running tests with tags: $(TAGS)"; \ | ||
fi | ||
@go test -tags "$(TAGS)" -v $(PKG) | ||
# Build the wallet command | ||
build-wallet: | ||
go build -o $(WALLET_BIN) ./cmd | ||
|
||
# Install golangci-lint | ||
lint-install: | ||
@echo "--> Installing golangci-lint $(GOLANGCI_VERSION)" | ||
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_VERSION) | ||
# Run the demo | ||
demo: | ||
cd demo; \ | ||
go run main.go | ||
|
||
# Run golangci-lint | ||
lint: | ||
@echo "--> Running linter" | ||
$(MAKE) lint-install | ||
@golangci-lint run --timeout=15m | ||
|
||
# Run golangci-lint and fix | ||
lint-fix: | ||
@echo "--> Running linter with fix" | ||
$(MAKE) lint-install | ||
@golangci-lint run --fix | ||
|
||
.PHONY: build test lint-install lint lint-fix | ||
# Clean built binaries | ||
clean: | ||
rm -f $(WALLET_BIN) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,55 @@ | ||
# crypto | ||
# crypto-provider | ||
|
||
cosmos-crypto is the cryptographic package adapted for the interchain stack | ||
<p align="center"> | ||
<img src="logo.png" alt="Crypto Provider Logo" width="200" /> | ||
</p> | ||
|
||
## Importing it | ||
## Overview | ||
|
||
To get the interfaces, | ||
`import "github.com/cosmos/crypto/types"` | ||
This is a Proof of Concept of the crypto-providers ADR as described in the [ADR-001 Crypto Provider](https://github.com/cosmos/crypto/blob/main/docs/architecture/adr-001-crypto-provider.md). | ||
|
||
## Main Components | ||
|
||
The main components of this project are located in the `components` package. They include: | ||
|
||
- **CryptoProvider**: Aggregates functionalities of signing, verifying, and hashing, and provides metadata. | ||
- **CryptoProviderFactory**: A factory interface for creating CryptoProviders. | ||
- **BuildSource**: Various implementations for building CryptoProviders from different sources. | ||
- **ProviderMetadata**: Metadata structure for the crypto provider. | ||
- **Signer, Verifier, Hasher**: Interfaces for signing, verifying, and hashing data. | ||
- **AddressFormatter**: Interface for formatting addresses from public key bytes. | ||
|
||
## Running the Demo App | ||
|
||
To run the demo app, just type the following command: | ||
|
||
```bash | ||
make demo | ||
``` | ||
|
||
### What the Demo Does | ||
|
||
The demo application performs the following steps: | ||
|
||
1. Creates a new wallet using an in-memory keyring. | ||
2. Loads a JSON file and creates a new crypto provider from it. | ||
3. Retrieves a signer from the selected provider. | ||
4. Generates random data and signs it using the signer. | ||
5. Retrieves a verifier from the provider and verifies the generated signature. | ||
|
||
### Demo Architecture | ||
|
||
```mermaid | ||
graph TD | ||
A[Demo Application] --> B[Wallet] | ||
B --> C[Keyring] | ||
B --> D[CryptoProviderFactory] | ||
B --> Q[SimpleAddressFormatter] | ||
D --> E[FileProviderFactory] | ||
E --> F[FileProvider] | ||
F --> G[Signer] | ||
F --> H[Verifier] | ||
F --> I[Hasher] | ||
F --> O[ProviderMetadata] | ||
F --> P[FileProviderConfig] | ||
``` |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var listCmd = &cobra.Command{ | ||
Use: "list", | ||
Short: "List all providers", | ||
Long: `This command lists all the crypto providers currently available in the wallet.`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
w, err := setup() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
providers, err := w.ListProviders() | ||
if err != nil { | ||
return fmt.Errorf("failed to list providers: %v", err) | ||
} | ||
|
||
if len(providers) == 0 { | ||
fmt.Println("No providers found.") | ||
} else { | ||
fmt.Println("Available providers:") | ||
for _, provider := range providers { | ||
fmt.Printf("- %s\n", provider) | ||
} | ||
} | ||
|
||
return nil | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package register | ||
|
||
import ( | ||
// Import all provider packages here | ||
"crypto-provider/pkg/factory" | ||
_ "crypto-provider/pkg/provider/file" | ||
_ "crypto-provider/pkg/provider/file/cmd" | ||
// Add other providers as needed | ||
// _ "crypto-provider/pkg/provider/someprovider" | ||
) | ||
|
||
// Init is a dummy function to ensure this package is imported | ||
func Init() { | ||
_ = factory.GetFactory() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package main | ||
|
||
import ( | ||
"crypto-provider/pkg/cli" | ||
"crypto-provider/pkg/keyring" | ||
"crypto-provider/pkg/wallet" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
flags struct { | ||
providersDir string | ||
} | ||
) | ||
|
||
// SimpleAddressFormatter implementation | ||
type SimpleAddressFormatter struct{} | ||
|
||
func (f SimpleAddressFormatter) FormatAddress(pubKey []byte) (string, error) { | ||
return fmt.Sprintf("addr_%x", pubKey[:8]), nil | ||
} | ||
|
||
func setup() (wallet.Wallet, error) { | ||
addressFormatter := SimpleAddressFormatter{} | ||
w, err := wallet.NewKeyringWallet("wallet-app", keyring.BackendMemory, flags.providersDir, addressFormatter) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create wallet: %v", err) | ||
} | ||
return w, nil | ||
} | ||
|
||
func initFlags(rootCmd *cobra.Command) { | ||
rootCmd.PersistentFlags().StringVar(&flags.providersDir, "providers-dir", "", "Directory containing provider configurations") | ||
_ = rootCmd.MarkPersistentFlagRequired("providers-dir") | ||
} | ||
|
||
func main() { | ||
rootCmd := cli.GetRootCmd() | ||
initFlags(rootCmd) | ||
rootCmd.AddCommand(listCmd) | ||
|
||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.