-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
samuel
committed
Feb 8, 2024
1 parent
23c93b8
commit db0166c
Showing
8 changed files
with
365 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -459,19 +459,111 @@ describe('Admin Endpoints', () => { | |
], | ||
request: { | ||
action: 'setPolicyRules', | ||
nonce: 'random-nonce', | ||
data: [ | ||
{ | ||
then: 'permit', | ||
name: 'examplePermitPolicy', | ||
when: [ | ||
{ | ||
criterion: 'checkTransferResourceIntegrity', | ||
args: null | ||
}, | ||
{ | ||
criterion: 'checkNonceExists', | ||
args: null | ||
}, | ||
{ | ||
criterion: 'checkAction', | ||
args: ['signTransaction'] | ||
}, | ||
{ | ||
criterion: 'checkPrincipalId', | ||
args: ['[email protected]'] | ||
}, | ||
{ | ||
criterion: 'checkWalletId', | ||
args: ['eip155:eoa:0x90d03a8971a2faa19a9d7ffdcbca28fe826a289b'] | ||
}, | ||
{ | ||
criterion: 'checkIntentType', | ||
args: ['transferNative'] | ||
}, | ||
{ | ||
criterion: 'checkIntentToken', | ||
args: ['eip155:137/slip44:966'] | ||
}, | ||
{ | ||
criterion: 'checkIntentAmount', | ||
args: { | ||
currency: '*', | ||
operator: 'lte', | ||
value: '1000000000000000000' | ||
} | ||
}, | ||
{ | ||
criterion: 'checkApprovals', | ||
args: [ | ||
{ | ||
approvalCount: 2, | ||
countPrincipal: false, | ||
approvalEntityType: 'Narval::User', | ||
entityIds: ['[email protected]', '[email protected]'] | ||
}, | ||
{ | ||
approvalCount: 1, | ||
countPrincipal: false, | ||
approvalEntityType: 'Narval::UserRole', | ||
entityIds: ['admin'] | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
then: 'forbid', | ||
name: 'exampleForbidPolicy', | ||
when: [ | ||
{ | ||
criterion: 'checkTransferResourceIntegrity', | ||
args: null | ||
}, | ||
{ | ||
criterion: 'checkNonceExists', | ||
args: null | ||
}, | ||
{ | ||
criterion: 'checkAction', | ||
args: ['signTransaction'] | ||
}, | ||
{ | ||
criterion: 'checkPrincipalId', | ||
args: ['[email protected]'] | ||
}, | ||
{ | ||
criterion: 'checkWalletId', | ||
args: ['eip155:eoa:0x90d03a8971a2faa19a9d7ffdcbca28fe826a289b'] | ||
}, | ||
{ | ||
criterion: 'checkIntentType', | ||
args: ['transferNative'] | ||
}, | ||
{ | ||
criterion: 'checkIntentToken', | ||
args: ['eip155:137/slip44:966'] | ||
}, | ||
{ | ||
criterion: 'checkSpendingLimit', | ||
args: { | ||
limit: '1000000000000000000', | ||
timeWindow: { | ||
type: 'rolling', | ||
value: 43200 | ||
}, | ||
filters: { | ||
tokens: ['eip155:137/slip44:966'], | ||
users: ['[email protected]'] | ||
} | ||
} | ||
} | ||
] | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/authz-shared/src/lib/decorators/is-account-id.decorator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { applyDecorators } from '@nestjs/common' | ||
import { Matches, ValidationOptions } from 'class-validator' | ||
|
||
export function IsAccountId(validationOptions?: ValidationOptions) { | ||
const regex = new RegExp('^eip155:d+/w+$') | ||
return applyDecorators(Matches(regex, validationOptions)) | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/authz-shared/src/lib/decorators/is-asset-id.decorator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { applyDecorators } from '@nestjs/common' | ||
import { Matches, ValidationOptions } from 'class-validator' | ||
|
||
export function IsAssetId(validationOptions?: ValidationOptions) { | ||
const regex = new RegExp('^(eip155:d+/(erc1155|erc20|erc721):w+/w+|eip155:d+/slip44:d+)$') | ||
return applyDecorators(Matches(regex, validationOptions)) | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/authz-shared/src/lib/decorators/is-not-empty-array-enum.decorator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { applyDecorators } from '@nestjs/common' | ||
import { ApiProperty } from '@nestjs/swagger' | ||
import { ArrayMinSize, IsArray, IsDefined, IsEnum } from 'class-validator' | ||
|
||
export function IsNotEmptyArrayEnum(Enum: object) { | ||
return applyDecorators( | ||
IsDefined, | ||
IsArray, | ||
IsEnum(Enum, { each: true }), | ||
ApiProperty({ | ||
enum: Object.values(Enum), | ||
isArray: true | ||
}), | ||
ArrayMinSize(1) | ||
) | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/authz-shared/src/lib/decorators/is-not-empty-array-string.decorator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { applyDecorators } from '@nestjs/common'; | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsDefined, IsArray, IsString, ArrayMinSize } from 'class-validator'; | ||
|
||
export function IsNotEmptyArrayString() { | ||
return applyDecorators( | ||
IsDefined(), | ||
IsArray(), | ||
IsString({ each: true }), | ||
ApiProperty({ type: String, isArray: true }), | ||
ArrayMinSize(1) | ||
); | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/authz-shared/src/lib/decorators/validate-criterion.decorator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { applyDecorators } from '@nestjs/common' | ||
import { ApiProperty } from '@nestjs/swagger' | ||
import { IsDefined, IsString, Matches } from 'class-validator' | ||
import { Criterion } from '../type/policy-builder.type' | ||
|
||
export function ValidateCriterion(name: string) { | ||
return applyDecorators(IsDefined(), IsString(), Matches(name), ApiProperty({ type: Criterion, default: name })) | ||
} |
Oops, something went wrong.