Skip to content

Conversation

@developerfred
Copy link
Owner

@developerfred developerfred commented Dec 23, 2025

User description

This PR adds a comprehensive People Chain identity operations example to the PAPI Simulator.

Changes

  • Created PeopleChainExample.ts with identity management operations
  • Demonstrates identity registration, verification, and sub-accounts
  • Shows DID operations, username management, and registrar queries
  • Advanced level example covering identity operations

Features Demonstrated

  • Identity Registration: Setting up on-chain identity with multiple fields
  • Judgement Requests: Requesting verification from registrars
  • Sub-Accounts: Managing sub-accounts under main identity
  • DID Operations: Decentralized identity document management
  • Username System: On-chain username registration

This example helps developers understand Polkadot's identity system and how to implement user identity management.

Closes #52


PR Type

Enhancement


Description

  • Add three advanced example implementations for Polkadot ecosystem chains

  • OpenGov example demonstrates governance operations, voting, and referenda

  • Coretime example shows core purchasing, renewal, and workload management

  • People Chain example covers identity registration, verification, and DID operations

  • Register all examples in the example registry for discoverability


Diagram Walkthrough

flowchart LR
  A["Example Factory"] --> B["OpenGovExample"]
  A --> C["CoretimeExample"]
  A --> D["PeopleChainExample"]
  B --> E["Governance Operations"]
  C --> F["Coretime Operations"]
  D --> G["Identity Operations"]
  E --> H["Registry"]
  F --> H
  G --> H
Loading

File Walkthrough

Relevant files
Enhancement
OpenGovExample.ts
OpenGov governance operations example implementation         

src/lib/examples/OpenGovExample.ts

  • Create new OpenGov operations example class extending ExampleFactory
  • Demonstrate referendum submission, voting, and decision deposits
  • Show whitelisted caller operations and track information queries
  • Include conviction voting state and fellowship information examples
+169/-0 
CoretimeExample.ts
Coretime chain operations example implementation                 

src/lib/examples/CoretimeExample.ts

  • Create new Coretime operations example class extending ExampleFactory
  • Demonstrate core purchasing, renewal, partitioning, and assignment
    operations
  • Show workload queries, reservations, and instant pool management
  • Include core status queries and allowed renewal records examples
+180/-0 
PeopleChainExample.ts
People Chain identity operations example implementation   

src/lib/examples/PeopleChainExample.ts

  • Create new People Chain identity example class extending
    ExampleFactory
  • Demonstrate identity registration, verification requests, and
    sub-account management
  • Show DID operations, username registration, and registrar queries
  • Include identity judgments and super identity relationship examples
+210/-0 
Configuration changes
index.ts
Register new advanced examples in registry                             

src/lib/examples/index.ts

  • Import three new example classes: OpenGovExample, CoretimeExample,
    PeopleChainExample
  • Register all three examples in the example registry
  • Maintain existing example imports and registrations
+12/-0   

- Create OpenGovExample.ts demonstrating OpenGov operations
- Shows referendum submission, voting, decision deposits
- Includes whitelisted caller operations and track information
- Advanced level example with governance, opengov, voting, referenda categories
- Registered the example in the example registry
- Create CoretimeExample.ts demonstrating Coretime operations
- Shows core purchasing, renewal, partitioning, and assignment
- Includes pool operations and workload queries
- Advanced level example with coretime, parachains, assets categories
- Registered the example in the example registry
- Create PeopleChainExample.ts demonstrating identity operations
- Shows identity registration, verification, sub-accounts
- Includes DID operations and username management
- Advanced level example with identity, people-chain, did categories
- Registered the example in the example registry
@vercel
Copy link

vercel bot commented Dec 23, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
papi-simulator Error Error Dec 23, 2025 7:43pm

- Create XcmV4Example.ts demonstrating latest XCM V4 features
- Shows teleport assets, reserve transfers, limited teleports
- Includes XCM message execution and version negotiation
- Advanced level example with xcm, cross-chain, assets categories
- Registered the example in the example registry
@qodo-code-review
Copy link

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🟡
🎫 #52
🟢 Create examples for Polkadot People Chain identity operations.
Include identity verification/judgement request examples.
Include management of on-chain identities (e.g., querying identity, sub-accounts,
registrars/judgements, updates/clearing).
🔴 Include DID creation and DID-related operations examples.
Ensure the People Chain identity example is correctly registered and discoverable in the
example registry (the src/lib/examples/index.ts diff appears syntactically malformed and
may prevent registration/build).
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

🔴
Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status:
Errors swallowed: Multiple catch (error) blocks suppress exceptions with generic messages and no actionable
context (operation details, error message), making failures hard to diagnose and masking
edge cases.

