Castor is a powerful and flexible library for working with DIDs. Whether you are building a decentralised application or a more traditional system requiring secure and private identity management, Castor provides the tools and features you need to easily create, manage, and resolve DIDs.

Hierarchy

  • Castor

Implements

Constructors

Properties

apollo: Domain.Apollo
resolvers: DIDResolver[]

Methods

  • Creates a DID for a peer (a device or server that acts as a DID subject) using given key agreement and authentication key pairs and a list of services.

    Parameters

    Returns Promise<DID>

    Example

    This function creates new peer DID, using a given key agreement, authentication key pairs, and a list of services. It may throw an error if the key pairs or services are invalid.

    const peerDid = await castor.createPeerDID(
    [keyPairFromCurveEd25519, keyPairFromCurveX25519],
    [exampleService]
    );

    Async

  • Creates a DID for a prism (a device or server that acts as a DID owner and controller) using a given master public key and list of services.

    Parameters

    Returns Promise<DID>

    Example

    This function creates a new prism DID, using a given master Public Key and a list of Services. The Public Key may be an individual Key or a KeyPair It may throw an error if the master Public Key or Services are invalid.

    const exampleServiceEndpoint = new Domain.Service("didcomm", ["DIDCommMessaging"], {
    uri: "https://example.com/endpoint",
    accept: ["didcomm/v2"],
    routingKeys: ["did:example:somemediator#somekey"],
    });
    const prismDid = await castor.createPrismDID(
    keyPairFromCurveSecp256K1.publicKey,
    [exampleServiceEndpoint]
    );

    Async

  • Parses a string representation of a Decentralized Identifier (DID) into a DID object.

    Parameters

    • did: string

    Returns DID

    Example

    This function takes a string representation of a DID and returns an instance of Domain.DID. It may throw an error if the string is not a valid DID.

    const parsedPrismDid = castor.parseDID(
    "did:prism:b6c0c33d701ac1b9a262a14454d1bbde3d127d697a76950963c5fd930605:Cj8KPRI7CgdtYXN0ZXIwEAFKLgoJc2VmsxEiECSTjyV7sUfCr_ArpN9rvCwR9fRMAhcsr_S7ZRiJk4p5k"
    );
  • Asynchronously resolves a DID to its corresponding DID Document. This function may throw an error if the DID is invalid or the document cannot be retrieved. Note: only prism and peer DID methods are currently supported!

    Parameters

    • did: string

    Returns Promise<DIDDocument>

    Example

    This function asynchronously resolves a DID to its corresponding DID Document. It may throw an error if the DID is invalid or the document is unretrievable.

    const didDocument = await castor.resolveDID("did:prism:123456")
    

    Async

  • Verifies the authenticity of a signature using the corresponding DID Document, challenge, and signature data. This function returns a boolean value indicating whether the signature is valid or not. This function may throw an error if the DID Document or signature data are invalid.

    Parameters

    • did: DID
    • challenge: Uint8Array
    • signature: Uint8Array

    Returns Promise<boolean>

    Example

    This function verifies the authenticity of a signature using given DID, challenge, and signature data. It returns a boolean value indicating whether the signature is valid or not. It may throw an error if the DID or signature data are invalid.

    const message = "data to sign";
    const messageBytes = new TextEncoder().encode(message);
    const signatureSecp256K1 = apollo.signStringMessage(keyPairSecp256K1.privateKey, message);

    const did = castor.parseDID("did:prism:123456");
    const challenge = messageBytes
    const signature = signatureSecp256K1.value;

    const isValid = castor.verifySignature(
    castor.parseDID("did:prism:123456"),
    challenge, // Uint8Array
    signature // Uint8Array
    );

    Async