Skip to content

Commit 9089ec3

Browse files
committed
fix(conflicts): resolve
2 parents 1c44f37 + a9d6774 commit 9089ec3

File tree

15 files changed

+1628
-246
lines changed

15 files changed

+1628
-246
lines changed

apps/docs/src/components/sample-data.ts

Lines changed: 1358 additions & 0 deletions
Large diffs are not rendered by default.

apps/docs/src/components/test-zkapp.tsx

Lines changed: 110 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,16 @@ import { createStore } from "@mina-js/connect";
22
import { useLocalStorage, useObjectState } from "@uidotdev/usehooks";
33
import { clsx } from "clsx";
44
import { useState, useSyncExternalStore } from "react";
5+
import {
6+
sampleCredentialRecursiveUpdated,
7+
samplePresentationRequestHttpsFromExampleUpdated,
8+
} from "./sample-data";
59

610
const store = createStore();
711

8-
const sampleCredential = {
9-
version: "v0",
10-
witness: {
11-
type: "simple",
12-
issuer: {
13-
_type: "PublicKey",
14-
value: "B62qqMxueXzenrchT5CKC5eCSmfcbHic9wJd9GEdHVcd9uCWrjPJjHS",
15-
},
16-
issuerSignature: {
17-
_type: "Signature",
18-
value: {
19-
r: "27355434072539307953235904941558417174103383443074165997458891331674091021280",
20-
s: "22156398191479529717864137276005168653180340733374387165875910835098679659803",
21-
},
22-
},
23-
},
24-
credential: {
25-
owner: {
26-
_type: "PublicKey",
27-
value: "B62qqCMx9YvvjhMFVcRXBqHtAbjWWUhyA9HmgpYCehLHTGKgXsxiZpz",
28-
},
29-
data: {
30-
age: {
31-
_type: "Field",
32-
value: "25",
33-
},
34-
},
35-
},
12+
const sampleSignFieldsWithPassphrase = {
13+
fields: ["1", "2", "3"],
14+
passphrase: "1234",
3615
};
3716

3817
export const TestZkApp = () => {
@@ -42,8 +21,13 @@ export const TestZkApp = () => {
4221
);
4322
const [message, setMessage] = useState("A message to sign");
4423
const [fields, setFields] = useState('["1", "2", "3"]');
24+
const [signFieldsWithPassphraseInput, setSignFieldsWithPassphraseInput] =
25+
useState(JSON.stringify(sampleSignFieldsWithPassphrase, null, 2));
4526
const [credentialInput, setCredentialInput] = useState(
46-
JSON.stringify(sampleCredential, null, 2),
27+
JSON.stringify(sampleCredentialRecursiveUpdated, null, 2),
28+
);
29+
const [presentationRequest, setPresentationRequest] = useState(
30+
JSON.stringify(samplePresentationRequestHttpsFromExampleUpdated, null, 2),
4731
);
4832
const [transactionBody, setTransactionBody] = useObjectState({
4933
to: "B62qnVUL6A53E4ZaGd3qbTr6RCtEZYTu3kTijVrrquNpPo4d3MuJ3nb",
@@ -58,9 +42,11 @@ export const TestZkApp = () => {
5842
mina_getBalance: "",
5943
mina_sign: "",
6044
mina_signFields: "",
45+
mina_signFieldsWithPassphrase: "",
6146
mina_signTransaction: "",
6247
mina_switchChain: "",
6348
mina_storePrivateCredential: "",
49+
mina_requestPresentation: "",
6450
});
6551
const providers = useSyncExternalStore(store.subscribe, store.getProviders);
6652
const provider = providers.find(
@@ -85,6 +71,24 @@ export const TestZkApp = () => {
8571
}
8672
};
8773

74+
const requestPresentation = async () => {
75+
if (!provider) return;
76+
try {
77+
const parsedRequest = JSON.parse(presentationRequest);
78+
const { result } = await provider.request({
79+
method: "mina_requestPresentation",
80+
params: [parsedRequest],
81+
});
82+
setResults(() => ({
83+
mina_requestPresentation: result,
84+
}));
85+
} catch (error) {
86+
setResults(() => ({
87+
mina_requestPresentation: `Error: ${error.message}`,
88+
}));
89+
}
90+
};
91+
8892
const fetchAccounts = async () => {
8993
if (!provider) return;
9094
const { result } = await provider.request({
@@ -132,6 +136,23 @@ export const TestZkApp = () => {
132136
mina_signFields: JSON.stringify(result, undefined, "\t"),
133137
}));
134138
};
139+
const signFieldsWithPassphrase = async () => {
140+
if (!provider) return;
141+
try {
142+
const parsedInput = JSON.parse(signFieldsWithPassphraseInput);
143+
const { result } = await provider.request({
144+
method: "mina_signFieldsWithPassphrase",
145+
params: [parsedInput],
146+
});
147+
setResults(() => ({
148+
mina_signFieldsWithPassphrase: JSON.stringify(result, null, 2),
149+
}));
150+
} catch (error) {
151+
setResults(() => ({
152+
mina_signFieldsWithPassphrase: `Error: ${error.message}`,
153+
}));
154+
}
155+
};
135156
const createNullifier = async () => {
136157
if (!provider) return;
137158
const parsedFields = JSON.parse(fields);
@@ -479,6 +500,66 @@ export const TestZkApp = () => {
479500
</div>
480501
</div>
481502
</section>
503+
<section className="card bg-neutral">
504+
<div className="card-body gap-4">
505+
<h2 className="card-title">Request Presentation</h2>
506+
<p>mina_requestPresentation</p>
507+
<div className="flex flex-col gap-2">
508+
<div className="flex flex-col gap-4">
509+
<textarea
510+
value={presentationRequest}
511+
onChange={(event) => setPresentationRequest(event.target.value)}
512+
className="textarea textarea-bordered h-48 font-mono text-sm"
513+
placeholder="Enter presentation request JSON..."
514+
/>
515+
<button
516+
type="button"
517+
className="btn btn-primary"
518+
onClick={requestPresentation}
519+
>
520+
Request Presentation
521+
</button>
522+
</div>
523+
<label>Result</label>
524+
<textarea
525+
value={results.mina_requestPresentation}
526+
readOnly
527+
className="textarea textarea-bordered h-24 resize-none font-mono"
528+
/>
529+
</div>
530+
</div>
531+
</section>
532+
<section className="card bg-neutral">
533+
<div className="card-body gap-4">
534+
<h2 className="card-title">Sign Fields With Passphrase</h2>
535+
<p>mina_signFieldsWithPassphrase</p>
536+
<div className="flex flex-col gap-2">
537+
<div className="flex flex-col gap-4">
538+
<textarea
539+
value={signFieldsWithPassphraseInput}
540+
onChange={(event) =>
541+
setSignFieldsWithPassphraseInput(event.target.value)
542+
}
543+
className="textarea textarea-bordered h-48 font-mono text-sm"
544+
placeholder="Enter fields and passphrase JSON..."
545+
/>
546+
<button
547+
type="button"
548+
className="btn btn-primary"
549+
onClick={signFieldsWithPassphrase}
550+
>
551+
Sign Fields With Passphrase
552+
</button>
553+
</div>
554+
<label>Result</label>
555+
<textarea
556+
value={results.mina_signFieldsWithPassphrase}
557+
readOnly
558+
className="textarea textarea-bordered h-24 resize-none font-mono"
559+
/>
560+
</div>
561+
</div>
562+
</section>
482563
</main>
483564
);
484565
};

apps/klesia/src/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ describe("Mina Devnet RPC", () => {
5353
// biome-ignore lint/suspicious/noExplicitAny: TODO
5454
const { result } = (await response.json()) as any;
5555
expect(BigInt(result.nonce)).toBeGreaterThanOrEqual(0);
56-
expect(BigInt(result.balance)).toBeGreaterThanOrEqual(0);
56+
expect(BigInt(result.balance.total)).toBeGreaterThanOrEqual(0);
5757
});
5858
});

apps/klesia/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ api.use(
2727
c.req.header("x-forwarded-for") ??
2828
getConnInfo(c).remote.address ??
2929
nanoid(),
30-
limit: 10,
30+
limit: 100,
3131
}),
3232
);
3333
api.use("/api", cors({ origin: "*" }));

