@sondreb/did-stellar
v0.0.5
Published
DID Stellar Method
Downloads
21
Maintainers
Readme
did:stellar
A JavaScript library implementing the "did:stellar" Decentralized Identifier (DID) method, which uses Stellar cryptography for DID creation and resolution.
Installation
npm install @sondreb/did-stellarOverview
This library enables creation and resolution of DIDs using the Stellar blockchain's cryptographic functions. The did:stellar method uses Stellar public keys as identifiers, allowing for seamless integration with the Stellar ecosystem.
Features
- Create DIDs from Stellar public or private keys
- Resolve DIDs to standard DID Documents
- Convert Stellar keys to multibase format for DID Documents
- Ed25519 key verification and handling
Usage
Importing the Library
import { DidStellar, StrKey } from '@sondreb/did-stellar';Creating a DID from a Public Key
const publicKeyText = 'GCFXHS4GXL6BVUCXBWXGTITROWLVYXQKQLF4YH5O5JT3YZXCYPAFBJZB';
const didDocument = DidStellar.fromPublicKey(publicKeyText);
console.log(didDocument.id); // 'did:stellar:GCFXHS4GXL6BVUCXBWXGTITROWLVYXQKQLF4YH5O5JT3YZXCYPAFBJZB'Creating a DID from a Private Key
const privateKeyText = 'SAV76USXIJOBMEQXPANUOQM6F5LIOTLPDIDVRJBFFE2MDJXG24TAPUU7';
const didDocument = DidStellar.fromPrivateKey(privateKeyText);
console.log(didDocument.id); // Will output the DID derived from the public keyResolving a DID
const did = 'did:stellar:GCFXHS4GXL6BVUCXBWXGTITROWLVYXQKQLF4YH5O5JT3YZXCYPAFBJZB';
const resolution = DidStellar.resolve(did);
console.log(resolution.didDocument); // Full DID DocumentGetting a DID Document
const did = 'did:stellar:GCFXHS4GXL6BVUCXBWXGTITROWLVYXQKQLF4YH5O5JT3YZXCYPAFBJZB';
const document = DidStellar.getDocument(did);
console.log(document); // DID DocumentGetting a Public Key from a Private Key
const privateKeyText = 'SAV76USXIJOBMEQXPANUOQM6F5LIOTLPDIDVRJBFFE2MDJXG24TAPUU7';
const publicKeyText = DidStellar.getPublicKey(privateKeyText);
console.log(publicKeyText); // Stellar public keyWorking with Stellar Keys
The package includes the StrKey utility for handling Stellar key formats:
import { StrKey } from '@sondreb/did-stellar';
// Encode raw bytes to a Stellar public key
const encodedKey = StrKey.encodeEd25519PublicKey(publicKeyBytes);
// Decode a Stellar public key to raw bytes
const decodedBytes = StrKey.decodeEd25519PublicKey(publicKeyText);
// Validate a Stellar public key
const isValid = StrKey.isValidEd25519PublicKey(publicKeyText);API Reference
DidStellar
static resolve(did: string)
Resolves a DID to a compliant DID Resolution Result.
static fromPublicKey(publicKeyText: string)
Creates a DID Document from a Stellar public key.
static fromPrivateKey(privateKeyText: string)
Creates a DID Document from a Stellar private key.
static getPublicKey(privateKeyText: string)
Derives a Stellar public key from a Stellar private key.
static getDocument(did: string)
Generates a standard DID Document from a did:stellar identifier.
static publicKeyToMultibase(publicKeyBytes: Uint8Array)
Converts a public key to multibase format for use in DID Documents.
StrKey
Utility class for handling Stellar key formats. See full documentation in the code.
DID Document Example
{
"@context": [
"https://www.w3.org/ns/did/v1",
"https://w3id.org/security/suites/ed25519-2020/v1"
],
"id": "did:stellar:GCFXHS4GXL6BVUCXBWXGTITROWLVYXQKQLF4YH5O5JT3YZXCYPAFBJZB",
"verificationMethod": [
{
"id": "did:stellar:GCFXHS4GXL6BVUCXBWXGTITROWLVYXQKQLF4YH5O5JT3YZXCYPAFBJZB#0",
"type": "Ed25519VerificationKey2020",
"controller": "did:stellar:GCFXHS4GXL6BVUCXBWXGTITROWLVYXQKQLF4YH5O5JT3YZXCYPAFBJZB",
"publicKeyMultibase": "z1APN5d6ZRjZQXsVegnYhKBcyifsU96gpVM5FrD3fdJLVd"
}
],
"authentication": [
"did:stellar:GCFXHS4GXL6BVUCXBWXGTITROWLVYXQKQLF4YH5O5JT3YZXCYPAFBJZB#0"
],
"assertionMethod": [
"did:stellar:GCFXHS4GXL6BVUCXBWXGTITROWLVYXQKQLF4YH5O5JT3YZXCYPAFBJZB#0"
],
"capabilityDelegation": [
"did:stellar:GCFXHS4GXL6BVUCXBWXGTITROWLVYXQKQLF4YH5O5JT3YZXCYPAFBJZB#0"
],
"capabilityInvocation": [
"did:stellar:GCFXHS4GXL6BVUCXBWXGTITROWLVYXQKQLF4YH5O5JT3YZXCYPAFBJZB#0"
],
"keyAgreement": [
"did:stellar:GCFXHS4GXL6BVUCXBWXGTITROWLVYXQKQLF4YH5O5JT3YZXCYPAFBJZB#0"
]
}License
This project is licensed under the MIT License - see the LICENSE file for details.
