LTO Network
  • Getting started
  • What is LTO Network?
  • Tutorials
    • Buying and staking LTO
      • Exchanges
        • Binance
        • AscendEX (Bitmax)
        • Uniswap
        • PancakeSwap
        • Other exchanges
      • Creating your LTO web wallet
      • Using the LTO token bridge
      • Staking LTO tokens
    • Mining
      • Setup your node wallets
      • Node management
      • Public community nodes
    • Anchoring
      • Hashing
    • LetsFlow
  • Wallets
    • LTO Web Wallet
      • Using Ledger
    • Universal Wallet
    • LTO CLI
    • Third-Party Wallets
      • Stakely.io wallet
        • Web wallet
        • Commandline
    • ERC20 Token Swap
  • Running a node
    • Public node
      • Installation Guide
        • Mainnet & Testnet
        • Requirements
        • Configuration
        • (Virtual) Machine
        • Nginx reverse proxy (optional)
        • Troubleshooting FAQ
      • Cloud installation
        • Alibaba Cloud
        • AWS Elastic Beanstalk
        • Google Cloud
        • IBM Cloud
        • Microsoft Azure
        • OKD (OpenShift)
        • Raspberry Pi (Expert)
        • Ubuntu Linux with Container
        • Windows with Container
      • REST API
        • Address
        • Wallet
        • Lease Transactions
        • Peers
        • Blocks
        • Utils
        • FAQ
      • Security Notes
      • FAQ
      • Exchange integration guide
    • Anchor node
      • Installation Guide
        • Linux
        • MacOS
        • Windows
      • REST API
    • Identity node
      • Installation guide
        • Linux
        • MacOs
        • Windows
      • Configuration
        • Trust network
      • REST API
    • Workflow node
      • Installation Guide
        • MacOS
        • Windows
        • Ubuntu Linux
      • REST API
  • Ownables
    • What are Ownables?
    • Making your first ownable
    • Ownables SDK
      • Prerequisites
      • Setup
    • Ownables Architecture
      • Smart Contract
      • Widget
    • Ownables Bridge
  • Templates Overview
  • Libraries
    • JavaScript
      • Accounts
      • Transactions
      • Event chain
      • Messages
      • Identities
      • HTTP Authentication
    • Python
      • Accounts
      • Public layer
    • PHP
      • Accounts
      • Identities
      • Public layer
      • Private layer
      • HTTP Authentication
      • Commandline scripts
    • Java
  • Protocol
    • Cryptography
    • Accounts
      • ED25519
      • secp256k1
      • secp256r1
    • Identities
      • Decentralized identifiers (DID)
      • Trust network
      • Verifiable credentials
    • Public layer
      • Transactions
        • Transfer
        • Lease
        • Cancel Lease
        • Mass Transfer
        • Set Script
        • Data
        • Anchor
        • Association
        • Revoke Association
        • Sponsorship
        • Cancel Sponsorship
        • Register
        • Burn
        • Mapped Anchor
        • Statement
      • Transaction fees
      • Consensus protocol
      • Activation Protocol
      • Data Structures
    • Private layer
      • Event chain
        • Event
      • Messaging
        • Sending messages
Powered by GitBook
On this page
  • Verification methods
  • Services
  • Deactivation
  1. Libraries
  2. JavaScript

Identities

Create a DID Document for an account

Any account on LTO network, for which the public key is known, can be resolved as DID (decentralized identifier). To explicitly create a DID use the identity builder.

import LTO from '@ltonetwork/lto';
import { IdentityBuilder } from '@ltonetwork/lto/identities';

const lto = new LTO('T');
const account = lto.account();

new IdentityBuilder(account)
  .transactions.map(tx => lto.node.broadcast(tx));

The main account is known as the management key.

Use Promise.all() if you wait to await for the transactions to be broadcasted.

Verification methods

By default, the account's public key is the only verification method of the DID. Other verification methods can be added through associations with other accounts.

import LTO from '@ltonetwork/lto';
import { IdentityBuilder } from '@ltonetwork/lto/identities';

const lto = new LTO('T');
const account = lto.account();
const key1 = lto.account({ publicKey: "8cMyCW5Esx98zBqQCy9N36UaGZuNcuJhVe17DuG42dHS" });
const key2 = lto.account({ publicKey: "9ubzzV9tRYTcQee68v1mUPJW7PHdB74LZEgG1MgZUExf" });

const expires = new Date();
expires.setFullYear(expires.getFullYear() + 1);

new IdentityBuilder(account)
  .addVerificationMethod(key1)
  .addVerificationMethod(key2, ['authentication', 'assertionMethod'], expires)
  .transactions.map(tx => lto.node.broadcast(tx));

If no verification relationships are specified, it is only listed as a verification method, which is typically not what you want. Optionally, you can have the verification method automatically expire.

Revoking verification methods

import LTO from '@ltonetwork/lto';
import { IdentityBuilder } from '@ltonetwork/lto/identities';

const lto = new LTO('T');
const account = lto.account();
const key = lto.account({publicKey: "8cMyCW5Esx98zBqQCy9N36UaGZuNcuJhVe17DuG42dHS"});

new IdentityBuilder(account)
  .removeVerificationMethod(key)
  .transactions.map(tx => lto.node.broadcast(tx));

Verification methods can also be removed by address.

Services

import LTO from '@ltonetwork/lto';
import { IdentityBuilder } from '@ltonetwork/lto/identities';

const lto = new LTO('T');
const account = lto.account();

new IdentityBuilder(account)
  .addService({type: 'LTORelay', serviceEndpoint: 'ampq://relay.lto.network'})
  .transactions.map(tx => lto.node.broadcast(tx));

Removing services

import LTO from '@ltonetwork/lto';
import { IdentityBuilder } from '@ltonetwork/lto/identities';

const lto = new LTO('T');
const account = lto.account();

new IdentityBuilder(account)
  .removeService({type: 'LTORelay'})
  .transactions.map(tx => lto.node.broadcast(tx));

A service may also be removed by id.

Deactivation

If the management key is compromised, the DID should be deactivated.

import LTO from '@ltonetwork/lto';
import { IdentityBuilder } from '@ltonetwork/lto/identities';

const lto = new LTO('T');
const account = lto.account();

new IdentityBuilder(account).deactivate().broadcastTo(lto.node);

Grant deactivation capability

Allow a trusted party to deactivate the DID in case the management key is lost.

import LTO from '@ltonetwork/lto';
import { IdentityBuilder } from '@ltonetwork/lto/identities';

const lto = new LTO('T');
const account = lto.account();
const trustedAccount = lto.account({publicKey: "8cMyCW5Esx98zBqQCy9N36UaGZuNcuJhVe17DuG42dHS"});

const expires = new Date();
expires.setFullYear(expires.getFullYear() + 1);

const revokeDelay = 86400_000; // 24h in ms

new IdentityBuilder(account)
  .grantDisableCapability(trustedAccount, expires, revokeDelay)
  .transactions.map(tx => lto.node.broadcast(tx));

The expires and revokeDelay arguments are optional.

Revoke deactivation capability

import LTO from '@ltonetwork/lto';
import { IdentityBuilder } from '@ltonetwork/lto/identities';

const lto = new LTO('T');
const account = lto.account();
const trustedAccount = lto.account({publicKey: "8cMyCW5Esx98zBqQCy9N36UaGZuNcuJhVe17DuG42dHS"});

new IdentityBuilder(account)
  .revokeDisableCapability(trustedAccount)
  .transactions.map(tx => lto.node.broadcast(tx));
PreviousMessagesNextHTTP Authentication

Last updated 2 months ago