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

Create a more idiomatic way of building a SEP010 Challenge Transaction #1466

Closed
ryanleecode opened this issue Jul 1, 2019 · 5 comments
Closed
Assignees
Labels
txnbuild 2nd-generation transaction build library for Go SDK

Comments

@ryanleecode
Copy link

ryanleecode commented Jul 1, 2019

Creating a challenge transaction for the SEP010 protocol should be something thats embeded in the SDK, given that most of the parameters can be predetermined.

Current to build such a transaction, you would need to do this...

	randomNounce, err := GenerateRandomString(48)
	if err != nil {
		panic(err)
	}

	var seed [32]byte
	copy(seed[:], []byte("MY_SECRET_KEY_HERE"))
	fiKeyPair, err := keypair.FromRawSeed(seed)
	if err != nil {
		panic(err)
	}
	account.Sequence = "0"
	currentTime := time.Now().UTC().Unix()
	tx := txnbuild.Transaction{
		SourceAccount: &account,
		Timebounds: txnbuild.NewTimebounds(
			currentTime,
			currentTime + 300,
		),
		Operations: []txnbuild.Operation{
			&txnbuild.ManageData{
				SourceAccount: &account,
				Name: "Stellar FI Anchor auth",
				Value: []byte(randomNounce),
			},
		},
		Network: network.TestNetworkPassphrase,
	}
	base64Txn, err := tx.BuildSignEncode(fiKeyPair)

Note that I have set the account sequence to "0" but the transaction builder will increment it to 1. And you can't set it to -1 because you will get
couldn't build transaction: failed to parse sequence number: Failed to parse account sequence number: strconv.ParseUint: parsing "-1": invalid syntax.

Generating a random nounce is trival but still an annoyance.

Something like the following would be a lot less effort.

	var seed [32]byte
	copy(seed[:], []byte("MY_SECRET_KEY_HERE"))
	fiKeyPair, err := keypair.FromRawSeed(seed)
	if err != nil {
		panic(err)
	}
	tx := txnbuild.Transaction{
		SourceAccount: &account,
		Network: network.TestNetworkPassphrase,
	}
        anchorName := "Stellar FI Anchor auth"
        tx.BuildChallenge(anchorName)
        tx.Sign(fiKeyPair)
	base64Txn, err := tx.Base64()
@ire-and-curses
Copy link
Member

Yes, we need to address at a minimum the "0" problem ASAP, but I really like this convenience function idea as well. @poliha let's hold off on this week's planned release until we can include something to address this, and get it in at the same time. Anchors are implementing SEP 10 so this is urgent.

@ire-and-curses ire-and-curses added the txnbuild 2nd-generation transaction build library for Go SDK label Jul 1, 2019
@ire-and-curses ire-and-curses added this to the horizonclient 1.3.0 milestone Jul 1, 2019
@bartekn
Copy link
Contributor

bartekn commented Jul 2, 2019

Note that I have set the account sequence to "0" but the transaction builder will increment it to 1.

This is tracked in #1259.

@poliha
Copy link
Contributor

poliha commented Jul 2, 2019

There is already a workaround for the "0" problem. Using Transaction.SimpleAccount struct you can set Sequence to -1. We do something similar for the compliance server, see here. This should help before we implement the convenience function.

@ire-and-curses
Copy link
Member

@poliha is right. For this edge case (and in general when creating accounts manually), you can create a SimpleAccount. It has the following shape:

type SimpleAccount struct {
	AccountID string
	Sequence  int64
}

Here Sequence is an int64 so can be set to -1 and incremented to 0 in the build step as you needed. The convenience function is still nice but less urgent.

@ire-and-curses ire-and-curses self-assigned this Jul 2, 2019
@poliha poliha removed this from the horizonclient 1.3.0 milestone Jul 8, 2019
@poliha
Copy link
Contributor

poliha commented Jul 16, 2019

Closed in #1468

@poliha poliha closed this as completed Jul 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
txnbuild 2nd-generation transaction build library for Go SDK
Projects
None yet
Development

No branches or pull requests

4 participants