@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
- createPeerDID
- createPrismDID
- extractVerificationMethods
- getEcnumbasis
- parseDID
- resolveDID
- verifySignature
Constructors
constructor
• new Castor(apollo
, extraResolvers?
): Castor
Creates an instance of Castor as soon as a valid cryptographic interface is provided (Apollo).
Parameters
Name | Type | Default value |
---|---|---|
apollo | Apollo | undefined |
extraResolvers | ExtraResolver [] | [] |
Returns
Defined in
Properties
apollo
• Private
apollo: Apollo
Defined in
resolvers
• Private
resolvers: DIDResolver
[]
Defined in
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
Name | Type |
---|---|
publicKeys | PublicKey [] |
services | Service [] |
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
Defined in
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
Name | Type | Default value |
---|---|---|
key | PublicKey | KeyPair | undefined |
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
Defined in
extractVerificationMethods
▸ extractVerificationMethods(coreProperties
): VerificationMethod
[]
Extracts the verificationMethods from an array of CoreProperties inside a DID Document
Parameters
Name | Type |
---|---|
coreProperties | DIDDocumentCoreProperty [] |
Returns
Defined in
getEcnumbasis
▸ getEcnumbasis(did
, publicKey
): string
Returns ecnumbasis from a valid DID and its related publicKey
Parameters
Name | Type |
---|---|
did | DID |
publicKey | PublicKey |
Returns
string
Implementation of
Defined in
parseDID
▸ parseDID(did
): DID
Parses a string representation of a Decentralized Identifier (DID) into a DID object.
Parameters
Name | Type |
---|---|
did | string |
Returns
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
Defined in
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
Name | Type |
---|---|
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
Implementation of
Defined in
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
Name | Type |
---|---|
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