DID Operations
The DID (Decentralized Identifier) endpoints allow you to create and resolve did:key identifiers with Ed25519 keypairs.
Create a DID
Section titled “Create a DID”Creates a new did:key identifier with an Ed25519 keypair.
POST /v1/didAuthentication
Section titled “Authentication”Requires BearerAuth or ApiKeyAuth.
Request Body
Section titled “Request Body”| Field | Type | Required | Description |
|---|---|---|---|
public_key | string | No | Base64-encoded Ed25519 public key. If not provided, a new keypair will be generated. |
Request Example
Section titled “Request Example”# Generate new keypaircurl -X POST "https://api.veriglob.com/v1/did" \ -H "Authorization: Bearer your-api-key" \ -H "Content-Type: application/json"
# With existing public key
curl -X POST "https://api.veriglob.com/v1/did" \ -H "Authorization: Bearer your-api-key" \ -H "Content-Type: application/json" \ -d '{"public_key": "base64-encoded-public-key"}'interface CreateDIDRequest { public_key?: string;}
interface CreateDIDResponse { status: string; message: string; data: { did: string; public_key: string; private_key?: string; };}
async function createDID( apiKey: string, publicKey?: string): Promise<CreateDIDResponse> { const response = await fetch('https://api.veriglob.com/v1/did', { method: 'POST', headers: { 'Authorization': `Bearer ${apiKey}`, 'Content-Type': 'application/json' }, body: publicKey ? JSON.stringify({ public_key: publicKey }) : undefined });
if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); }
return response.json();}
// Usage - Generate new keypairconst newDID = await createDID('your-api-key');console.log('DID:', newDID.data.did);console.log('Private Key:', newDID.data.private_key);package main
import ( "bytes" "encoding/json" "fmt" "net/http")
type CreateDIDRequest struct {PublicKey string `json:"public_key,omitempty"`}
type CreateDIDResponse struct {Status string `json:"status"`Message string `json:"message"`Data struct {DID string `json:"did"`PublicKey string `json:"public_key"`PrivateKey string `json:"private_key,omitempty"`} `json:"data"`}
func CreateDID(apiKey string, publicKey string) (*CreateDIDResponse, error) {var body *bytes.Bufferif publicKey != "" {jsonData, \_ := json.Marshal(CreateDIDRequest{PublicKey: publicKey})body = bytes.NewBuffer(jsonData)} else {body = bytes.NewBuffer(nil)}
req, err := http.NewRequest("POST", "https://api.veriglob.com/v1/did", body) if err != nil { return nil, err }
req.Header.Set("Authorization", "Bearer "+apiKey) req.Header.Set("Content-Type", "application/json")
client := &http.Client{} resp, err := client.Do(req) if err != nil { return nil, err } defer resp.Body.Close()
var result CreateDIDResponse json.NewDecoder(resp.Body).Decode(&result) return &result, nil
}
func main() {result, \_ := CreateDID("your-api-key", "")fmt.Printf("DID: %s\n", result.Data.DID)}import requestsfrom typing import Optional
def create_did(api_key: str, public_key: Optional[str] = None) -> dict: """Create a new DID with optional existing public key.""" payload = {} if public_key: payload['public_key'] = public_key
response = requests.post( 'https://api.veriglob.com/v1/did', headers={ 'Authorization': f'Bearer {api_key}', 'Content-Type': 'application/json' }, json=payload if payload else None ) response.raise_for_status() return response.json()
# Usageresult = create_did('your-api-key')print(f"DID: {result['data']['did']}")print(f"Private Key: {result['data']['private_key']}")Response
Section titled “Response”201 Created
{ "status": "success", "message": "DID created successfully", "data": { "did": "did:key:z6MkhsiKBzbNixeXD7mzEzEiuRDFJEKpofi62adE1ZpauNeh", "public_key": "base64-encoded-public-key", "private_key": "base64-encoded-private-key" }}Error Responses
Section titled “Error Responses”| Status | Description |
|---|---|
| 400 | Invalid public key format |
| 401 | Invalid or missing API key |
| 429 | Rate limit exceeded |
Resolve a DID
Section titled “Resolve a DID”Resolves a did:key identifier to extract its public key.
GET /v1/did/{did}Authentication
Section titled “Authentication”Requires BearerAuth or ApiKeyAuth.
Path Parameters
Section titled “Path Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
did | string | Yes | The DID to resolve |
Request Example
Section titled “Request Example”curl -X GET "https://api.veriglob.com/v1/did/did:key:z6MkhsiKBzbNixeXD7mzEzEiuRDFJEKpofi62adE1ZpauNeh" \ -H "Authorization: Bearer your-api-key"interface ResolveDIDResponse { status: string; message: string; data: { did: string; public_key: string; };}
async function resolveDID(apiKey: string, did: string): Promise<ResolveDIDResponse> {const response = await fetch(`https://api.veriglob.com/v1/did/${encodeURIComponent(did)}`,{ headers: { 'Authorization': `Bearer ${apiKey}` } });
if (!response.ok) {throw new Error(`HTTP error! status: ${response.status}`);}return response.json();}
// Usageconst result = await resolveDID('your-api-key', 'did:key:z6Mk...');console.log('Public Key:', result.data.public_key);func ResolveDID(apiKey string, did string) (*ResolveDIDResponse, error) { encodedDID := url.PathEscape(did) req, _ := http.NewRequest("GET", "https://api.veriglob.com/v1/did/"+encodedDID, nil) req.Header.Set("Authorization", "Bearer "+apiKey)
client := &http.Client{} resp, err := client.Do(req) if err != nil { return nil, err } defer resp.Body.Close()
var result ResolveDIDResponse json.NewDecoder(resp.Body).Decode(&result) return &result, nil}from urllib.parse import quote
def resolve_did(api_key: str, did: str) -> dict:"""Resolve a DID to get its public key."""encoded_did = quote(did, safe='')response = requests.get(f'https://api.veriglob.com/v1/did/{encoded_did}',headers={'Authorization': f'Bearer {api_key}'})response.raise_for_status()return response.json()
# Usage
result = resolve_did('your-api-key', 'did:key:z6Mk...')print(f"Public Key: {result['data']['public_key']}")Response
Section titled “Response”200 OK
{ "status": "success", "message": "DID resolved successfully", "data": { "did": "did:key:z6MkhsiKBzbNixeXD7mzEzEiuRDFJEKpofi62adE1ZpauNeh", "public_key": "base64-encoded-public-key" }}Error Responses
Section titled “Error Responses”| Status | Description |
|---|---|
| 400 | Invalid DID format |
| 401 | Invalid or missing API key |
| 404 | DID not found |
| 429 | Rate limit exceeded |
Get DID Document
Section titled “Get DID Document”Returns the full W3C DID Document for a did:key identifier.
GET /v1/did/{did}/documentAuthentication
Section titled “Authentication”Requires BearerAuth or ApiKeyAuth.
Path Parameters
Section titled “Path Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
did | string | Yes | The DID to get the document for |
Request Example
Section titled “Request Example”curl -X GET "https://api.veriglob.com/v1/did/did:key:z6MkhsiKBzbNixeXD7mzEzEiuRDFJEKpofi62adE1ZpauNeh/document" \ -H "Authorization: Bearer your-api-key"interface DIDDocument { '@context': string[]; id: string; verificationMethod: Array<{ id: string; type: string; controller: string; publicKeyMultibase: string; }>; authentication: string[]; assertionMethod: string[];}
async function getDIDDocument(apiKey: string, did: string) {const response = await fetch(`https://api.veriglob.com/v1/did/${encodeURIComponent(did)}/document`,{ headers: { 'Authorization': `Bearer ${apiKey}` } });
if (!response.ok) {throw new Error(`HTTP error! status: ${response.status}`);}return response.json();}
// Usageconst result = await getDIDDocument('your-api-key', 'did:key:z6Mk...');console.log('DID Document:', JSON.stringify(result.data.document, null, 2));func GetDIDDocument(apiKey string, did string) (*GetDIDDocumentResponse, error) { encodedDID := url.PathEscape(did) req, _ := http.NewRequest("GET", "https://api.veriglob.com/v1/did/"+encodedDID+"/document", nil) req.Header.Set("Authorization", "Bearer "+apiKey)
client := &http.Client{} resp, err := client.Do(req) if err != nil { return nil, err } defer resp.Body.Close()
var result GetDIDDocumentResponse json.NewDecoder(resp.Body).Decode(&result) return &result, nil}def get_did_document(api_key: str, did: str) -> dict: """Get the full W3C DID Document for a DID.""" encoded_did = quote(did, safe='') response = requests.get( f'https://api.veriglob.com/v1/did/{encoded_did}/document', headers={'Authorization': f'Bearer {api_key}'} ) response.raise_for_status() return response.json()
# Usage
result = get_did_document('your-api-key', 'did:key:z6Mk...')print(json.dumps(result['data']['document'], indent=2))Response
Section titled “Response”200 OK
{ "status": "success", "message": "DID Document retrieved successfully", "data": { "document": { "@context": [ "https://www.w3.org/ns/did/v1", "https://w3id.org/security/suites/ed25519-2020/v1" ], "id": "did:key:z6MkhsiKBzbNixeXD7mzEzEiuRDFJEKpofi62adE1ZpauNeh", "verificationMethod": [ { "id": "did:key:z6MkhsiKBzbNixeXD7mzEzEiuRDFJEKpofi62adE1ZpauNeh#z6MkhsiKBzbNixeXD7mzEzEiuRDFJEKpofi62adE1ZpauNeh", "type": "Ed25519VerificationKey2020", "controller": "did:key:z6MkhsiKBzbNixeXD7mzEzEiuRDFJEKpofi62adE1ZpauNeh", "publicKeyMultibase": "z6MkhsiKBzbNixeXD7mzEzEiuRDFJEKpofi62adE1ZpauNeh" } ], "authentication": [ "did:key:z6MkhsiKBzbNixeXD7mzEzEiuRDFJEKpofi62adE1ZpauNeh#z6MkhsiKBzbNixeXD7mzEzEiuRDFJEKpofi62adE1ZpauNeh" ], "assertionMethod": [ "did:key:z6MkhsiKBzbNixeXD7mzEzEiuRDFJEKpofi62adE1ZpauNeh#z6MkhsiKBzbNixeXD7mzEzEiuRDFJEKpofi62adE1ZpauNeh" ] } }}Error Responses
Section titled “Error Responses”| Status | Description |
|---|---|
| 400 | Invalid DID format |
| 401 | Invalid or missing API key |
| 404 | DID not found |
| 429 | Rate limit exceeded |
DID Format
Section titled “DID Format”Veriglob uses the did:key method with Ed25519 public keys. The format is:
did:key:z6Mk[base58-encoded-public-key]Example:
did:key:z6MkhsiKBzbNixeXD7mzEzEiuRDFJEKpofi62adE1ZpauNehThe z6Mk prefix indicates:
z- Base58btc multibase encoding6Mk- Ed25519 public key multicodec identifier