Referred Code
try {
  const coretimeConfig = await typedApi.query.Broker.Configuration.getValue();
  console.log("Coretime configuration:", coretimeConfig);
} catch (error) {
  console.log("Coretime configuration not available");
}

// 2. Query core sales status
console.log("\\n🏷️ Querying core sales status:");
try {
  const saleInfo = await typedApi.query.Broker.SaleInfo.getValue();
  console.log("Current sale information:", saleInfo);
} catch (error) {
  console.log("Sale info not available");
}

// 3. Query available cores
console.log("\\n🔍 Querying available cores:");
try {
  const cores = await typedApi.query.Broker.CoreSchedules.getEntries();
  console.log("Found", cores.length, "cores with schedules");


 ... (clipped 106 lines)

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status:
Raw error exposure: The example prints raw error objects to the console (console.error(..., error) /
.catch(console.error)), which can expose internal details/stack traces to the user.

Referred Code
  } catch (error) {
    console.error("❌ Error in People Chain identity operations:", error);
  }
};

demonstratePeopleChainIdentity().catch(console.error);

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status:
PII in logs: The example logs identity and DID data (e.g., email, legal name, web URL, DID document
contents) via console.log, which risks exposing PII in application logs.

Referred Code
  const aliceIdentity = await typedApi.query.Identity.IdentityOf.getValue(aliceAddress);
  console.log("Alice's identity:", aliceIdentity);

  const bobIdentity = await typedApi.query.Identity.IdentityOf.getValue(bobAddress);
  console.log("Bob's identity:", bobIdentity);
} catch (error) {
  console.log("Identity queries not available or different structure");
}

// 2. Query super identities
console.log("\\n👑 Querying super identities:");
try {
  const superOf = await typedApi.query.Identity.SuperOf.getValue(aliceAddress);
  console.log("Alice's super identity:", superOf);
} catch (error) {
  console.log("Super identity queries not available");
}

