Skip to content

Commit c07429c

Browse files
committed
feat(connect): add chain related methods
1 parent 363f34c commit c07429c

File tree

7 files changed

+139
-204
lines changed

7 files changed

+139
-204
lines changed

apps/docs/src/pages/connect/wallet-interface.mdx

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ To make your zkApp compatible with Mina wallets, we've created a strongly typed
66

77
### mina_accounts
88

9+
Get accounts. If not authorized, the response is an empty array.
10+
911
```ts twoslash
1012
import { createStore } from '@mina-js/connect'
1113

@@ -14,8 +16,22 @@ const { provider } = store.getProviders()[0]
1416
const { result } = await provider.request<'mina_accounts'>({ method: 'mina_accounts' })
1517
```
1618

19+
### mina_requestAccounts
20+
21+
Acts like `mina_accounts` but with a prompt to authorize in case user didn't authorize yet.
22+
23+
```ts twoslash
24+
import { createStore } from '@mina-js/connect'
25+
26+
const store = createStore()
27+
const { provider } = store.getProviders()[0]
28+
const { result } = await provider.request<'mina_requestAccounts'>({ method: 'mina_requestAccounts' })
29+
```
30+
1731
### mina_chainId
1832

33+
Get the chain ID. It's a string that represents the current network. Values are `mina:mainnet` or `mina:testnet`.
34+
1935
```ts twoslash
2036
import { createStore } from '@mina-js/connect'
2137

@@ -26,6 +42,8 @@ const { result } = await provider.request<'mina_chainId'>({ method: 'mina_chainI
2642

2743
### mina_getBalance
2844

45+
Get the balance of the current account. The value is already parsed to Mina units.
46+
2947
```ts twoslash
3048
import { createStore } from '@mina-js/connect'
3149

@@ -36,6 +54,8 @@ const { result } = await provider.request<'mina_getBalance'>({ method: 'mina_get
3654

3755
### mina_chainInformation
3856

57+
Get chain information. Similar to `mina_chainId`, but more detailed. It returns current network's RPC url, name, and slug (chain ID).
58+
3959
```ts twoslash
4060
import { createStore } from '@mina-js/connect'
4161

@@ -44,6 +64,21 @@ const { provider } = store.getProviders()[0]
4464
const { result } = await provider.request<'mina_chainInformation'>({ method: 'mina_chainInformation' })
4565
```
4666

67+
### mina_getState
68+
69+
Returns filtered Public Credentials.
70+
71+
```ts twoslash
72+
import { createStore } from '@mina-js/connect'
73+
74+
const store = createStore()
75+
const { provider } = store.getProviders()[0]
76+
const { result } = await provider.request<'mina_getState'>({
77+
method: 'mina_getState',
78+
params: [{ issuer: "University of Example" }, []],
79+
})
80+
```
81+
4782
## Commands
4883

4984
### mina_sign
@@ -128,3 +163,74 @@ const { result } = await provider.request<'mina_createNullifier'>({
128163
params: [['1', '2', '3']]
129164
})
130165
```
166+
167+
### mina_sendTransaction
168+
169+
Send a signed transaction to the network.
170+
171+
```ts twoslash
172+
import { createStore } from '@mina-js/connect'
173+
174+
const store = createStore()
175+
const { provider } = store.getProviders()[0]
176+
const { result } = await provider.request<'mina_sendTransaction'>({
177+
method: 'mina_sendTransaction',
178+
params: [{ input: {}, signature: { field: 'xyz', scalar: 'xyz' } }, 'payment']
179+
})
180+
```
181+
182+
### mina_setState
183+
184+
Saves a new Public Credential.
185+
186+
```ts twoslash
187+
import { createStore } from '@mina-js/connect'
188+
189+
const store = createStore()
190+
const { provider } = store.getProviders()[0]
191+
const { result } = await provider.request<'mina_setState'>({
192+
method: "mina_setState",
193+
params: [
194+
{
195+
objectName: "Pallad Mock Credential",
196+
object: {}, // DID Credential with a Kimchi proof
197+
},
198+
],
199+
})
200+
```
201+
202+
### mina_switchChain
203+
204+
Prompts user to switch to another network. It's useful for dApps that support multiple networks.
205+
206+
```ts twoslash
207+
import { createStore } from '@mina-js/connect'
208+
209+
const store = createStore()
210+
const { provider } = store.getProviders()[0]
211+
await provider.request<'mina_switchChain'>({
212+
method: 'mina_switchChain',
213+
params: ['mina:mainnet']
214+
})
215+
```
216+
217+
### mina_addChain
218+
219+
Prompts user to add a new chain.
220+
221+
```ts twoslash
222+
import { createStore } from '@mina-js/connect'
223+
224+
const store = createStore()
225+
const { provider } = store.getProviders()[0]
226+
await provider.request<'mina_addChain'>({
227+
method: 'mina_addChain',
228+
params: [
229+
{
230+
name: 'Mina Fakenet',
231+
slug: 'mina:fakenet',
232+
url: 'https://fakenet.example.com',
233+
}
234+
]
235+
})
236+
```

apps/klesia/src/methods/mina.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
import {
2+
SendTransactionBodySchema,
3+
SendZkAppBodySchema,
4+
type Sendable,
5+
} from "@mina-js/utils";
16
import { gql } from "@urql/core";
27
import { match } from "ts-pattern";
3-
import { SendTransactionBodySchema, SendZkAppBodySchema } from "../schema";
48
import { getNodeClient } from "../utils/node";
59

610
export const PRIORITY = {
@@ -83,8 +87,7 @@ const sendTransaction = async ({
8387
signedTransaction,
8488
type,
8589
}: {
86-
// biome-ignore lint/suspicious/noExplicitAny: TODO
87-
signedTransaction: any;
90+
signedTransaction: Sendable;
8891
type: "payment" | "delegation" | "zkapp";
8992
}) => {
9093
const client = getNodeClient();

apps/klesia/src/schema.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { PublicKeySchema, TransactionBodySchema } from "@mina-js/utils";
1+
import { PublicKeySchema } from "@mina-js/utils";
22
import { z } from "zod";
3-
import { SendZkappInput } from "./zkapp";
43

54
export const KlesiaNetwork = z.enum(["devnet", "mainnet", "zeko_devnet"]);
65
export const PublicKeyParamsSchema = z.array(PublicKeySchema).length(1);
@@ -11,17 +10,6 @@ export const SignatureSchema = z.union([
1110
}),
1211
z.object({ field: z.string(), scalar: z.string() }),
1312
]);
14-
export const SendTransactionBodySchema = z.object({
15-
input: TransactionBodySchema,
16-
signature: SignatureSchema,
17-
});
18-
export const SendZkAppBodySchema = z.object({
19-
input: SendZkappInput,
20-
});
21-
export const SendableSchema = z.union([
22-
SendTransactionBodySchema,
23-
SendZkAppBodySchema,
24-
]);
2513
export const SendTransactionSchema = z.tuple([
2614
z.any(),
2715
z.enum(["payment", "delegation", "zkapp"]),

apps/klesia/src/zkapp.ts

Lines changed: 0 additions & 184 deletions
This file was deleted.

0 commit comments

Comments
 (0)