A class containing utility methods for working with DWN messages.

Constructors

Methods

  • Compares message CID in lexicographical order according to the spec.

    Returns Promise<number>

    1 if a is larger than b; -1 if a is smaller/older than b; 0 otherwise (same message)

  • Compares the messageTimestamp of the given messages with a fallback to message CID according to the spec.

    Returns Promise<number>

    1 if a is larger/newer than b; -1 if a is smaller/older than b; 0 otherwise (same age)

  • Creates a generic signature from the given DWN message descriptor by including descriptorCid as the required property in the signature payload. NOTE: there is an opportunity to consolidate RecordsWrite.createSignerSignature() wth this method

    Parameters

    • descriptor: Descriptor
    • signer: Signer
    • OptionaladditionalPayloadProperties: {
          delegatedGrantId?: string;
          permissionGrantId?: string;
          protocolRole?: string;
      }
      • OptionaldelegatedGrantId?: string
      • OptionalpermissionGrantId?: string
      • OptionalprotocolRole?: string

    Returns Promise<GeneralJws>

  • Gets the DID of the signer of the given message, returns undefined if message is not signed.

    Parameters

    Returns undefined | string

  • Validates the given message against the corresponding JSON schema.

    Parameters

    • rawMessage: any

    Returns void

    if fails validation.

  • Validates the structural integrity of the message signature given:

    1. The message signature must contain exactly 1 signature
    2. Passes JSON schema validation
    3. The descriptorCid property matches the CID of the message descriptor NOTE: signature is NOT verified.

    Parameters

    • messageSignature: GeneralJws
    • messageDescriptor: Descriptor
    • payloadJsonSchemaKey: string = 'GenericSignaturePayload'

      The key to look up the JSON schema referenced in compile-validators.js and perform payload schema validation on.

    Returns Promise<GenericSignaturePayload>

    the parsed JSON payload object if validation succeeds.