Skip to content

Commit ce28b1d

Browse files
committed
feat(connect): add wallet interface docs
1 parent 4eeda33 commit ce28b1d

File tree

14 files changed

+190
-112
lines changed

14 files changed

+190
-112
lines changed

apps/docs/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"scripts": {
66
"dev": "bunx vocs dev",
77
"build": "bunx vocs build",
8-
"preview": "bunx vocs preview"
8+
"preview": "bunx vocs preview",
9+
"cleanup": "rimraf dist .turbo node_modules"
910
},
1011
"dependencies": {
1112
"@theguild/remark-mermaid": "^0.1.2",
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Wallet Interface [Make your zkApp compatible with Mina wallets.]
2+
3+
To make your zkApp compatible with Mina wallets, we've created a strongly typed interface for `window.mina` and injected providers found by [Provider Discovery](/connect/provider-discovery).
4+
5+
## Queries
6+
7+
### mina_accounts
8+
9+
```ts twoslash
10+
import { createStore } from '@mina-js/connect'
11+
12+
const store = createStore()
13+
const { provider } = store.getProviders()[0]
14+
const { result } = await provider.request<'mina_accounts'>({ method: 'mina_accounts' })
15+
```
16+
17+
### mina_chainId
18+
19+
```ts twoslash
20+
import { createStore } from '@mina-js/connect'
21+
22+
const store = createStore()
23+
const { provider } = store.getProviders()[0]
24+
const { result } = await provider.request<'mina_chainId'>({ method: 'mina_chainId' })
25+
```
26+
27+
### mina_getBalance
28+
29+
```ts twoslash
30+
import { createStore } from '@mina-js/connect'
31+
32+
const store = createStore()
33+
const { provider } = store.getProviders()[0]
34+
const { result } = await provider.request<'mina_getBalance'>({ method: 'mina_getBalance' })
35+
```
36+
37+
### mina_chainInformation
38+
39+
```ts twoslash
40+
import { createStore } from '@mina-js/connect'
41+
42+
const store = createStore()
43+
const { provider } = store.getProviders()[0]
44+
const { result } = await provider.request<'mina_chainInformation'>({ method: 'mina_chainInformation' })
45+
```
46+
47+
## Commands
48+
49+
### mina_sign
50+
51+
```ts twoslash
52+
import { createStore } from '@mina-js/connect'
53+
54+
const store = createStore()
55+
const { provider } = store.getProviders()[0]
56+
const { result } = await provider.request<'mina_sign'>({ method: 'mina_sign', params: ['My message'] })
57+
```
58+
59+
### mina_signTransaction
60+
61+
```ts twoslash
62+
import { createStore } from '@mina-js/connect'
63+
64+
const store = createStore()
65+
const { provider } = store.getProviders()[0]
66+
const { result } = await provider.request<'mina_signTransaction'>({
67+
method: 'mina_signTransaction',
68+
params: [{
69+
// You should probably get the right nonce from Klesia for that.
70+
nonce: 1n,
71+
from: "B62qmWKtvNQTtUqo1LxfEEDLyWMg59cp6U7c4uDC7aqgaCEijSc3Hx5",
72+
to: "B62qmWKtvNQTtUqo1LxfEEDLyWMg59cp6U7c4uDC7aqgaCEijSc3Hx5",
73+
amount: 3000000000n,
74+
fee: 100000000n,
75+
}]
76+
})
77+
```
78+
79+
### mina_signFields
80+
81+
```ts twoslash
82+
import { createStore } from '@mina-js/connect'
83+
84+
const store = createStore()
85+
const { provider } = store.getProviders()[0]
86+
const { result } = await provider.request<'mina_signFields'>({
87+
method: 'mina_signFields',
88+
params: [[1n, 2n, 3n]]
89+
})
90+
```
91+
92+
### mina_createNullifier
93+
94+
```ts twoslash
95+
import { createStore } from '@mina-js/connect'
96+
97+
const store = createStore()
98+
const { provider } = store.getProviders()[0]
99+
const { result } = await provider.request<'mina_createNullifier'>({
100+
method: 'mina_createNullifier',
101+
params: [[1n, 2n, 3n]]
102+
})
103+
```

apps/docs/vocs.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export default defineConfig({
8686
{ text: "Introduction", link: "/connect" },
8787
{ text: "Getting Started", link: "/connect/getting-started" },
8888
{ text: "Provider Discovery", link: "/connect/provider-discovery" },
89+
{ text: "Wallet Interface", link: "/connect/wallet-interface" },
8990
],
9091
},
9192
{

apps/klesia/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"build": "tsup-node",
1616
"dev": "tsup-node --watch --onSuccess \"node dist/server.js\"",
1717
"start": "node dist/server.js",
18-
"test": "bun test"
18+
"test": "bun test",
19+
"cleanup": "rimraf dist .turbo node_modules"
1920
},
2021
"dependencies": {
2122
"@hono/node-server": "^1.12.2",

bun.lockb

88 Bytes
Binary file not shown.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"scripts": {
55
"build": "turbo build",
66
"test": "turbo test",
7-
"cleanup": "bun run --filter '*' cleanup",
7+
"cleanup": "bun run --filter '*' cleanup && rimraf node_modules .turbo",
88
"lint": "bunx biome check .",
99
"format": "bunx biome check . --write --unsafe"
1010
},

packages/accounts/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"@scure/base": "^1.1.8",
2626
"@scure/bip32": "1.4.0",
2727
"@scure/bip39": "1.3.0",
28-
"mina-signer": "3.0.7"
28+
"mina-signer": "3.0.7",
29+
"zod": "^3.23.8"
2930
},
3031
"peerDependencies": {
3132
"typescript": "^5.0.0"

packages/accounts/src/types.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import type {
2-
CreateNullifier,
2+
Nullifier,
33
PublicKey,
4-
SignFields,
5-
SignMessage,
6-
SignTransaction,
4+
SignedFields,
5+
SignedMessage,
6+
SignedTransaction,
77
} from "@mina-js/shared";
88
import type { HDKey } from "@scure/bip32";
99
import type { Simplify } from "type-fest";
10+
import type { z } from "zod";
11+
import type {
12+
CreateNullifierParamsSchema,
13+
SignFieldsParamsSchema,
14+
SignMessageParamsSchema,
15+
SignTransactionParamsSchema,
16+
} from "./validation";
1017

1118
export enum MinaKeyConst {
1219
PURPOSE = 44,
@@ -63,3 +70,23 @@ export type HDAccount = Simplify<
6370
export type PrivateKeyAccount = Simplify<LocalAccount<"privateKey">>;
6471

6572
export type { HDKey };
73+
74+
/**
75+
* Parameter types
76+
*/
77+
export type SignFieldsParams = z.infer<typeof SignFieldsParamsSchema>;
78+
export type SignMessageParams = z.infer<typeof SignMessageParamsSchema>;
79+
export type CreateNullifierParams = z.infer<typeof CreateNullifierParamsSchema>;
80+
export type SignTransactionParams = z.infer<typeof SignTransactionParamsSchema>;
81+
82+
/**
83+
* Signer methods
84+
*/
85+
export type SignFields = (params: SignFieldsParams) => Promise<SignedFields>;
86+
export type SignMessage = (params: SignMessageParams) => Promise<SignedMessage>;
87+
export type CreateNullifier = (
88+
params: CreateNullifierParams,
89+
) => Promise<Nullifier>;
90+
export type SignTransaction = (
91+
params: SignTransactionParams,
92+
) => Promise<SignedTransaction>;

packages/accounts/src/validation.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { FieldSchema, TransactionPayload } from "@mina-js/shared";
2+
import { z } from "zod";
3+
4+
export const SignFieldsParamsSchema = z
5+
.object({
6+
fields: z.array(FieldSchema),
7+
})
8+
.strict();
9+
10+
export const SignMessageParamsSchema = z
11+
.object({
12+
message: z.string(),
13+
})
14+
.strict();
15+
16+
export const CreateNullifierParamsSchema = z
17+
.object({
18+
message: z.array(FieldSchema),
19+
})
20+
.strict();
21+
22+
export const SignTransactionParamsSchema = z
23+
.object({
24+
transaction: TransactionPayload,
25+
})
26+
.strict();

packages/providers/src/types.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import type { z } from "zod";
22
import type {
3-
MinaProviderDetailSchema,
43
MinaProviderInfoSchema,
54
ProviderListenerSchema,
6-
ProviderRequestParamsSchema,
5+
ProviderRequestParamsUnion,
76
ProviderRpcErrorSchema,
87
ResultType,
98
} from "./validation";
109

11-
export type MinaProviderDetail = z.infer<typeof MinaProviderDetailSchema>;
10+
export type MinaProviderDetail = {
11+
info: MinaProviderInfo;
12+
provider: MinaProviderClient;
13+
};
1214

1315
export type MinaProviderInfo = z.infer<typeof MinaProviderInfoSchema>;
1416

@@ -32,11 +34,12 @@ export type ProviderRpcEvent =
3234

3335
export type ProviderListener = z.infer<typeof ProviderListenerSchema>;
3436

37+
export type ProviderRequestParams = z.infer<typeof ProviderRequestParamsUnion>;
38+
3539
export type MinaProviderRequest = <M extends string>(
36-
args: Extract<M, z.infer<typeof ProviderRequestParamsSchema>>,
40+
args: Extract<ProviderRequestParams, { method: M }>,
3741
) => Promise<ResultType<M>>;
3842

39-
// export type MinaProviderClient = z.infer<typeof MinaProviderClientSchema>;
4043
export type MinaProviderClient = {
4144
request: MinaProviderRequest;
4245
on: ProviderListener;

0 commit comments

Comments
 (0)