apps/klesia/src/methods/mina.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ it("should return network id", async () => {
2626
it("should get account info", async () => {
2727
const result = await mina.getAccount({ publicKey: TEST_PKEY });
2828
expect(BigInt(result.nonce)).toBeGreaterThanOrEqual(0);
29-
expect(BigInt(result.balance)).toBeGreaterThanOrEqual(0);
29+
expect(BigInt(result.balance.total)).toBeGreaterThanOrEqual(0);
3030
});

apps/klesia/src/methods/mina.ts

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,23 +150,61 @@ const getAccount = async ({ publicKey }: { publicKey: string }) => {
150150
gql`
151151
query {
152152
account(publicKey: $publicKey) {
153+
publicKey
154+
token
153155
nonce
154156
balance {
155157
total
156158
}
159+
tokenSymbol
160+
receiptChainHash
161+
timing {
162+
initialMinimumBalance
163+
cliffTime
164+
cliffAmount
165+
vestingPeriod
166+
vestingIncrement
167+
}
168+
permissions {
169+
editState
170+
access
171+
send
172+
receive
173+
setDelegate
174+
setPermissions
175+
setVerificationKey {
176+
auth
177+
txnVersion
178+
}
179+
setZkappUri
180+
editActionState
181+
setTokenSymbol
182+
incrementNonce
183+
setVotingFor
184+
setTiming
185+
}
186+
delegateAccount { publicKey }
187+
votingFor
188+
zkappState
189+
verificationKey {
190+
verificationKey
191+
hash
192+
}
193+
actionState
194+
provedState
195+
zkappUri
157196
}
158197
}
159198
`,
160199
{ publicKey },
161200
);
162-
return {
163-
nonce: data.account.nonce,
164-
balance: data.account.balance.total,
165-
};
201+
return data.account;
166202
} catch {
167203
return {
168204
nonce: "0",
169-
balance: "0",
205+
balance: {
206+
total: "0",
207+
},
170208
};
171209
}
172210
};

