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 the authorization property to be included in a DWN message.

    Parameters

    • input: {
          delegatedGrant?: RecordsWriteMessage;
          descriptor: Descriptor;
          permissionGrantId?: string;
          protocolRole?: string;
          signer: Signer;
      }
      • Optional delegatedGrant?: RecordsWriteMessage
      • descriptor: Descriptor
      • Optional permissionGrantId?: string
      • Optional protocolRole?: string
      • signer: Signer

    Returns Promise<AuthorizationModel>

    used as an authorization property.

  • 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
    • Optional additionalPayloadProperties: {
          delegatedGrantId?: string;
          permissionGrantId?: string;
          protocolRole?: string;
      }
      • Optional delegatedGrantId?: string
      • Optional permissionGrantId?: string
      • Optional protocolRole?: 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

    Throws

    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.