Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .yarn/install-state.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion license-header.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2018-2023, Built on KILT.
* Copyright (c) 2018-2024, Built on KILT.
*
* This source code is licensed under the BSD 4-Clause "Original" license
* found in the LICENSE file in the root directory of this source tree.
Expand Down
5 changes: 3 additions & 2 deletions src/messaging/CredentialApiMessageType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
isIConfirmPayment,
} from '../utils/index.js'
import * as MessageError from './Error.js'
import { SDKErrors as SDKErrorMessage } from '@kiltprotocol/sdk-js'
import type { IMessage, CredentialApiMessageBody } from '../types/index.js'
import { verifyMessageEnvelope } from './MessageEnvelope.js'

Expand Down Expand Up @@ -52,7 +53,7 @@ export function assertKnownMessageBody(message: IMessage): void {
Attestation.verifyDataStructure(message.body.content.attestation)
} else if (isRejectAttestation(message)) {
if (!isHex(message.body.content)) {
throw new MessageError.HashMalformedError()
throw new SDKErrorMessage.HashMalformedError()
}
} else if (isIRequestCredential(message)) {
message.body.content.cTypes.forEach(({ cTypeHash, trustedAttesters, requiredProperties }) => {
Expand All @@ -66,7 +67,7 @@ export function assertKnownMessageBody(message: IMessage): void {
message.body.content.forEach((presentation) => {
Credential.verifyDataStructure(presentation)
if (!Did.isDidSignature(presentation.claimerSignature)) {
throw new MessageError.SignatureMalformedError()
throw new SDKErrorMessage.SignatureMalformedError()
}
})
} else if (isIRequestPayment(message) || isIConfirmPayment(message)) {
Expand Down
25 changes: 10 additions & 15 deletions src/messaging/Error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,15 @@
* found in the LICENSE file in the root directory of this source tree.
*/

export declare class MessageError extends Error {}
export declare class HashMalformedError extends MessageError {
constructor(hash?: string, type?: string)
}
import { SDKErrors } from '@kiltprotocol/sdk-js'

export declare class SignatureMalformedError extends MessageError {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this?

export declare class UnknownMessageBodyTypeError extends MessageError {}
export declare class DecodingMessageError extends MessageError {}
export declare class CTypeUnknownPropertiesError extends MessageError {}
export declare class InvalidDidFormatError extends MessageError {}
export declare class KeyError extends MessageError {}
export declare class DidError extends MessageError {
constructor(context?: string, type?: string)
}
export declare class IdentityMismatchError extends MessageError {
constructor(context?: string, type?: string)
export class UnknownMessageBodyTypeError extends SDKErrors.SDKError {}
export class DecodingMessageError extends SDKErrors.SDKError {}
export class CTypeUnknownPropertiesError extends SDKErrors.SDKError {}
export class KeyError extends SDKErrors.SDKError {}
export class IdentityMismatchError extends SDKErrors.SDKError {
constructor(context?: string, type?: string) {
super(`Identity mismatch${context ? ` in context: ${context}` : ''}${type ? ` of type ${type}` : ''}`)
this.name = 'IdentityMismatchError'
}
}
13 changes: 3 additions & 10 deletions src/messaging/Message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,10 @@

/* eslint-disable @typescript-eslint/ban-ts-comment */

/**
* Copyright (c) 2018-2024, BOTLabs GmbH.
*
* This source code is licensed under the BSD 4-Clause "Original" license
* found in the LICENSE file in the root directory of this source tree.
*/

import { u8aToHex } from '@polkadot/util'
import { Attestation, CType, Claim, Credential, Quote } from '@kiltprotocol/core'
import * as Did from '@kiltprotocol/did'
import { init } from '@kiltprotocol/sdk-js'
import { init, SDKErrors as SDKErrorMessage } from '@kiltprotocol/sdk-js'
import * as MessageError from './Error'
import { Crypto } from '@kiltprotocol/utils'
import type {
Expand Down Expand Up @@ -714,7 +707,7 @@ describe('Error checking / Verification', () => {
it('message envelope verifier should throw errors on faulty envelopes', () => {
// @ts-ignore
messageSubmitTerms.sender = 'this is not a sender did'
expect(() => verifyMessageEnvelope(messageSubmitTerms)).toThrowError(MessageError.InvalidDidFormatError)
expect(() => verifyMessageEnvelope(messageSubmitTerms)).toThrowError(SDKErrorMessage.InvalidDidFormatError)
// @ts-ignore
messageRequestAttestationForClaim.messageId = 12
expect(() => verifyMessageEnvelope(messageRequestAttestationForClaim)).toThrowError(TypeError)
Expand All @@ -730,7 +723,7 @@ describe('Error checking / Verification', () => {
})
it('message body verifier should throw errors on faulty bodies', () => {
submitTermsBody.content.delegationId = 'this is not a delegation id'
expect(() => assertKnownMessageBody(messageSubmitTerms)).toThrowError(MessageError.HashMalformedError)
expect(() => assertKnownMessageBody(messageSubmitTerms)).toThrowError(SDKErrorMessage.HashMalformedError)

submitCredentialBody.content[0].claimerSignature = {
signature: 'this is not the claimers signature',
Expand Down
3 changes: 2 additions & 1 deletion src/messaging/MessageEnvelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { DecryptCallback, DidResolveKey, DidResourceUri, EncryptCallback } from '@kiltprotocol/types'
import * as Did from '@kiltprotocol/did'
import * as MessageError from './Error.js'
import { SDKErrors as SDKErrorMessage } from '@kiltprotocol/sdk-js'
import { hexToU8a, stringToU8a, u8aToHex, u8aToString } from '@polkadot/util'

import type { IEncryptedMessage, IEncryptedMessageContents, IMessage } from '../types/index.js'
Expand Down Expand Up @@ -59,7 +60,7 @@ export async function decrypt(

const { fragment } = Did.parse(receiverKeyUri)
if (!fragment) {
throw new MessageError.DidError(`No fragment for the receiver key ID "${receiverKeyUri}"`)
throw new SDKErrorMessage.DidError(`No fragment for the receiver key ID "${receiverKeyUri}"`)
}

let data: Uint8Array
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4673,4 +4673,4 @@ zip-stream@^4.1.0:
dependencies:
archiver-utils "^3.0.4"
compress-commons "^4.1.2"
readable-stream "^3.6.0"
readable-stream "^3.6.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this missing?

Maybe in your settings you don't include line break at the bottom.