Skip to content

Commit

Permalink
Fixing case where signingJobs is empty for non-DERIVE_KEY_AND_SIGN re…
Browse files Browse the repository at this point in the history
…quests.
  • Loading branch information
JasonCWang committed Nov 27, 2024
1 parent b756433 commit 00cc9c6
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions remotesigning/remote_signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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 {
Expand Down

0 comments on commit 00cc9c6

Please sign in to comment.