diff --git a/.gitignore b/.gitignore index d77462f..deaa6e3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore +.turbo dist # Logs diff --git a/.turbo/cache/1aa298330ad02f31-meta.json b/.turbo/cache/1aa298330ad02f31-meta.json deleted file mode 100644 index 91d690a..0000000 --- a/.turbo/cache/1aa298330ad02f31-meta.json +++ /dev/null @@ -1 +0,0 @@ -{ "hash": "1aa298330ad02f31", "duration": 837 } diff --git a/.turbo/cache/1aa298330ad02f31.tar.zst b/.turbo/cache/1aa298330ad02f31.tar.zst deleted file mode 100644 index 06852f3..0000000 Binary files a/.turbo/cache/1aa298330ad02f31.tar.zst and /dev/null differ diff --git a/.turbo/cache/1c9102b79471b0f5-meta.json b/.turbo/cache/1c9102b79471b0f5-meta.json deleted file mode 100644 index 5c77f27..0000000 --- a/.turbo/cache/1c9102b79471b0f5-meta.json +++ /dev/null @@ -1 +0,0 @@ -{ "hash": "1c9102b79471b0f5", "duration": 1607 } diff --git a/.turbo/cache/1c9102b79471b0f5.tar.zst b/.turbo/cache/1c9102b79471b0f5.tar.zst deleted file mode 100644 index 86fca09..0000000 Binary files a/.turbo/cache/1c9102b79471b0f5.tar.zst and /dev/null differ diff --git a/.turbo/cache/1d0efba35ca2970e-meta.json b/.turbo/cache/1d0efba35ca2970e-meta.json deleted file mode 100644 index c1cf641..0000000 --- a/.turbo/cache/1d0efba35ca2970e-meta.json +++ /dev/null @@ -1 +0,0 @@ -{ "hash": "1d0efba35ca2970e", "duration": 939 } diff --git a/.turbo/cache/1d0efba35ca2970e.tar.zst b/.turbo/cache/1d0efba35ca2970e.tar.zst deleted file mode 100644 index 02edb12..0000000 Binary files a/.turbo/cache/1d0efba35ca2970e.tar.zst and /dev/null differ diff --git a/.turbo/cache/2f46586394088f1d-meta.json b/.turbo/cache/2f46586394088f1d-meta.json deleted file mode 100644 index 4cb9924..0000000 --- a/.turbo/cache/2f46586394088f1d-meta.json +++ /dev/null @@ -1 +0,0 @@ -{ "hash": "2f46586394088f1d", "duration": 1047 } diff --git a/.turbo/cache/2f46586394088f1d.tar.zst b/.turbo/cache/2f46586394088f1d.tar.zst deleted file mode 100644 index b7ddb1b..0000000 Binary files a/.turbo/cache/2f46586394088f1d.tar.zst and /dev/null differ diff --git a/.turbo/cache/3dd7889bb40ab82a-meta.json b/.turbo/cache/3dd7889bb40ab82a-meta.json deleted file mode 100644 index 5e5178a..0000000 --- a/.turbo/cache/3dd7889bb40ab82a-meta.json +++ /dev/null @@ -1 +0,0 @@ -{ "hash": "3dd7889bb40ab82a", "duration": 1324 } diff --git a/.turbo/cache/3dd7889bb40ab82a.tar.zst b/.turbo/cache/3dd7889bb40ab82a.tar.zst deleted file mode 100644 index a0794d5..0000000 Binary files a/.turbo/cache/3dd7889bb40ab82a.tar.zst and /dev/null differ diff --git a/.turbo/cache/41b765d0ea1c4abb-meta.json b/.turbo/cache/41b765d0ea1c4abb-meta.json deleted file mode 100644 index 2b7da0d..0000000 --- a/.turbo/cache/41b765d0ea1c4abb-meta.json +++ /dev/null @@ -1 +0,0 @@ -{ "hash": "41b765d0ea1c4abb", "duration": 887 } diff --git a/.turbo/cache/41b765d0ea1c4abb.tar.zst b/.turbo/cache/41b765d0ea1c4abb.tar.zst deleted file mode 100644 index 614c686..0000000 Binary files a/.turbo/cache/41b765d0ea1c4abb.tar.zst and /dev/null differ diff --git a/.turbo/cache/426d85d05f1125d4-meta.json b/.turbo/cache/426d85d05f1125d4-meta.json deleted file mode 100644 index 57b3814..0000000 --- a/.turbo/cache/426d85d05f1125d4-meta.json +++ /dev/null @@ -1 +0,0 @@ -{ "hash": "426d85d05f1125d4", "duration": 823 } diff --git a/.turbo/cache/426d85d05f1125d4.tar.zst b/.turbo/cache/426d85d05f1125d4.tar.zst deleted file mode 100644 index 496cabe..0000000 Binary files a/.turbo/cache/426d85d05f1125d4.tar.zst and /dev/null differ diff --git a/.turbo/cache/42b97f968f64c135-meta.json b/.turbo/cache/42b97f968f64c135-meta.json deleted file mode 100644 index 311fe21..0000000 --- a/.turbo/cache/42b97f968f64c135-meta.json +++ /dev/null @@ -1 +0,0 @@ -{ "hash": "42b97f968f64c135", "duration": 1241 } diff --git a/.turbo/cache/42b97f968f64c135.tar.zst b/.turbo/cache/42b97f968f64c135.tar.zst deleted file mode 100644 index fff99ac..0000000 Binary files a/.turbo/cache/42b97f968f64c135.tar.zst and /dev/null differ diff --git a/.turbo/cache/4883f8ac8b0355de-meta.json b/.turbo/cache/4883f8ac8b0355de-meta.json deleted file mode 100644 index bf34ce2..0000000 --- a/.turbo/cache/4883f8ac8b0355de-meta.json +++ /dev/null @@ -1 +0,0 @@ -{ "hash": "4883f8ac8b0355de", "duration": 1970 } diff --git a/.turbo/cache/4883f8ac8b0355de.tar.zst b/.turbo/cache/4883f8ac8b0355de.tar.zst deleted file mode 100644 index ce3fa86..0000000 Binary files a/.turbo/cache/4883f8ac8b0355de.tar.zst and /dev/null differ diff --git a/.turbo/cache/572ab72c4c2dda9e-meta.json b/.turbo/cache/572ab72c4c2dda9e-meta.json deleted file mode 100644 index 5d73f4c..0000000 --- a/.turbo/cache/572ab72c4c2dda9e-meta.json +++ /dev/null @@ -1 +0,0 @@ -{ "hash": "572ab72c4c2dda9e", "duration": 1852 } diff --git a/.turbo/cache/572ab72c4c2dda9e.tar.zst b/.turbo/cache/572ab72c4c2dda9e.tar.zst deleted file mode 100644 index bbf78f6..0000000 Binary files a/.turbo/cache/572ab72c4c2dda9e.tar.zst and /dev/null differ diff --git a/.turbo/cache/7ac2a161e1aa81b0-meta.json b/.turbo/cache/7ac2a161e1aa81b0-meta.json deleted file mode 100644 index 54fc39f..0000000 --- a/.turbo/cache/7ac2a161e1aa81b0-meta.json +++ /dev/null @@ -1 +0,0 @@ -{ "hash": "7ac2a161e1aa81b0", "duration": 1703 } diff --git a/.turbo/cache/7ac2a161e1aa81b0.tar.zst b/.turbo/cache/7ac2a161e1aa81b0.tar.zst deleted file mode 100644 index e49d198..0000000 Binary files a/.turbo/cache/7ac2a161e1aa81b0.tar.zst and /dev/null differ diff --git a/.turbo/cache/8bc7f03fd570b2ed-meta.json b/.turbo/cache/8bc7f03fd570b2ed-meta.json deleted file mode 100644 index ed7b06f..0000000 --- a/.turbo/cache/8bc7f03fd570b2ed-meta.json +++ /dev/null @@ -1 +0,0 @@ -{ "hash": "8bc7f03fd570b2ed", "duration": 1369 } diff --git a/.turbo/cache/8bc7f03fd570b2ed.tar.zst b/.turbo/cache/8bc7f03fd570b2ed.tar.zst deleted file mode 100644 index 9c39e14..0000000 Binary files a/.turbo/cache/8bc7f03fd570b2ed.tar.zst and /dev/null differ diff --git a/.turbo/cache/9b8892abb7e01e4e-meta.json b/.turbo/cache/9b8892abb7e01e4e-meta.json deleted file mode 100644 index 8f4f85f..0000000 --- a/.turbo/cache/9b8892abb7e01e4e-meta.json +++ /dev/null @@ -1 +0,0 @@ -{ "hash": "9b8892abb7e01e4e", "duration": 1205 } diff --git a/.turbo/cache/9b8892abb7e01e4e.tar.zst b/.turbo/cache/9b8892abb7e01e4e.tar.zst deleted file mode 100644 index 847257f..0000000 Binary files a/.turbo/cache/9b8892abb7e01e4e.tar.zst and /dev/null differ diff --git a/.turbo/cache/9df78ba43790ddfd-meta.json b/.turbo/cache/9df78ba43790ddfd-meta.json deleted file mode 100644 index 318e846..0000000 --- a/.turbo/cache/9df78ba43790ddfd-meta.json +++ /dev/null @@ -1 +0,0 @@ -{ "hash": "9df78ba43790ddfd", "duration": 896 } diff --git a/.turbo/cache/9df78ba43790ddfd.tar.zst b/.turbo/cache/9df78ba43790ddfd.tar.zst deleted file mode 100644 index 591f623..0000000 Binary files a/.turbo/cache/9df78ba43790ddfd.tar.zst and /dev/null differ diff --git a/.turbo/cache/c71ed518e7beda73-meta.json b/.turbo/cache/c71ed518e7beda73-meta.json deleted file mode 100644 index d58bf08..0000000 --- a/.turbo/cache/c71ed518e7beda73-meta.json +++ /dev/null @@ -1 +0,0 @@ -{ "hash": "c71ed518e7beda73", "duration": 1110 } diff --git a/.turbo/cache/c71ed518e7beda73.tar.zst b/.turbo/cache/c71ed518e7beda73.tar.zst deleted file mode 100644 index 423efbf..0000000 Binary files a/.turbo/cache/c71ed518e7beda73.tar.zst and /dev/null differ diff --git a/.turbo/cache/cf4b544cb2131de8-meta.json b/.turbo/cache/cf4b544cb2131de8-meta.json deleted file mode 100644 index 70ac57b..0000000 --- a/.turbo/cache/cf4b544cb2131de8-meta.json +++ /dev/null @@ -1 +0,0 @@ -{ "hash": "cf4b544cb2131de8", "duration": 941 } diff --git a/.turbo/cache/cf4b544cb2131de8.tar.zst b/.turbo/cache/cf4b544cb2131de8.tar.zst deleted file mode 100644 index e6908af..0000000 Binary files a/.turbo/cache/cf4b544cb2131de8.tar.zst and /dev/null differ diff --git a/.turbo/cache/cfb9ea92802d73fa-meta.json b/.turbo/cache/cfb9ea92802d73fa-meta.json deleted file mode 100644 index 6c83591..0000000 --- a/.turbo/cache/cfb9ea92802d73fa-meta.json +++ /dev/null @@ -1 +0,0 @@ -{ "hash": "cfb9ea92802d73fa", "duration": 1032 } diff --git a/.turbo/cache/cfb9ea92802d73fa.tar.zst b/.turbo/cache/cfb9ea92802d73fa.tar.zst deleted file mode 100644 index a4e568a..0000000 Binary files a/.turbo/cache/cfb9ea92802d73fa.tar.zst and /dev/null differ diff --git a/.turbo/cache/d9eba1afee15d5d3-meta.json b/.turbo/cache/d9eba1afee15d5d3-meta.json deleted file mode 100644 index ddf42dd..0000000 --- a/.turbo/cache/d9eba1afee15d5d3-meta.json +++ /dev/null @@ -1 +0,0 @@ -{ "hash": "d9eba1afee15d5d3", "duration": 1022 } diff --git a/.turbo/cache/d9eba1afee15d5d3.tar.zst b/.turbo/cache/d9eba1afee15d5d3.tar.zst deleted file mode 100644 index 6e7ae52..0000000 Binary files a/.turbo/cache/d9eba1afee15d5d3.tar.zst and /dev/null differ diff --git a/.turbo/cache/fc0ef2a9abd4deca-meta.json b/.turbo/cache/fc0ef2a9abd4deca-meta.json deleted file mode 100644 index 7ef1596..0000000 --- a/.turbo/cache/fc0ef2a9abd4deca-meta.json +++ /dev/null @@ -1 +0,0 @@ -{ "hash": "fc0ef2a9abd4deca", "duration": 1154 } diff --git a/.turbo/cache/fc0ef2a9abd4deca.tar.zst b/.turbo/cache/fc0ef2a9abd4deca.tar.zst deleted file mode 100644 index b93de27..0000000 Binary files a/.turbo/cache/fc0ef2a9abd4deca.tar.zst and /dev/null differ diff --git a/.turbo/cookies/1.cookie b/.turbo/cookies/1.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/10.cookie b/.turbo/cookies/10.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/11.cookie b/.turbo/cookies/11.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/12.cookie b/.turbo/cookies/12.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/13.cookie b/.turbo/cookies/13.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/14.cookie b/.turbo/cookies/14.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/15.cookie b/.turbo/cookies/15.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/16.cookie b/.turbo/cookies/16.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/17.cookie b/.turbo/cookies/17.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/18.cookie b/.turbo/cookies/18.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/19.cookie b/.turbo/cookies/19.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/2.cookie b/.turbo/cookies/2.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/20.cookie b/.turbo/cookies/20.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/21.cookie b/.turbo/cookies/21.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/22.cookie b/.turbo/cookies/22.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/23.cookie b/.turbo/cookies/23.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/24.cookie b/.turbo/cookies/24.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/25.cookie b/.turbo/cookies/25.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/26.cookie b/.turbo/cookies/26.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/27.cookie b/.turbo/cookies/27.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/28.cookie b/.turbo/cookies/28.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/29.cookie b/.turbo/cookies/29.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/3.cookie b/.turbo/cookies/3.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/30.cookie b/.turbo/cookies/30.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/31.cookie b/.turbo/cookies/31.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/32.cookie b/.turbo/cookies/32.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/33.cookie b/.turbo/cookies/33.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/34.cookie b/.turbo/cookies/34.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/35.cookie b/.turbo/cookies/35.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/36.cookie b/.turbo/cookies/36.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/37.cookie b/.turbo/cookies/37.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/38.cookie b/.turbo/cookies/38.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/39.cookie b/.turbo/cookies/39.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/4.cookie b/.turbo/cookies/4.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/40.cookie b/.turbo/cookies/40.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/41.cookie b/.turbo/cookies/41.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/42.cookie b/.turbo/cookies/42.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/43.cookie b/.turbo/cookies/43.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/44.cookie b/.turbo/cookies/44.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/45.cookie b/.turbo/cookies/45.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/46.cookie b/.turbo/cookies/46.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/47.cookie b/.turbo/cookies/47.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/48.cookie b/.turbo/cookies/48.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/49.cookie b/.turbo/cookies/49.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/5.cookie b/.turbo/cookies/5.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/50.cookie b/.turbo/cookies/50.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/51.cookie b/.turbo/cookies/51.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/52.cookie b/.turbo/cookies/52.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/53.cookie b/.turbo/cookies/53.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/54.cookie b/.turbo/cookies/54.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/55.cookie b/.turbo/cookies/55.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/56.cookie b/.turbo/cookies/56.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/57.cookie b/.turbo/cookies/57.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/58.cookie b/.turbo/cookies/58.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/59.cookie b/.turbo/cookies/59.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/6.cookie b/.turbo/cookies/6.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/60.cookie b/.turbo/cookies/60.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/61.cookie b/.turbo/cookies/61.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/62.cookie b/.turbo/cookies/62.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/63.cookie b/.turbo/cookies/63.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/64.cookie b/.turbo/cookies/64.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/65.cookie b/.turbo/cookies/65.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/66.cookie b/.turbo/cookies/66.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/67.cookie b/.turbo/cookies/67.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/68.cookie b/.turbo/cookies/68.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/69.cookie b/.turbo/cookies/69.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/7.cookie b/.turbo/cookies/7.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/70.cookie b/.turbo/cookies/70.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/71.cookie b/.turbo/cookies/71.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/8.cookie b/.turbo/cookies/8.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/cookies/9.cookie b/.turbo/cookies/9.cookie deleted file mode 100644 index e69de29..0000000 diff --git a/.turbo/daemon/8c827086adca0deb-turbo.log.2024-08-03 b/.turbo/daemon/8c827086adca0deb-turbo.log.2024-08-03 deleted file mode 100644 index e69de29..0000000 diff --git a/apps/klesia/.env.example b/apps/klesia/.env.example new file mode 100644 index 0000000..d45fa30 --- /dev/null +++ b/apps/klesia/.env.example @@ -0,0 +1,3 @@ +MINA_NETWORK=devnet +NODE_API_DEVNET=https://api.minascan.io/node/devnet/v1/graphql +NODE_API_MAINNET=https://api.minascan.io/node/mainnet/v1/graphql diff --git a/apps/klesia/README.md b/apps/klesia/README.md new file mode 100644 index 0000000..cd8d8a0 --- /dev/null +++ b/apps/klesia/README.md @@ -0,0 +1,3 @@ +# Klesia + +JSON-RPC 2.0 wrapper over common Mina Protocol tools and services. diff --git a/apps/klesia/package.json b/apps/klesia/package.json new file mode 100644 index 0000000..2cb55f7 --- /dev/null +++ b/apps/klesia/package.json @@ -0,0 +1,16 @@ +{ + "name": "@mina-js/klesia", + "scripts": { + "dev": "bun run --hot src/index.ts" + }, + "dependencies": { + "@hono/zod-openapi": "^0.16.0", + "@scalar/hono-api-reference": "^0.5.143", + "@urql/core": "^5.0.6", + "dayjs": "^1.11.13", + "hono": "^4.5.10", + "ofetch": "^1.3.4", + "ts-pattern": "^5.3.1", + "zod": "^3.23.8" + } +} diff --git a/apps/klesia/src/index.ts b/apps/klesia/src/index.ts new file mode 100644 index 0000000..9a235e5 --- /dev/null +++ b/apps/klesia/src/index.ts @@ -0,0 +1,74 @@ +import { OpenAPIHono, createRoute } from "@hono/zod-openapi"; +import { apiReference } from "@scalar/hono-api-reference"; +import { match } from "ts-pattern"; +import { mina } from "./methods/mina"; +import { RpcMethodSchema, RpcResponseSchema } from "./schema"; +import { buildResponse } from "./utils/build-response"; + +const api = new OpenAPIHono(); + +api.doc("/api/openapi", { + openapi: "3.0.0", + info: { + version: "1.0.0", + title: "Klesia API", + }, +}); + +const rpcRoute = createRoute({ + method: "post", + path: "/api", + request: { + body: { content: { "application/json": { schema: RpcMethodSchema } } }, + }, + responses: { + 200: { + content: { + "application/json": { + schema: RpcResponseSchema, + }, + }, + description: "JSON-RPC response.", + }, + }, +}); + +api.openapi(rpcRoute, async ({ req, json }) => { + const body = req.valid("json"); + return match(body) + .with({ method: "mina_getTransactionCount" }, async ({ params }) => { + const [publicKey] = params; + const result = await mina.getTransactionCount({ publicKey }); + return json(buildResponse(result), 200); + }) + .with({ method: "mina_getBalance" }, async ({ params }) => { + const [publicKey] = params; + const result = await mina.getBalance({ publicKey }); + return json(buildResponse(result), 200); + }) + .with({ method: "mina_blockHash" }, async () => { + const result = await mina.blockHash(); + return json(buildResponse(result), 200); + }) + .with({ method: "mina_chainId" }, async () => { + const result = await mina.chainId(); + return json(buildResponse(result), 200); + }) + .with({ method: "mina_sendTransaction" }, async ({ params }) => { + const [signedTransaction, type] = params; + const result = await mina.sendTransaction({ signedTransaction, type }); + return json(buildResponse(result), 200); + }) + .exhaustive(); +}); + +api.get( + "/api", + apiReference({ + spec: { + url: "/api/openapi", + }, + }), +); + +export default api; diff --git a/apps/klesia/src/methods/mina.ts b/apps/klesia/src/methods/mina.ts new file mode 100644 index 0000000..8dda210 --- /dev/null +++ b/apps/klesia/src/methods/mina.ts @@ -0,0 +1,133 @@ +import { gql } from "@urql/core"; +import { match } from "ts-pattern"; +import { getNodeClient } from "../utils/node"; + +const getTransactionCount = async ({ publicKey }: { publicKey: string }) => { + const client = getNodeClient(); + const { data } = await client.query( + gql` + query { + account(publicKey: $publicKey) { + nonce + } + } + `, + { publicKey }, + ); + return Number.parseInt(data.account.nonce); +}; + +const getBalance = async ({ publicKey }: { publicKey: string }) => { + const client = getNodeClient(); + const { data } = await client.query( + gql` + query { + account(publicKey: $publicKey) { + balance { + total + } + } + } + `, + { publicKey }, + ); + return data.account.balance.total; +}; + +const blockHash = async () => { + const client = getNodeClient(); + const { data } = await client.query( + gql` + query { + daemonStatus { + stateHash + } + } + `, + {}, + ); + return data.daemonStatus.stateHash; +}; + +const chainId = async () => { + const client = getNodeClient(); + const { data } = await client.query( + gql` + query { + daemonStatus { + chainId + } + } + `, + {}, + ); + return data.daemonStatus.chainId; +}; + +const sendTransaction = async ({ + signedTransaction, + type, +}: { + // biome-ignore lint/suspicious/noExplicitAny: TODO + signedTransaction: any; + type: "payment" | "delegation" | "zkapp"; +}) => { + const client = getNodeClient(); + return match(type) + .with("payment", async () => { + const { signature, data: input } = signedTransaction; + const { data } = await client.mutation( + gql` + mutation { + sendPayment(signature: $signature, input: $input) { + payment { + hash + } + } + } + `, + { signature, input }, + ); + return data.sendPayment.payment.hash; + }) + .with("delegation", async () => { + const { signature, data: input } = signedTransaction; + const { data } = await client.mutation( + gql` + mutation { + sendDelegation(signature: $signature, input: $input) { + delegation { + hash + } + } + } + `, + { signature, input }, + ); + return data.sendDelegation.delegation.hash; + }) + .with("zkapp", async () => { + const { data } = await client.mutation( + gql` + mutation { + sendZkapp(input: $input) { + zkapp { + hash + } + } + } + `, + { input: signedTransaction }, + ); + return data.sendZkapp.zkapp.hash; + }) + .exhaustive(); +}; + +export const mina = { + getTransactionCount, + getBalance, + blockHash, + chainId, + sendTransaction, +}; diff --git a/apps/klesia/src/schema.ts b/apps/klesia/src/schema.ts new file mode 100644 index 0000000..ddedebf --- /dev/null +++ b/apps/klesia/src/schema.ts @@ -0,0 +1,34 @@ +import { z } from "zod"; + +export const PublicKeySchema = z.string().length(55); +export const PublicKeyParamsSchema = z.array(PublicKeySchema).length(1); +export const EmptyParamsSchema = z.array(z.string()).length(0).optional(); +export const SendTransactionSchema = z.array(z.any(), z.string()).length(2); + +export const RpcMethodSchema = z.discriminatedUnion("method", [ + z.object({ + method: z.literal("mina_getTransactionCount"), + params: PublicKeyParamsSchema, + }), + z.object({ + method: z.literal("mina_getBalance"), + params: PublicKeyParamsSchema, + }), + z.object({ + method: z.literal("mina_blockHash"), + params: EmptyParamsSchema, + }), + z.object({ + method: z.literal("mina_chainId"), + params: EmptyParamsSchema, + }), + z.object({ + method: z.literal("mina_sendTransaction"), + params: SendTransactionSchema, + }), +]); + +export const RpcResponseSchema = z.object({ + jsonrpc: z.literal("2.0"), + result: z.unknown(), +}); diff --git a/apps/klesia/src/utils/build-response.ts b/apps/klesia/src/utils/build-response.ts new file mode 100644 index 0000000..48af077 --- /dev/null +++ b/apps/klesia/src/utils/build-response.ts @@ -0,0 +1,4 @@ +export const buildResponse = (data: unknown) => ({ + jsonrpc: "2.0", + result: data, +}); diff --git a/apps/klesia/src/utils/node.ts b/apps/klesia/src/utils/node.ts new file mode 100644 index 0000000..0e98b3f --- /dev/null +++ b/apps/klesia/src/utils/node.ts @@ -0,0 +1,17 @@ +import { Client, cacheExchange, fetchExchange } from "@urql/core"; +import { match } from "ts-pattern"; + +const MINA_NETWORK = process.env.MINA_NETWORK; + +export const getNodeApiUrl = () => { + return match(MINA_NETWORK) + .with("devnet", () => process.env.NODE_API_DEVNET) + .with("mainnet", () => process.env.NODE_API_MAINNET) + .run(); +}; + +export const getNodeClient = () => { + const url = getNodeApiUrl(); + if (!url) throw new Error("Invalid network config."); + return new Client({ url, exchanges: [cacheExchange, fetchExchange] }); +}; diff --git a/apps/klesia/tsconfig.json b/apps/klesia/tsconfig.json new file mode 100644 index 0000000..9c845ae --- /dev/null +++ b/apps/klesia/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "strict": true, + "jsx": "react-jsx", + "jsxImportSource": "hono/jsx" + } +} diff --git a/bun.lockb b/bun.lockb index 4e5fb58..460b1ad 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 883a021..8f6eff0 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,7 @@ "test": "bun run --filter '*' test", "cleanup": "bun run --filter '*' cleanup", "lint": "bunx biome check .", - "format": "bunx biome check . --write", - "format:unsafe": "bunx biome check . --write --unsafe" + "format": "bunx biome check . --write --unsafe" }, "devDependencies": { "@biomejs/biome": "1.8.3", @@ -19,6 +18,6 @@ "turbo": "^2.0.11", "typescript": "5.5.4" }, - "workspaces": ["packages/*"], + "workspaces": ["packages/*", "apps/*"], "packageManager": "bun@1.1.21" } diff --git a/packages/accounts/.turbo/turbo-build.log b/packages/accounts/.turbo/turbo-build.log index 2e54462..6d59910 100644 --- a/packages/accounts/.turbo/turbo-build.log +++ b/packages/accounts/.turbo/turbo-build.log @@ -8,13 +8,13 @@ CLI Cleaning output folder ESM Build start CJS Build start -ESM dist/index.mjs 575.00 B -ESM dist/index.mjs.map 1.35 KB -ESM ⚡️ Build success in 6ms CJS dist/index.js 2.25 KB CJS dist/index.js.map 1.44 KB -CJS ⚡️ Build success in 6ms +CJS ⚡️ Build success in 8ms +ESM dist/index.mjs 575.00 B +ESM dist/index.mjs.map 1.35 KB +ESM ⚡️ Build success in 8ms DTS Build start -DTS ⚡️ Build success in 483ms +DTS ⚡️ Build success in 499ms DTS dist/index.d.mts 631.00 B DTS dist/index.d.ts 631.00 B diff --git a/packages/accounts/src/private-key-to-account.ts b/packages/accounts/src/private-key-to-account.ts index d767681..af3ef61 100644 --- a/packages/accounts/src/private-key-to-account.ts +++ b/packages/accounts/src/private-key-to-account.ts @@ -1,32 +1,32 @@ -// import MinaSigner from "mina-signer"; +import MinaSigner from "mina-signer"; -// /** -// * @description Creates an Account from a private key. -// * -// * @returns A Private Key Account. -// */ -// export function privateKeyToAccount(privateKey: string): PrivateKeyAccount { -// const client = new MinaSigner({ network: "mainnet" }); -// const publicKey = client.derivePublicKey(privateKey); -// const account = toAccount({ -// publicKey, -// async sign({ hash }) { -// return sign({ hash, privateKey, to: "hex" }); -// }, -// async signMessage({ message }) { -// return signMessage({ message, privateKey }); -// }, -// async signTransaction(transaction, { serializer } = {}) { -// return signTransaction({ privateKey, transaction, serializer }); -// }, -// async signTypedData(typedData) { -// return signTypedData({ ...typedData, privateKey }); -// }, -// }); +/** + * @description Creates an Account from a private key. + * + * @returns A Private Key Account. + */ +export function privateKeyToAccount(privateKey: string): PrivateKeyAccount { + const client = new MinaSigner({ network: "mainnet" }); + const publicKey = client.derivePublicKey(privateKey); + const account = toAccount({ + publicKey, + async signMessage({ message }) { + return signMessage({ message, privateKey }); + }, + async signTransaction({ transaction }) { + return signTransaction({ privateKey, transaction }); + }, + async createNullifier({ message }) { + return createNullifier({ message, privateKey }); + }, + async signFields({ fields }) { + return signFields({ fields, privateKey }); + }, + }); -// return { -// ...account, -// publicKey, -// source: "privateKey", -// } as PrivateKeyAccount; -// } + return { + ...account, + publicKey, + source: "privateKey", + } as PrivateKeyAccount; +} diff --git a/packages/accounts/src/to-account.ts b/packages/accounts/src/to-account.ts new file mode 100644 index 0000000..f2411cd --- /dev/null +++ b/packages/accounts/src/to-account.ts @@ -0,0 +1,55 @@ +import { + InvalidAddressError, + type InvalidAddressErrorType, +} from "../errors/address.js"; +import { + type IsAddressErrorType, + isAddress, +} from "../utils/address/isAddress.js"; + +import type { PublicKey } from "@mina-js/shared"; +import type { ErrorType } from "../errors/utils.js"; +import type { + AccountSource, + CustomSource, + JsonRpcAccount, + LocalAccount, +} from "./types.js"; + +type GetAccountReturnType = + | (accountSource extends PublicKey ? JsonRpcAccount : never) + | (accountSource extends CustomSource ? LocalAccount : never); + +export type ToAccountErrorType = + | InvalidAddressErrorType + | IsAddressErrorType + | ErrorType; + +/** + * @description Creates an Account from a custom signing implementation. + * @returns A Local Account. + */ +export function toAccount( + source: accountSource, +): GetAccountReturnType { + if (typeof source === "string") { + if (!isAddress(source, { strict: false })) + throw new InvalidAddressError({ address: source }); + return { + address: source, + type: "json-rpc", + } as GetAccountReturnType; + } + + if (!isAddress(source.address, { strict: false })) + throw new InvalidAddressError({ address: source.address }); + return { + publicKey: source.publicKey, + signMessage: source.signMessage, + signTransaction: source.signTransaction, + createNullifier: source.createNullifier, + signFields: source.signFields, + source: "custom", + type: "local", + } as GetAccountReturnType; +} diff --git a/packages/accounts/src/types.ts b/packages/accounts/src/types.ts index ae0aada..ba73911 100644 --- a/packages/accounts/src/types.ts +++ b/packages/accounts/src/types.ts @@ -1,5 +1,16 @@ +import type { + CreateNullifier, + SignFields, + SignMessage, + SignTransaction, +} from "@mina-js/shared"; + export type CustomSource = { publicKey: string; + signMessage: SignMessage; + signTransaction: SignTransaction; + createNullifier: CreateNullifier; + signFields: SignFields; }; export type LocalAccount = CustomSource & { diff --git a/packages/connect/.turbo/turbo-build.log b/packages/connect/.turbo/turbo-build.log index b01ba1a..b56e313 100644 --- a/packages/connect/.turbo/turbo-build.log +++ b/packages/connect/.turbo/turbo-build.log @@ -8,13 +8,13 @@ CLI Cleaning output folder ESM Build start CJS Build start -ESM dist/index.mjs 1.99 KB -ESM dist/index.mjs.map 5.61 KB -ESM ⚡️ Build success in 7ms CJS dist/index.js 3.07 KB CJS dist/index.js.map 6.11 KB CJS ⚡️ Build success in 7ms +ESM dist/index.mjs 1.99 KB +ESM dist/index.mjs.map 5.61 KB +ESM ⚡️ Build success in 7ms DTS Build start -DTS ⚡️ Build success in 547ms +DTS ⚡️ Build success in 574ms DTS dist/index.d.mts 2.51 KB DTS dist/index.d.ts 2.51 KB diff --git a/packages/providers/.turbo/turbo-build.log b/packages/providers/.turbo/turbo-build.log index 069717c..a8ce4e5 100644 --- a/packages/providers/.turbo/turbo-build.log +++ b/packages/providers/.turbo/turbo-build.log @@ -8,13 +8,13 @@ CLI Cleaning output folder ESM Build start CJS Build start -CJS dist/index.cjs 3.67 KB -CJS dist/index.cjs.map 3.75 KB -CJS ⚡️ Build success in 6ms -ESM dist/index.js 1.70 KB -ESM dist/index.js.map 3.58 KB -ESM ⚡️ Build success in 6ms +ESM dist/index.js 1.52 KB +ESM dist/index.js.map 3.07 KB +ESM ⚡️ Build success in 7ms +CJS dist/index.cjs 3.40 KB +CJS dist/index.cjs.map 3.24 KB +CJS ⚡️ Build success in 7ms DTS Build start -DTS ⚡️ Build success in 611ms -DTS dist/index.d.ts 12.34 KB -DTS dist/index.d.cts 12.34 KB +DTS ⚡️ Build success in 670ms +DTS dist/index.d.ts 12.32 KB +DTS dist/index.d.cts 12.32 KB diff --git a/packages/providers/src/types.ts b/packages/providers/src/types.ts index 8b880d6..bf5a170 100644 --- a/packages/providers/src/types.ts +++ b/packages/providers/src/types.ts @@ -154,6 +154,6 @@ export type ProviderListener = export type MinaProviderClient = { request: ProviderRequest; - addListener: ProviderListener; + on: ProviderListener; removeListener: ProviderListener; }; diff --git a/packages/providers/src/validation.ts b/packages/providers/src/validation.ts index 1214287..024a985 100644 --- a/packages/providers/src/validation.ts +++ b/packages/providers/src/validation.ts @@ -1,12 +1,5 @@ import { z } from "zod"; -const literalSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]); -type Literal = z.infer; -type Json = Literal | { [key: string]: Json } | Json[]; -const jsonSchema: z.ZodType = z.lazy(() => - z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)]), -); - export const signFieldsRequestSchema = z.object({ fields: z.array(z.coerce.number()), }); diff --git a/packages/shared/.turbo/turbo-build.log b/packages/shared/.turbo/turbo-build.log index 9ead33a..8be1c83 100644 --- a/packages/shared/.turbo/turbo-build.log +++ b/packages/shared/.turbo/turbo-build.log @@ -8,13 +8,13 @@ CLI Cleaning output folder ESM Build start CJS Build start -ESM dist/index.js 33.00 B -ESM dist/index.js.map 71.00 B -ESM ⚡️ Build success in 6ms -CJS dist/index.cjs 788.00 B -CJS dist/index.cjs.map 447.00 B -CJS ⚡️ Build success in 6ms +ESM dist/index.js 2.33 KB +ESM dist/index.js.map 4.16 KB +ESM ⚡️ Build success in 7ms +CJS dist/index.cjs 4.62 KB +CJS dist/index.cjs.map 4.36 KB +CJS ⚡️ Build success in 7ms DTS Build start -DTS ⚡️ Build success in 598ms -DTS dist/index.d.ts 4.46 KB -DTS dist/index.d.cts 4.46 KB +DTS ⚡️ Build success in 728ms +DTS dist/index.d.ts 11.44 KB +DTS dist/index.d.cts 11.44 KB diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index 8d4bd9f..0b70ea2 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts @@ -1,17 +1,2 @@ -export type { - SignedMessage, - SignedFields, - Nullifier, - PublicKey, - TransactionReceipt, -} from "./types"; -export type { - SignatureSchema, - SignedMessageSchema, - FieldSchema, - GroupSchema, - NullifierSchema, - PublicKeySchema, - SignedFieldsSchema, - TransactionReceiptSchema, -} from "./validation"; +export * from "./types"; +export * from "./validation"; diff --git a/packages/shared/src/types.ts b/packages/shared/src/types.ts index 64ca6a6..9fd3c11 100644 --- a/packages/shared/src/types.ts +++ b/packages/shared/src/types.ts @@ -1,18 +1,57 @@ import type { z } from "zod"; import type { + CreateNullifierParamsSchema, + LiteralSchema, NullifierSchema, + PrivateKeySchema, PublicKeySchema, + SendTransactionParamsSchema, + SignFieldsParamsSchema, + SignMessageParamsSchema, + SignTransactionParamsSchema, SignedFieldsSchema, SignedMessageSchema, + SignedTransactionSchema, TransactionReceiptSchema, } from "./validation"; +/** + * Primitive types + */ +export type Literal = z.infer; +export type Json = Literal | { [key: string]: Json } | Json[]; export type PublicKey = z.infer; +export type PrivateKey = z.infer; -export type SignedMessage = z.infer; +/** + * Parameter types + */ +export type SignFieldsParams = z.infer; +export type SignMessageParams = z.infer; +export type CreateNullifierParams = z.infer; +export type SignTransactionParams = z.infer; +export type SendTransactionParams = z.infer; +/** + * Return types + */ +export type SignedMessage = z.infer; export type SignedFields = z.infer; - export type Nullifier = z.infer; - +export type SignedTransaction = z.infer; export type TransactionReceipt = z.infer; + +/** + * Signer methods + */ +export type SignFields = (params: SignFieldsParams) => Promise; +export type SignMessage = (params: SignMessageParams) => Promise; +export type CreateNullifier = ( + params: CreateNullifierParams, +) => Promise; +export type SignTransaction = ( + params: SignTransactionParams, +) => Promise; +export type SendTransaction = ( + params: SendTransactionParams, +) => Promise; diff --git a/packages/shared/src/validation.ts b/packages/shared/src/validation.ts index 7c96089..5eaf7d1 100644 --- a/packages/shared/src/validation.ts +++ b/packages/shared/src/validation.ts @@ -1,4 +1,18 @@ import { z } from "zod"; +import type { Json } from "./types"; + +/** + * Data primitive schemas + */ +export const LiteralSchema = z.union([ + z.string(), + z.number(), + z.boolean(), + z.null(), +]); +const JsonSchema: z.ZodType = z.lazy(() => + z.union([LiteralSchema, z.array(JsonSchema), z.record(JsonSchema)]), +); export const FieldSchema = z.coerce.bigint(); @@ -9,6 +23,45 @@ export const GroupSchema = z.object({ export const PublicKeySchema = z.string().length(55).startsWith("B62"); +export const PrivateKeySchema = z.string().length(52); + +export const TransactionPayload = z.object({ + from: PublicKeySchema, + to: PublicKeySchema, + memo: z.string().optional(), + fee: z.coerce.number(), + amount: z.coerce.number(), + nonce: z.coerce.number(), + validUntil: z.coerce.number().optional(), +}); + +/** + * Parameter schemas + */ +export const SignFieldsParamsSchema = z.object({ + fields: z.array(z.coerce.number()), +}); + +export const SignMessageParamsSchema = z.object({ + message: z.string(), +}); + +export const CreateNullifierParamsSchema = z.object({ + message: z.array(z.coerce.number()), +}); + +export const SignTransactionParamsSchema = z.object({ + transaction: TransactionPayload, +}); + +export const SendTransactionParamsSchema = z.object({ + signedTransaction: TransactionPayload.strict(), + transactionType: z.enum(["payment", "delegation", "zkapp"]), +}); + +/** + * Return type schemas + */ export const SignatureSchema = z .object({ field: z.string(), @@ -43,6 +96,12 @@ export const NullifierSchema = z.object({ }), }); +export const SignedTransactionSchema = z.object({ + signature: SignatureSchema, + publicKey: PublicKeySchema, + data: TransactionPayload, +}); + export const TransactionReceiptSchema = z.object({ hash: z.string(), });