npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sphereon/lto-did-ts

v0.1.8-unstable.0

Published

LTO DID support

Downloads

257

Readme

CI codecov NPM Version

LTO DID support library (Typescript)

This is a Typescript project that allows you to create DIDs, add Verification Methods and resolve DIDs on LTO Network.

Please note we also have a Veramo.io DID manager plugin as well as a Universal Registrar driver accompanying this library.

Creating a DID

Creating a DID means you have to create a public/private keypair first. You can do this using lto-api package or any other means to create a ed25519 keypair. We are accepting an optional ed25519 private key to keep it flexible for everyone. If it is not provided we will create a random private/public keypair for you.

Internally it will create an LTO didAccount or import the key into an didAccount. We expose the didAccount using the didAccount() method for your retrieval.

Initializing the DID class

import {Account, LTO} from "lto-api";
import {DIDService, Network} from "@sphereon/lto-did-ts";

const ltoAccount = new LTO(Network.TESTNET, 'https://testnet.lto.network')
const didPrivateKeyBase58 = base58encode(ltoAccount.sign.privateKey)

const didService = new DIDService({
    didPrivateKeyBase58,
    network: Network.TESTNET,
});


// The didAccount is either constructed from the supplied private key, or a random didAccount is created
const didAccount: Account = didService.didAccount()

Create a DID on chain

The above only initialized the DID service, so now lets actually publish/create a DID on chain.

const createdDid = didService.createDID();
console.log(createdDid) // Returns the did string
console.log(didService.did()) // Returns the same did string
// Output: 
// did:lto:<address-value>
// did:lto:<address-value>

Add verificationMethod(s)

You can add one or more verification methods to an existing DID, or you can add them during DID creation. Internally this is accomplished using LTO Networks, associations. This means new private/public keypairs are need. Again you can use your own ed25519 private key, or have one randomly created for you. Obviously you do need to retrieve them from the didService afterwards in that case.

In order to make the internal LTO Network association the target didAccount of the association needs to have been published on the network before that. The public key needs to be known for the LTO indexer to index it. The boolean option createVerificationDID can create the respective didAccount for you. Do note that the library will wait for several seconds to ensure the didAccount is published before creating the association.

import {Account, LTO} from "lto-api";
import {DIDService, Network} from "@sphereon/lto-did-ts";
import {LtoVerificationMethod} from "./index";

const vmAccount = new LTO(Network.TESTNET, 'https://testnet.lto.network').createAccount()
const verificationMethodPrivateKeyBase58 = base58encode(vmAccount.sign.privateKey)
const verificationMethod = LtoVerificationMethod.CapabilityInvocation


const verificationMethodResult = didService.addVerificationMethod({
    verificationMethodPrivateKeyBase58,
    verificationMethod,
    createVerificationDID: true
})

Using a sponsorAccount

You can use a sponsorAccount for creating the DIDs. The sponsorAccount pays for the actual transaction, so that you do not have to transfer LTO tokens to all DID addresses in order to create DIDs. The sponsorAccount is being used on a per transaction level, as to not have to use the sponsorAccount didAccount feature, which means the sponsorAccount pays for all transactions in the future of an didAccount.

We work with the base 58 encoded privateKey of the sponsorAccount. So if you are using the lto-api and already have an Account object, you can get the private key by base58 encoding the didAccount.sign.privateKey property.

You can pass the sponsorAccount as argument for the DIDService constructor

import {Account, LTO} from "lto-api";
import {DIDService, Network} from "@sphereon/lto-did-ts";
import {LtoVerificationMethod} from "./index";

// Create sponsor account from a seed and convert to private key, could be a direct private key as well of course
const sponsorAccount = new LTO(Network.TESTNET, 'https://testnet.lto.network').createAccountFromExistingPhrase('my seed')
const sponsorPrivateKeyBase58 = base58encode(sponsorAccount.sign.privateKey)

const didAccount = new LTO(Network.TESTNET, 'https://testnet.lto.network')
const didPrivateKeyBase58 = base58encode(didAccount.sign.privateKey)

const didService = new DIDService({
    didPrivateKeyBase58,
    sponsorPrivateKeyBase58,
    network: Network.TESTNET,
});


didService.sponsorAccount()