Skip to main content

@atala/prism-wallet-sdk / Exports / Castor

Class: Castor

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.

Castor

Implements

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new Castor(apollo, extraResolvers?): Castor

Creates an instance of Castor as soon as a valid cryptographic interface is provided (Apollo).

Parameters

NameTypeDefault value
apolloApolloundefined
extraResolversExtraResolver[][]

Returns

Castor

Defined in

src/castor/Castor.ts:66

Properties

apollo

Private apollo: Apollo

Defined in

src/castor/Castor.ts:56


resolvers

Private resolvers: DIDResolver[]

Defined in

src/castor/Castor.ts:57

Methods

createPeerDID

createPeerDID(publicKeys, services): Promise<DID>

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

NameType
publicKeysPublicKey[]
servicesService[]

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

Implementation of

Castor.createPeerDID

Defined in

src/castor/Castor.ts:207


createPrismDID

createPrismDID(key, services?, issuingKeys?): Promise<DID>

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

NameTypeDefault value
keyPublicKey | KeyPairundefined
services?Service[]undefined
issuingKeys(PublicKey | KeyPair)[][]

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

Implementation of

Castor.createPrismDID

Defined in

src/castor/Castor.ts:121


extractVerificationMethods

extractVerificationMethods(coreProperties): VerificationMethod[]

Extracts the verificationMethods from an array of CoreProperties inside a DID Document

Parameters

NameType
corePropertiesDIDDocumentCoreProperty[]

Returns

VerificationMethod[]

Defined in

src/castor/Castor.ts:250


getEcnumbasis

getEcnumbasis(did, publicKey): string

Returns ecnumbasis from a valid DID and its related publicKey

Parameters

NameType
didDID
publicKeyPublicKey

Returns

string

Implementation of

Castor.getEcnumbasis

Defined in

src/castor/Castor.ts:409


parseDID

parseDID(did): DID

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

Parameters

NameType
didstring

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"
);

Implementation of

Castor.parseDID

Defined in

src/castor/Castor.ts:91


resolveDID

resolveDID(did): Promise<DIDDocument>

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

NameType
didstring

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

Implementation of

Castor.resolveDID

Defined in

src/castor/Castor.ts:232


verifySignature

verifySignature(did, challenge, signature): Promise<boolean>

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

NameType
didDID
challengeUint8Array
signatureUint8Array

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

Implementation of

Castor.verifySignature

Defined in

src/castor/Castor.ts:294