@dotprotocol/identity
v0.3.0
Published
DOT Protocol identity — keypair + genesis DOT + export/import.
Downloads
44
Readme
@dotprotocol/identity
Persistent keypair + DID for DOT Protocol. Your key, your identity.
Install
npm install @dotprotocol/identityQuick start
import { loadOrCreate, generateDID } from '@dotprotocol/identity';
// Load existing keypair or create a new one
const keypair = await loadOrCreate('./my-identity.json');
// Derive a DID from the public key
const did = generateDID(keypair.pubkey);
// "did:dot:abc123def456..."API
loadOrCreate(path, options?)
Load keypair from file. If the file doesn't exist, generate and save a new one.
const keypair = await loadOrCreate('./identity.json');
// { pubkey: Uint8Array(32), privkey: Uint8Array(64) }loadKeypair(path)
Load keypair from file. Throws if not found.
const keypair = await loadKeypair('./identity.json');saveKeypair(keypair, path)
Save keypair to file.
await saveKeypair(keypair, './identity.json');generateDID(pubkey)
Derive a did:dot: DID from an Ed25519 public key.
const did = generateDID(keypair.pubkey);
// "did:dot:z6Mk..." (base58btc-encoded)Identity file format
{
"pubkey": "hex-encoded-32-bytes",
"privkey": "hex-encoded-64-bytes",
"created": 1709000000000
}Store this file securely. Anyone with the privkey can sign DOTs as you.
Key backup
Your keypair IS your identity. There is no recovery service. Back it up:
# Backup
cp identity.json identity.backup.json
# Or export as hex
node -e "const k = require('./identity.json'); console.log(k.privkey)"License
MIT
