Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
susumutomita committed Feb 3, 2024
1 parent 8c4641e commit ac0d115
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16'
node-version: '20'

- name: Cache Node modules
uses: actions/cache@v3
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/hooks/useGenerateProof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const messages = {
failure: {
en: 'Failed to verify your age.',
ja: '年齢の確認に失敗しました。',
}
},
};

export const useGenerateProof = () => {
Expand All @@ -31,6 +31,6 @@ export const useGenerateProof = () => {
age,
setAge,
proofResult,
handleGenerateProof
handleGenerateProof,
};
};
8 changes: 4 additions & 4 deletions packages/frontend/src/locales/en.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const en = {
enterAge: "Enter your age",
verifyAge: "Verify Age",
ageVerified: "Your age has been verified successfully.",
verificationFailed: "Failed to verify your age.",
enterAge: 'Enter your age',
verifyAge: 'Verify Age',
ageVerified: 'Your age has been verified successfully.',
verificationFailed: 'Failed to verify your age.',
};

export default en;
8 changes: 4 additions & 4 deletions packages/frontend/src/locales/ja.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const ja = {
enterAge: "年齢を入力",
verifyAge: "年齢を証明",
ageVerified: "年齢が確認されました。",
verificationFailed: "年齢の確認に失敗しました。",
enterAge: '年齢を入力',
verifyAge: '年齢を証明',
ageVerified: '年齢が確認されました。',
verificationFailed: '年齢の確認に失敗しました。',
};

export default ja;
37 changes: 20 additions & 17 deletions packages/frontend/src/sindri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import axios from 'axios';
import Config from 'react-native-config';

// APIキーとURLの取得
const API_KEY: string = Config.SINDRI_API_KEY || "";
const API_URL_PREFIX: string = Config.SINDRI_API_URL || "https://sindri.app/api/";
const API_VERSION: string = "v1";
const API_KEY: string = Config.SINDRI_API_KEY || '';
const API_URL_PREFIX: string =
Config.SINDRI_API_URL || 'https://sindri.app/api/';
const API_VERSION: string = 'v1';
const API_URL: string = API_URL_PREFIX.concat(API_VERSION);

const headersJson = {
Accept: "application/json",
Authorization: `Bearer ${API_KEY}`
Accept: 'application/json',
Authorization: `Bearer ${API_KEY}`,
};

async function pollForStatus(endpoint: string, timeout: number = 20 * 60) {
Expand All @@ -20,7 +21,7 @@ async function pollForStatus(endpoint: string, timeout: number = 20 * 60) {
});

const status = response.data.status;
if (["Ready", "Failed"].includes(status)) {
if (['Ready', 'Failed'].includes(status)) {
console.log(`Poll exited after ${i} seconds with status: ${status}`);
return response;
}
Expand All @@ -36,9 +37,9 @@ function parseTOML(tomlString: string): Record<string, any> {
const result: Record<string, any> = {};
const lines = tomlString.split(/\r?\n/);

lines.forEach(line => {
lines.forEach((line) => {
if (line.trim().startsWith('#') || line.trim() === '') return;
const [key, value] = line.split('=').map(s => s.trim());
const [key, value] = line.split('=').map((s) => s.trim());
if (value === 'true') {
result[key] = true;
} else if (value === 'false') {
Expand All @@ -55,29 +56,31 @@ function parseTOML(tomlString: string): Record<string, any> {

export async function generateProof(input: number) {
try {
const circuitId = "e98c114f-6b0d-4fe0-9379-4ee91a1c6963";
const circuitId = 'e98c114f-6b0d-4fe0-9379-4ee91a1c6963';
console.log(circuitId);
console.log("Proving circuit...");
console.log('Proving circuit...');
const tomlString = `input = ${input}`;
const proofInput = parseTOML(tomlString)
const proofInput = parseTOML(tomlString);
console.log(proofInput);
console.log(API_KEY);

const proveResponse = await axios.post(
API_URL + `/circuit/${circuitId}/prove`,
{ proof_input: proofInput },
{ headers: headersJson, validateStatus: (status) => status === 201 },
{ headers: headersJson, validateStatus: (status) => status === 201 }
);
const proofId: string = proveResponse.data.proof_id;
console.log(proofId);

const proofDetailResponse = await pollForStatus(`/proof/${proofId}/detail`);
if (proofDetailResponse.data.status === "Failed") {
throw new Error("Proving failed");
if (proofDetailResponse.data.status === 'Failed') {
throw new Error('Proving failed');
}

const proverTomlContent = proofDetailResponse.data.proof_input['Prover.toml'];
const verifierTomlContent = proofDetailResponse.data.public['Verifier.toml'];
const proverTomlContent =
proofDetailResponse.data.proof_input['Prover.toml'];
const verifierTomlContent =
proofDetailResponse.data.public['Verifier.toml'];

console.log(proverTomlContent);
console.log(verifierTomlContent);
Expand All @@ -87,7 +90,7 @@ export async function generateProof(input: number) {
if (error instanceof Error) {
console.error(error.message);
} else {
console.error("An unknown error occurred.");
console.error('An unknown error occurred.');
}
}
}

0 comments on commit ac0d115

Please sign in to comment.