Skip to content
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

rpc: pass through adoptChildWallet response #85

Merged
merged 1 commit into from
Dec 12, 2024
Merged
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
5 changes: 3 additions & 2 deletions rpc/intents.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,11 @@ func (s *RPC) SendIntent(ctx context.Context, protoIntent *proto.Intent) (*proto
if err != nil {
return nil, err
}
if err := s.adoptChildWallet(ctx, sess, intentTyped); err != nil {
res, err := s.adoptChildWallet(ctx, sess, intentTyped)
if err != nil {
return nil, err
}
return makeTypedIntentResponse(&intents.IntentResponseChildWalletAdopted{})
return convertIntentResponse(res), nil

case intents.IntentName_getIdToken:
intentTyped, err := intents.NewIntentTypedFromIntent[intents.IntentDataGetIdToken](intent)
Expand Down
16 changes: 8 additions & 8 deletions rpc/wallet_adoption.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ import (

func (s *RPC) adoptChildWallet(
ctx context.Context, sess *data.Session, intent *intents.IntentTyped[intents.IntentDataAdoptChildWallet],
) error {
) (*proto_wallet.IntentResponse, error) {
tnt := tenant.FromContext(ctx)

signerWallet, err := ethwallet.NewWalletFromPrivateKey(tnt.PrivateKey)
if err != nil {
return fmt.Errorf("recovering parent wallet: %w", err)
return nil, fmt.Errorf("recovering parent wallet: %w", err)
}

if !common.IsHexAddress(intent.Data.Adopter) {
return fmt.Errorf("invalid adopter: %s", intent.Data.Adopter)
return nil, fmt.Errorf("invalid adopter: %s", intent.Data.Adopter)
}

adopterAddress := common.HexToAddress(intent.Data.Adopter)
Expand All @@ -51,13 +51,13 @@ func (s *RPC) adoptChildWallet(

subdigest, err := sequence.SubDigest(big.NewInt(0), common.HexToAddress(intent.Data.Wallet), approval.Hash)
if err != nil {
return fmt.Errorf("calculating digest: %w", err)
return nil, fmt.Errorf("calculating digest: %w", err)
}

// Our EOA belongs to the *parent* wallet, so we need to sign the subdigest with the parent key
sig, parentSubdigest, err := s.signUsingParent(signerWallet, tnt.ParentAddress, subdigest, big.NewInt(0))
if err != nil {
return fmt.Errorf("signing subdigest using parent wallet: %w", err)
return nil, fmt.Errorf("signing subdigest using parent wallet: %w", err)
}

signatures := []*proto_wallet.ProvidedSignature{
Expand All @@ -69,9 +69,9 @@ func (s *RPC) adoptChildWallet(
}

apiIntent := waasapi.ConvertToAPIIntent(&intent.Intent)
_, err = s.Wallets.AdoptChildWallet(waasapi.Context(ctx), apiIntent, childWalletConfig.Checkpoint_, signatures)
res, err := s.Wallets.AdoptChildWallet(waasapi.Context(ctx), apiIntent, childWalletConfig.Checkpoint_, signatures)
if err != nil {
return fmt.Errorf("adopting child wallet: %w", err)
return nil, fmt.Errorf("adopting child wallet: %w", err)
}
return nil
return res, nil
}
Loading