// 3. Query subs (sub-accounts)
console.log("\\n👥 Querying sub-accounts:");
try {


 ... (clipped 117 lines)

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status:
Missing audit context: The example performs and demonstrates sensitive identity-related actions but only uses
ad-hoc console.log statements without user identifiers, timestamps, or structured outcomes
needed to reconstruct an audit trail.

Referred Code
console.log("🆔 Starting People Chain identity operations demonstration...");

// 1. Query identity information
console.log("\\n🔍 Querying identity information:");
const aliceAddress = "${this.getTestAccount("alice")}";
const bobAddress = "${this.getTestAccount("bob")}";

try {
  const aliceIdentity = await typedApi.query.Identity.IdentityOf.getValue(aliceAddress);
  console.log("Alice's identity:", aliceIdentity);

  const bobIdentity = await typedApi.query.Identity.IdentityOf.getValue(bobAddress);
  console.log("Bob's identity:", bobIdentity);
} catch (error) {
  console.log("Identity queries not available or different structure");
}

// 2. Query super identities
console.log("\\n👑 Querying super identities:");
try {
  const superOf = await typedApi.query.Identity.SuperOf.getValue(aliceAddress);


 ... (clipped 153 lines)

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status:
No input validation: Transactions and queries are constructed from values that may come from runtime
configuration (network.endpoint, descriptor selection, and example parameters) without
visible validation/sanitization in the diff, so safety depends on upstream constraints not
shown here.

Referred Code
		return `// OpenGov Operations Example on ${network.name}
${this.getImports(network, true)}

// Connect to ${network.name}
const client = createClient(
  withPolkadotSdkCompat(
    getWsProvider("${network.endpoint}")
  )
);

// Get the typed API using the descriptors
const typedApi = client.getTypedApi(${network.descriptorKey});

// OpenGov operations demonstration
const demonstrateOpenGovOperations = async () => {
  try {
    console.log("🏛️ Starting OpenGov operations demonstration...");

    // 1. Query current referenda
    console.log("\\n📋 Querying active referenda:");
    const referenda = await typedApi.query.Referenda.ReferendumInfoFor.getEntries();


 ... (clipped 131 lines)

Learn more about managing compliance generic rules or creating your own custom rules

Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@developerfred developerfred merged commit e468f1c into main Dec 23, 2025
2 of 3 checks passed
@qodo-code-review
Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Fix example registration placement

Move the new PeopleChainExample(), new CoretimeExample(), and new
OpenGovExample() instantiations inside the exampleRegistry array to ensure they
are properly registered.

src/lib/examples/index.ts [17-24]

-import { AcalaDeFiExample } from "./AcalaDeFiExample";
-...
+// inside the array where other examples are instantiated:
+new AcalaDeFiExample(),
 new PeopleChainExample(),
-...
-import type { Example, ExampleLevel } from "../types/example";
 new CoretimeExample(),
-...
-import { PolkadotGovernanceExample } from "./PolkadotGovernanceExample";
+new PolkadotGovernanceExample(),
 new OpenGovExample(),
+... (rest of examples)

[To ensure code accuracy, apply this suggestion manually]

Suggestion importance[1-10]: 10

__

Why: This suggestion correctly identifies a critical bug where the new examples are instantiated but not added to the exampleRegistry, rendering them unused. The fix is essential for the PR's primary goal of adding these new examples to the application.

High
Fix undefined variable runtime error

Replace the undefined MultiAddress.Id() call with the correct object literal {
Id: bobAddress } to prevent a runtime error and fix the transaction payload.

src/lib/examples/PeopleChainExample.ts [115-132]

 // 7. Demonstrate sub-account addition
 console.log("\\n👶 Sub-Account Addition Example:");
 console.log("This would add a sub-account to an identity:");
 const addSubTx = typedApi.tx.Identity.addSub({
-  sub: MultiAddress.Id(bobAddress),
+  sub: { Id: bobAddress },
   data: {
     Raw: "Bob Assistant"
   }
 });
 console.log("Add sub-account transaction created (not submitted in simulator)");
 
 // 8. Demonstrate sub-account removal
 console.log("\\n👋 Sub-Account Removal Example:");
 console.log("This would remove a sub-account from an identity:");
 const removeSubTx = typedApi.tx.Identity.removeSub({
-  sub: MultiAddress.Id(bobAddress)
+  sub: { Id: bobAddress }
 });
 console.log("Remove sub-account transaction created (not submitted in simulator)");
  • Apply / Chat
Suggestion importance[1-10]: 9

__

Why: The suggestion correctly identifies that MultiAddress is not defined, which would cause a runtime ReferenceError. The proposed fix to use { Id: bobAddress } is the correct way to structure the transaction payload, thus fixing a bug in the generated example code.

High
High-level
Abstract common logic into base class

Refactor the new example classes by abstracting duplicated boilerplate code,
such as client setup and the main async function structure, into the
ExampleFactory base class to improve code reuse and maintainability.

Examples:

src/lib/examples/CoretimeExample.ts [15-179]
	generateCode(network: Network): string {
		return `// Coretime Chain Operations Example on ${network.name}
${this.getImports(network, true)}

// Connect to ${network.name} Coretime Chain
const client = createClient(
  withPolkadotSdkCompat(
    getWsProvider("${network.endpoint}")
  )
);

 ... (clipped 155 lines)
src/lib/examples/OpenGovExample.ts [15-168]
	generateCode(network: Network): string {
		return `// OpenGov Operations Example on ${network.name}
${this.getImports(network, true)}

// Connect to ${network.name}
const client = createClient(
  withPolkadotSdkCompat(
    getWsProvider("${network.endpoint}")
  )
);

 ... (clipped 144 lines)

Solution Walkthrough:

Before:

// In CoretimeExample.ts
class CoretimeExample extends ExampleFactory {
  generateCode(network: Network): string {
    return `// ... boilerplate ...
      const client = createClient(...);
      const typedApi = client.getTypedApi(...);

      const demonstrateCoretimeOperations = async () => {
        try {
          // ... coretime specific logic ...
        } catch (error) { ... }
      };
      demonstrateCoretimeOperations().catch(console.error);
    `;
  }
}
// ... similar duplication in OpenGovExample.ts and PeopleChainExample.ts

After:

// In ExampleFactory.ts (new abstract method)
abstract class ExampleFactory {
  abstract generateOperationsCode(network: Network): string;

  generateCode(network: Network): string {
    const operationsCode = this.generateOperationsCode(network);
    return `// ... boilerplate ...
      const client = createClient(...);
      const typedApi = client.getTypedApi(...);
      const demonstrateOperations = async () => {
        try {
          ${operationsCode}
        } catch (error) { ... }
      };
      demonstrateOperations().catch(console.error);
    `;
  }
}

// In CoretimeExample.ts
class CoretimeExample extends ExampleFactory {
  generateOperationsCode(network: Network): string {
    return `// ... coretime specific logic ...`;
  }
}
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies significant code duplication across the three new example files and proposes a valid architectural improvement to enhance maintainability by abstracting common logic into the base class.

Medium
General
Include error details in logs

In the catch block, log the error object alongside the "Coretime configuration
not available" message to provide more context for debugging.

src/lib/examples/CoretimeExample.ts [39-41]

 } catch (error) {
-  console.log("Coretime configuration not available");
+  console.log("Coretime configuration not available:", error);
 }
  • Apply / Chat
Suggestion importance[1-10]: 5

__

Why: The suggestion improves debugging by logging the error object in the catch block. While this is good practice, it's a minor enhancement to an example file and does not fix a functional bug.

Low
  • More

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add People Chain Identity Examples

2 participants