Compare commits
2 commits
9e62a54e59
...
0a1f35eefc
Author | SHA1 | Date | |
---|---|---|---|
0a1f35eefc | |||
620fca5827 |
5 changed files with 98 additions and 7 deletions
|
@ -9,8 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- RPC method `shieldnotes`
|
- RPC methods:
|
||||||
- RPC method `deshieldfunds`
|
- `shieldnotes`
|
||||||
|
- `deshieldfunds`
|
||||||
|
- `getfullvk`
|
||||||
|
- `getincomingvk`
|
||||||
|
|
||||||
## [0.7.2.0-beta]
|
## [0.7.2.0-beta]
|
||||||
|
|
||||||
|
|
|
@ -129,6 +129,7 @@ data ZenithMethod
|
||||||
| ShieldNotes
|
| ShieldNotes
|
||||||
| DeshieldFunds
|
| DeshieldFunds
|
||||||
| GetFVK
|
| GetFVK
|
||||||
|
| GetIVK
|
||||||
| UnknownMethod
|
| UnknownMethod
|
||||||
deriving (Eq, Prelude.Show)
|
deriving (Eq, Prelude.Show)
|
||||||
|
|
||||||
|
@ -147,6 +148,7 @@ instance ToJSON ZenithMethod where
|
||||||
toJSON ShieldNotes = Data.Aeson.String "shieldnotes"
|
toJSON ShieldNotes = Data.Aeson.String "shieldnotes"
|
||||||
toJSON DeshieldFunds = Data.Aeson.String "deshieldfunds"
|
toJSON DeshieldFunds = Data.Aeson.String "deshieldfunds"
|
||||||
toJSON GetFVK = Data.Aeson.String "getfullvk"
|
toJSON GetFVK = Data.Aeson.String "getfullvk"
|
||||||
|
toJSON GetIVK = Data.Aeson.String "getincomingvk"
|
||||||
toJSON UnknownMethod = Data.Aeson.Null
|
toJSON UnknownMethod = Data.Aeson.Null
|
||||||
|
|
||||||
instance FromJSON ZenithMethod where
|
instance FromJSON ZenithMethod where
|
||||||
|
@ -166,6 +168,7 @@ instance FromJSON ZenithMethod where
|
||||||
"shieldnotes" -> pure ShieldNotes
|
"shieldnotes" -> pure ShieldNotes
|
||||||
"deshieldfunds" -> pure DeshieldFunds
|
"deshieldfunds" -> pure DeshieldFunds
|
||||||
"getfullvk" -> pure GetFVK
|
"getfullvk" -> pure GetFVK
|
||||||
|
"getincomingvk" -> pure GetIVK
|
||||||
_ -> pure UnknownMethod
|
_ -> pure UnknownMethod
|
||||||
|
|
||||||
data ZenithParams
|
data ZenithParams
|
||||||
|
@ -548,6 +551,16 @@ instance FromJSON RpcCall where
|
||||||
pure $ RpcCall v i GetFVK (ViewingKeyParams x)
|
pure $ RpcCall v i GetFVK (ViewingKeyParams x)
|
||||||
else pure $ RpcCall v i GetFVK BadParams
|
else pure $ RpcCall v i GetFVK BadParams
|
||||||
_anyOther -> pure $ RpcCall v i GetFVK BadParams
|
_anyOther -> pure $ RpcCall v i GetFVK BadParams
|
||||||
|
GetIVK -> do
|
||||||
|
p <- obj .: "params"
|
||||||
|
case p of
|
||||||
|
Array a ->
|
||||||
|
if V.length a == 1
|
||||||
|
then do
|
||||||
|
x <- parseJSON $ a V.! 0
|
||||||
|
pure $ RpcCall v i GetIVK (ViewingKeyParams x)
|
||||||
|
else pure $ RpcCall v i GetIVK BadParams
|
||||||
|
_anyOther -> pure $ RpcCall v i GetIVK BadParams
|
||||||
|
|
||||||
type ZenithRPC
|
type ZenithRPC
|
||||||
= "status" :> Get '[ JSON] Value :<|> BasicAuth "zenith-realm" Bool :> ReqBody
|
= "status" :> Get '[ JSON] Value :<|> BasicAuth "zenith-realm" Bool :> ReqBody
|
||||||
|
@ -1089,6 +1102,34 @@ zenithServer state = getinfo :<|> handleRPC
|
||||||
ErrorResponse (callId req) (-32006) "Account does not exist."
|
ErrorResponse (callId req) (-32006) "Account does not exist."
|
||||||
_anyOtherParams ->
|
_anyOtherParams ->
|
||||||
return $ ErrorResponse (callId req) (-32602) "Invalid params"
|
return $ ErrorResponse (callId req) (-32602) "Invalid params"
|
||||||
|
GetIVK -> do
|
||||||
|
case parameters req of
|
||||||
|
ViewingKeyParams aid -> do
|
||||||
|
let dbPath = w_dbPath state
|
||||||
|
let net = w_network state
|
||||||
|
pool <- liftIO $ runNoLoggingT $ initPool dbPath
|
||||||
|
acc <- liftIO $ getAccountById pool $ toSqlKey $ fromIntegral aid
|
||||||
|
case acc of
|
||||||
|
Just acc' -> do
|
||||||
|
ivk <-
|
||||||
|
liftIO $
|
||||||
|
try
|
||||||
|
(deriveUivk
|
||||||
|
net
|
||||||
|
(getOrchSK $ zcashAccountOrchSpendKey $ entityVal acc')
|
||||||
|
(getSapSK $ zcashAccountSapSpendKey $ entityVal acc')
|
||||||
|
(getTranSK $ zcashAccountTPrivateKey $ entityVal acc')) :: Handler
|
||||||
|
(Either SomeException T.Text)
|
||||||
|
case ivk of
|
||||||
|
Left _ ->
|
||||||
|
return $
|
||||||
|
ErrorResponse (callId req) (-32010) "Internal Error"
|
||||||
|
Right ivk' -> return $ ViewingKeyResponse (callId req) ivk'
|
||||||
|
Nothing ->
|
||||||
|
return $
|
||||||
|
ErrorResponse (callId req) (-32006) "Account does not exist."
|
||||||
|
_anyOtherParams ->
|
||||||
|
return $ ErrorResponse (callId req) (-32602) "Invalid params"
|
||||||
|
|
||||||
authenticate :: Config -> BasicAuthCheck Bool
|
authenticate :: Config -> BasicAuthCheck Bool
|
||||||
authenticate config = BasicAuthCheck check
|
authenticate config = BasicAuthCheck check
|
||||||
|
|
|
@ -774,6 +774,55 @@ main = do
|
||||||
Left e -> assertFailure e
|
Left e -> assertFailure e
|
||||||
Right (ViewingKeyResponse i c) -> c `shouldNotBe` ""
|
Right (ViewingKeyResponse i c) -> c `shouldNotBe` ""
|
||||||
Right x -> assertFailure $ show x
|
Right x -> assertFailure $ show x
|
||||||
|
describe "Incoming" $ do
|
||||||
|
it "bad credentials" $ do
|
||||||
|
res <-
|
||||||
|
makeZenithCall
|
||||||
|
"127.0.0.1"
|
||||||
|
nodePort
|
||||||
|
"baduser"
|
||||||
|
"idontknow"
|
||||||
|
GetIVK
|
||||||
|
BlankParams
|
||||||
|
res `shouldBe` Left "Invalid credentials"
|
||||||
|
describe "correct credentials" $ do
|
||||||
|
it "no parameters" $ do
|
||||||
|
res <-
|
||||||
|
makeZenithCall
|
||||||
|
"127.0.0.1"
|
||||||
|
nodePort
|
||||||
|
nodeUser
|
||||||
|
nodePwd
|
||||||
|
GetIVK
|
||||||
|
BlankParams
|
||||||
|
case res of
|
||||||
|
Left e -> assertFailure e
|
||||||
|
Right (ErrorResponse i c m) -> c `shouldBe` (-32602)
|
||||||
|
it "invalid account" $ do
|
||||||
|
res <-
|
||||||
|
makeZenithCall
|
||||||
|
"127.0.0.1"
|
||||||
|
nodePort
|
||||||
|
nodeUser
|
||||||
|
nodePwd
|
||||||
|
GetIVK
|
||||||
|
(ViewingKeyParams 27)
|
||||||
|
case res of
|
||||||
|
Left e -> assertFailure e
|
||||||
|
Right (ErrorResponse i c m) -> c `shouldBe` (-32006)
|
||||||
|
it "valid account" $ do
|
||||||
|
res <-
|
||||||
|
makeZenithCall
|
||||||
|
"127.0.0.1"
|
||||||
|
nodePort
|
||||||
|
nodeUser
|
||||||
|
nodePwd
|
||||||
|
GetIVK
|
||||||
|
(ViewingKeyParams 1)
|
||||||
|
case res of
|
||||||
|
Left e -> assertFailure e
|
||||||
|
Right (ViewingKeyResponse i c) -> c `shouldNotBe` ""
|
||||||
|
Right x -> assertFailure $ show x
|
||||||
|
|
||||||
startAPI :: Config -> IO ()
|
startAPI :: Config -> IO ()
|
||||||
startAPI config = do
|
startAPI config = do
|
||||||
|
|
|
@ -833,15 +833,13 @@
|
||||||
"name": "getincomingvk",
|
"name": "getincomingvk",
|
||||||
"summary": "Get the incoming viewing key for the given account.",
|
"summary": "Get the incoming viewing key for the given account.",
|
||||||
"description": "Derives the incoming viewing key for the given account per ZIP-316.",
|
"description": "Derives the incoming viewing key for the given account per ZIP-316.",
|
||||||
"tags": [
|
"tags": [],
|
||||||
{ "$ref": "#/components/tags/draft"}
|
|
||||||
],
|
|
||||||
"params": [
|
"params": [
|
||||||
{ "$ref": "#/components/contentDescriptors/AccountId"}
|
{ "$ref": "#/components/contentDescriptors/AccountId"}
|
||||||
],
|
],
|
||||||
"paramStructure": "by-position",
|
"paramStructure": "by-position",
|
||||||
"result": {
|
"result": {
|
||||||
"name": "Full viewing key",
|
"name": "Incoming viewing key",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/components/schemas/ViewingKey"
|
"$ref": "#/components/schemas/ViewingKey"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
cabal-version: 3.0
|
cabal-version: 3.0
|
||||||
name: zenith
|
name: zenith
|
||||||
version: 0.7.2.0-beta
|
version: 0.8.0.0-beta
|
||||||
license: MIT
|
license: MIT
|
||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
author: Rene Vergara
|
author: Rene Vergara
|
||||||
|
|
Loading…
Reference in a new issue