bun.lockb

335 KB
Binary file not shown.

packages/accounts/src/accounts/__snapshots__/private-key-to-account.spec.ts.snap

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,32 @@ exports[`signs fields 1`] = `
5353
"signature": "7mXCUvhLhFvG9ptrdfNceCrpThkCUyg1ct2z8uwY7eQbKz7UNmhv33TbuDjTznaypJtXRiMJyQWDnf27TH1FSXG7uJHTKAd9",
5454
}
5555
`;
56+
57+
exports[`signs a zkapp command 1`] = `
58+
{
59+
"data": {
60+
"feePayer": {
61+
"fee": "100000000",
62+
"feePayer": "B62qmWKtvNQTtUqo1LxfEEDLyWMg59cp6U7c4uDC7aqgaCEijSc3Hx5",
63+
"memo": "Test",
64+
"nonce": "0",
65+
"validUntil": "null",
66+
},
67+
"zkappCommand": {
68+
"accountUpdates": [],
69+
"feePayer": {
70+
"authorization": "7mXWqNfmqMTM5uSCS2xLfsRBLTjGZKTtpEakdsrdQz1EUgYXogSvKxxtfGbBkqQ2mZRMA3uPAM8riaCF56pkqpZBLr2kNBLa",
71+
"body": {
72+
"fee": "100000000",
73+
"nonce": "0",
74+
"publicKey": "B62qmWKtvNQTtUqo1LxfEEDLyWMg59cp6U7c4uDC7aqgaCEijSc3Hx5",
75+
"validUntil": null,
76+
},
77+
},
78+
"memo": "E4YVT4x3A9rUhmjkjGn8ZYBLZn7zK4cfvnMtBYZFdWkg37n2s3nrP",
79+
},
80+
},
81+
"publicKey": "B62qmWKtvNQTtUqo1LxfEEDLyWMg59cp6U7c4uDC7aqgaCEijSc3Hx5",
82+
"signature": "7mXWqNfmqMTM5uSCS2xLfsRBLTjGZKTtpEakdsrdQz1EUgYXogSvKxxtfGbBkqQ2mZRMA3uPAM8riaCF56pkqpZBLr2kNBLa",
83+
}
84+
`;

packages/accounts/src/accounts/private-key-to-account.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,35 @@ it("signs a transaction", async () => {
3333
expect(signedTransaction).toMatchSnapshot();
3434
});
3535

36+
it("signs a zkapp command", async () => {
37+
const account = privateKeyToAccount({
38+
privateKey: Test.accounts[0].privateKey,
39+
});
40+
const command = {
41+
zkappCommand: {
42+
accountUpdates: [],
43+
memo: "E4YM2vTHhWEg66xpj52JErHUBU4pZ1yageL4TVDDpTTSsv8mK6YaH",
44+
feePayer: {
45+
body: {
46+
publicKey: "B62qmWKtvNQTtUqo1LxfEEDLyWMg59cp6U7c4uDC7aqgaCEijSc3Hx5",
47+
fee: "100000000",
48+
validUntil: "100000",
49+
nonce: "1",
50+
},
51+
authorization: "",
52+
},
53+
},
54+
feePayer: {
55+
feePayer: "B62qmWKtvNQTtUqo1LxfEEDLyWMg59cp6U7c4uDC7aqgaCEijSc3Hx5",
56+
fee: "100000000",
57+
nonce: "0",
58+
memo: "Test",
59+
},
60+
};
61+
const signedTransaction = await account.signTransaction({ command });
62+
expect(signedTransaction).toMatchSnapshot();
63+
});
64+
3665
it("creates a nullifier", async () => {
3766
const account = privateKeyToAccount({
3867
privateKey: Test.accounts[0].privateKey,

packages/accounts/src/accounts/private-key-to-account.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,14 @@ export function privateKeyToAccount({
2929
async signMessage({ message }) {
3030
return SignedMessageSchema.parse(client.signMessage(message, privateKey));
3131
},
32-
async signTransaction({ transaction }) {
32+
async signTransaction(signable) {
33+
if ("transaction" in signable) {
34+
return SignedTransactionSchema.parse(
35+
client.signTransaction(signable.transaction, privateKey),
36+
);
37+
}
3338
return SignedTransactionSchema.parse(
34-
client.signTransaction(transaction, privateKey),
39+
client.signTransaction(signable.command as never, privateKey),
3540
);
3641
},
3742
async createNullifier({ message }) {

0 commit comments

Comments
 (0)