The DidIon class provides an implementation of the did:ion DID method.

Features:

  • DID Creation: Create new did:ion DIDs.
  • DID Key Management: Instantiate a DID object from an existing key in a Key Management System (KMS). If supported by the KMS, a DID's key can be exported to a portable DID format.
  • DID Resolution: Resolve a did:ion to its corresponding DID Document stored in the Sidetree network.
  • Signature Operations: Sign and verify messages using keys associated with a DID.

See

Example

// DID Creation
const did = await DidIon.create();

// DID Creation with a KMS
const keyManager = new LocalKeyManager();
const did = await DidIon.create({ keyManager });

// DID Resolution
const resolutionResult = await DidIon.resolve({ did: did.uri });

// Signature Operations
const signer = await did.getSigner();
const signature = await signer.sign({ data: new TextEncoder().encode('Message') });
const isValid = await signer.verify({ data: new TextEncoder().encode('Message'), signature });

// Key Management

// Instantiate a DID object for a published DID with existing keys in a KMS
const did = await DidIon.fromKeyManager({
didUri: 'did:ion:EiAzB7K-xDIKc1csXo5HX2eNBoemK9feNhL3cKwfukYOug',
keyManager
});

// Convert a DID object to a portable format
const portableDid = await DidIon.toKeys({ did });

Hierarchy (view full)

Constructors

Properties

methodName: string = 'ion'

Name of the DID method, as defined in the DID ION specification.

Methods

  • Creates a new DID using the did:ion method formed from a newly generated key.

    Notes:

    • If no options are given, by default a new Ed25519 key will be generated.

    Type Parameters

    Parameters

    • params: {
          keyManager?: TKms;
          options?: DidIonCreateOptions<TKms>;
      } = {}

      The parameters for the create operation.

      • Optional keyManager?: TKms

        Optionally specify a Key Management System (KMS) used to generate keys and sign data.

      • Optional options?: DidIonCreateOptions<TKms>

        Optional parameters that can be specified when creating a new DID.

    Returns Promise<BearerDid>

    A Promise resolving to a BearerDid object representing the new DID.

    Example

    // DID Creation
    const did = await DidIon.create();

    // DID Creation with a KMS
    const keyManager = new LocalKeyManager();
    const did = await DidIon.create({ keyManager });
  • Given the W3C DID Document of a did:ion DID, return the verification method that will be used for signing messages and credentials. If given, the methodId parameter is used to select the verification method. If not given, the first verification method in the authentication property in the DID Document is used.

    Parameters

    • params: {
          didDocument: DidDocument;
          methodId?: string;
      }

      The parameters for the getSigningMethod operation.

      • didDocument: DidDocument

        DID Document to get the verification method from.

      • Optional methodId?: string

        ID of the verification method to use for signing.

    Returns Promise<DidVerificationMethod>

    Verification method to use for signing.

  • Publishes a DID to a Sidetree node, making it publicly discoverable and resolvable.

    This method handles the publication of a DID Document associated with a did:ion DID to a Sidetree node.

    Parameters

    • params: {
          did: BearerDid;
          gatewayUri?: string;
      }

      The parameters for the publish operation.

      • did: BearerDid

        The BearerDid object representing the DID to be published.

      • Optional gatewayUri?: string

        Optional. The URI of a server involved in executing DID method operations. In the context of publishing, the endpoint is expected to be a Sidetree node. If not specified, a default node is used.

    Returns Promise<DidRegistrationResult>

    A Promise resolving to a boolean indicating whether the publication was successful.

    Remarks

    • This method is typically invoked automatically during the creation of a new DID unless the publish option is set to false.
    • For existing, unpublished DIDs, it can be used to publish the DID Document to a Sidetree node.
    • The method relies on the specified Sidetree node to interface with the network.

    Example

    // Generate a new DID and keys but explicitly disable publishing.
    const did = await DidIon.create({ options: { publish: false } });
    // Publish the DID to the Sidetree network.
    const isPublished = await DidIon.publish({ did });
    // `isPublished` is true if the DID was successfully published.
  • Resolves a did:ion identifier to its corresponding DID document.

    This method performs the resolution of a did:ion DID, retrieving its DID Document from the Sidetree-based DID overlay network. The process involves querying a Sidetree node to retrieve the DID Document that corresponds to the given DID identifier.

    Parameters

    • didUri: string

      The DID to be resolved.

    • options: DidResolutionOptions = {}

      Optional parameters for resolving the DID. Unused by this DID method.

    Returns Promise<DidResolutionResult>

    A Promise resolving to a DidResolutionResult object representing the result of the resolution.

    Remarks

    • If a gatewayUri option is not specified, a default node is used to access the Sidetree network.
    • It decodes the DID identifier and retrieves the associated DID Document and metadata.
    • In case of resolution failure, appropriate error information is returned.

    Example

    const resolutionResult = await DidIon.resolve('did:ion:example');