From 00cc9c60a41d7f101facacc6624ce0d3f28f6cca Mon Sep 17 00:00:00 2001 From: Jason Wang Date: Tue, 26 Nov 2024 16:41:05 -0800 Subject: [PATCH] Fixing case where signingJobs is empty for non-DERIVE_KEY_AND_SIGN requests. --- remotesigning/remote_signing.go | 44 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/remotesigning/remote_signing.go b/remotesigning/remote_signing.go index e45abdc..6fbf32b 100644 --- a/remotesigning/remote_signing.go +++ b/remotesigning/remote_signing.go @@ -58,31 +58,30 @@ func GraphQLResponseForRemoteSigningWebhook( webhook webhooks.WebhookEvent, seedBytes []byte, ) (SigningResponse, error) { - // Calculate the xpub for each L1 signing job + // If derive key and sign, calculate the xpub for each L1 signing job + subEventTypeStr := (*webhook.Data)["sub_event_type"].(string) signingJobs, hasSigningJobs := (*webhook.Data)["signing_jobs"].([]interface{}) - if !hasSigningJobs { - return nil, fmt.Errorf("signing_jobs not found or invalid type") - } - var xpubs []string - for _, job := range signingJobs { - jobMap, isValidJobMap := job.(map[string]interface{}) - if !isValidJobMap { - return nil, fmt.Errorf("invalid signing job format") - } - derivationPath := jobMap["derivation_path"].(string) - - hardenedPath, _, err := SplitDerivationPath(derivationPath) - if err != nil { - return nil, err - } - - masterSeedHex := hex.EncodeToString(seedBytes) - xpub, err := utils.GenHardenedXPub(masterSeedHex, hardenedPath, "mainnet") - if err != nil { - return nil, err + if subEventTypeStr == "DERIVE_KEY_AND_SIGN" && hasSigningJobs { + for _, job := range signingJobs { + jobMap, isValidJobMap := job.(map[string]interface{}) + if !isValidJobMap { + return nil, fmt.Errorf("invalid signing job format") + } + derivationPath := jobMap["derivation_path"].(string) + + hardenedPath, _, err := SplitDerivationPath(derivationPath) + if err != nil { + return nil, err + } + + masterSeedHex := hex.EncodeToString(seedBytes) + xpub, err := utils.GenHardenedXPub(masterSeedHex, hardenedPath, "mainnet") + if err != nil { + return nil, err + } + xpubs = append(xpubs, xpub) } - xpubs = append(xpubs, xpub) } if !validator.ShouldSign(webhook, xpubs) { return nil, errors.New("declined to sign messages") @@ -94,7 +93,6 @@ func GraphQLResponseForRemoteSigningWebhook( return nil, errors.New("webhook data is missing") } var subtype objects.RemoteSigningSubEventType - subEventTypeStr := (*webhook.Data)["sub_event_type"].(string) log.Printf("Received remote signing webhook with sub_event_type %s", subEventTypeStr) err := subtype.UnmarshalJSON([]byte(`"` + subEventTypeStr + `"`)) if err != nil {