Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #141 from w3f/identity-hash
Browse files Browse the repository at this point in the history
Prepare identity info hash for `provideJudgement`
  • Loading branch information
ironoa authored Sep 29, 2022
2 parents 3fdf932 + c6cbda5 commit 9956857
Show file tree
Hide file tree
Showing 9 changed files with 391 additions and 341 deletions.
4 changes: 2 additions & 2 deletions charts/polkadot-registrar-watcher/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
description: Polkadot Watcher
name: polkadot-registrar-watcher
version: v0.3.33
appVersion: v0.3.33
version: v0.4.0
appVersion: v0.4.0
apiVersion: v2
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "polkadot-registrar-watcher",
"version": "0.3.33",
"version": "0.4.0",
"description": "Registrar",
"repository": "[email protected]:w3f/polkadot-registrar-watcher.git",
"author": "W3F Infrastructure Team <[email protected]>",
Expand All @@ -18,7 +18,7 @@
"start": "node ./dist/index.js start"
},
"dependencies": {
"@polkadot/api": "^9.2.2",
"@polkadot/api": "^9.4.2",
"@types/ws": "^7.2.7",
"@w3f/config": "^0.1.1",
"@w3f/logger": "^0.4.3",
Expand Down
2 changes: 1 addition & 1 deletion src/messageCenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class WsMessageCenter {

if(data['event'] == 'judgementResult'){
const judgementResult: WsJudgementResult = data['data']
await this.subscriber.handleTriggerExtrinsicJudgement(judgementResult.judgement,judgementResult.address)
await this.subscriber.handleTriggerExtrinsicJudgement(judgementResult.judgement,judgementResult.address, judgementResult.verified)
}

if(data['event'] == 'pendingJudgementsRequest'){
Expand Down
4 changes: 2 additions & 2 deletions src/subscriber/ISubscriber.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/interface-name-prefix */

import { WsChallengeRequest, WsChallengeUnrequest, WsPendingChallengesResponse, WsAck, WsDisplayNameResponse } from "../types";
import { WsChallengeRequest, WsChallengeUnrequest, WsPendingChallengesResponse, WsAck, WsDisplayNameResponse, WsVerifiedField } from "../types";

export interface ISubscriber{
start(): Promise<void>;
Expand All @@ -9,5 +9,5 @@ export interface ISubscriber{
setJudgementGivenHandler(handler: (request: WsAck) => void ): void;
getAllOurPendingWsChallengeRequests(): Promise<WsPendingChallengesResponse>;
getAllDisplayNames(): Promise<WsDisplayNameResponse>;
handleTriggerExtrinsicJudgement(result: string,address: string): Promise<boolean>;
handleTriggerExtrinsicJudgement(result: string, address: string, verified: Array<WsVerifiedField>): Promise<boolean>;
}
72 changes: 61 additions & 11 deletions src/subscriber/subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { SessionIndex, Registration, IdentityInfo, Event } from '@polkadot/types
import { Logger } from '@w3f/logger';
import { Text } from '@polkadot/types/primitive';
import {
InputConfig, JudgementResult, WsChallengeRequest, WsChallengeUnrequest, WsPendingChallengesResponse, WsAck, WsDisplayNameResponse
InputConfig, JudgementResult, WsChallengeRequest, WsChallengeUnrequest, WsPendingChallengesResponse, WsAck, WsDisplayNameResponse, WsVerifiedField
} from '../types';
import { Option } from '@polkadot/types'
import fs from 'fs'
import { KeyringPair, KeyringPair$Json } from '@polkadot/keyring/types';
import {Keyring} from '@polkadot/keyring'
import { buildWsChallengeRequest, buildWsChallengeUnrequest, isJudgementGivenEvent, isJudgementUnrequested, isClaimChallengeCompliant, isJudgementRequestedEvent, isIdentityClearedEvent, extractJudgementInfoFromEvent, extractIdentityInfoFromEvent, buildWsChallengeRequestData, isIdentitySetEvent, buildJudgementGivenAck, extractRegistrationEntry, isDataPresent, isJudgementsFieldDisplayNamesCompliant, delay } from "../utils";
import { ISubscriber } from './ISubscriber'
import { IU8a } from '@polkadot/types-codec/types';

export class Subscriber implements ISubscriber {
private chain: Text;
Expand Down Expand Up @@ -258,7 +259,54 @@ export class Subscriber implements ISubscriber {
return await this.api.query.identity.identityOf(accountId)
}

public handleTriggerExtrinsicJudgement = async (judgementResult: string, target: string): Promise<boolean> => {
private _verifyOnchainMatch = async (target: string, verified: Array<WsVerifiedField>): Promise<IU8a> => {
// Fetch the full identity from chain. Unwrapping on a `None` value would
// indicate a bug since the target is checked in
// `handleTriggerExtrinsicJudgement`.
const info = (await this._getIdentity(target)).unwrap().info;

// Check if the verified values match the on-chain identity.
for (const field of verified) {
switch (field.accountTy) {
case "legal_name":
if (field.value != info.legal.toHuman()) {
throw new Error("Verified legal name does not mache on-chain value");
}
break;
case "display_name":
if (field.value != info.display.toHuman()) {
throw new Error("Verified display name does not mache on-chain value");
}
break;
case "email":
if (field.value != info.email.toHuman()) {
throw new Error("Verified email does not mache on-chain value");
}
break;
case "twitter":
if (field.value != info.twitter.toHuman()) {
throw new Error("Verified twitter does not mache on-chain value");
}
break;
case "matrix":
if (field.value != info.riot.toHuman()) {
throw new Error("Verified matrix does not mache on-chain value");
}
break;
case "web":
if (field.value != info.web.toHuman()) {
throw new Error("Verified web does not mache on-chain value");
}
break;
default:
throw new Error(`Verified unsupported entries: ${field.accountTy}`);
}
}

return info.hash;
}

public handleTriggerExtrinsicJudgement = async (judgementResult: string, target: string, verified: Array<WsVerifiedField>): Promise<boolean> => {

if( ! await this._isAccountIdWaitingOurJudgement(target) ){
this.logger.info(`the account id ${target} is not present in the pending judgment request set for our registrar...`)
Expand All @@ -272,10 +320,12 @@ export class Subscriber implements ISubscriber {
try {

if(judgementResult == JudgementResult[JudgementResult.erroneous] ){
await this.triggerExtrinsicErroneous(target)
const identityHash = await this._verifyOnchainMatch(target,verified)
await this.triggerExtrinsicErroneous(target, identityHash)
}
else if(judgementResult == JudgementResult[JudgementResult.reasonable] ){
await this.triggerExtrinsicReasonable(target)
const identityHash = await this._verifyOnchainMatch(target,verified)
await this.triggerExtrinsicReasonable(target, identityHash)
}

// the transaction has been successfully transmitted
Expand All @@ -288,17 +338,17 @@ export class Subscriber implements ISubscriber {

}

public triggerExtrinsicReasonable = async (target: string): Promise<void> => {
await this._triggerExtrinsicProvideJudgement(target,{Reasonable: true})
public triggerExtrinsicReasonable = async (target: string, identityHash: IU8a): Promise<void> => {
await this._triggerExtrinsicProvideJudgement(target,{Reasonable: true}, identityHash)
}

public triggerExtrinsicErroneous = async (target: string): Promise<void> =>{
await this._triggerExtrinsicProvideJudgement(target,{Erroneous: true})
public triggerExtrinsicErroneous = async (target: string, identityHash: IU8a): Promise<void> =>{
await this._triggerExtrinsicProvideJudgement(target,{Erroneous: true}, identityHash)
}

protected _triggerExtrinsicProvideJudgement = async (target: string, judgement: {Reasonable: boolean} | {Erroneous: boolean} ): Promise<void> =>{
const extrinsic = this.api.tx.identity.provideJudgement(this.registrarIndex,target,judgement)
const txHash = await extrinsic.signAndSend(this.registrarAccount)
protected _triggerExtrinsicProvideJudgement = async (target: string, judgement: {Reasonable: boolean} | {Erroneous: boolean} , identityHash: IU8a): Promise<void> =>{
const extrinsic = this.api.tx.identity.provideJudgement(this.registrarIndex,target,judgement, identityHash);
const txHash = await extrinsic.signAndSend(this.registrarAccount);
this.logger.info(`Judgement Submitted with hash ${txHash}`);
}

Expand Down
5 changes: 3 additions & 2 deletions src/subscriber/subscriberProxy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Logger } from "@w3f/logger";
import { InputConfig } from "../types";
import { Subscriber } from "./subscriber";
import { IU8a } from '@polkadot/types-codec/types';

export class SubscriberProxy extends Subscriber {

Expand All @@ -14,9 +15,9 @@ export class SubscriberProxy extends Subscriber {
this.registrarPrimaryAccount = cfg.registrar.proxy.primaryAccount
}

protected _triggerExtrinsicProvideJudgement = async (target: string, judgement: {Reasonable: boolean} | {Erroneous: boolean} ): Promise<void> =>{
protected _triggerExtrinsicProvideJudgement = async (target: string, judgement: {Reasonable: boolean} | {Erroneous: boolean}, identityHash: IU8a ): Promise<void> =>{

const call = this.api.tx.identity.provideJudgement(this.registrarIndex,target,judgement)
const call = this.api.tx.identity.provideJudgement(this.registrarIndex,target,judgement,identityHash)
const extrinsic = this.api.tx.proxy.proxy(this.registrarPrimaryAccount, null, call)
const txHash = await extrinsic.signAndSend(this.registrarAccount)
this.logger.info(`Judgement Submitted with hash ${txHash}`);
Expand Down
5 changes: 3 additions & 2 deletions src/subscriber/subscriberProxy2Levels.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Logger } from "@w3f/logger";
import { InputConfig } from "../types";
import { Subscriber } from "./subscriber";
import { IU8a } from '@polkadot/types-codec/types';

export class SubscriberProxy2Levels extends Subscriber {

Expand All @@ -16,9 +17,9 @@ export class SubscriberProxy2Levels extends Subscriber {
this.registrarPrimaryAccount = cfg.registrar.proxy2Levels.primaryAccount
}

protected _triggerExtrinsicProvideJudgement = async (target: string, judgement: {Reasonable: boolean} | {Erroneous: boolean} ): Promise<void> =>{
protected _triggerExtrinsicProvideJudgement = async (target: string, judgement: {Reasonable: boolean} | {Erroneous: boolean}, identityHash: IU8a ): Promise<void> =>{

const call = this.api.tx.identity.provideJudgement(this.registrarIndex,target,judgement)
const call = this.api.tx.identity.provideJudgement(this.registrarIndex,target,judgement,identityHash)
const callMidlle = this.api.tx.proxy.proxy(this.registrarPrimaryAccount, null, call)
const extrinsic = this.api.tx.proxy.proxy(this.registrarMiddleAccount, null, callMidlle)
const txHash = await extrinsic.signAndSend(this.registrarAccount)
Expand Down
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ export interface WsChallengeResponse {
export interface WsJudgementResult{
address: string;
judgement: string;
verified: Array<WsVerifiedField>;
}

export interface WsVerifiedField {
accountTy: string;
value: string;
}

export interface WsChallengeUnrequest {
Expand Down
Loading

0 comments on commit 9956857

Please sign in to comment.