mirror of
https://github.com/RoboSats/robosats.git
synced 2025-07-22 18:53:52 +00:00
Merge pull request #1904 from RoboSats/validate-rating-tokens
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 { federation } = useContext<UseFederationStoreType>(FederationContext);
|
||||
|
||||
const [, setRating] = useState<number[]>([0, 0]);
|
||||
const [rating, setRating] = useState<number[]>([0, 0]);
|
||||
const [averageRating, setAvergeRating] = useState<number>(0);
|
||||
const [expanded, setExpanded] = useState<'summary' | 'stats' | 'policies' | undefined>(undefined);
|
||||
const [coordinator, setCoordinator] = useState<Coordinator>(
|
||||
@ -442,7 +442,7 @@ const CoordinatorDialog = ({ open = false, onClose, shortAlias }: Props): JSX.El
|
||||
disabled={settings.connection !== 'nostr'}
|
||||
/>
|
||||
<Typography variant='caption' color='text.secondary'>
|
||||
{`(${parseFloat((averageRating * 10).toFixed(1))})`}
|
||||
{`(${rating[1]})`}
|
||||
</Typography>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
@ -135,7 +135,7 @@ const FederationTable = ({
|
||||
return {
|
||||
field: 'rating',
|
||||
headerName: t('Rating'),
|
||||
width: mobile ? 60 : 170,
|
||||
width: mobile ? 60 : 180,
|
||||
renderCell: (params: any) => {
|
||||
const coordinator = federation.getCoordinator(params.row.shortAlias);
|
||||
const coordinatorRating = ratings[coordinator.nostrHexPubkey];
|
||||
@ -166,7 +166,7 @@ const FederationTable = ({
|
||||
}}
|
||||
/>
|
||||
<Typography variant='caption' color='text.secondary'>
|
||||
{`(${parseFloat((average * 10).toFixed(1))})`}
|
||||
{`(${coordinatorRating[1]})`}
|
||||
</Typography>
|
||||
</>
|
||||
)}
|
||||
|
@ -141,7 +141,7 @@ class RoboPool {
|
||||
const requestRatings = [
|
||||
'REQ',
|
||||
'subscribeRatings',
|
||||
{ kinds: [31986], '#p': pubkeys, since: 1745509494 },
|
||||
{ kinds: [31986], '#p': pubkeys, since: 1746316800 },
|
||||
];
|
||||
|
||||
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) => {
|
||||
const d = event.tags.find((t) => t[0] === 'd')?.[1];
|
||||
const orderId = d?.split(':')?.[1];
|
||||
const signature = event.tags.find((t) => t[0] === 'sig')?.[1];
|
||||
const hash = `${event.pubkey}${orderId ?? ''}`;
|
||||
const coordinatorPubKey = event.tags.find((t) => t[0] === 'p')?.[1];
|
||||
if (signature && coordinatorPubKey) {
|
||||
const signatureHex = event.tags.find((t) => t[0] === 'sig')?.[1];
|
||||
const coordinatorPubKeyHex = event.tags.find((t) => t[0] === 'p')?.[1];
|
||||
const message = `${event.pubkey}${orderId ?? ''}`;
|
||||
|
||||
if (signatureHex && coordinatorPubKeyHex) {
|
||||
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);
|
||||
} catch (e) {
|
||||
return false;
|
||||
@ -123,4 +127,13 @@ export const verifyCoordinatorToken: (event: Event) => boolean = (event) => {
|
||||
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;
|
||||
|
Reference in New Issue
Block a user