Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

account-api: add extra syntax validation #541

Merged
merged 6 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
50 changes: 25 additions & 25 deletions docs/account/index.html

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions libs/types/src/dtos/account/accounts.request.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@ export class RetireMsaRequestDto extends RetireMsaPayloadResponseDto {
example:
'0x065d733ca151c9e65b78f2ba77348224d31647e6913c44ad2765c6e8ba06f834dc21d8182447d01c30f84a41d90a8f2e58001d825c6f0d61b0afe89f984eec85',
})
@IsSignature({
message: 'signature should be a 64 (or 65 if it is MultiSignature type) bytes value in hex format!',
})
@IsSignature()
signature: HexString;

@ApiProperty({
type: String,
description: 'AccountId in hex or SS58 format',
example: '1LSLqpLWXo7A7xuiRdu6AQPnBPNJHoQSu8DBsUYJgsNEJ4N',
})
@IsAccountIdOrAddress({ message: 'Account id should be a 32 bytes value in hex or SS58 format!' })
@IsAccountIdOrAddress()
accountId: string;
}

Expand Down
10 changes: 5 additions & 5 deletions libs/types/src/dtos/account/accounts.response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,25 @@ export class MsaIdResponseDto {
export class RetireMsaPayloadResponseDto {
@ApiProperty({
type: String,
description: 'encodedExtrinsic to be added!',
description: 'Hex-encoded representation of the "RetireMsa" extrinsic',
example: '0x1234',
})
@IsHexValue({ minLength: 2, message: 'encodedExtrinsic should be in hex format!' })
@IsHexValue({ minLength: 2 })
encodedExtrinsic: HexString;

@ApiProperty({
type: String,
description: 'payload to be signed!',
description: 'payload to be signed',
example: '0x1234',
})
@IsHexValue({ minLength: 2, message: 'payloadToSign should be in hex format!' })
@IsHexValue({ minLength: 2 })
payloadToSign: HexString;

@ApiProperty({
type: String,
description: 'AccountId in hex or SS58 format',
example: '1LSLqpLWXo7A7xuiRdu6AQPnBPNJHoQSu8DBsUYJgsNEJ4N',
})
@IsAccountIdOrAddress({ message: 'Account id should be a 32 bytes value in hex or SS58 format!' })
@IsAccountIdOrAddress()
accountId: string;
}
8 changes: 4 additions & 4 deletions libs/types/src/dtos/account/delegation.request.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import { IsOptional } from 'class-validator';
import { IsMsaId } from '#utils/decorators/is-msa-id.decorator';

export class ProviderDelegationRequestDto {
@ApiProperty({ description: 'Msa Id representing the target of this request', type: String, example: '3' })
@IsMsaId({ message: 'msaId should be a valid positive number' })
@ApiProperty({ description: 'MSA Id of the user requesting the delegation', type: String, example: '3' })
@IsMsaId()
msaId: string;

@ApiPropertyOptional({
description: 'provider MsaId representing the target of this request',
description: 'MSA Id of the provider to whom the requesting user wishes to delegate',
type: String,
example: '1',
})
@IsOptional()
@IsMsaId({ message: 'providerId should be a valid positive number' })
@IsMsaId()
providerId?: string;
}

Expand Down
30 changes: 14 additions & 16 deletions libs/types/src/dtos/account/graphs.request.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ export class ItemActionDto {

@ApiProperty({
type: String,
description: 'encodedPayload to be added!',
description: 'encodedPayload to be added',
example: '0x1234',
})
@ValidateIf((o) => o.type === ItemActionType.ADD_ITEM)
@IsHexValue({ minLength: 2, maxLength: 1024, message: 'encodedPayload should be in hex format!' })
@IsHexValue({ minLength: 2, maxLength: 2048 })
encodedPayload?: string;

@ApiProperty({
Expand All @@ -41,7 +41,7 @@ export class ItemActionDto {
example: '0',
})
@ValidateIf((o) => o.type === ItemActionType.DELETE_ITEM)
@IsIntValue({ minValue: 0, message: 'index should be zero or positive!' })
@IsIntValue({ minValue: 0 })
index?: number;
}

Expand All @@ -51,19 +51,19 @@ export class ItemizedSignaturePayloadDto {
description: 'schemaId related to the payload',
example: '1',
})
@IsSchemaId({ message: 'schemaId should be positive number' })
@IsSchemaId()
schemaId: number;

@ApiProperty({
type: 'number',
description: 'targetHash related to the stateful storage',
example: '1234',
})
@IsIntValue({ minValue: 0, maxValue: 4_294_967_296, message: 'targetHash should be a positive number!' })
@IsIntValue({ minValue: 0, maxValue: 4_294_967_296 })
targetHash: number;

@ApiProperty({ type: 'number', description: 'expiration block number for this payload', example: '1' })
@IsIntValue({ minValue: 0, maxValue: 4_294_967_296, message: 'expiration should be a positive number!' })
@IsIntValue({ minValue: 0, maxValue: 4_294_967_296 })
expiration: number;

@ApiProperty({
Expand All @@ -87,7 +87,7 @@ export class AddNewPublicKeyAgreementRequestDto {
description: 'AccountId in hex or SS58 format',
example: '1LSLqpLWXo7A7xuiRdu6AQPnBPNJHoQSu8DBsUYJgsNEJ4N',
})
@IsAccountIdOrAddress({ message: 'Account id should be a 32 bytes value in hex or SS58 format!' })
@IsAccountIdOrAddress()
accountId: string;

@ApiProperty({
Expand All @@ -104,9 +104,7 @@ export class AddNewPublicKeyAgreementRequestDto {
example:
'0x065d733ca151c9e65b78f2ba77348224d31647e6913c44ad2765c6e8ba06f834dc21d8182447d01c30f84a41d90a8f2e58001d825c6f0d61b0afe89f984eec85',
})
@IsSignature({
message: 'Proof should be a 64 (or 65 if it is MultiSignature type) bytes value in hex format!',
})
@IsSignature()
proof: HexString;
}

Expand All @@ -119,10 +117,10 @@ export class AddNewPublicKeyAgreementPayloadRequest {

@ApiProperty({
type: String,
description: 'encodedPayload to be added!',
description: 'encodedPayload to be added',
example: '0x1234',
})
@IsHexValue({ minLength: 2, maxLength: 1024, message: 'encodedPayload should be in hex format!' })
@IsHexValue({ minLength: 2, maxLength: 2048 })
encodedPayload: HexString;
}

Expand All @@ -133,15 +131,15 @@ export type PublicKeyAgreementRequestDto = AddNewPublicKeyAgreementRequestDto &
export type PublishPublicKeyAgreementRequestDto = PublicKeyAgreementRequestDto;

export class PublicKeyAgreementsKeyPayload {
@ApiProperty({ description: 'Msa Id representing the target of this request', type: String, example: '3' })
@IsMsaId({ message: 'msaId should be a valid positive number' })
@ApiProperty({ description: 'MSA Id representing the target of this request', type: String, example: '3' })
@IsMsaId()
msaId: string;

@ApiProperty({
type: String,
description: 'Public key should be a 32 bytes value in hex format!',
description: 'New public key to be added to the account (32-byte value in hex format)',
example: '0x0ed2f8c714efcac51ca2325cfe95637e5e0b898ae397aa365978b7348a717d0b',
})
@IsHexValue({ minLength: 64, maxLength: 64, message: 'Public key should be a 32 bytes value in hex format!' })
@IsHexValue({ minLength: 64, maxLength: 64 })
newKey: HexString;
}
14 changes: 6 additions & 8 deletions libs/types/src/dtos/account/handles.request.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ import { IsSignature } from '#utils/decorators/is-signature.decorator';
class HandlePayloadDto {
@ApiProperty({
type: 'string',
description: 'base handle in the request!',
description: 'base handle in the request',
example: 'handle',
})
@MinLength(3)
@IsString()
baseHandle: string;

@ApiProperty({ type: 'number', description: 'expiration block number for this payload', example: '1' })
@IsIntValue({ minValue: 0, maxValue: 4_294_967_296, message: 'expiration should be a positive number!' })
@IsIntValue({ minValue: 0, maxValue: 4_294_967_296 })
expiration: number;
}

export class HandleRequestDto {
@ApiProperty({
type: String,
description: 'AccountId in hex or SS58 format!',
description: 'AccountId in hex or SS58 format',
example: '1LSLqpLWXo7A7xuiRdu6AQPnBPNJHoQSu8DBsUYJgsNEJ4N',
})
@IsAccountIdOrAddress({ message: 'Account id should be a 32 bytes value in hex or SS58 format!' })
@IsAccountIdOrAddress()
accountId: string;

@ApiProperty()
Expand All @@ -45,9 +45,7 @@ export class HandleRequestDto {
example:
'0x065d733ca151c9e65b78f2ba77348224d31647e6913c44ad2765c6e8ba06f834dc21d8182447d01c30f84a41d90a8f2e58001d825c6f0d61b0afe89f984eec85',
})
@IsSignature({
message: 'Proof should be a 64 (or 65 if it is MultiSignature type) bytes value in hex format!',
})
@IsSignature()
proof: HexString;
}

Expand All @@ -63,7 +61,7 @@ export class ChangeHandlePayloadRequest {
type: String,
example: '0x012345',
})
@IsHexValue({ minLength: 2, message: 'encodedPayload should be in hex format!' })
@IsHexValue({ minLength: 2 })
encodedPayload: HexString;
}

