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

Cadence breaking changes #2

Closed
lmcmz opened this issue Apr 23, 2022 · 5 comments · Fixed by #3
Closed

Cadence breaking changes #2

lmcmz opened this issue Apr 23, 2022 · 5 comments · Fixed by #3
Assignees

Comments

@lmcmz
Copy link
Member

lmcmz commented Apr 23, 2022

[Transfer from: https://github.com/zed-io/flow-swift/issues/7]
Overview
A new version of Cadence will cause some breaking changes in this SDK. It's important that those changes are addressed in a timely manner (by the end of the month) or else it will break the software using the SDK.

Breaking Change
This SDK is using a deprecated API for adding keys to the account.
DEPRECATED

account.addPublicKey()
NEW

account.keys.add()
Refactor
The cadence templates should be changed according to the account key documentation found here. We have already prepared those templates for you and they can be found here.

If you need any help implementing the changes you can always reach out to me directly on discord or here (both places with sideninja nick).

@lmcmz lmcmz self-assigned this Apr 23, 2022
@lmcmz
Copy link
Member Author

lmcmz commented Apr 26, 2022

Hi @sidenijia

I have updated the new way to add the public key.
But it always throw out invalid public key errors, even I use the public key from the official example.
Do I miss anything here ?

Example:
https://testnet.flowscan.org/transaction/6aac6a370a40c31b9dc840c0a5393993a21d86fff26a4e79c6a726016d460e75/script

Screen Shot 2022-04-24 at 2 04 12 am

Screen Shot 2022-04-24 at 2 02 42 am

@psiemens
Copy link

psiemens commented Apr 27, 2022

@lmcmz I think I found out why this isn't working. Cadence SignatureAlgorithm enum values aren't consistent with the enum values in flow-go and most SDKs.

I'm not sure it's feasible for this to be fixed in Cadence at this point, but I'll see.

Maybe the Swift SDK could have a function toCadence on the SignatureAlgorithm values that does the right conversion?

Have you run into this problem before @sideninja?

@lmcmz
Copy link
Member Author

lmcmz commented Apr 27, 2022

@psiemens Gotcha, in swift SDK, there is one for code and one for index.
I guess at this point I should use index instead. I can see similar logic in flow JVM SDK.

Yep, it works now after switching to index. Let me finish the rest of the change. :)
https://testnet.flowscan.org/transaction/7089f247d402477e11482642197d67be2895150e2e1abe63e604a3dbcdcf33d9/script

@lmcmz
Copy link
Member Author

lmcmz commented Apr 27, 2022

Hi @psiemens and @sideninja

Is there a way to pass KeyListEntry struct on client-side as cadence argument?
I know a normal structure will need a cadence address to make a structure, but this one looks a bit special, it comes from built-in contract Crypto.

https://github.com/onflow/sdks/blob/main/templates/cadence/add-account-key.cdc#L3

@psiemens
Copy link

This is what keyListEntry looks like as JSON:

