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 native AccountKey type and update account key methods #371

Closed
11 tasks
turbolent opened this issue Sep 11, 2020 · 2 comments · Fixed by #633
Closed
11 tasks

Add native AccountKey type and update account key methods #371

turbolent opened this issue Sep 11, 2020 · 2 comments · Fixed by #633
Assignees

Comments

@turbolent
Copy link
Member

turbolent commented Sep 11, 2020

Context

Currently account public keys are encoded together with their signature algorithm, hashing algorithm and weight before being passed into Cadence as byte strings. This solution is a relic of the early days of Cadence, before we had support for more sophisticated composite types.

We'd like to move towards a more user-friendly solution, perhaps something like this:

transaction {
  prepare(signer: AuthAccount) {
    let key = AccountKey(
      publicKey: pubKeyBytes, 
      sigAlgo: crypto.ECDSA_P256, 
      hashAlgo: crypto.SHA3_256, 
      weight: 1000,
    )
    signer.keys.add(key)
  }
}

Definition of Done

  • Add an AccountKey type:

    struct AccountKey {
          let keyIndex: Int
          let publicKey: Crypto.PublicKey
          let hashAlgorithm: Crypto.HashAlgorithm
          let weight: UFix64
          let isRevoked: Bool
    }
    
  • Add an AuthAccount.Keys type with the following functions:

    • Add a AuthAccount.Keys.add function:

      /// Adds a new key with the given weight
      fun add(
          _ publicKey: PublicKey,
          hashAlgorithm: HashAlgorithm,
          weight: UFix64
      ): AccountKey
      
    • Add a AuthAccount.Keys.get function:

      /// Returns the key at the given index, if it exists.
      /// Revoked keys are always returned, but they have `isRevoked` field set to true
      fun get(keyIndex: Int): AccountKey?
      
    • Add a AuthAccount.Keys.revoke function:

      /// Marks the key at the given index revoked, but does not delete it
      fun revoke(keyIndex: Int)
      
  • Add an AuthAccount.keys field with type AuthAccount.Keys

  • Add an PublicAccount.Keys type with the following functions:

    • Add a PublicAccount.Keys.get function:

      /// Returns the key at the given index, if it exists.
      /// Revoked keys are always returned, but they have `isRevoked` field set to true
      fun get(keyIndex: Int): AccountKey?
      
  • Add an PublicAccount.keys field with type PublicAccount.Keys

  • Tests

  • Documentation

@turbolent
Copy link
Member Author

@SupunS Maybe you could take this on next? Adding this new account key management API would be a great UX improvement. Let me know if you want to talk this through

@SupunS
Copy link
Member

SupunS commented Feb 17, 2021

@turbolent nice, I will have a look.

@SupunS SupunS self-assigned this Feb 17, 2021
@Kay-Zee Kay-Zee added this to the Sprint 32 - Post Beta Mainnet - Part 14 [Feb 15 -Feb 26] milestone Feb 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants