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

Add Signing module with mkStdTx #166

Merged
merged 3 commits into from
Apr 24, 2019
Merged

Add Signing module with mkStdTx #166

merged 3 commits into from
Apr 24, 2019

Conversation

Anviking
Copy link
Collaborator

@Anviking Anviking commented Apr 9, 2019

Issue Number

Overview

I'll try and test this first Think we could get this in first

  • I ported mkStdTx in a minimal way
  • Added shuffle in CoinSelection
  • Added AddressScheme class

Comments

  • Not tested
  • The testnet protocol-magic is now hard-coded in

@Anviking Anviking force-pushed the anviking/95/mkstdtx branch 5 times, most recently from 85b9547 to 3725931 Compare April 10, 2019 19:10
@Anviking Anviking marked this pull request as ready for review April 10, 2019 19:16
src/Cardano/Wallet/Primitive/Signing.hs Outdated Show resolved Hide resolved
src/Cardano/Wallet/Primitive/Signing.hs Outdated Show resolved Hide resolved
src/Cardano/Wallet/Primitive/Signing.hs Outdated Show resolved Hide resolved
src/Cardano/Wallet/Primitive/Signing.hs Outdated Show resolved Hide resolved
@Anviking Anviking force-pushed the anviking/95/mkstdtx branch 2 times, most recently from e82a9b4 to 5025ef3 Compare April 11, 2019 10:29
:: Address
-> (Key 'RootK XPrv, Passphrase "encryption")
-> s
-> (Maybe (Key 'AddressK XPrv), s)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the AddressScheme class

@Anviking Anviking force-pushed the anviking/95/mkstdtx branch 2 times, most recently from d6e8806 to dcf2678 Compare April 23, 2019 15:46
@Anviking Anviking requested a review from KtorZ April 23, 2019 15:47
-> [(TxIn, TxOut)]
-- ^ Selected inputs
-> [TxOut]
-- ^ Selected outputs (including change)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are missing the change outputs here. Those are part of the CoinSelection but are simply Coins. In practice, we do need to generate change addresses on the internal chain for all change, in sequence.

However, we also want to leave that flexible in the long-run in order to let users pick their own change addresses if needed.

Copy link
Collaborator Author

@Anviking Anviking Apr 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, assumed they were included in the CoinSelection outputs, but makes a lot of sense

However, we also want to leave that flexible in the long-run in order to let users pick their own change addresses if needed.

Yes, sounds good to me (Edit: with users I thought of callers of mkStdTx)

Adding a function

generateChangeOutput :: s -> Coin -> TxOut

to AddressScheme?

Or have it specific to SeqState?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is indeed specific to the scheme state. Your suggestion is sound. We'll see later how we enable this to be set by users 👍

SignTx (Hash payload) -> "\x01" <> network <> payload
where
network = toByteString . CBOR.encodeInt32 $ pm
pm = 1097911063 -- testnet; TODO: need to decide on how to pass this in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Anviking and others added 3 commits April 24, 2019 12:42
Not tested yet. For the time being we hard-code the testnet protocol
magic in the signing.
encodeXPub (publicKey xPrv) <>
getHash (sign (SignTx tx) (xPrv, pwd))
mkWitness tx xPrv = PublicKeyWitness $
encodeXPub (publicKey xPrv) <> getHash (sign (SignTx tx) (xPrv, pwd))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was no particular reason to change that 🤷‍♂️

hashTx :: Tx -> Hash "tx"
hashTx txSigData = Hash
$ convert
$ (hash @ByteString @Blake2b_256)
$ BA.convert
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small change here, using qualified import for ambiguous function. The context is probably enough here, but, usually, for functions like this that exist in many modules, it's good to be specific (like map or filter or encode ... )

emptyPendingIxs :: PendingIxs
emptyPendingIxs = PendingIxs mempty

-- | Update the set of pending indexes by discarding every indexes _below_ the
Copy link
Collaborator Author

@Anviking Anviking Apr 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KtorZ Can I suggest calling it like discardIxsBelow then?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm.. I wouldn't. So that the logic remains encapsulated in the PendingIxs structure. What the update does is actually irrelevant to the caller so I wouldn't have the name conveying any behavior here but rather, be fairly abstract like "update" or "adjust".

@KtorZ KtorZ merged commit becd645 into master Apr 24, 2019
@KtorZ KtorZ deleted the anviking/95/mkstdtx branch April 26, 2019 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants