Skip to content

Commit b3db7fa

Browse files
authored
Support non-text memos in sep7 handler (keybase#17642)
* Revendor stellarnet for non-text memo support * Support non-text memos in sep7 handler
1 parent a10fde3 commit b3db7fa

14 files changed

Lines changed: 273 additions & 66 deletions

File tree

‎go/client/cmd_wallet_handle_uri.go‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,7 @@ func (c *CmdWalletHandleURI) Run() (err error) {
7575
ui.Printf("Message: %q\n\n", v.Message)
7676
}
7777
if v.Memo != "" {
78-
if v.MemoType == "MEMO_TEXT" {
79-
ui.Printf("Public memo: %q\n\n", v.Memo)
80-
} else {
81-
// CORE-10865 will remedy this situation...
82-
ui.Printf("Request contains a public memo with an unsupported type (%s): %q\n", v.MemoType, v.Memo)
83-
ui.Printf("At this time, Keybase does not support that memo type.\n")
84-
85-
// shouldn't proceed if we can't include it in the transaction.
86-
return nil
87-
}
78+
ui.Printf("Public memo: %q\n\n", v.Memo)
8879
}
8980

9081
switch v.Operation {

‎go/stellar/relays/relays.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ type Input struct {
7070
From stellar1.SecretKey
7171
AmountXLM string
7272
Note string
73-
PublicMemo string
73+
PublicMemo *stellarnet.Memo
7474
// Implicit-team key to encrypt for
7575
EncryptFor keybase1.TeamApplicationKey
7676
SeqnoProvider build.SequenceProvider
@@ -104,7 +104,7 @@ func Create(in Input) (res Output, err error) {
104104
if err != nil {
105105
return res, err
106106
}
107-
sig, err := stellarnet.CreateAccountXLMTransaction(senderSeed, relayAccountID, in.AmountXLM,
107+
sig, err := stellarnet.CreateAccountXLMTransactionWithMemo(senderSeed, relayAccountID, in.AmountXLM,
108108
in.PublicMemo, in.SeqnoProvider, in.Timebounds, in.BaseFee)
109109
if err != nil {
110110
return res, err

‎go/stellar/send.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/keybase/client/go/libkb"
99
"github.com/keybase/client/go/protocol/stellar1"
1010
"github.com/keybase/client/go/stellar/stellarcommon"
11+
"github.com/keybase/stellarnet"
1112
)
1213

1314
func SendPaymentLocal(mctx libkb.MetaContext, arg stellar1.SendPaymentLocalArg) (res stellar1.SendPaymentResLocal, err error) {
@@ -81,7 +82,7 @@ func SendPaymentLocal(mctx libkb.MetaContext, arg stellar1.SendPaymentLocalArg)
8182
Amount: arg.Amount,
8283
DisplayBalance: displayBalance,
8384
SecretNote: arg.SecretNote,
84-
PublicMemo: arg.PublicMemo,
85+
PublicMemo: stellarnet.NewMemoText(arg.PublicMemo),
8586
ForceRelay: false,
8687
QuickReturn: arg.QuickReturn,
8788
})

‎go/stellar/stellar.go‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,8 @@ type SendPaymentArg struct {
498498
To stellarcommon.RecipientInput
499499
Amount string // Amount of XLM to send.
500500
DisplayBalance DisplayBalance
501-
SecretNote string // Optional.
502-
PublicMemo string // Optional.
501+
SecretNote string // Optional.
502+
PublicMemo *stellarnet.Memo // Optional.
503503
ForceRelay bool
504504
QuickReturn bool
505505
}
@@ -612,7 +612,7 @@ func sendPayment(mctx libkb.MetaContext, walletState *WalletState, sendArg SendP
612612
var seqno uint64
613613
if !funded {
614614
// if no balance, create_account operation
615-
sig, err := stellarnet.CreateAccountXLMTransaction(senderSeed2, *recipient.AccountID, sendArg.Amount, sendArg.PublicMemo, sp, tb, baseFee)
615+
sig, err := stellarnet.CreateAccountXLMTransactionWithMemo(senderSeed2, *recipient.AccountID, sendArg.Amount, sendArg.PublicMemo, sp, tb, baseFee)
616616
if err != nil {
617617
return res, err
618618
}
@@ -621,7 +621,7 @@ func sendPayment(mctx libkb.MetaContext, walletState *WalletState, sendArg SendP
621621
seqno = sig.Seqno
622622
} else {
623623
// if balance, payment operation
624-
sig, err := stellarnet.PaymentXLMTransaction(senderSeed2, *recipient.AccountID, sendArg.Amount, sendArg.PublicMemo, sp, tb, baseFee)
624+
sig, err := stellarnet.PaymentXLMTransactionWithMemo(senderSeed2, *recipient.AccountID, sendArg.Amount, sendArg.PublicMemo, sp, tb, baseFee)
625625
if err != nil {
626626
return res, err
627627
}
@@ -701,7 +701,7 @@ type SendPathPaymentArg struct {
701701
To stellarcommon.RecipientInput
702702
Path stellar1.PaymentPath
703703
SecretNote string
704-
PublicMemo string
704+
PublicMemo *stellarnet.Memo
705705
QuickReturn bool
706706
}
707707

@@ -744,7 +744,7 @@ func PathPaymentTx(mctx libkb.MetaContext, walletState *WalletState, sendArg Sen
744744
sp, unlock := NewSeqnoProvider(mctx, walletState)
745745
defer unlock()
746746

747-
sig, err := stellarnet.PathPaymentTransaction(senderSeed, to, sendArg.Path.SourceAsset, sendArg.Path.SourceAmountMax, sendArg.Path.DestinationAsset, sendArg.Path.DestinationAmount, AssetSliceToAssetBase(sendArg.Path.Path), sendArg.PublicMemo, sp, nil, baseFee)
747+
sig, err := stellarnet.PathPaymentTransactionWithMemo(senderSeed, to, sendArg.Path.SourceAsset, sendArg.Path.SourceAmountMax, sendArg.Path.DestinationAsset, sendArg.Path.DestinationAmount, AssetSliceToAssetBase(sendArg.Path.Path), sendArg.PublicMemo, sp, nil, baseFee)
748748
if err != nil {
749749
return nil, nil, nil, err
750750
}
@@ -1173,7 +1173,7 @@ func prepareMiniChatPaymentRelay(mctx libkb.MetaContext, remoter remote.Remoter,
11731173
// The balance of the relay account can be claimed by either party.
11741174
func sendRelayPayment(mctx libkb.MetaContext, walletState *WalletState,
11751175
from stellar1.SecretKey, recipient stellarcommon.Recipient, amount string, displayBalance DisplayBalance,
1176-
secretNote string, publicMemo string, quickReturn bool, senderEntryPrimary bool, baseFee uint64) (res SendPaymentResult, err error) {
1176+
secretNote string, publicMemo *stellarnet.Memo, quickReturn bool, senderEntryPrimary bool, baseFee uint64) (res SendPaymentResult, err error) {
11771177
defer mctx.TraceTimed("Stellar.sendRelayPayment", func() error { return err })()
11781178
appKey, teamID, err := relays.GetKey(mctx, recipient)
11791179
if err != nil {

‎go/stellar/stellarsvc/frontend.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ func (s *Server) SendPathLocal(ctx context.Context, arg stellar1.SendPathLocalAr
840840
To: stellarcommon.RecipientInput(arg.Recipient),
841841
Path: arg.Path,
842842
SecretNote: arg.Note,
843-
PublicMemo: arg.PublicNote,
843+
PublicMemo: stellarnet.NewMemoText(arg.PublicNote),
844844
QuickReturn: true,
845845
})
846846
if err != nil {

‎go/stellar/stellarsvc/service.go‎

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func (s *Server) SendCLILocal(ctx context.Context, arg stellar1.SendCLILocalArg)
208208
SecretNote: arg.Note,
209209
ForceRelay: arg.ForceRelay,
210210
QuickReturn: false,
211-
PublicMemo: arg.PublicNote,
211+
PublicMemo: stellarnet.NewMemoText(arg.PublicNote),
212212
})
213213
if err != nil {
214214
return res, err
@@ -240,7 +240,7 @@ func (s *Server) SendPathCLILocal(ctx context.Context, arg stellar1.SendPathCLIL
240240
To: stellarcommon.RecipientInput(arg.Recipient),
241241
Path: arg.Path,
242242
SecretNote: arg.Note,
243-
PublicMemo: arg.PublicNote,
243+
PublicMemo: stellarnet.NewMemoText(arg.PublicNote),
244244
QuickReturn: false,
245245
})
246246
if err != nil {
@@ -618,7 +618,7 @@ func (s *Server) ValidateStellarURILocal(ctx context.Context, arg stellar1.Valid
618618

619619
const zeroSourceAccount = "00000000000000000000000000000000000000000000000000000000"
620620

621-
func (s *Server) validateStellarURI(mctx libkb.MetaContext, uri string, getter stellarnet.HTTPGetter) (*stellar1.ValidateStellarURIResultLocal, *xdr.TransactionEnvelope, error) {
621+
func (s *Server) validateStellarURI(mctx libkb.MetaContext, uri string, getter stellarnet.HTTPGetter) (*stellar1.ValidateStellarURIResultLocal, *stellarnet.ValidatedStellarURI, error) {
622622
validated, err := stellarnet.ValidateStellarURI(uri, getter)
623623
if err != nil {
624624
return nil, nil, err
@@ -654,7 +654,7 @@ func (s *Server) validateStellarURI(mctx libkb.MetaContext, uri string, getter s
654654
}
655655
}
656656

657-
return &local, validated.TxEnv, nil
657+
return &local, validated, nil
658658
}
659659

660660
func (s *Server) ApproveTxURILocal(ctx context.Context, arg stellar1.ApproveTxURILocalArg) (txID stellar1.TransactionID, err error) {
@@ -668,11 +668,12 @@ func (s *Server) ApproveTxURILocal(ctx context.Context, arg stellar1.ApproveTxUR
668668
}
669669

670670
// revalidate the URI
671-
vp, txEnv, err := s.validateStellarURI(mctx, arg.InputURI, http.DefaultClient)
671+
vp, validated, err := s.validateStellarURI(mctx, arg.InputURI, http.DefaultClient)
672672
if err != nil {
673673
return "", err
674674
}
675675

676+
txEnv := validated.TxEnv
676677
if txEnv == nil {
677678
return "", errors.New("no tx envelope in URI")
678679
}
@@ -739,14 +740,18 @@ func (s *Server) ApprovePayURILocal(ctx context.Context, arg stellar1.ApprovePay
739740
}
740741

741742
// revalidate the URI
742-
vp, _, err := s.validateStellarURI(mctx, arg.InputURI, http.DefaultClient)
743+
vp, validated, err := s.validateStellarURI(mctx, arg.InputURI, http.DefaultClient)
743744
if err != nil {
744745
return "", err
745746
}
746747

747748
if vp.Amount == "" {
748749
vp.Amount = arg.Amount
749750
}
751+
memo, err := validated.MemoExport()
752+
if err != nil {
753+
return "", err
754+
}
750755

751756
if vp.CallbackURL != "" {
752757
recipient, err := stellar.LookupRecipient(mctx, stellarcommon.RecipientInput(vp.Recipient), arg.FromCLI)
@@ -765,20 +770,13 @@ func (s *Server) ApprovePayURILocal(ctx context.Context, arg stellar1.ApprovePay
765770
if err != nil {
766771
return "", err
767772
}
768-
var memoText string
769-
if vp.MemoType == "MEMO_TEXT" {
770-
memoText = vp.Memo
771-
} else if vp.Memo != "" {
772-
// CORE-10865 will fix this:
773-
return "", errors.New("keybase cannot handle non-text memos currently")
774-
}
775773

776774
sp, unlock := stellar.NewSeqnoProvider(mctx, s.walletState)
777775
defer unlock()
778776

779777
baseFee := s.walletState.BaseFee(mctx)
780778

781-
sig, err := stellarnet.PaymentXLMTransaction(senderSeed, recipientAddr, vp.Amount, memoText, sp, nil, baseFee)
779+
sig, err := stellarnet.PaymentXLMTransactionWithMemo(senderSeed, recipientAddr, vp.Amount, memo, sp, nil, baseFee)
782780
if err != nil {
783781
return "", err
784782
}
@@ -789,11 +787,9 @@ func (s *Server) ApprovePayURILocal(ctx context.Context, arg stellar1.ApprovePay
789787
}
790788

791789
sendArg := stellar.SendPaymentArg{
792-
To: stellarcommon.RecipientInput(vp.Recipient),
793-
Amount: vp.Amount,
794-
}
795-
if vp.MemoType == "MEMO_TEXT" {
796-
sendArg.PublicMemo = vp.Memo
790+
To: stellarcommon.RecipientInput(vp.Recipient),
791+
Amount: vp.Amount,
792+
PublicMemo: memo,
797793
}
798794

799795
var res stellar.SendPaymentResult
@@ -824,17 +820,20 @@ func (s *Server) ApprovePathURILocal(ctx context.Context, arg stellar1.ApprovePa
824820
}
825821

826822
// revalidate the URI
827-
vp, _, err := s.validateStellarURI(mctx, arg.InputURI, http.DefaultClient)
823+
vp, validated, err := s.validateStellarURI(mctx, arg.InputURI, http.DefaultClient)
828824
if err != nil {
829825
return "", err
830826
}
831827

832-
sendArg := stellar.SendPathPaymentArg{
833-
To: stellarcommon.RecipientInput(vp.Recipient),
834-
Path: arg.FullPath,
828+
memo, err := validated.MemoExport()
829+
if err != nil {
830+
return "", err
835831
}
836-
if vp.MemoType == "MEMO_TEXT" {
837-
sendArg.PublicMemo = vp.Memo
832+
833+
sendArg := stellar.SendPathPaymentArg{
834+
To: stellarcommon.RecipientInput(vp.Recipient),
835+
Path: arg.FullPath,
836+
PublicMemo: memo,
838837
}
839838

840839
if vp.CallbackURL != "" {

‎go/tools/sep7uri/sep7uri.go‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ var key string
1515
var domain string
1616
var message string
1717
var xdr string
18+
var memo string
19+
var memoType string
1820

1921
func main() {
2022
parseFlags()
@@ -34,6 +36,8 @@ func parseFlags() {
3436
flag.StringVar(&message, "message", "", "message to include")
3537
flag.StringVar(&message, "m", "", "message to include (shorthand)")
3638
flag.StringVar(&xdr, "xdr", "", "base64-encoded xdr transaction envelope")
39+
flag.StringVar(&memo, "memo", "", "public memo")
40+
flag.StringVar(&memoType, "memo-type", "", "MEMO_TEXT, MEMO_ID, MEMO_HASH, MEMO_RETURN")
3741

3842
flag.Parse()
3943

@@ -59,6 +63,10 @@ func parseFlags() {
5963
flag.PrintDefaults()
6064
os.Exit(1)
6165
}
66+
67+
if memo != "" && memoType == "" {
68+
memoType = "MEMO_TEXT"
69+
}
6270
}
6371

6472
func run() string {
@@ -86,6 +94,10 @@ func run() string {
8694
if amount != "" {
8795
q.Set("amount", amount)
8896
}
97+
if memo != "" {
98+
q.Set("memo", memo)
99+
q.Set("memo_type", memoType)
100+
}
89101
case "tx":
90102
q.Set("xdr", xdr)
91103
}

‎go/vendor/github.com/keybase/stellarnet/account.go‎

Lines changed: 26 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎go/vendor/github.com/keybase/stellarnet/amounts.go‎

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)