Skip to content

Commit 445af04

Browse files
imalsogregjwiegleyedmundnoblelarskuhtz
authored
webauthn signatures (#1193)
* Implement webauthn signature checking * Bump base64-bytestring Co-authored-by: John Wiegley <[email protected]> Co-authored-by: Edmund Noble <[email protected]> Co-authored-by: Lars Kuhtz <[email protected]>
1 parent 8a65a50 commit 445af04

22 files changed

+500
-654
lines changed

cabal.project

-7
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ packages: .
33
-- temporary upper bounds
44
constraints: sbv <10
55

6-
-- these upper bounds are required in order to not break payload validation in chainweb
7-
constraints: base16-bytestring <1
8-
constraints: base64-bytestring <1.1
9-
10-
allow-newer: base64-bytestring:*
11-
allow-newer: base16-bytestring:*
12-
136
-- test upper bounds
147
constraints: hspec-golden <0.2,
158

docs/en/pact-functions.md

+2-10
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ Return ID if called during current pact execution, failing if not.
461461
Obtain current pact build version.
462462
```lisp
463463
pact> (pact-version)
464-
"4.8"
464+
"4.9"
465465
```
466466

467467
Top level only: this function will fail if used in module code.
@@ -1928,7 +1928,7 @@ Retreive any accumulated events and optionally clear event state. Object returne
19281928
*&rarr;*&nbsp;`[string]`
19291929

19301930

1931-
Queries, or with arguments, sets execution config flags. Valid flags: ["AllowReadInLocal","DisableHistoryInTransactionalMode","DisableInlineMemCheck","DisableModuleInstall","DisableNewTrans","DisablePact40","DisablePact420","DisablePact43","DisablePact431","DisablePact44","DisablePact45","DisablePact46","DisablePact47","DisablePact48","DisablePactEvents","DisableRuntimeReturnTypeChecking","EnforceKeyFormats","OldReadOnlyBehavior","PreserveModuleIfacesBug","PreserveModuleNameBug","PreserveNsModuleInstallBug","PreserveShowDefs"]
1931+
Queries, or with arguments, sets execution config flags. Valid flags: ["AllowReadInLocal","DisableHistoryInTransactionalMode","DisableInlineMemCheck","DisableModuleInstall","DisableNewTrans","DisablePact40","DisablePact420","DisablePact43","DisablePact431","DisablePact44","DisablePact45","DisablePact46","DisablePact47","DisablePact48","DisablePact49","DisablePactEvents","DisableRuntimeReturnTypeChecking","EnforceKeyFormats","OldReadOnlyBehavior","PreserveModuleIfacesBug","PreserveModuleNameBug","PreserveNsModuleInstallBug","PreserveShowDefs"]
19321932
```lisp
19331933
pact> (env-exec-config ['DisableHistoryInTransactionalMode]) (env-exec-config)
19341934
["DisableHistoryInTransactionalMode"]
@@ -2104,14 +2104,6 @@ pact> (expect-that "addition" (> 2) (+ 1 2))
21042104
```
21052105

21062106

2107-
### format-address {#format-address}
2108-
2109-
*scheme*&nbsp;`string` *public-key*&nbsp;`string` *&rarr;*&nbsp;`string`
2110-
2111-
2112-
Transform PUBLIC-KEY into an address (i.e. a Pact Runtime Public Key) depending on its SCHEME.
2113-
2114-
21152107
### load {#load}
21162108

21172109
*file*&nbsp;`string` *&rarr;*&nbsp;`string`

flake.lock

+13-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pact.cabal

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.2
22
name: pact
3-
version: 4.8
3+
version: 4.9
44
-- ^ 4 digit is prerelease, 3- or 2-digit for prod release
55
synopsis: Smart contract language library and REPL
66
description:
@@ -145,7 +145,6 @@ library
145145
Pact.Types.Command
146146
Pact.Types.Continuation
147147
Pact.Types.Crypto
148-
Pact.Types.ECDSA
149148
Pact.Types.Exp
150149
Pact.Types.ExpParser
151150
Pact.Types.Gas
@@ -229,6 +228,7 @@ library
229228
, scientific >= 0.3
230229
, semigroupoids >=5.0
231230
, semirings
231+
, serialise >= 0.2.6
232232
, servant
233233
, servant-client >=0.16
234234
, servant-client-core >=0.16
@@ -242,6 +242,7 @@ library
242242
, vector-algorithms >=0.7
243243
, vector-space >=0.10.4
244244
, yaml
245+
, webauthn >= 0.7
245246

246247
if flag(build-tool)
247248
cpp-options: -DBUILD_TOOL

src/Pact/ApiReq.hs

+15-18
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ loadSigData fp = do
296296
Left e -> Left $ "Error loading SigData file " <> fp <> ": " <> show e
297297
Right sd -> Right sd
298298

299-
addSigToSigData :: SomeKeyPair -> SigData a -> IO (SigData a)
299+
addSigToSigData :: Ed25519KeyPair -> SigData a -> IO (SigData a)
300300
addSigToSigData kp sd = do
301301
sig <- signHash (_sigDataHash sd) kp
302302
let k = PublicKeyHex $ toB16Text $ getPublic kp
@@ -384,7 +384,7 @@ addSigReq sd keyFile = do
384384
kp <- importKeyFile keyFile
385385
addSigToSigData kp sd
386386

387-
importKeyFile :: FilePath -> IO SomeKeyPair
387+
importKeyFile :: FilePath -> IO Ed25519KeyPair
388388
importKeyFile keyFile = do
389389
v :: Value <- decodeYaml keyFile
390390
let ekp = do
@@ -393,7 +393,7 @@ importKeyFile keyFile = do
393393
pub <- getKey "public" v
394394
sec <- getKey "secret" v
395395

396-
importKeyPair defaultScheme (Just $ PubBS pub) (PrivBS sec)
396+
importKeyPair (Just $ PubBS pub) (PrivBS sec)
397397
case ekp of
398398
Left e -> dieAR $ "Could not parse key file " <> keyFile <> ": " <> e
399399
Right kp -> return kp
@@ -480,7 +480,7 @@ signCmd keyFiles bs = do
480480
withKeypairsOrSigner
481481
:: Bool
482482
-> ApiReq
483-
-> ([SomeKeyPairCaps] -> IO a)
483+
-> ([Ed25519KeyPairCaps] -> IO a)
484484
-> ([Signer] -> IO a)
485485
-> IO a
486486
withKeypairsOrSigner unsignedReq ApiReq{..} keypairAction signerAction =
@@ -548,7 +548,7 @@ mkExec
548548
-- ^ optional environment data
549549
-> PublicMeta
550550
-- ^ public metadata
551-
-> [SomeKeyPairCaps]
551+
-> [Ed25519KeyPairCaps]
552552
-- ^ signing keypairs + caplists
553553
-> Maybe NetworkId
554554
-- ^ optional 'NetworkId'
@@ -635,7 +635,7 @@ mkCont
635635
-- ^ environment data
636636
-> PublicMeta
637637
-- ^ command public metadata
638-
-> [SomeKeyPairCaps]
638+
-> [Ed25519KeyPairCaps]
639639
-- ^ signing keypairs
640640
-> Maybe Text
641641
-- ^ optional nonce
@@ -687,12 +687,11 @@ mkUnsignedCont txid step rollback mdata pubMeta kps ridm proof nid = do
687687
(Continuation (ContMsg txid step rollback (toLegacyJson mdata) proof) :: (PactRPC ContMsg))
688688
return $ decodeUtf8 <$> cmd
689689

690-
mkKeyPairs :: [ApiKeyPair] -> IO [SomeKeyPairCaps]
690+
-- Parse `APIKeyPair`s into Ed25519 keypairs.
691+
mkKeyPairs :: [ApiKeyPair] -> IO [Ed25519KeyPairCaps]
691692
mkKeyPairs keyPairs = traverse mkPair keyPairs
692693
where importValidKeyPair ApiKeyPair{..} = fmap (,maybe [] id _akpCaps) $
693-
case _akpScheme of
694-
Nothing -> importKeyPair defaultScheme _akpPublic _akpSecret
695-
Just ppk -> importKeyPair (toScheme ppk) _akpPublic _akpSecret
694+
importKeyPair _akpPublic _akpSecret
696695

697696
mkPair akp = case _akpAddress akp of
698697
Nothing -> either dieAR return (importValidKeyPair akp)
@@ -703,14 +702,12 @@ mkKeyPairs keyPairs = traverse mkPair keyPairs
703702
-- Enforces that user provided address matches the address derived from the Public Key
704703
-- for transparency and a better user experience. User provided address not used except
705704
-- for this purpose.
706-
707-
case (addrBS, formatPublicKey (fst kp)) of
708-
(expectAddr, actualAddr)
709-
| expectAddr == actualAddr -> return kp
710-
| otherwise -> dieAR $ "Address provided "
711-
++ show (toB16Text expectAddr)
712-
++ " does not match actual Address "
713-
++ show (toB16Text actualAddr)
705+
if addrBS == getPublic (fst kp)
706+
then return kp
707+
else dieAR $ "Address provided "
708+
++ show (toB16Text addrBS)
709+
++ " does not match actual Address "
710+
++ show (toB16Text $ getPublic $ fst kp)
714711

715712
dieAR :: String -> IO a
716713
dieAR errMsg = throwM . userError $ intercalate "\n" $

src/Pact/Bench.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ benchReadValue benchMod (DataTable t) _k
234234
benchReadValue _ (TxTable _t) _k = rcp Nothing
235235

236236

237-
mkBenchCmd :: [SomeKeyPairCaps] -> (String, Text) -> IO (String, Command ByteString)
237+
mkBenchCmd :: [Ed25519KeyPairCaps] -> (String, Text) -> IO (String, Command ByteString)
238238
mkBenchCmd kps (str, t) = do
239239
cmd <- mkCommand' kps
240240
$ J.encodeStrict
@@ -291,7 +291,7 @@ main = do
291291
!priv <- eitherDie "priv" $
292292
parseB16TextOnly "6c938ed95a8abf99f34a1b5edd376f790a2ea8952413526af91b4c3eb0331b3c"
293293
!keyPair <- eitherDie "keyPair" $
294-
importKeyPair defaultScheme (Just $ PubBS pub) (PrivBS priv)
294+
importKeyPair (Just $ PubBS pub) (PrivBS priv)
295295
!parsedExps <- force <$> mapM (mapM (eitherDie "parseExps" . parseExprs)) exps
296296
!pureDb <- perfEnv dbPerf <$> mkPureEnv neverLog
297297
initSchema pureDb

src/Pact/Main.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,6 @@ echoBuiltins = do
245245

246246
genKeys :: IO ()
247247
genKeys = do
248-
kp <- genKeyPair defaultScheme
248+
kp <- genKeyPair
249249
putStrLn $ "public: " ++ unpack (toB16Text $ getPublic kp)
250250
putStrLn $ "secret: " ++ unpack (toB16Text $ getPrivate kp)

0 commit comments

Comments
 (0)