Expand Down
18 changes: 7 additions & 11 deletions libs/types/src/dtos/account/keys.request.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ import { Type } from 'class-transformer';
import { IsSignature } from '#utils/decorators/is-signature.decorator';

class KeysRequestPayloadDto {
@ApiProperty({ description: 'Msa Id representing the target of this request', type: String, example: '3' })
@IsMsaId({ message: 'msaId should be a valid positive number' })
@ApiProperty({ description: 'MSA Id of the user requesting the new key', type: String, example: '3' })
@IsMsaId()
msaId: string;

@ApiProperty({ type: 'number', description: 'expiration block number for this payload', example: '1' })
@IsIntValue({ minValue: 0, maxValue: 4_294_967_296, message: 'expiration should be a positive number!' })
@IsIntValue({ minValue: 0, maxValue: 4_294_967_296 })
expiration: number;

@ApiProperty({
type: String,
description: 'newPublicKey in hex format',
example: '0x0ed2f8c714efcac51ca2325cfe95637e5e0b898ae397aa365978b7348a717d0b',
})
@IsHexValue({ minLength: 64, maxLength: 64, message: 'newPublicKey should be a 32 bytes value in hex format!' })
@IsHexValue({ minLength: 64, maxLength: 64 })
newPublicKey: string;
}

