From 741b668b800833e930457df8dc5edd656270322a Mon Sep 17 00:00:00 2001 From: Tim Hawbaker Date: Tue, 31 Oct 2023 22:50:41 -0700 Subject: [PATCH] bump go-sdk --- src/cmd/turnkey/pkg/activities.go | 31 +++++---- src/cmd/turnkey/pkg/address-formats.go | 2 +- src/cmd/turnkey/pkg/curves.go | 2 +- src/cmd/turnkey/pkg/ethereum.go | 25 ++++---- src/cmd/turnkey/pkg/organizations.go | 16 ++--- src/cmd/turnkey/pkg/private-keys.go | 80 +++++------------------- src/cmd/turnkey/pkg/raw.go | 33 +++++----- src/cmd/turnkey/pkg/transaction-types.go | 2 +- src/go.mod | 2 +- src/go.sum | 4 +- 10 files changed, 70 insertions(+), 127 deletions(-) diff --git a/src/cmd/turnkey/pkg/activities.go b/src/cmd/turnkey/pkg/activities.go index f9b6aca..c2a74a5 100644 --- a/src/cmd/turnkey/pkg/activities.go +++ b/src/cmd/turnkey/pkg/activities.go @@ -32,47 +32,46 @@ var activitiesListCmd = &cobra.Command{ Use: "list", Short: "Return the set of activities for an organization", Run: func(cmd *cobra.Command, args []string) { - activitiesFilter := make([]models.V1ActivityStatus, len(activitiesListStatus)) + activitiesFilter := make([]models.ActivityStatus, len(activitiesListStatus)) for i, s := range activitiesListStatus { if s == Help { - Output(models.ActivityStatuses()) + Output(models.ActivityStatusEnum) return } if s == "all" { - activitiesFilter = models.ActivityStatuses() - + activitiesFilter = models.ActivityStatusEnum break } switch s { case "created": - activitiesFilter[i] = models.V1ActivityStatusACTIVITYSTATUSCREATED + activitiesFilter[i] = models.ActivityStatusCreated case "pending": - activitiesFilter[i] = models.V1ActivityStatusACTIVITYSTATUSPENDING + activitiesFilter[i] = models.ActivityStatusPending case "completed": - activitiesFilter[i] = models.V1ActivityStatusACTIVITYSTATUSCOMPLETED + activitiesFilter[i] = models.ActivityStatusCompleted case "failed": - activitiesFilter[i] = models.V1ActivityStatusACTIVITYSTATUSFAILED + activitiesFilter[i] = models.ActivityStatusFailed case "consensus": - activitiesFilter[i] = models.V1ActivityStatusACTIVITYSTATUSCONSENSUSNEEDED + activitiesFilter[i] = models.ActivityStatusConsensusNeeded case "consensus_needed": - activitiesFilter[i] = models.V1ActivityStatusACTIVITYSTATUSCONSENSUSNEEDED + activitiesFilter[i] = models.ActivityStatusConsensusNeeded case "rejected": - activitiesFilter[i] = models.V1ActivityStatusACTIVITYSTATUSREJECTED + activitiesFilter[i] = models.ActivityStatusRejected default: - activitiesFilter[i] = models.V1ActivityStatus(s) + activitiesFilter[i] = models.ActivityStatus(s) } } - params := activities.NewPublicAPIServiceGetActivitiesParams().WithDefaults().WithBody(&models.V1GetActivitiesRequest{ + params := activities.NewGetActivitiesParams().WithDefaults().WithBody(&models.GetActivitiesRequest{ FilterByStatus: activitiesFilter, OrganizationID: &Organization, }) - res, err := APIClient.V0().Activities.PublicAPIServiceGetActivities(params, APIClient.Authenticator) + res, err := APIClient.V0().Activities.GetActivities(params, APIClient.Authenticator) if err != nil { OutputError(err) } @@ -88,12 +87,12 @@ var activitiesGetCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { id := args[0] - params := activities.NewPublicAPIServiceGetActivityParams().WithDefaults().WithBody(&models.V1GetActivityRequest{ + params := activities.NewGetActivityParams().WithDefaults().WithBody(&models.GetActivityRequest{ ActivityID: &id, OrganizationID: &Organization, }) - res, err := APIClient.V0().Activities.PublicAPIServiceGetActivity(params, APIClient.Authenticator) + res, err := APIClient.V0().Activities.GetActivity(params, APIClient.Authenticator) if err != nil { OutputError(err) } diff --git a/src/cmd/turnkey/pkg/address-formats.go b/src/cmd/turnkey/pkg/address-formats.go index 2d7aaf0..0d73081 100644 --- a/src/cmd/turnkey/pkg/address-formats.go +++ b/src/cmd/turnkey/pkg/address-formats.go @@ -21,6 +21,6 @@ var addressFormatsListCmd = &cobra.Command{ Use: "list", Short: "Return the available key formats", Run: func(cmd *cobra.Command, args []string) { - Output(models.AddressFormats()) + Output(models.AddressFormatEnum) }, } diff --git a/src/cmd/turnkey/pkg/curves.go b/src/cmd/turnkey/pkg/curves.go index e16ef84..984035e 100644 --- a/src/cmd/turnkey/pkg/curves.go +++ b/src/cmd/turnkey/pkg/curves.go @@ -21,6 +21,6 @@ var curvesListCmd = &cobra.Command{ Use: "list", Short: "Return the available curve types", Run: func(cmd *cobra.Command, args []string) { - Output(models.Curves()) + Output(models.CurveEnum) }, } diff --git a/src/cmd/turnkey/pkg/ethereum.go b/src/cmd/turnkey/pkg/ethereum.go index 5c58ac1..2df081a 100644 --- a/src/cmd/turnkey/pkg/ethereum.go +++ b/src/cmd/turnkey/pkg/ethereum.go @@ -4,18 +4,20 @@ import ( "github.com/rotisserie/eris" "github.com/spf13/cobra" - "github.com/tkhq/go-sdk/pkg/api/client/private_keys" + "github.com/tkhq/go-sdk/pkg/api/client/signers" "github.com/tkhq/go-sdk/pkg/api/models" "github.com/tkhq/go-sdk/pkg/util" ) -var ethTxPayload string +var ( + ethTxSigner string + ethTxPayload string +) func init() { - ethCmd.PersistentFlags().StringVarP(&signingKeyID, "private-key", "s", "", "name or ID of the private signing key") - rootCmd.AddCommand(ethCmd) + ethTxCmd.Flags().StringVarP(ðTxSigner, "signer", "s", "", "wallet account address, private key address, or private key ID") ethTxCmd.Flags().StringVar(ðTxPayload, "payload", "", "payload of the transaction") ethCmd.AddCommand(ethTxCmd) @@ -28,7 +30,6 @@ var ethCmd = &cobra.Command{ PersistentPreRun: func(cmd *cobra.Command, args []string) { basicSetup(cmd) LoadKeypair("") - LoadSigningKey("") LoadClient() }, } @@ -38,8 +39,8 @@ var ethTxCmd = &cobra.Command{ Short: "Perform signing and other actions for a transaction", Aliases: []string{"tx"}, Run: func(cmd *cobra.Command, args []string) { - transactionType := models.V1TransactionTypeTRANSACTIONTYPEETHEREUM - activityType := string(models.V1ActivityTypeACTIVITYTYPESIGNTRANSACTION) + transactionType := models.TransactionTypeEthereum + activityType := string(models.ActivityTypeSignTransaction) payload, err := ParameterToString(ethTxPayload) if err != nil { @@ -52,11 +53,11 @@ var ethTxCmd = &cobra.Command{ OutputError(eris.New("payload cannot be empty")) } - params := private_keys.NewPublicAPIServiceSignTransactionParams().WithBody( - &models.V1SignTransactionRequest{ + params := signers.NewSignTransactionParams().WithBody( + &models.SignTransactionRequest{ OrganizationID: &Organization, - Parameters: &models.V1SignTransactionIntent{ - PrivateKeyID: &signingKeyID, + Parameters: &models.SignTransactionIntentV2{ + SignWith: ðTxSigner, Type: &transactionType, UnsignedTransaction: &payload, }, @@ -65,7 +66,7 @@ var ethTxCmd = &cobra.Command{ }, ) - resp, err := APIClient.V0().PrivateKeys.PublicAPIServiceSignTransaction(params, APIClient.Authenticator) + resp, err := APIClient.V0().Signers.SignTransaction(params, APIClient.Authenticator) if err != nil { OutputError(eris.Wrap(err, "request failed")) } diff --git a/src/cmd/turnkey/pkg/organizations.go b/src/cmd/turnkey/pkg/organizations.go index fa61105..c883939 100644 --- a/src/cmd/turnkey/pkg/organizations.go +++ b/src/cmd/turnkey/pkg/organizations.go @@ -38,19 +38,19 @@ var organizationsCreateCmd = &cobra.Command{ } }, Run: func(cmd *cobra.Command, args []string) { - curve := models.Immutablecommonv1Curve(privateKeysCreateCurve) + curve := models.Curve(privateKeysCreateCurve) - addressFormats := make([]models.Immutablecommonv1AddressFormat, len(privateKeysCreateAddressFormats)) + addressFormats := make([]models.AddressFormat, len(privateKeysCreateAddressFormats)) for n, f := range privateKeysCreateAddressFormats { - addressFormats[n] = models.Immutablecommonv1AddressFormat(f) + addressFormats[n] = models.AddressFormat(f) } - params := private_keys.NewPublicAPIServiceCreatePrivateKeysParams() - params.SetBody(&models.V1CreatePrivateKeysRequest{ + params := private_keys.NewCreatePrivateKeysParams() + params.SetBody(&models.CreatePrivateKeysRequest{ OrganizationID: &Organization, - Parameters: &models.V1CreatePrivateKeysIntentV2{ - PrivateKeys: []*models.V1PrivateKeyParams{ + Parameters: &models.CreatePrivateKeysIntentV2{ + PrivateKeys: []*models.PrivateKeyParams{ { AddressFormats: addressFormats, Curve: &curve, @@ -61,7 +61,7 @@ var organizationsCreateCmd = &cobra.Command{ }, }) - resp, err := APIClient.V0().PrivateKeys.PublicAPIServiceCreatePrivateKeys(params, APIClient.Authenticator) + resp, err := APIClient.V0().PrivateKeys.CreatePrivateKeys(params, APIClient.Authenticator) if err != nil { OutputError(eris.Wrap(err, "request failed")) } diff --git a/src/cmd/turnkey/pkg/private-keys.go b/src/cmd/turnkey/pkg/private-keys.go index 846b459..de7e6f7 100644 --- a/src/cmd/turnkey/pkg/private-keys.go +++ b/src/cmd/turnkey/pkg/private-keys.go @@ -1,7 +1,6 @@ package pkg import ( - "github.com/google/uuid" "github.com/rotisserie/eris" "github.com/spf13/cobra" @@ -11,8 +10,6 @@ import ( ) var ( - signingKeyID string - privateKeysCreateAddressFormats []string privateKeysCreateCurve string privateKeysCreateName string @@ -59,33 +56,31 @@ var privateKeysCreateCmd = &cobra.Command{ } }, Run: func(cmd *cobra.Command, args []string) { - curve := models.Immutablecommonv1Curve(privateKeysCreateCurve) + curve := models.Curve(privateKeysCreateCurve) if curve == Help { - Output(models.Curves()) - + Output(models.CurveEnum) return } - addressFormats := make([]models.Immutablecommonv1AddressFormat, len(privateKeysCreateAddressFormats)) + addressFormats := make([]models.AddressFormat, len(privateKeysCreateAddressFormats)) for n, f := range privateKeysCreateAddressFormats { if f == Help { - Output(models.AddressFormats()) - + Output(models.AddressFormatEnum) return } - addressFormats[n] = models.Immutablecommonv1AddressFormat(f) + addressFormats[n] = models.AddressFormat(f) } - activity := string(models.V1ActivityTypeACTIVITYTYPECREATEPRIVATEKEYS) + activity := string(models.ActivityTypeCreatePrivateKeys) - params := private_keys.NewPublicAPIServiceCreatePrivateKeysParams() - params.SetBody(&models.V1CreatePrivateKeysRequest{ + params := private_keys.NewCreatePrivateKeysParams() + params.SetBody(&models.CreatePrivateKeysRequest{ OrganizationID: &Organization, - Parameters: &models.V1CreatePrivateKeysIntentV2{ - PrivateKeys: []*models.V1PrivateKeyParams{ + Parameters: &models.CreatePrivateKeysIntentV2{ + PrivateKeys: []*models.PrivateKeyParams{ { AddressFormats: addressFormats, Curve: &curve, @@ -102,7 +97,7 @@ var privateKeysCreateCmd = &cobra.Command{ OutputError(eris.Wrap(err, "request validation failed")) } - resp, err := APIClient.V0().PrivateKeys.PublicAPIServiceCreatePrivateKeys(params, APIClient.Authenticator) + resp, err := APIClient.V0().PrivateKeys.CreatePrivateKeys(params, APIClient.Authenticator) if err != nil { OutputError(eris.Wrap(err, "request failed")) } @@ -119,9 +114,9 @@ var privateKeysListCmd = &cobra.Command{ Use: "list", Short: "Return private keys for the organization", Run: func(cmd *cobra.Command, args []string) { - params := private_keys.NewPublicAPIServiceGetPrivateKeysParams() + params := private_keys.NewGetPrivateKeysParams() - params.SetBody(&models.V1GetPrivateKeysRequest{ + params.SetBody(&models.GetPrivateKeysRequest{ OrganizationID: &Organization, }) @@ -129,7 +124,7 @@ var privateKeysListCmd = &cobra.Command{ OutputError(eris.Wrap(err, "request validation failed")) } - resp, err := APIClient.V0().PrivateKeys.PublicAPIServiceGetPrivateKeys(params, APIClient.Authenticator) + resp, err := APIClient.V0().PrivateKeys.GetPrivateKeys(params, APIClient.Authenticator) if err != nil { OutputError(eris.Wrap(err, "request failed")) } @@ -141,50 +136,3 @@ var privateKeysListCmd = &cobra.Command{ Output(resp.Payload) }, } - -// LoadSigningKey require-loads a signing key. -func LoadSigningKey(name string) { - if name != "" { - signingKeyID = name - } - - if signingKeyID == "" { - OutputError(eris.New("no private key provided")) - } - - if _, err := uuid.Parse(signingKeyID); err != nil { - signingKeyID, err = lookupPrivateKeyByName(signingKeyID) - if err != nil { - OutputError(eris.Wrap(err, "provided private key was not a UUID and lookup by name failed")) - } - } -} - -func lookupPrivateKeyByName(name string) (string, error) { - params := private_keys.NewPublicAPIServiceGetPrivateKeysParams() - - params.SetBody(&models.V1GetPrivateKeysRequest{ - OrganizationID: &Organization, - }) - - if err := params.Body.Validate(nil); err != nil { - return "", eris.Wrap(err, "formulation of a lookup by name request failed") - } - - resp, err := APIClient.V0().PrivateKeys.PublicAPIServiceGetPrivateKeys(params, APIClient.Authenticator) - if err != nil { - return "", eris.Wrap(err, "lookup by name failed") - } - - if !resp.IsSuccess() { - return "", eris.Errorf("lookup by name failed: %s", resp.Error()) - } - - for _, k := range resp.Payload.PrivateKeys { - if *k.PrivateKeyName == name { - return *k.PrivateKeyID, nil - } - } - - return "", eris.Errorf("private key name %q not found in list of private keys", name) -} diff --git a/src/cmd/turnkey/pkg/raw.go b/src/cmd/turnkey/pkg/raw.go index 0db2067..98a7c61 100644 --- a/src/cmd/turnkey/pkg/raw.go +++ b/src/cmd/turnkey/pkg/raw.go @@ -4,24 +4,24 @@ import ( "github.com/rotisserie/eris" "github.com/spf13/cobra" - "github.com/tkhq/go-sdk/pkg/api/client/private_keys" + "github.com/tkhq/go-sdk/pkg/api/client/signers" "github.com/tkhq/go-sdk/pkg/api/models" "github.com/tkhq/go-sdk/pkg/util" ) var ( + rawSigner string rawSignPayloadEncoding string rawSignHashFunction string rawSignPayload string ) func init() { - rawCmd.Flags().StringVar(&signingKeyID, "private-key", "", "name or ID of the private signing key") - + rawSignCmd.Flags().StringVarP(&rawSigner, "signer", "s", "", "wallet account address, private key address, or private key ID") rawSignCmd.Flags().StringVar(&rawSignPayloadEncoding, "payload-encoding", - string(models.V1PayloadEncodingPAYLOADENCODINGTEXTUTF8), "encoding of payload") + string(models.PayloadEncodingTextUTF8), "encoding of payload") rawSignCmd.Flags().StringVar(&rawSignHashFunction, "hash-function", - string(models.V1HashFunctionHASHFUNCTIONSHA256), "hash function") + string(models.HashFunctionSha256), "hash function") rawSignCmd.Flags().StringVar(&rawSignPayload, "payload", "", "payload to be signed") @@ -35,11 +35,7 @@ var rawCmd = &cobra.Command{ Short: "Send low-level (raw) requests to the Turnkey API", PersistentPreRun: func(cmd *cobra.Command, args []string) { basicSetup(cmd) - LoadKeypair("") - - LoadSigningKey("") - LoadClient() }, } @@ -48,24 +44,23 @@ var rawSignCmd = &cobra.Command{ Use: "sign", Short: "Sign a raw payload", Run: func(cmd *cobra.Command, args []string) { - payloadEncoding := models.Immutableactivityv1PayloadEncoding(rawSignPayloadEncoding) - - hashFunction := models.Immutableactivityv1HashFunction(rawSignHashFunction) + payloadEncoding := models.PayloadEncoding(rawSignPayloadEncoding) + hashFunction := models.HashFunction(rawSignHashFunction) payload, err := ParameterToString(rawSignPayload) if err != nil { OutputError(eris.Wrap(err, "failed to read payload")) } - activityType := string(models.V1ActivityTypeACTIVITYTYPESIGNRAWPAYLOAD) + activityType := string(models.ActivityTypeSignRawPayload) - params := private_keys.NewPublicAPIServiceSignRawPayloadParams().WithBody( - &models.V1SignRawPayloadRequest{ + params := signers.NewSignRawPayloadParams().WithBody( + &models.SignRawPayloadRequest{ OrganizationID: &Organization, - Parameters: &models.V1SignRawPayloadIntent{ + Parameters: &models.SignRawPayloadIntentV2{ + SignWith: &rawSigner, Encoding: &payloadEncoding, HashFunction: &hashFunction, - PrivateKeyID: &signingKeyID, Payload: &payload, }, TimestampMs: util.RequestTimestamp(), @@ -73,13 +68,13 @@ var rawSignCmd = &cobra.Command{ }, ) - resp, err := APIClient.V0().PrivateKeys.PublicAPIServiceSignRawPayload(params, APIClient.Authenticator) + resp, err := APIClient.V0().Signers.SignRawPayload(params, APIClient.Authenticator) if err != nil { OutputError(eris.Wrap(err, "request failed")) } if !resp.IsSuccess() { - OutputError(eris.Errorf("failed to create private key: %s", resp.Error())) + OutputError(eris.Errorf("failed to sign raw payload: %s", resp.Error())) } Output(resp.Payload) diff --git a/src/cmd/turnkey/pkg/transaction-types.go b/src/cmd/turnkey/pkg/transaction-types.go index 802882c..4daf471 100644 --- a/src/cmd/turnkey/pkg/transaction-types.go +++ b/src/cmd/turnkey/pkg/transaction-types.go @@ -21,6 +21,6 @@ var transactionTypesListCmd = &cobra.Command{ Use: "list", Short: "Return the available transaction types", Run: func(cmd *cobra.Command, args []string) { - Output(models.TransactionTypes()) + Output(models.TransactionTypeEnum) }, } diff --git a/src/go.mod b/src/go.mod index 7785457..860330e 100644 --- a/src/go.mod +++ b/src/go.mod @@ -7,7 +7,7 @@ require ( github.com/rotisserie/eris v0.5.4 github.com/spf13/cobra v1.7.0 github.com/stretchr/testify v1.8.4 - github.com/tkhq/go-sdk v0.0.0-20231012184607-a212c3c99c0a + github.com/tkhq/go-sdk v0.0.0-20231101200934-5338f37bc020 gopkg.in/yaml.v3 v3.0.1 ) diff --git a/src/go.sum b/src/go.sum index 9037065..17f206d 100644 --- a/src/go.sum +++ b/src/go.sum @@ -156,8 +156,8 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= -github.com/tkhq/go-sdk v0.0.0-20231012184607-a212c3c99c0a h1:pPUO6fXZJCrCQsl1WqpMv/qh8nsBgAquWUT4aehtBWs= -github.com/tkhq/go-sdk v0.0.0-20231012184607-a212c3c99c0a/go.mod h1:P0yocuYTkq0h2OMtgcOEDp9qnys5aWUev37qVobbTw0= +github.com/tkhq/go-sdk v0.0.0-20231101200934-5338f37bc020 h1:XaFlAdJNvIWTGVGkt0BbqZ7kh6Ky7AdL9fnw1q0jrzk= +github.com/tkhq/go-sdk v0.0.0-20231101200934-5338f37bc020/go.mod h1:P0yocuYTkq0h2OMtgcOEDp9qnys5aWUev37qVobbTw0= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs= github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g=