-
Notifications
You must be signed in to change notification settings - Fork 717
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CCQ: Reorg code into a query package (#3112)
* CCQ: Reorg code into a query package * Make requestTimeout public
- Loading branch information
1 parent
e8c561a
commit 7c5b3f9
Showing
11 changed files
with
237 additions
and
179 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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,58 @@ | ||
package query | ||
|
||
import ( | ||
"crypto/ecdsa" | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
nodev1 "github.com/certusone/wormhole/node/pkg/proto/node/v1" | ||
|
||
ethCrypto "github.com/ethereum/go-ethereum/crypto" | ||
"golang.org/x/crypto/openpgp/armor" //nolint | ||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
const ( | ||
GuardianKeyArmoredBlock = "WORMHOLE GUARDIAN PRIVATE KEY" | ||
) | ||
|
||
// loadGuardianKey loads a serialized guardian key from disk. | ||
func loadGuardianKey(filename string) (*ecdsa.PrivateKey, error) { | ||
f, err := os.Open(filename) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to open file: %w", err) | ||
} | ||
|
||
p, err := armor.Decode(f) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to read armored file: %w", err) | ||
} | ||
|
||
if p.Type != GuardianKeyArmoredBlock { | ||
return nil, fmt.Errorf("invalid block type: %s", p.Type) | ||
} | ||
|
||
b, err := io.ReadAll(p.Body) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to read file: %w", err) | ||
} | ||
|
||
var m nodev1.GuardianKey | ||
err = proto.Unmarshal(b, &m) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to deserialize protobuf: %w", err) | ||
} | ||
|
||
gk, err := ethCrypto.ToECDSA(m.Data) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to deserialize raw key data: %w", err) | ||
} | ||
|
||
return gk, nil | ||
} | ||
|
||
func makeChannelPair[T any](cap int) (<-chan T, chan<- T) { | ||
out := make(chan T, cap) | ||
return out, out | ||
} |
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,4 +1,4 @@ | ||
package common | ||
package query | ||
|
||
import ( | ||
"encoding/hex" | ||
|
Oops, something went wrong.