Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feature/refactor-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
samteb committed Feb 5, 2024
2 parents 99f0353 + 4d3e6e3 commit ddd7d85
Show file tree
Hide file tree
Showing 16 changed files with 374 additions and 250 deletions.
14 changes: 2 additions & 12 deletions apps/authz/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AdminService } from '@app/authz/app/core/admin.service'
import { AdminController } from '@app/authz/app/http/rest/controller/admin.controller'
import { AdminRepository } from '@app/authz/app/persistence/repository/admin.repository'
import { PersistenceModule } from '@app/authz/shared/module/persistence/persistence.module'
import { Logger, Module, OnApplicationBootstrap, ValidationPipe } from '@nestjs/common'
import { Module, ValidationPipe } from '@nestjs/common'
import { ConfigModule } from '@nestjs/config'
import { APP_PIPE } from '@nestjs/core'
import { load } from './app.config'
Expand Down Expand Up @@ -30,14 +30,4 @@ import { OpaService } from './opa/opa.service'
}
]
})
export class AppModule implements OnApplicationBootstrap {
private logger = new Logger(AppModule.name)

constructor(private opaService: OpaService) {}

async onApplicationBootstrap() {
this.logger.log('Armory Engine app module boot')

await this.opaService.onApplicationBootstrap()
}
}
export class AppModule {}
4 changes: 2 additions & 2 deletions apps/authz/src/app/opa/opa.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AdminRepository } from '@app/authz/app/persistence/repository/admin.repository'
import { RegoData, User, UserGroup, WalletGroup } from '@app/authz/shared/types/entities.types'
import { OpaResult, RegoInput } from '@app/authz/shared/types/rego'
import { Injectable, Logger } from '@nestjs/common'
import { Injectable, Logger, OnApplicationBootstrap } from '@nestjs/common'
import { loadPolicy } from '@open-policy-agent/opa-wasm'
import { readFileSync } from 'fs'
import path from 'path'
Expand All @@ -13,7 +13,7 @@ type OpaEngine = PromiseType<ReturnType<typeof loadPolicy>>
const OPA_WASM_PATH = path.join(process.cwd(), './rego-build/policy.wasm')

