-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add signature verification tool in rosetta-cli (#387)
* add verify and readme * format * verify json example
- Loading branch information
1 parent
1188c48
commit 679464c
Showing
8 changed files
with
151 additions
and
14 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
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,33 @@ | ||
## Key Sign Tool | ||
|
||
Rosetta CLI has a key sign tool, which you can use to sign and verify various curves supported | ||
by rosetta-specifications. This should only be used for local development. Never share private keys anywhere. | ||
|
||
### Usage | ||
#### Sign | ||
``` | ||
rosetta-cli key:sign --configuration-file config.json | ||
``` | ||
|
||
A sample config file is located [here](../examples/configuration/sign.json) | ||
|
||
Required fields includes | ||
- `pub_key` | ||
- `private_key` | ||
- `signing_payload` | ||
|
||
|
||
#### Verify | ||
``` | ||
rosetta-cli key:verify --configuration-file verify.json | ||
``` | ||
A sample config file is located [here](../examples/configuration/verify.json) | ||
|
||
Required fields includes | ||
- `pub_key` | ||
- `signing_payload` | ||
- `signature` | ||
|
||
|
||
### Troubleshoot | ||
- `account_identifier` field in `signing_payload` field should've a dummy address for providing valid payload. |
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
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,69 @@ | ||
// Copyright 2023 Coinbase, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"github.com/coinbase/rosetta-sdk-go/keys" | ||
"github.com/fatih/color" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
keyVerifyCmd = &cobra.Command{ | ||
Use: "key:verify", | ||
Short: "Verify the signature using the public key", | ||
Long: `Verify the signature using the public key | ||
It supports Keypair specified by https://github.com/coinbase/rosetta-specifications`, | ||
RunE: runKeyVerifyCmd, | ||
} | ||
) | ||
|
||
func runKeyVerifyCmd(_ *cobra.Command, _ []string) error { | ||
if Config.Sign == nil { | ||
return errors.New("sign configuration is missing") | ||
} | ||
|
||
if len(Config.Sign.Signature.Bytes) == 0 || | ||
Config.Sign.SigningPayload == nil || | ||
Config.Sign.SigningPayload.SignatureType == "" || | ||
Config.Sign.PubKey == nil { | ||
color.Red("invalid verify input") | ||
} | ||
|
||
keyPair := keys.KeyPair{ | ||
PublicKey: Config.Sign.PubKey, | ||
} | ||
|
||
signer, err := keyPair.Signer() | ||
if err != nil { | ||
color.Red("signer invalid with err %#v", err) | ||
return err | ||
} | ||
|
||
signature := Config.Sign.Signature | ||
signature.SignatureType = Config.Sign.SigningPayload.SignatureType | ||
signature.SigningPayload = Config.Sign.SigningPayload | ||
signature.PublicKey = Config.Sign.PubKey | ||
|
||
err = signer.Verify(signature) | ||
if err != nil { | ||
color.Red("invalid signature with err %#v", err) | ||
return err | ||
} | ||
|
||
color.Green("Signature Verified.") | ||
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
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
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
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,18 @@ | ||
{ | ||
"sign": { | ||
"pub_key": { | ||
"curve_type": "secp256k1", | ||
"hex_bytes": "03c7e625aa08cad8f257d9ee2b9b7a0214f19f981afd5b498c728ad7ed6c0c3df6" | ||
}, | ||
"signing_payload": { | ||
"hex_bytes": "370e74254e8cbaa343af3564901456082ec7af967e45ff24ba061233b1a1b04f", | ||
"signature_type": "ecdsa", | ||
"account_identifier": { | ||
"address": "dummy" | ||
} | ||
}, | ||
"signature": { | ||
"hex_bytes": "c80547470b7e4d3fc17c988b2244dfebc909b3e9f7fd0c1387763263cc70d16d24f326b9c12ba2ea278164c0b30f128a809585fc503eda43de429aadb9f893ef" | ||
} | ||
} | ||
} |