Skip to content

Commit 2581cf3

Browse files
authored
Merge pull request #71 from reclaimprotocol/stellar-zk-fetch
Stellar zk fetch
2 parents 6092815 + 7b03e3d commit 2581cf3

File tree

4 files changed

+133
-6
lines changed

4 files changed

+133
-6
lines changed

content/docs/zkfetch/cardano/cardano_zk_fetch.md renamed to content/docs/zkfetch/cardano.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Cardano zkFetch Integration
2+
title: Cardano
33
description: Guide for using zkFetch with Cardano blockchain data and services
44
---
55

content/docs/zkfetch/cardano/meta.json

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

content/docs/zkfetch/meta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"title": "ZK Fetch",
3-
"pages": ["quickstart", "cardano"]
3+
"pages": ["quickstart", "cardano", "stellar"]
44
}

content/docs/zkfetch/stellar.mdx

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
---
2+
title: Stellar
3+
description: Guide for using zkFetch with Stellar blockchain data and services
4+
---
5+
6+
import { Step, Steps } from "fumadocs-ui/components/steps";
7+
8+
## Pre-requisite
9+
10+
You can access the code on Github:
11+
12+
- [zkFetch Stellar Example](https://github.com/reclaimprotocol/zkfetch-stellar-example).
13+
14+
You will need a valid Stellar account seed phrase. Make sure you have enough funds to sign and send transactions. [Freighter](https://www.freighter.app/) wallet is a convenient option.
15+
16+
## Code Exploration
17+
18+
<Steps>
19+
20+
### /src/requestProof.js
21+
22+
This is the core part of the process, this code snippet shows how to fetch the latest XML price from CoinGecko's API in the form of a Reclaim proof. Once a proof is fetched, it gets written to `/src/proof.json`.
23+
24+
```js copy
25+
// Example URL to fetch the data from
26+
const url =
27+
"https://api.coingecko.com/api/v3/simple/price?ids=stellar&vs_currencies=usd";
28+
29+
// Generate the proof
30+
const proof = await reclaimClient.zkFetch(
31+
url,
32+
{ method: "GET" },
33+
{
34+
responseMatches: [
35+
{
36+
type: "regex",
37+
value: '\\{"stellar":\\{"usd":(?<price>[\\d\\.]+)\\}\\}',
38+
},
39+
],
40+
}
41+
);
42+
```
43+
44+
### /src/utils.js
45+
46+
A couple of Reclaim-specific methods for parsing proofs.
47+
48+
```js copy
49+
50+
// Returns the ECDSA signature recovery ID
51+
export const getRecId = (signature) => {
52+
...
53+
}
54+
55+
// Removes the `0x` prefix from signature
56+
export const formatSignature = (signature) => {
57+
...
58+
}
59+
60+
// Serializes the claim
61+
export const getSerializedClaim = (proof) => {
62+
...
63+
}
64+
65+
// Returns the Keccak256 hash of the prefixed original message
66+
export const getHash = (serializedClaim) => {
67+
...
68+
}
69+
```
70+
71+
### /src/verifyProof.js
72+
73+
The main script, it builds, signs, and sends the verification transaction to the network.
74+
75+
```js copy
76+
const tx = txBuilder
77+
.addOperation(
78+
contract.call(
79+
FUNCTION_NAME,
80+
...[
81+
StellarSdk.nativeToScVal(message, { type: "bytes" }),
82+
StellarSdk.nativeToScVal(signature, { type: "bytes" }),
83+
StellarSdk.nativeToScVal(recId, { type: "u32" }),
84+
]
85+
)
86+
)
87+
.setTimeout(StellarSdk.TimeoutInfinite)
88+
.build();
89+
```
90+
91+
</Steps>
92+
93+
## Try it
94+
95+
<Steps>
96+
97+
### Clone the repo
98+
99+
```bash
100+
git clone https://github.com/reclaimprotocol/zkfetch-stellar-example.git
101+
102+
cd zkfetch-stellar-example
103+
104+
npm install
105+
```
106+
107+
### Download ZK files
108+
These are crucial for proof requesting, a device should have them locally to request Reclaim proofs.
109+
110+
```bash copy
111+
node node_modules/@reclaimprotocol/zk-symmetric-crypto/lib/scripts/download-files
112+
```
113+
114+
### Add your seed phrase
115+
Add the secret phrase of your signing account to `.env`.
116+
```bash
117+
SEEDPHRASE=
118+
```
119+
120+
### Request a proof
121+
Change directory into `/src` and run:
122+
```bash
123+
node requestProof
124+
```
125+
126+
### Verify the proof
127+
Once you have the proof in `proof.json`, run the following to verify on-chain:
128+
```bash
129+
node verifyProof
130+
```
131+
</Steps>

0 commit comments

Comments
 (0)