@Injectable()
export class OpaService {
export class OpaService implements OnApplicationBootstrap {
private logger = new Logger(OpaService.name)
private opaEngine: OpaEngine | undefined

Expand Down
82 changes: 45 additions & 37 deletions apps/authz/src/opa/rego/__test__/main_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -52,56 +52,64 @@ approvalsReq = [
{"userId": "0xaaa8ee1cbaa1856f4550c6fc24abb16c5c9b2a43"},
]

transfersReq = [
feedsReq = [
{
"amount": "3051000000",
"from": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"token": "eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
"rates": {"fiat:usd": "0.99", "fiat:eur": "1.10"},
"timestamp": elevenHoursAgo,
"chainId": 137,
"initiatedBy": "test-alice-uid",
},
{
"amount": "2000000000",
"from": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"token": "eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
"rates": {"fiat:usd": "0.99", "fiat:eur": "1.10"},
"timestamp": tenHoursAgo,
"chainId": 137,
"initiatedBy": "test-alice-uid",
"source": "armory/price-feed",
"sig": {},
"data": {
"eip155:137/slip44:966": {
"fiat:usd": "0.99",
"fiat:eur": "1.10",
},
"eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aa84174": {
"fiat:usd": "0.99",
"fiat:eur": "1.10",
},
},
},
{
"amount": "1500000000",
"from": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"token": "eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
"rates": {"fiat:usd": "0.99", "fiat:eur": "1.10"},
"timestamp": twentyHoursAgo,
"chainId": 137,
"initiatedBy": "test-alice-uid",
"source": "armory/historical-transfer-feed",
"sig": {},
"data": [
{
"amount": "3051000000",
"from": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"token": "eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
"rates": {"fiat:usd": "0.99", "fiat:eur": "1.10"},
"timestamp": elevenHoursAgo,
"chainId": 137,
"initiatedBy": "test-alice-uid",
},
{
"amount": "2000000000",
"from": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"token": "eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
"rates": {"fiat:usd": "0.99", "fiat:eur": "1.10"},
"timestamp": tenHoursAgo,
"chainId": 137,
"initiatedBy": "test-alice-uid",
},
{
"amount": "1500000000",
"from": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"token": "eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
"rates": {"fiat:usd": "0.99", "fiat:eur": "1.10"},
"timestamp": twentyHoursAgo,
"chainId": 137,
"initiatedBy": "test-alice-uid",
},
],
},
]

pricesReq = {
"eip155:137/slip44:966": {
"fiat:usd": "0.99",
"fiat:eur": "1.10",
},
"eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aa84174": {
"fiat:usd": "0.99",
"fiat:eur": "1.10",
},
}

request = {
"action": "signTransaction",
"transactionRequest": transactionRequestReq,
"principal": principalReq,
"resource": resourceReq,
"intent": intentReq,
"approvals": approvalsReq,
"transfers": transfersReq,
"prices": pricesReq,
"feeds": feedsReq,
}

entities = {
Expand Down
112 changes: 61 additions & 51 deletions apps/authz/src/opa/rego/__test__/policies/e2e_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -48,64 +48,74 @@ e2e_req = {
"pubKey": "0xab88c8785D0C00082dE75D801Fcb1d5066a6311e",
},
],
"transfers": [
"feeds": [
{
"amount": "100000000000000000",
"from": "eip155:137:0x90d03a8971a2faa19a9d7ffdcbca28fe826a289b",
"to": "eip155:137:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4",
"chainId": 137,
"token": "eip155:137/slip44:966",
"rates": {
"fiat:usd": "0.99",
"fiat:eur": "1.10",
},
"initiatedBy": "matt@narval.xyz",
"timestamp": elevenHoursAgo,
},
{
"amount": "100000000000000000",
"from": "eip155:137:0x90d03a8971a2faa19a9d7ffdcbca28fe826a289b",
"to": "eip155:137:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4",
"chainId": 137,
"token": "eip155:137/slip44:966",
"rates": {
"fiat:usd": "0.99",
"fiat:eur": "1.10",
},
"initiatedBy": "matt@narval.xyz",
"timestamp": tenHoursAgo,
"source": "armory/historical-transfer-feed",
"sig": {},
"data": [
{
"amount": "100000000000000000",
"from": "eip155:137:0x90d03a8971a2faa19a9d7ffdcbca28fe826a289b",
"to": "eip155:137:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4",
"chainId": 137,
"token": "eip155:137/slip44:966",
"rates": {
"fiat:usd": "0.99",
"fiat:eur": "1.10",
},
"initiatedBy": "matt@narval.xyz",
"timestamp": elevenHoursAgo,
},
{
"amount": "100000000000000000",
"from": "eip155:137:0x90d03a8971a2faa19a9d7ffdcbca28fe826a289b",
"to": "eip155:137:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4",
"chainId": 137,
"token": "eip155:137/slip44:966",
"rates": {
"fiat:usd": "0.99",
"fiat:eur": "1.10",
},
"initiatedBy": "matt@narval.xyz",
"timestamp": tenHoursAgo,
},
{
"amount": "100000000000000000",
"from": "eip155:137:0x90d03a8971a2faa19a9d7ffdcbca28fe826a289b",
"to": "eip155:137:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4",
"chainId": 137,
"token": "eip155:137/slip44:966",
"rates": {
"fiat:usd": "0.99",
"fiat:eur": "1.10",
},
"initiatedBy": "matt@narval.xyz",
"timestamp": elevenHoursAgo,
},
{
"amount": "100000000000000000",
"from": "eip155:137:0x90d03a8971a2faa19a9d7ffdcbca28fe826a289b",
"to": "eip155:137:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4",
"chainId": 137,
"token": "eip155:137/slip44:966",
"rates": {
"fiat:usd": "0.99",
"fiat:eur": "1.10",
},
"initiatedBy": "matt@narval.xyz",
"timestamp": tenHoursAgo,
},
],
},
{
"amount": "100000000000000000",
"from": "eip155:137:0x90d03a8971a2faa19a9d7ffdcbca28fe826a289b",
"to": "eip155:137:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4",
"chainId": 137,
"token": "eip155:137/slip44:966",
"rates": {
"fiat:usd": "0.99",
"fiat:eur": "1.10",
},
"initiatedBy": "matt@narval.xyz",
"timestamp": elevenHoursAgo,
},
{
"amount": "100000000000000000",
"from": "eip155:137:0x90d03a8971a2faa19a9d7ffdcbca28fe826a289b",
"to": "eip155:137:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4",
"chainId": 137,
"token": "eip155:137/slip44:966",
"rates": {
"source": "armory/price-feed",
"sig": {},
"data": {"eip155:137/slip44:966": {
"fiat:usd": "0.99",
"fiat:eur": "1.10",
},
"initiatedBy": "matt@narval.xyz",
"timestamp": tenHoursAgo,
}},
},
],
"prices": {"eip155:137/slip44:966": {
"fiat:usd": "0.99",
"fiat:eur": "1.10",
}},
}

e2e_entities = {
Expand Down
Loading

0 comments on commit ddd7d85

Please sign in to comment.