{
  "type": "Struct",
  "value": {
    "id": "I.Crypto.Crypto.KeyListEntry",
    "fields": [
      {
        "name": "keyIndex",
        "value": {
          "type": "Int",
          "value": "1000"
        }
      },
      {
        "name": "publicKey",
        "value": {
          "type": "Struct",
          "value": {
            "id": "PublicKey",
            "fields": [
              {
                "name": "publicKey",
                "value": {
                  "type": "Array",
                  "value": [
                    {
                      "type": "UInt8",
                      "value": "141"
                    },
                    {
                      "type": "UInt8",
                      "value": "166"
                    },
                    {
                      "type": "UInt8",
                      "value": "11"
                    },
                    {
                      "type": "UInt8",
                      "value": "217"
                    },
                    {
                      "type": "UInt8",
                      "value": "138"
                    },
                    {
                      "type": "UInt8",
                      "value": "130"
                    },
                    {
                      "type": "UInt8",
                      "value": "124"
                    },
                    {
                      "type": "UInt8",
                      "value": "135"
                    },
                    {
                      "type": "UInt8",
                      "value": "226"
                    },
                    {
                      "type": "UInt8",
                      "value": "22"
                    },
                    {
                      "type": "UInt8",
                      "value": "34"
                    },
                    {
                      "type": "UInt8",
                      "value": "197"
                    },
                    {
                      "type": "UInt8",
                      "value": "7"
                    },
                    {
                      "type": "UInt8",
                      "value": "10"
                    },
                    {
                      "type": "UInt8",
                      "value": "227"
                    },
                    {
                      "type": "UInt8",
                      "value": "238"
                    },
                    {
                      "type": "UInt8",
                      "value": "68"
                    },
                    {
                      "type": "UInt8",
                      "value": "10"
                    },
                    {
                      "type": "UInt8",
                      "value": "191"
                    },
                    {
                      "type": "UInt8",
                      "value": "9"
                    },
                    {
                      "type": "UInt8",
                      "value": "39"
                    },
                    {
                      "type": "UInt8",
                      "value": "213"
                    },
                    {
                      "type": "UInt8",
                      "value": "219"
                    },
                    {
                      "type": "UInt8",
                      "value": "51"
                    },
                    {
                      "type": "UInt8",
                      "value": "249"
                    },
                    {
                      "type": "UInt8",
                      "value": "101"
                    },
                    {
                      "type": "UInt8",
                      "value": "44"
                    },
                    {
                      "type": "UInt8",
                      "value": "177"
                    },
                    {
                      "type": "UInt8",
                      "value": "48"
                    },
                    {
                      "type": "UInt8",
                      "value": "62"
                    },
                    {
                      "type": "UInt8",
                      "value": "184"
                    },
                    {
                      "type": "UInt8",
                      "value": "160"
                    },
                    {
                      "type": "UInt8",
                      "value": "77"
                    },
                    {
                      "type": "UInt8",
                      "value": "254"
                    },
                    {
                      "type": "UInt8",
                      "value": "65"
                    },
                    {
                      "type": "UInt8",
                      "value": "222"
                    },
                    {
                      "type": "UInt8",
                      "value": "162"
                    },
                    {
                      "type": "UInt8",
                      "value": "201"
                    },
                    {
                      "type": "UInt8",
                      "value": "234"
                    },
                    {
                      "type": "UInt8",
                      "value": "100"
                    },
                    {
                      "type": "UInt8",
                      "value": "238"
                    },
                    {
                      "type": "UInt8",
                      "value": "131"
                    },
                    {
                      "type": "UInt8",
                      "value": "238"
                    },
                    {
                      "type": "UInt8",
                      "value": "141"
                    },
                    {
                      "type": "UInt8",
                      "value": "124"
                    },
                    {
                      "type": "UInt8",
                      "value": "141"
                    },
                    {
                      "type": "UInt8",
                      "value": "6"
                    },
                    {
                      "type": "UInt8",
                      "value": "141"
                    },
                    {
                      "type": "UInt8",
                      "value": "184"
                    },
                    {
                      "type": "UInt8",
                      "value": "56"
                    },
                    {
                      "type": "UInt8",
                      "value": "108"
                    },
                    {
                      "type": "UInt8",
                      "value": "123"
                    },
                    {
                      "type": "UInt8",
                      "value": "171"
                    },
                    {
                      "type": "UInt8",
                      "value": "152"
                    },
                    {
                      "type": "UInt8",
                      "value": "105"
                    },
                    {
                      "type": "UInt8",
                      "value": "74"
                    },
                    {
                      "type": "UInt8",
                      "value": "249"
                    },
                    {
                      "type": "UInt8",
                      "value": "86"
                    },
                    {
                      "type": "UInt8",
                      "value": "224"
                    },
                    {
                      "type": "UInt8",
                      "value": "253"
                    },
                    {
                      "type": "UInt8",
                      "value": "174"
                    },
                    {
                      "type": "UInt8",
                      "value": "55"
                    },
                    {
                      "type": "UInt8",
                      "value": "24"
                    },
                    {
                      "type": "UInt8",
                      "value": "78"
                    }
                  ]
                }
              },
              {
                "name": "signatureAlgorithm",
                "value": {
                  "type": "Enum",
                  "value": {
                    "id": "SignatureAlgorithm",
                    "fields": [
                      {
                        "name": "rawValue",
                        "value": {
                          "type": "UInt8",
                          "value": "1"
                        }
                      }
                    ]
                  }
                }
              }
            ]
          }
        }
      },
      {
        "name": "hashAlgorithm",
        "value": {
          "type": "Enum",
          "value": {
            "id": "HashAlgorithm",
            "fields": [
              {
                "name": "rawValue",
                "value": {
                  "type": "UInt8",
                  "value": "3"
                }
              }
            ]
          }
        }
      },
      {
        "name": "weight",
        "value": {
          "type": "UFix64",
          "value": "1000.00000000"
        }
      },
      {
        "name": "isRevoked",
        "value": {
          "type": "Bool",
          "value": false
        }
      }
    ]
  }
}

Here's how the Go SDK creates it: https://github.com/onflow/flow-go-sdk/blob/1790a76727094d755ff2a2a2007be36500216421/templates/accounts.go#L102-L131

If this is too much code, you can split a key list entry into pieces (e.g. public key, hash algo, sig algo) and then reassemble it in the Cadence transaction.

@lmcmz lmcmz closed this as completed in #3 Apr 28, 2022
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 a pull request may close this issue.

2 participants