Expand All @@ -34,7 +34,7 @@ export class KeysRequestDto {
type: String,
example: '1LSLqpLWXo7A7xuiRdu6AQPnBPNJHoQSu8DBsUYJgsNEJ4N',
})
@IsAccountIdOrAddress({ message: 'msaOwnerAddress should be a 32 bytes value in hex or SS58 format!' })
@IsAccountIdOrAddress()
msaOwnerAddress: string;

@ApiProperty({
Expand All @@ -43,9 +43,7 @@ export class KeysRequestDto {
example:
'0x065d733ca151c9e65b78f2ba77348224d31647e6913c44ad2765c6e8ba06f834dc21d8182447d01c30f84a41d90a8f2e58001d825c6f0d61b0afe89f984eec85',
})
@IsSignature({
message: 'msaOwnerSignature should be a 64 (or 65 if it is MultiSignature type) bytes value in hex format!',
})
@IsSignature()
msaOwnerSignature: HexString;

@ApiProperty({
Expand All @@ -54,9 +52,7 @@ export class KeysRequestDto {
example:
'0x065d733ca151c9e65b78f2ba77348224d31647e6913c44ad2765c6e8ba06f834dc21d8182447d01c30f84a41d90a8f2e58001d825c6f0d61b0afe89f984eec85',
})
@IsSignature({
message: 'newKeyOwnerSignature should be a 64 (or 65 if it is MultiSignature type) bytes value in hex format!',
})
@IsSignature()
newKeyOwnerSignature: HexString;

@ApiProperty()
Expand Down
22 changes: 12 additions & 10 deletions libs/types/src/dtos/account/revokeDelegation.request.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,31 @@ export class RevokeDelegationPayloadResponseDto {
description: 'AccountId in hex or SS58 format',
example: '1LSLqpLWXo7A7xuiRdu6AQPnBPNJHoQSu8DBsUYJgsNEJ4N',
})
@IsAccountIdOrAddress({ message: 'Account id should be a 32 bytes value in hex or SS58 format!' })
@IsAccountIdOrAddress()
accountId: string;

@ApiProperty({ description: 'provider MsaId representing the target of this request', type: String, example: '3' })
@IsMsaId({ message: 'providerId should be a valid positive number' })
@ApiProperty({
description: 'MSA Id of the provider to whom the requesting user wishes to delegate',
type: String,
example: '3',
})
@IsMsaId()
providerId: string;

@ApiProperty({
type: String,
description: 'encodedExtrinsic to be added!',
description: 'Hex-encoded representation of the "revokeDelegation" extrinsic',
example: '0x1234',
})
@IsHexValue({ minLength: 2, message: 'encodedExtrinsic should be in hex format!' })
@IsHexValue({ minLength: 2 })
encodedExtrinsic: HexString;

@ApiProperty({
type: String,
description: 'payload to be signed!',
description: 'payload to be signed',
example: '0x1234',
})
@IsHexValue({ minLength: 2, message: 'payloadToSign should be in hex format!' })
@IsHexValue({ minLength: 2 })
payloadToSign: HexString;
}

