{"id":28907310,"url":"https://github.com/edjcase/motoko_did","last_synced_at":"2026-02-11T00:31:15.551Z","repository":{"id":300300987,"uuid":"1005180225","full_name":"edjCase/motoko_did","owner":"edjCase","description":"A library for handling Decentralized Identifiers (DIDs)","archived":false,"fork":false,"pushed_at":"2025-08-01T18:45:10.000Z","size":28,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-01T20:47:10.933Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Motoko","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/edjCase.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-19T20:01:28.000Z","updated_at":"2025-08-01T18:45:14.000Z","dependencies_parsed_at":"2025-08-01T20:33:44.222Z","dependency_job_id":"2aac4fc4-f3e8-43dd-8cf9-cd878917aed7","html_url":"https://github.com/edjCase/motoko_did","commit_stats":null,"previous_names":["edjcase/motoko_did"],"tags_count":0,"template":false,"template_full_name":"edjCase/motoko-library-template","purl":"pkg:github/edjCase/motoko_did","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edjCase%2Fmotoko_did","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edjCase%2Fmotoko_did/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edjCase%2Fmotoko_did/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edjCase%2Fmotoko_did/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/edjCase","download_url":"https://codeload.github.com/edjCase/motoko_did/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edjCase%2Fmotoko_did/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271752125,"owners_count":24814750,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-21T15:31:09.408Z","updated_at":"2026-02-11T00:31:15.540Z","avatar_url":"https://github.com/edjCase.png","language":"Motoko","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Motoko DID\n\n[![MOPS](https://img.shields.io/badge/MOPS-did-blue)](https://mops.one/did)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/edjcase/motoko_did/blob/main/LICENSE)\n\nA comprehensive Motoko implementation for working with Decentralized Identifiers (DIDs) supporting multiple DID methods including did:key, did:plc, and did:web.\n\n## Package\n\n### MOPS\n\n```bash\nmops add did\n```\n\nTo set up MOPS package manager, follow the instructions from the [MOPS Site](https://mops.one)\n\n## What are DIDs?\n\nDecentralized Identifiers (DIDs) are a type of identifier that enables verifiable, decentralized digital identity. A DID refers to any subject (e.g., a person, organization, thing, data model, abstract entity, etc.) as determined by the controller of the DID. Unlike typical, federated identifiers, DIDs have been designed so that they may be decoupled from centralized registries, identity providers, and certificate authorities.\n\nThis library supports three DID methods:\n\n-   **did:key** - Cryptographic key-based identifiers that encode public keys directly\n-   **did:plc** - Public Ledger of Credentials identifiers used in AT Protocol\n-   **did:web** - Web-based identifiers that resolve to DID documents over HTTPS\n\n## Quick Start\n\n### Example 1: Working with did:key\n\n```motoko\nimport DID \"mo:did\";\nimport Debug \"mo:core/Debug\";\n\n// Create a did:key from public key bytes\nlet publicKey = \"\\E3\\B0\\C4\\42\\98\\FC\\1C\\14\\9A\\FB\\F4\\C8\\99\\6F\\B9\\24\\27\\AE\\41\\E4\\64\\9B\\93\\4C\\A4\\95\\99\\1B\\78\\52\\B8\\55\";\nlet didKey : DID.DID = #key({\n  keyType = #ed25519;\n  publicKey = publicKey;\n});\n\n// Convert to text representation\nlet text = DID.toText(didKey);\nDebug.print(text); // \"did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK\"\n```\n\n### Example 2: Working with did:plc\n\n```motoko\nimport DID \"mo:did\";\n\n// Create a did:plc identifier\nlet didPLC : DID.DID = #plc({\n  identifier = \"yk4dd2qkboz2yv6tpubpc6co\";\n});\n\n// Convert to text representation\nlet text = DID.toText(didPLC);\n// Returns: \"did:plc:yk4dd2qkboz2yv6tpubpc6co\"\n```\n\n### Example 3: Working with did:web\n\n```motoko\nimport DID \"mo:did\";\n\nlet didWeb : DID.DID = #web({\n  hostname = \"example.com\";\n  port = null;\n  path = [\"users\", \"alice\"];\n});\n\n// Convert to text representation\nlet text = DID.toText(didWeb);\n// Returns: \"did:web:example.com:users:alice\"\n```\n\n### Example 4: Parsing DIDs from Text\n\n```motoko\nimport DID \"mo:did\";\n\n// Parse any supported DID method\nlet examples = [\n  \"did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK\",\n  \"did:plc:yk4dd2qkboz2yv6tpubpc6co\",\n  \"did:web:example.com:users:alice\"\n];\n\nfor (didText in examples.vals()) {\n  switch (DID.fromText(didText)) {\n    case (#ok(did)) {\n      Debug.print(\"Successfully parsed: \" # DID.toText(did));\n    };\n    case (#err(error)) {\n      Debug.print(\"Failed to parse: \" # error);\n    };\n  };\n};\n```\n\n## API Reference\n\n### Main Types\n\n```motoko\n// Main DID type supporting multiple methods\npublic type DID = {\n  #key : Key.DID;\n  #plc : Plc.DID;\n  #web : Web.DID;\n};\n\n// did:key specific types\npublic type Key.DID = {\n  keyType : KeyType;\n  publicKey : Blob;\n};\n\npublic type KeyType = { #ed25519; #secp256k1; #p256 };\n\n// did:plc specific types\npublic type Plc.DID = {\n  identifier : Text;\n};\n\n// did:web specific types\npublic type Web.DID = {\n  hostname : Text;\n  port : ?Nat16;\n  path : [Text];\n};\n```\n\n### Core Functions\n\n```motoko\n// Convert any DID to text representation\npublic func toText(did : DID) : Text;\n\n// Parse text to DID (auto-detects method)\npublic func fromText(text : Text) : Result.Result\u003cDID, Text\u003e;\n\n// Check if two DIDs are equal\npublic func equal(did1 : DID, did2 : DID) : Bool;\n```\n\n### did:key Functions\n\n```motoko\n// Convert did:key to text with specified multibase encoding\npublic func toText(did : Key.DID, multibase : MultiBase.MultiBase) : Text;\n\n// Convert did:key to text with specified multibase encoding but without the \"did:key:\" prefix\npublic func toTextRaw(did : Key.DID, multibase : MultiBase.MultiBase) : Text;\n\n// Parse did:key from text\npublic func fromText(text : Text) : Result.Result\u003cKey.DID, Text\u003e;\n\n// Create did:key from raw public key\npublic func fromPublicKey(keyType : KeyType, publicKey : Blob) : Result.Result\u003cKey.DID, Text\u003e;\n\n// Check equality\npublic func equal(did1 : Key.DID, did2 : Key.DID) : Bool;\n```\n\n### did:plc Functions\n\n```motoko\n// Convert did:plc to text\npublic func Plc.toText(did : Plc.DID) : Text;\n\n// Parse did:plc from text\npublic func Plc.fromText(text : Text) : Result.Result\u003cPlc.DID, Text\u003e;\n\n// Check equality\npublic func Plc.equal(did1 : Plc.DID, did2 : Plc.DID) : Bool;\n```\n\n### did:web Functions\n\n```motoko\n// Convert did:web to text\npublic func Web.toText(did : Web.DID) : Text;\n\n// Parse did:web from text\npublic func Web.fromText(text : Text) : Result.Result\u003cWeb.DID, Text\u003e;\n\n// Create did:web from hostname and path\npublic func Web.fromHostnameAndPath(hostname : Text, path : [Text]) : Result.Result\u003cWeb.DID, Text\u003e;\n\n// Get HTTPS URL for DID document resolution\npublic func Web.toHttpsUrl(did : Web.DID) : Text;\n\n// Check equality\npublic func Web.equal(did1 : Web.DID, did2 : Web.DID) : Bool;\n```\n\n## Supported Key Types\n\n### did:key\n\n-   **ed25519** - Most common elliptic curve signature system (32 bytes)\n-   **secp256k1** - Bitcoin-style elliptic curve (33 bytes compressed)\n-   **p256** - NIST P-256 elliptic curve (33 bytes compressed)\n\n## DID Method Specifications\n\nThis implementation follows the official DID specifications:\n\n### did:key\n\n-   [W3C DID Key Method Specification](https://w3c-ccg.github.io/did-method-key/)\n-   Uses multicodec for key type encoding and multibase (base58btc) for text representation\n\n### did:plc\n\n-   [AT Protocol PLC Method](https://web.plc.directory/)\n-   Used primarily in the AT Protocol ecosystem for decentralized social networking\n\n### did:web\n\n-   [W3C DID Web Method Specification](https://w3c-ccg.github.io/did-method-web/)\n-   Resolves DID documents over HTTPS at `/.well-known/did.json`\n\n## Dependencies\n\nThis library depends on:\n\n-   `mo:core` - Core Motoko utilities\n-   `mo:multiformats` - Multicodec and multibase encoding\n-   `mo:url-kit` - URL and host parsing utilities\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedjcase%2Fmotoko_did","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedjcase%2Fmotoko_did","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedjcase%2Fmotoko_did/lists"}