mirror of
https://github.com/RoboSats/robosats.git
synced 2025-07-28 17:03:20 +00:00
Validate ratign tokens
This commit is contained in:
@ -360,7 +360,7 @@ const CoordinatorDialog = ({ open = false, onClose, shortAlias }: Props): JSX.El
|
|||||||
const { clientVersion, page, settings, origin } = useContext(AppContext);
|
const { clientVersion, page, settings, origin } = useContext(AppContext);
|
||||||
const { federation } = useContext<UseFederationStoreType>(FederationContext);
|
const { federation } = useContext<UseFederationStoreType>(FederationContext);
|
||||||
|
|
||||||
const [, setRating] = useState<number[]>([0, 0]);
|
const [rating, setRating] = useState<number[]>([0, 0]);
|
||||||
const [averageRating, setAvergeRating] = useState<number>(0);
|
const [averageRating, setAvergeRating] = useState<number>(0);
|
||||||
const [expanded, setExpanded] = useState<'summary' | 'stats' | 'policies' | undefined>(undefined);
|
const [expanded, setExpanded] = useState<'summary' | 'stats' | 'policies' | undefined>(undefined);
|
||||||
const [coordinator, setCoordinator] = useState<Coordinator>(
|
const [coordinator, setCoordinator] = useState<Coordinator>(
|
||||||
@ -442,7 +442,7 @@ const CoordinatorDialog = ({ open = false, onClose, shortAlias }: Props): JSX.El
|
|||||||
disabled={settings.connection !== 'nostr'}
|
disabled={settings.connection !== 'nostr'}
|
||||||
/>
|
/>
|
||||||
<Typography variant='caption' color='text.secondary'>
|
<Typography variant='caption' color='text.secondary'>
|
||||||
{`(${parseFloat((averageRating * 10).toFixed(1))})`}
|
{`(${rating[1]})`}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
@ -135,7 +135,7 @@ const FederationTable = ({
|
|||||||
return {
|
return {
|
||||||
field: 'rating',
|
field: 'rating',
|
||||||
headerName: t('Rating'),
|
headerName: t('Rating'),
|
||||||
width: mobile ? 60 : 170,
|
width: mobile ? 60 : 180,
|
||||||
renderCell: (params: any) => {
|
renderCell: (params: any) => {
|
||||||
const coordinator = federation.getCoordinator(params.row.shortAlias);
|
const coordinator = federation.getCoordinator(params.row.shortAlias);
|
||||||
const coordinatorRating = ratings[coordinator.nostrHexPubkey];
|
const coordinatorRating = ratings[coordinator.nostrHexPubkey];
|
||||||
@ -166,7 +166,7 @@ const FederationTable = ({
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Typography variant='caption' color='text.secondary'>
|
<Typography variant='caption' color='text.secondary'>
|
||||||
{`(${parseFloat((average * 10).toFixed(1))})`}
|
{`(${coordinatorRating[1]})`}
|
||||||
</Typography>
|
</Typography>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
@ -141,7 +141,7 @@ class RoboPool {
|
|||||||
const requestRatings = [
|
const requestRatings = [
|
||||||
'REQ',
|
'REQ',
|
||||||
'subscribeRatings',
|
'subscribeRatings',
|
||||||
{ kinds: [31986], '#p': pubkeys, since: 1745509494 },
|
{ kinds: [31986], '#p': pubkeys, since: 1746316800 },
|
||||||
];
|
];
|
||||||
|
|
||||||
this.messageHandlers.push((_url: string, messageEvent: MessageEvent) => {
|
this.messageHandlers.push((_url: string, messageEvent: MessageEvent) => {
|
||||||
|
@ -110,11 +110,15 @@ const eventToPublicOrder = (event: Event): { dTag: string; publicOrder: PublicOr
|
|||||||
export const verifyCoordinatorToken: (event: Event) => boolean = (event) => {
|
export const verifyCoordinatorToken: (event: Event) => boolean = (event) => {
|
||||||
const d = event.tags.find((t) => t[0] === 'd')?.[1];
|
const d = event.tags.find((t) => t[0] === 'd')?.[1];
|
||||||
const orderId = d?.split(':')?.[1];
|
const orderId = d?.split(':')?.[1];
|
||||||
const signature = event.tags.find((t) => t[0] === 'sig')?.[1];
|
const signatureHex = event.tags.find((t) => t[0] === 'sig')?.[1];
|
||||||
const hash = `${event.pubkey}${orderId ?? ''}`;
|
const coordinatorPubKeyHex = event.tags.find((t) => t[0] === 'p')?.[1];
|
||||||
const coordinatorPubKey = event.tags.find((t) => t[0] === 'p')?.[1];
|
const message = `${event.pubkey}${orderId ?? ''}`;
|
||||||
if (signature && coordinatorPubKey) {
|
|
||||||
|
if (signatureHex && coordinatorPubKeyHex) {
|
||||||
try {
|
try {
|
||||||
|
const signature = Uint8Array.from(hexToBytes(signatureHex));
|
||||||
|
const coordinatorPubKey = Uint8Array.from(hexToBytes(coordinatorPubKeyHex));
|
||||||
|
const hash = new TextEncoder().encode(message);
|
||||||
return schnorr.verify(signature, hash, coordinatorPubKey);
|
return schnorr.verify(signature, hash, coordinatorPubKey);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
@ -123,4 +127,13 @@ export const verifyCoordinatorToken: (event: Event) => boolean = (event) => {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const hexToBytes: (hex: string) => Uint8Array = (hex) => {
|
||||||
|
if (hex.length % 2 !== 0) throw new Error('Hex must have an even lenght');
|
||||||
|
const bytes = new Uint8Array(hex.length / 2);
|
||||||
|
for (let i = 0; i < bytes.length; i++) {
|
||||||
|
bytes[i] = parseInt(hex.substr(i * 2, 2), 16);
|
||||||
|
}
|
||||||
|
return bytes;
|
||||||
|
};
|
||||||
|
|
||||||
export default eventToPublicOrder;
|
export default eventToPublicOrder;
|
||||||
|
Reference in New Issue
Block a user