Expand All @@ -44,9 +48,7 @@ export class RevokeDelegationPayloadRequestDto extends RevokeDelegationPayloadRe
example:
'0x065d733ca151c9e65b78f2ba77348224d31647e6913c44ad2765c6e8ba06f834dc21d8182447d01c30f84a41d90a8f2e58001d825c6f0d61b0afe89f984eec85',
})
@IsSignature({
message: 'signature should be a 64 (or 65 if it is MultiSignature type) bytes value in hex format!',
})
@IsSignature()
signature: HexString;
}

Expand Down
8 changes: 3 additions & 5 deletions libs/types/src/dtos/account/wallet.login.request.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ export class SiwsPayloadDto implements SiwsPayload {
example:
'0x64f8dd8846ba72cbb1954761ec4b2e44b886abb4b4ef7455b869355f17b4ce4a601ad26eabc57a682244a97bc9a2001b59469ae76fea105b724e988967d4928d',
})
@IsSignature({
message: 'signature should be a 64 (or 65 if it is MultiSignature type) bytes value in hex format!',
})
@IsSignature()
signature: string | HexString;
}
export class SignInResponseDto implements SignInResponse {
Expand Down Expand Up @@ -68,10 +66,10 @@ export class EncodedExtrinsicDto implements EncodedExtrinsic {

@ApiProperty({
type: String,
description: 'Scale encoded extrinsic',
description: 'Hex-encoded representation of the extrinsic',
example: '0x00112233',
})
@IsHexValue({ minLength: 2, message: 'encodedExtrinsic should be in valid hex format!' })
@IsHexValue({ minLength: 2 })
encodedExtrinsic: string | HexString;
}

Expand Down
6 changes: 3 additions & 3 deletions libs/types/src/dtos/common/params.dto.ts
JoeCap08055 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { IsAccountIdOrAddress } from '#utils/decorators/is-account-id-address.de

export class MsaIdDto {
@ApiProperty({ name: 'msaId', type: String, description: 'Msa Id of requested account', example: '2' })
@IsMsaId({ message: 'Msa Id should be a valid positive number' })
@IsMsaId()
msaId: string;
}

export class ProviderMsaIdDto {
@ApiProperty({ name: 'providerId', type: String, description: 'Msa Id of provider', example: '1' })
@IsMsaId({ message: 'providerId should be a valid positive number' })
@IsMsaId()
providerId: string;
}

Expand Down Expand Up @@ -45,6 +45,6 @@ export class AccountIdDto {
description: 'AccountId in hex or SS58 format',
example: '1LSLqpLWXo7A7xuiRdu6AQPnBPNJHoQSu8DBsUYJgsNEJ4N',
})
@IsAccountIdOrAddress({ message: 'Account id should be a 32 bytes value in hex or SS58 format!' })
@IsAccountIdOrAddress()
accountId: string;
}
2 changes: 1 addition & 1 deletion libs/types/src/dtos/graph/connection.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Type } from 'class-transformer';
import { IsMsaId } from '#utils/decorators/is-msa-id.decorator';

export class ConnectionDto {
@IsMsaId({ each: true, message: 'dsnpId should be a valid positive number' })
@IsMsaId({ each: true })
@ApiProperty({ description: 'MSA Id representing the target of this connection', type: String, example: '3' })
dsnpId: string;

Expand Down
Loading