Skip to content

support exporting solana keys #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions digests.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
01ab04b339665e62223015b7fcf8a8189956dc967967eaa7007856b69b1bf609 turnkey.darwin-aarch64
175db6f89e62eb192509600d63425333c43d283dbe2370bf2ca74a5b786fa808 turnkey.darwin-x86_64
5ee6e78e9e4d769b47e0132a449246863c4cff0d012b542090ba31d7df6931b6 turnkey.linux-aarch64
0fc53177e42030084d748a2920d5680ca63a51c9fc6d3d8d6f3757dda7639069 turnkey.linux-x86_64
4e6881ec55c1172aa6fcc870710eb4b36bcfc906cd3df334b4041c7ce558db32 turnkey.darwin-aarch64
118f9162601dd9c4a1f2f3630cb21ba63a832719596958ea2d416cff7fc9926a turnkey.darwin-x86_64
766943ceae6945de5f70c43b923a743026b22f7563c21e0bf7299634db5343dd turnkey.linux-aarch64
4b688b6c8bc032fda2ddb78ba1b8c1753ca597832d3462882e8ae63db0127a4d turnkey.linux-x86_64
27 changes: 25 additions & 2 deletions src/cmd/turnkey/pkg/decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package pkg

import (
"crypto/ecdsa"
"encoding/hex"
"fmt"

"github.com/btcsuite/btcutil/base58"
"github.com/rotisserie/eris"
"github.com/spf13/cobra"
"github.com/tkhq/go-sdk/pkg/enclave_encrypt"
Expand All @@ -15,12 +18,16 @@ var (

// EncryptionKeypair is the loaded Encryption Keypair.
EncryptionKeypair *encryptionkey.Key

// Solana address, required for exporting Solana private keys in the proper format
solanaAddress string
)

func init() {
decryptCmd.Flags().StringVar(&exportBundlePath, "export-bundle-input", "", "filepath to read the export bundle from.")
decryptCmd.Flags().StringVar(&plaintextPath, "plaintext-output", "", "optional filepath to write the plaintext from that will be decrypted.")
decryptCmd.Flags().StringVar(&signerPublicKeyOverride, "signer-quorum-key", "", "optional override for the signer quorum key. This option should be used for testing only. Leave this value empty for production decryptions.")
decryptCmd.Flags().StringVar(&solanaAddress, "solana-address", "", "optional solana address, for use when exporting solana private keys.")

rootCmd.AddCommand(decryptCmd)
}
Expand Down Expand Up @@ -71,11 +78,27 @@ var decryptCmd = &cobra.Command{
// decrypt ciphertext
plaintextBytes, err := encryptClient.Decrypt([]byte(exportBundle), Organization)
if err != nil {
OutputError(err)
OutputError(eris.Errorf("unable to decrypt export bundle: %v", err))
}

plaintext := string(plaintextBytes)

// apply formatting, if applicable
if solanaAddress != "" {
hexEncodedPlaintext := hex.EncodeToString(plaintextBytes)

decodedAddressBytes := base58.Decode(solanaAddress)
decodedAddress := hex.EncodeToString(decodedAddressBytes)

combinedHex := fmt.Sprintf("%s%s", hexEncodedPlaintext, decodedAddress)
combinedBytes, err := hex.DecodeString(combinedHex)
if err != nil {
OutputError(eris.Errorf("unable to decode combined hex string: %v", err))
}

plaintext = base58.Encode(combinedBytes)
}

// output the plaintext if no filepath is passed
if plaintextPath == "" {
Output(plaintext)
Expand All @@ -84,7 +107,7 @@ var decryptCmd = &cobra.Command{

err = writeFile(plaintext, plaintextPath)
if err != nil {
OutputError(err)
OutputError(eris.Errorf("unable to write plaintext secret to file: %v", err))
}
},
}
Expand Down
1 change: 1 addition & 0 deletions src/cmd/turnkey/pkg/wallets.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func init() {

walletAccountsCmd.AddCommand(walletAccountsListCmd)
walletAccountsCmd.AddCommand(walletAccountCreateCmd)
walletAccountsCmd.AddCommand(walletAccountExportCmd)
walletsCmd.AddCommand(walletCreateCmd)
walletsCmd.AddCommand(walletsListCmd)
walletsCmd.AddCommand(walletExportCmd)
Expand Down
Loading