kadena-io / pact

The Pact Smart Contract Language
https://docs.kadena.io/build/pact
BSD 3-Clause "New" or "Revised" License
579 stars 100 forks source link

WebAuthn key format #1318

Closed edmundnoble closed 9 months ago

edmundnoble commented 10 months ago

This PR allows WebAuthn keys in keysets.

Public keys of different formats are distinguished by their prefix.

The new enum DynKeyPair ranges over Ed25519 keypairs and WebAuthn keypairs. Our client-side function for building commands (mkCommand, mkCommand') have counterparts that accept DynKeyPair instead of Ed25519KeyPair: mkCommandWithDynKeys. The new command generators will perform different signing algorithms and produce different signatures, depending on the type of keypair used. This distinction is only meaningful in tests, because real users will never have a WebAuthn private key. Real users using WebAuthn-signed transactions would be using a web client and an authenticator device that hold the secret key on the user's behalf.

The PR adds a lot of new functions for generating, parsing and printing WebAuthn keys. The functions applying to WebAuthn private keys are only used for testing.

The following repl session demonstrates that "WEBAUTHN-" prefixed keys pass format enforcement and are usable as keyset guards:

pact> (env-exec-config ["EnforceKeyFormats"])
["EnforceKeyFormats"]
pact> (env-data {"k": ["WEBAUTHN-a4010103272006215820c18831c6f15306d6271e154842906b68f26c1af79b132dde6f6add79710303bf"]})
"Setting transaction data"
pact> (env-sigs [{"key": "WEBAUTHN-a4010103272006215820c18831c6f15306d6271e154842906b68f26c1af79b132dde6f6add79710303bf", "caps": []}])
"Setting transaction signatures/caps"
pact> (enforce-keyset (read-keyset 'k))
true

PR checklist:

Additionally, please justify why you should or should not do the following: