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 Private Key, Public Key, Address, and Script Types #5

Closed
nothingalike opened this issue Jul 22, 2021 · 7 comments
Closed

Add Private Key, Public Key, Address, and Script Types #5

nothingalike opened this issue Jul 22, 2021 · 7 comments
Labels
enhancement New feature or request

Comments

@nothingalike
Copy link
Member

nothingalike commented Jul 22, 2021

We need to convert the deconstructed returns to use types.

This will help us add better developer experience

Private/Public keys need to implement CIP005 for Bech32 output format.

@nothingalike nothingalike added the enhancement New feature or request label Jul 22, 2021
@nothingalike
Copy link
Member Author

#11 introduced the base Address Type.

@nothingalike
Copy link
Member Author

nothingalike commented Jul 30, 2021

I'm currently tinkering with the PrivateKey and PublicKey types. It makes me want to convert the KeyService class's BIP32 pieces to static extensions

var rootKey = _keyService.GetRootKey(entropy);
var paymentKey = rootKey.Derive(root: true) //m
  .Derive(1852) // purpose
  .Derive(1815) // coin
  .Derive(0) // account
  .Derive(0, hardened: false) // role
  .Derive(0, hardened: false); // index

This also crossed my mind while beginning the refactor, im starting to think it might make more sense having a class...

public class Key
{
  public byte[] PrivateKey { get; set; }
  public byte[] PublicKey { get; set; }
  public byte[] ChainCode { get; set; }
}

//instead of 
public class PrivateKey 
{
  public byte[] Key { get; set; }
  public byte[] ChainCode { get; set; }
}

public class PublicKey 
{
  public byte[] Key { get; set; }
  public byte[] ChainCode { get; set; }
}

@tweakch thoughts?

@tweakch
Copy link
Collaborator

tweakch commented Jul 30, 2021

I'm currently tinkering with the PrivateKey and PublicKey types. It makes me want to convert the KeyService class's BIP32 pieces to static extensions

How about this for partial derivation

var path = new WalletPath("m/1852'/1815'/0'/0/1");
var paymentKey = rootKey.Derive(path.GetSegments(depth: 4)); // zero based depth

// equivalent to
var paymentKey = rootKey.Derive(root: true) //m
  .Derive(1852) // purpose
  .Derive(1815) // coin
  .Derive(0) // account
  .Derive(0, hardened: false) // role

I think KeyPair would make it unambiguous

public class KeyPair
{
  public byte[] PrivateKey { get; set; }
  public byte[] PublicKey { get; set; }
  public byte[] ChainCode { get; set; }
}

@nothingalike
Copy link
Member Author

nothingalike commented Jul 30, 2021

How about this for partial derivation

var path = new WalletPath("m/1852'/1815'/0'/0/1");
var paymentKey = rootKey.Derive(path.GetSegments(depth: 4)); // zero based depth

This inspired my comment on your PR (#17 (comment))

// equivalent to
var paymentKey = rootKey.Derive(root: true) //m
  .Derive(1852) // purpose
  .Derive(1815) // coin
  .Derive(0) // account
  .Derive(0, hardened: false) // role

I think KeyPair would make it unambiguous

public class KeyPair
{
  public byte[] PrivateKey { get; set; }
  public byte[] PublicKey { get; set; }
  public byte[] ChainCode { get; set; }
}

I like this, ill start playing around with a KeyPair object defined like this.

@nothingalike
Copy link
Member Author

#17 introduced the PrivateKey, PublicKey, Mnemonic, WalletPath, and the various DerivationNode types...
The main types left are going to be around NativeScript. Technically these are already created but I believe they need some refactoring. Its not a very good experience build NativeScript which are used for Minting and MultiSig.

@nothingalike
Copy link
Member Author

@tweakch i believe we can close this ticket now, right?

@nothingalike
Copy link
Member Author

I believe this issue has been addressed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants