Skip to content

Commit

Permalink
Updating authz app to use shared TransactionRequest; consolidating ty…
Browse files Browse the repository at this point in the history
…pes into a single domain.type file
  • Loading branch information
mattschoch committed Jan 18, 2024
1 parent e609a92 commit b0d55fc
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 135 deletions.
6 changes: 4 additions & 2 deletions apps/authz/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ authz/rego/bundle:
authz/rego/eval:
opa eval \
--format="pretty" \
--bundle ${AUTHZ_PROJECT_DIR}/src/app/opa/build/policies.tar.gz \
--target="wasm" \
--bundle ./rego-build/policies.gz \
--input ${AUTHZ_PROJECT_DIR}/src/app/opa/rego/input.json \
'data.main.evaluate'
--data ./rego-build/data.json \
'main.evaluate'

authz/rego/test:
opa test \
Expand Down
2 changes: 1 addition & 1 deletion apps/authz/src/app/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EvaluationRequestDto } from '@app/authz/app/evaluation-request.dto'
import { generateInboundRequest } from '@app/authz/shared/module/persistence/mock_data'
import { AuthZRequestPayload } from '@app/authz/shared/types/http'
import { AuthZRequestPayload } from '@app/authz/shared/types/domain.type'
import { Body, Controller, Get, Logger, Post } from '@nestjs/common'
import { AppService } from './app.service'

Expand Down
4 changes: 2 additions & 2 deletions apps/authz/src/app/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { PersistenceRepository } from '@app/authz/shared/module/persistence/persistence.repository'
import { Alg } from '@app/authz/shared/types/enums'
import {
Alg,
AuthCredential,
AuthZRequest,
AuthZRequestPayload,
AuthZResponse,
NarvalDecision,
RequestSignature
} from '@app/authz/shared/types/http'
} from '@app/authz/shared/types/domain.type'
import { OpaResult, RegoInput } from '@app/authz/shared/types/rego'
import { hashRequest } from '@narval/authz-shared'
import { safeDecode } from '@narval/transaction-request-intent'
Expand Down
34 changes: 28 additions & 6 deletions apps/authz/src/app/evaluation-request.dto.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Action, Alg } from '@app/authz/shared/types/enums'
import { Address, FiatSymbols, Hex } from '@app/authz/shared/types/http'
import { AccessList, Action, Address, Alg, FiatSymbols, Hex } from '@app/authz/shared/types/domain.type'
import { ApiExtraModels, ApiProperty, getSchemaPath } from '@nestjs/swagger'
import { Transform, Type } from 'class-transformer'
import { IsDefined, IsEnum, IsEthereumAddress, IsString, ValidateNested } from 'class-validator'
import { IsDefined, IsEnum, IsEthereumAddress, IsOptional, IsString, ValidateNested } from 'class-validator'
import { Caip10 } from 'packages/transaction-request-intent/src/lib/caip'

export class RequestSignatureDto {
Expand Down Expand Up @@ -54,16 +53,39 @@ export class TransactionRequestDto {
})
data?: Hex

gas: Hex
@IsOptional()
@Transform(({ value }) => BigInt(value))
@ApiProperty({
format: 'bigint',
required: false,
type: 'string'
})
gas?: bigint
@IsOptional()
@Transform(({ value }) => BigInt(value))
@ApiProperty({
format: 'bigint',
required: false,
type: 'string'
})
maxFeePerGas?: bigint
@IsOptional()
@Transform(({ value }) => BigInt(value))
@ApiProperty({
format: 'bigint',
required: false,
type: 'string'
})
maxPriorityFeePerGas?: bigint

@ApiProperty()
nonce?: number

value?: Hex

chainId: string
chainId: number

accessList?: { address: Address; storageKeys: Hex[] }[]
accessList?: AccessList

type?: '2'
}
Expand Down
19 changes: 13 additions & 6 deletions apps/authz/src/shared/module/persistence/mock_data.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import {
AccountType,
Action,
Alg,
AuthCredential,
AuthZRequestPayload,
TransactionRequest,
UserRoles
} from '@app/authz/shared/types/domain.type'
import {
AddressBookAccount,
RegoData,
Expand All @@ -7,8 +16,6 @@ import {
Wallet,
WalletGroup
} from '@app/authz/shared/types/entities.types'
import { AccountType, Action, Alg, UserRoles } from '@app/authz/shared/types/enums'
import { AuthCredential, AuthZRequestPayload, TransactionRequest } from '@app/authz/shared/types/http'
import { RegoInput } from '@app/authz/shared/types/rego'
import { hashRequest } from '@narval/authz-shared'
import { Caip10, Caip19 } from 'packages/transaction-request-intent/src/lib/caip'
Expand Down Expand Up @@ -158,28 +165,28 @@ export const TREASURY_WALLET_GROUP: WalletGroup = {
export const SHY_ACCOUNT_137: AddressBookAccount = {
uid: 'eip155:137:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e',
address: '0xddcf208f219a6e6af072f2cfdc615b2c1805f98e',
chainId: '137',
chainId: 137,
classification: 'wallet'
}

export const SHY_ACCOUNT_1: AddressBookAccount = {
uid: 'eip155:1:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e',
address: '0xddcf208f219a6e6af072f2cfdc615b2c1805f98e',
chainId: '1',
chainId: 1,
classification: 'wallet'
}

export const ACCOUNT_Q_137: AddressBookAccount = {
uid: 'eip155:137:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4',
address: '0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4',
chainId: '137',
chainId: 137,
classification: 'wallet'
}

export const ACCOUNT_INTERNAL_WXZ_137: AddressBookAccount = {
uid: 'eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3',
address: '0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3',
chainId: '137',
chainId: 137,
classification: 'internal'
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AuthCredential } from '@app/authz/shared/types/http'
import { AuthCredential } from '@app/authz/shared/types/domain.type'
import { Injectable, Logger, OnModuleInit } from '@nestjs/common'
import { mockEntityData, userAddressStore, userCredentialStore } from './mock_data'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,47 @@
import { Action, TransactionRequest } from '@narval/authz-shared'
import { Caip10 } from 'packages/transaction-request-intent/src/lib/caip'
import { Action, Alg } from './enums'

export * from '@narval/authz-shared'

export enum AccountType {
EOA = 'eoa',
AA = '4337'
}

export enum UserRoles {
ROOT = 'root',
ADMIN = 'admin',
MEMBER = 'member',
MANAGER = 'manager'
}

export enum Decisions {
ALLOW = 'Allow',
DENY = 'Deny',
CONFIRM = 'Confirm'
}

export enum ValueOperators {
GREATER_THAN = 'gt',
LESS_THAN = 'lt',
GREATER_THAN_OR_EQUAL = 'gte',
LESS_THAN_OR_EQUAL = 'lte',
EQUAL = 'eq',
NOT_EQUAL = 'ne'
}

export enum IdentityOperators {
IS = 'is',
IS_NOT = 'is_not',
CONTAINS = 'contains',
IN = 'in'
}

export enum Alg {
ES256K = 'ES256K', // secp256k1, an Ethereum EOA
ES256 = 'ES256', // secp256r1, ecdsa but not ethereum
RS256 = 'RS256'
}

export enum FiatSymbols {
USD = 'fiat:usd',
Expand All @@ -17,28 +59,6 @@ export type HistoricalTransfer = {
timestamp: number // unix timestamp
}

// Types ripped from viem; combining a few though because they don't have chainId on txRequest
export type Hex = `0x${string}`
export type Address = `0x${string}`
export type AccessList = { address: Address; storageKeys: Hex[] }[]
export type TransactionRequest<TQuantity = Hex, TIndex = number, TTransactionType = '2'> = {
/** Contract code or a hashed method call with encoded args */
data?: Hex
/** Transaction sender */
from: Address
/** Gas provided for transaction execution */
gas?: TQuantity
/** Unique number identifying this transaction */
nonce?: TIndex
/** Transaction recipient */
to?: Address | null
/** Value in wei sent with this transaction */
value?: TQuantity
chainId: string | null
accessList?: AccessList
type?: TTransactionType
}

/**
* The activity/data being authorized. This must include all the data being authorized, and nothing except the data being authorized.
* This is the data that will be hashed and signed.
Expand Down
6 changes: 3 additions & 3 deletions apps/authz/src/shared/types/entities.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AccountType, UserRoles } from './enums'
import { AccountType, UserRoles } from './domain.type'

type UUID = string

Expand All @@ -18,7 +18,7 @@ export type Wallet = {
uid: string
address: string
accountType: AccountType
chainId?: string
chainId?: number
assignees?: string[] // userIds
}

Expand All @@ -31,7 +31,7 @@ export type WalletGroup = {
export type AddressBookAccount = {
uid: string
address: string
chainId: string
chainId: number
classification: string
}

Expand Down
67 changes: 0 additions & 67 deletions apps/authz/src/shared/types/enums.ts

This file was deleted.

3 changes: 1 addition & 2 deletions apps/authz/src/shared/types/rego.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Intent } from 'packages/transaction-request-intent/src/lib/intent.types'
import { Action } from './enums'
import { ApprovalRequirement, AuthCredential, HistoricalTransfer, TransactionRequest } from './http'
import { Action, ApprovalRequirement, AuthCredential, HistoricalTransfer, TransactionRequest } from './domain.type'

export type RegoInput = {
action: Action
Expand Down
6 changes: 4 additions & 2 deletions packages/authz-shared/src/lib/type/domain.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ export enum TransactionType {
export type TransactionRequest = {
chainId: number
from: Address
nonce: number
nonce?: number
accessList?: AccessList
data?: Hex
gas?: bigint
maxFeePerGas?: bigint
maxPriorityFeePerGas?: bigint
to?: Address | null
type?: `${TransactionType}`
type?: '2'
value?: Hex
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export type Wallet = {
uid: string
address: string
accountType: AccountType
chainId?: string
chainId?: number
assignees?: string[] // userIds
}

Expand All @@ -45,7 +45,7 @@ export type WalletGroup = {
export type AddressBookAccount = {
uid: string
address: string
chainId: string
chainId: number
classification: string
}

Expand Down Expand Up @@ -213,28 +213,28 @@ export const TREASURY_WALLET_GROUP: WalletGroup = {
export const SHY_ACCOUNT_137: AddressBookAccount = {
uid: 'eip155:137:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e',
address: '0xddcf208f219a6e6af072f2cfdc615b2c1805f98e',
chainId: '137',
chainId: 137,
classification: 'wallet'
}

export const SHY_ACCOUNT_1: AddressBookAccount = {
uid: 'eip155:1:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e',
address: '0xddcf208f219a6e6af072f2cfdc615b2c1805f98e',
chainId: '1',
chainId: 1,
classification: 'wallet'
}

export const ACCOUNT_Q_137: AddressBookAccount = {
uid: 'eip155:137:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4',
address: '0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4',
chainId: '137',
chainId: 137,
classification: 'wallet'
}

export const ACCOUNT_INTERNAL_WXZ_137: AddressBookAccount = {
uid: 'eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3',
address: '0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3',
chainId: '137',
chainId: 137,
classification: 'internal'
}

Expand Down
Loading

0 comments on commit b0d55fc

Please sign in to comment.