Skip to content

Commit f1743e2

Browse files
committed
update sui signer
1 parent e8acce9 commit f1743e2

File tree

10 files changed

+297
-90
lines changed

10 files changed

+297
-90
lines changed

functions/src/index.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,10 @@ export const update = onRequest({ cors: true }, async (req, res) => {
140140
return;
141141
}
142142

143-
const { uid, serializedSignedTx } = req.body;
143+
const { uid, signedData } = req.body;
144144

145-
if (!uid || !serializedSignedTx) {
146-
res
147-
.status(400)
148-
.send('Invalid input, missing "uid" or "serializedSignedTx"');
145+
if (!uid || !signedData || !signedData.message || !signedData.signature) {
146+
res.status(400).send('Invalid input, missing "uid" or "signedData"');
149147
return;
150148
}
151149

@@ -163,7 +161,7 @@ export const update = onRequest({ cors: true }, async (req, res) => {
163161
const newDocRef = firestore.collection('signed').doc(uid);
164162
await newDocRef.set({
165163
...data,
166-
serializedSignedTx,
164+
signedData,
167165
createdAt: admin.firestore.FieldValue.serverTimestamp(),
168166
});
169167

@@ -194,15 +192,14 @@ const _load = async (
194192
return;
195193
}
196194

197-
const { name, network, provenance, serializedSignedTx } =
198-
doc.data() as DocData;
195+
const { name, network, provenance, signedData } = doc.data() as DocData;
199196
if (collection === 'signed') {
200197
const storage = admin.storage();
201198
const bucket = storage.bucket('slsa-on-blockchain.appspot.com');
202199
const file = bucket.file(uid);
203200
await file.delete();
204201
await docRef.delete();
205-
res.status(200).json({ name, network, serializedSignedTx });
202+
res.status(200).json({ name, network, signedData });
206203
} else {
207204
res.status(200).json({ name, network, provenance });
208205
}

functions/src/types.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
interface Provenance {
2-
summary: string; // build summary
3-
commit: string; // source commit
4-
workflow: string; // build workflow
5-
ledger: string; // public ledger
6-
}
7-
81
export interface DocData {
92
name: string; // packageName
103
network: string;
11-
provenance: Provenance;
12-
serializedSignedTx?: string;
4+
provenance: string;
5+
signedData?:
6+
| {
7+
message: string;
8+
signature: string;
9+
}
10+
| string;
1311
}

package-lock.json

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
"@radix-ui/themes": "^3.1.1",
99
"@tanstack/react-query": "^5.51.1",
1010
"fflate": "^0.8.2",
11+
"notistack": "^3.0.1",
1112
"query-string": "^9.0.0",
1213
"react": "^18.3.1",
1314
"react-dom": "^18.3.1",
1415
"react-scripts": "5.0.1",
1516
"recoil": "^0.7.7",
17+
"smol-toml": "^1.2.2",
1618
"tar-stream": "^3.1.7",
1719
"web-vitals": "^2.1.4"
1820
},

src/component/Loading.tsx

Lines changed: 36 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const Loading = () => {
1313
const initialized = useRef<boolean>(false);
1414
const setState = useSetRecoilState(STATE);
1515

16-
const [message, setMessage] = useState<string>('Initializing ....');
16+
const [message, setMessage] = useState<string>('');
1717
const [error, setError] = useState<boolean>(false);
1818

1919
const unzip = async (
@@ -56,61 +56,43 @@ export const Loading = () => {
5656
const { q: uid } = queryString.parse(window.location.search) as {
5757
q: string;
5858
};
59-
fetch('https://read-jx4b2hndxq-uc.a.run.app', {
60-
method: 'POST',
61-
headers: {
62-
'Content-Type': 'application/json',
63-
},
64-
body: JSON.stringify({ uid }),
65-
})
66-
.then((res1) => {
67-
res1
68-
.json()
69-
.then((data) => {
70-
setMessage('Loading Data ....');
71-
fetch('https://download-jx4b2hndxq-uc.a.run.app', {
72-
method: 'POST',
73-
headers: {
74-
'Content-Type': 'application/json',
75-
},
76-
body: JSON.stringify({ filename: uid }),
77-
})
78-
.then((res2) => {
79-
res2
80-
.text()
81-
.then((gzip) => {
82-
unzip(gzip)
83-
.then((files) => {
84-
setState({
85-
uid,
86-
files,
87-
data,
88-
});
89-
})
90-
.catch((e) => {
91-
setError(true);
92-
setMessage(`${e}`);
93-
});
94-
})
95-
.catch((e) => {
96-
setError(true);
97-
setMessage(`${e}`);
98-
});
99-
})
100-
.catch((e) => {
101-
setError(true);
102-
setMessage(`${e}`);
103-
});
104-
})
105-
.catch((e) => {
106-
setError(true);
107-
setMessage(`${e}`);
108-
});
109-
})
110-
.catch((e) => {
59+
const fetchData = async () => {
60+
try {
61+
setMessage('Initializing ....');
62+
const res1 = await fetch('https://read-jx4b2hndxq-uc.a.run.app', {
63+
method: 'POST',
64+
headers: {
65+
'Content-Type': 'application/json',
66+
},
67+
body: JSON.stringify({ uid }),
68+
});
69+
const data = await res1.json();
70+
71+
setMessage('Loading Data ....');
72+
const res2 = await fetch(
73+
'https://download-jx4b2hndxq-uc.a.run.app',
74+
{
75+
method: 'POST',
76+
headers: {
77+
'Content-Type': 'application/json',
78+
},
79+
body: JSON.stringify({ filename: uid }),
80+
},
81+
);
82+
const gzip = await res2.text();
83+
const files = await unzip(gzip);
84+
setState({
85+
uid,
86+
files,
87+
data,
88+
});
89+
} catch (e) {
11190
setError(true);
11291
setMessage(`${e}`);
113-
});
92+
}
93+
};
94+
95+
fetchData();
11496
} else {
11597
setError(true);
11698
setMessage('Query params error');

src/component/Provenance.tsx

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,44 @@
1-
import { Avatar, Box, Button, Card, Flex, Link, Text } from '@radix-ui/themes';
1+
import type { ReactElement } from 'react';
2+
import { useEffect, useState } from 'react';
3+
4+
import { fromB64 } from '@mysten/sui/utils';
5+
import { Avatar, Box, Card, Flex, Link, Text } from '@radix-ui/themes';
26
import { useRecoilState } from 'recoil';
37

48
import { STATE } from '../recoil';
59

6-
export const Provenance = () => {
10+
interface GithubAction {
11+
summary: string; // build summary
12+
commit: string; // source commit
13+
workflow: string; // build workflow
14+
ledger: string; // public ledger
15+
}
16+
17+
export const Provenance = ({ BtnSign }: { BtnSign: ReactElement }) => {
718
const [state] = useRecoilState(STATE);
19+
const [gha, setGha] = useState<GithubAction | undefined>(undefined);
20+
21+
useEffect(() => {
22+
if (state && !gha) {
23+
const provenance = JSON.parse(
24+
new TextDecoder().decode(fromB64(state.data.provenance)),
25+
);
26+
const payload = JSON.parse(
27+
new TextDecoder().decode(fromB64(provenance.payload)),
28+
);
29+
setGha({
30+
summary: `https://github.com/zktx-io/move_on_github_action/actions/runs/${payload.predicate.invocation.environment.github_run_id}/attempts/${payload.predicate.invocation.environment.github_run_attempt}`,
31+
commit: `https://github.com/zktx-io/move_on_github_action/tree/${payload.predicate.invocation.environment.github_sha1}`,
32+
workflow: `https://github.com/zktx-io/move_on_github_action/actions/runs/${payload.predicate.invocation.environment.github_run_id}/workflow`,
33+
ledger: `https://search.sigstore.dev/?hash=${payload.subject[0].digest.sha256}`,
34+
});
35+
}
36+
// eslint-disable-next-line react-hooks/exhaustive-deps
37+
}, [state]);
38+
839
return (
940
<>
10-
{state && (
41+
{state && gha && (
1142
<Flex direction="column" gap="2">
1243
<Box maxWidth="240px">
1344
<Card>
@@ -32,18 +63,19 @@ export const Provenance = () => {
3263
<Card>
3364
<Flex gap="3" align="start" direction="column">
3465
<Text as="div" size="3" weight="bold">
35-
Built and signed on Github Actions
66+
Building and Deploying with GitHub Actions
3667
</Text>
3768
<Flex direction="column" gap="1" maxWidth="420px">
3869
<Flex direction="column">
3970
<Text size="2">Build Summary</Text>
4071
<Link
4172
size="1"
4273
color="gray"
43-
href={state.data.provenance.summary}
74+
href={gha.summary}
75+
target="_blank"
4476
>
4577
<Flex>
46-
<Text truncate>{state.data.provenance.summary}</Text>
78+
<Text truncate>{gha.summary}</Text>
4779
</Flex>
4880
</Link>
4981
</Flex>
@@ -52,10 +84,11 @@ export const Provenance = () => {
5284
<Link
5385
size="1"
5486
color="gray"
55-
href={state.data.provenance.commit}
87+
href={gha.commit}
88+
target="_blank"
5689
>
5790
<Flex>
58-
<Text truncate>{state.data.provenance.commit}</Text>
91+
<Text truncate>{gha.commit}</Text>
5992
</Flex>
6093
</Link>
6194
</Flex>
@@ -64,10 +97,11 @@ export const Provenance = () => {
6497
<Link
6598
size="1"
6699
color="gray"
67-
href={state.data.provenance.workflow}
100+
href={gha.workflow}
101+
target="_blank"
68102
>
69103
<Flex>
70-
<Text truncate>{state.data.provenance.workflow}</Text>
104+
<Text truncate>{gha.workflow}</Text>
71105
</Flex>
72106
</Link>
73107
</Flex>
@@ -76,15 +110,16 @@ export const Provenance = () => {
76110
<Link
77111
size="1"
78112
color="gray"
79-
href={state.data.provenance.ledger}
113+
href={gha.ledger}
114+
target="_blank"
80115
>
81116
<Flex>
82-
<Text truncate>{state.data.provenance.ledger}</Text>
117+
<Text truncate>{gha.ledger}</Text>
83118
</Flex>
84119
</Link>
85120
</Flex>
86121
</Flex>
87-
<Button>Sign</Button>
122+
{BtnSign}
88123
</Flex>
89124
</Card>
90125
</Box>

0 commit comments

Comments
 (0)