Demos Network Specifications
  • Introduction
    • What is Demos Network
    • Demos Network Architecture
  • FAQ
  • Cookbook
    • Project setup
      • Run the project (MacOS)
      • Run the project (Windows)
        • WSL 2 Setup on Windows (10 and 11 only)
        • Issue Troubleshooting
      • Run the project (Ubuntu)
  • SDK
    • Getting Started
    • WebSDK
      • Authentication
        • FIDO2 Passkeys
          • Under the Hood: FIDO2 Passkeys
      • NodeCalls
      • Transactions
        • Creating a transaction
        • Signing a transaction
        • Broadcasting a transaction
      • L2PS SDK
        • The l2ps module
        • Interacting with the L2PS
        • L2PS Messaging System
      • Instant Messaging
        • What is the Instant Messaging Protocol?
        • Architecture Overview
        • Encryption
        • Quickstart
        • Message Types
        • API Reference
        • FAQ
    • Cross Chain
      • General layout of the XM SDKs
      • EVM
      • BTC
      • Solana
      • MultiversX (EGLD)
      • NEAR
      • IBC
      • TON
      • XRPL
      • The XMScript
      • Identities
    • Demoswork
    • Cookbook
      • Demoswork
        • Creating work steps
        • Conditional Operation
        • Base Operation
        • Signing and broadcasting
      • Transactions
        • Crosschain Transaction
        • Native Transactions
      • SWAP
        • Crosschain SWAP
    • Web2
      • Quick Start
      • DAHR API Reference
        • Types
      • Making Requests
      • Identities
        • Twitter
        • GitHub
    • API Reference
    • Bridges
      • Rubic Bridge Test
    • Post Quantum Cryptography
  • Backend
    • Internal Mechanisms
      • Network Time Synchronization
      • Cross Context Identities
    • Global Change Registry
      • GCR Structure
      • How is GCR Synced?
    • Consensus Mechanism
      • Unparalleled Scalability
      • Decentralization in PoR-BFT
      • Enhanced Security
      • Comparative Advantage
      • Addressing Potential Criticisms
      • Conclusion
    • Communications Stack
    • L2PS (Subnet) Framework
      • How are L2PS transactions handled?
    • Miscellaneous
      • Browsing the Postgres DB via psql
    • Bridges
      • Rubic Bridge
    • Developers Testbed
      • Setting up the environment
      • Setting up the repository
      • Installing dependencies
      • Node Configuration
      • Running the node
  • Frontend
    • Demos Providers Discovery Mechanism
Powered by GitBook
On this page
  • Adding an Identity
  • Getting Identities
  • Removing an Identity
  1. SDK
  2. Cross Chain

Identities

PreviousThe XMScriptNextDemoswork

Last updated 11 days ago

Adding an Identity

You can associate a crosschain identity with a DEMOS address by creating a signature using your private key and sending it to the DEMOS network.

DEMOS network supports linking Web2 identities too (for example, login with Twitter or with Github). See web2 Identities

Check out how to create a signature on the "Signing Messages" section of the respective crosschain SDK documentation. eg.

0. Imports

import { Demos } from "@kynesyslabs/demosdk/websdk"
import { Identities } from "@kynesyslabs/demosdk/abstraction"
import { InferFromSignaturePayload } from "@kynesyslabs/demosdk/types/abstraction"

1. Creating the signature

Connect your wallet to the XM instance and create a signature

// connect your 
const xmAddress = instance.getAddress()
const message = `Link ${instance.name} address ${address} to Demos`
const signature = await instance.signMessage(message)

The signature will be verified on the network to prevent adding identities not owned by you

2. Creating the DEMOS payload

The payload to add a Sepolia address would look like this:

const payload: InferFromSignaturePayload = {
    method: "identity_assign_from_signature",
    target_identity: {
        chain: "eth",
        chainId: instance.chainId,
        subchain: "sepolia",
        isEVM: true,
        signature: signature,
        signedData: message,
        targetAddress: instance.getAddress(),
    },
}

3. Connecting to the network

Create a new Demos object and connnect the RPC and your private key.

const rpc = "https://demosnode.discus.sh"

// connect to the DEMOS rpc
const demos = new Demos()
await demos.connect(rpc)

// connect private key
await demos.connectWallet(mnemonic)

4. Sending the payload

Then send the identity payload to the network using the identities instance as shown:

Use identities.inferIdentity to create a transaction that adds your identity to the blockchain. Then broadcast the transaction using demos.broadcast.

const identities = new Identities()
const validityData = await identities.inferXmIdentity(demos, payload)

const res = await demos.broadcast(validityData)
console.log(res)

// {
//   result: 200,
//   response: { message: 'Signature verified. Transaction applied.' },
//   require_reply: false,
//   extra: { confirmationBlock: 3 }
// }

Getting Identities

After the confirmationBlock has been forged, you can retrieve all the identities associated with your DEMOS address as shown:

const res = await identities.getIdentities(demos)
console.log(res)

// {
//   "result": 200,
//   "response": {
//     "xm": {
//       "evm": {
//         "sepolia": [
//           "0x4298A9D2A573dA64102255d11d6908b7e3d89b02"
//         ]
//       }
//     },
//     "web2": {}
//   },
//   "require_reply": false,
//   "extra": null
// }

Removing an Identity

You can remove your crosschain identity from DEMOS as shown:

const validityData = await identities.removeXmIdentity(demos, {
    chain: "evm",
    subchain: "sepolia",
    targetAddress: instance.getAddress(), // the address to remove
})

const res = await demos.broadcast(validityData)
console.log(res)

// {
//   result: 200,
//   response: { message: 'Transaction applied, waiting for confirmation' },
//   require_reply: false,
//   extra: { confirmationBlock: 25 }
// }
EVM