Skip to content

Commit

Permalink
Merge branch 'main' into env/testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
alanrsoares committed Jan 11, 2024
2 parents af730b8 + 711749a commit 32f34cc
Show file tree
Hide file tree
Showing 12 changed files with 567 additions and 395 deletions.
4 changes: 2 additions & 2 deletions apps/maestro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@trpc/server": "^10.45.0",
"@vercel/kv": "^1.0.1",
"@vercel/postgres": "^0.5.1",
"@web3modal/wagmi": "^3.5.3",
"@web3modal/wagmi": "^3.5.5",
"drizzle-orm": "^0.29.3",
"lucide-react": "^0.265.0",
"next": "^14.0.4",
Expand All @@ -69,7 +69,7 @@
"trpc-openapi": "^1.2.0",
"unfetch": "^4.2.0",
"viem": "1.21.4",
"wagmi": "1.4.7",
"wagmi": "1.4.13",
"zod": "^3.22.4"
},
"devDependencies": {
Expand Down
25 changes: 24 additions & 1 deletion apps/maestro/src/config/next-auth.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { Maybe } from "@axelarjs/utils";
import type { NextAuthOptions } from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";

import { kv } from "@vercel/kv";
import { getAddress, verifyMessage } from "viem";

import db from "~/lib/drizzle/client";
import { getSignInMessage } from "~/server/routers/auth/createSignInMessage";
import MaestroKVClient from "~/services/db/kv";
import MaestroPostgresClient from "~/services/db/postgres/MaestroPostgresClient";

export type Web3Session = {
address: `0x${string}`;
};

const kvClient = new MaestroKVClient(kv);
const pgClient = new MaestroPostgresClient(db);

// augments the default session type
declare module "next-auth" {
Expand All @@ -35,7 +39,7 @@ export const NEXT_AUTH_OPTIONS: NextAuthOptions = {
placeholder: "0x0",
},
},
async authorize(credentials) {
async authorize(credentials, req) {
if (
!credentials?.address ||
!getAddress(credentials?.address) ||
Expand All @@ -53,6 +57,25 @@ export const NEXT_AUTH_OPTIONS: NextAuthOptions = {
]);

if (accountNonce === null || accountStatus === "disabled") {
if (accountStatus === "disabled") {
const { ip, userAgent } = Maybe.of(req.headers).mapOr(
{ ip: "", userAgent: "" },
(headers) => ({
ip: headers["x-real-ip"],
userAgent: headers["user-agent"],
})
);

// record unauthorized access attempt event to audit logs
await pgClient.recordAuditLogEvent({
kind: "unauthorized_access_attempt",
payload: {
ip,
userAgent,
accountAddress: address,
},
});
}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
DO $$ BEGIN
CREATE TYPE "audit_log_event_kind" AS ENUM('unauthorized_access_attempt');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "audit_logs" (
"id" varchar(66) PRIMARY KEY NOT NULL,
"event_kind" "audit_log_event_kind" NOT NULL,
"payload" varchar(2048) NOT NULL,
"timestamp" timestamp DEFAULT now() NOT NULL
);
250 changes: 250 additions & 0 deletions apps/maestro/src/lib/drizzle/migrations/meta/0002_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
{
"id": "10d8d21d-e5ff-4162-924e-e03bcc3dd483",
"prevId": "f3f3d7de-b427-49a6-a10a-0ce3d4988068",
"version": "5",
"dialect": "pg",
"tables": {
"audit_logs": {
"name": "audit_logs",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "varchar(66)",
"primaryKey": true,
"notNull": true
},
"event_kind": {
"name": "event_kind",
"type": "audit_log_event_kind",
"primaryKey": false,
"notNull": true
},
"payload": {
"name": "payload",
"type": "varchar(2048)",
"primaryKey": false,
"notNull": true
},
"timestamp": {
"name": "timestamp",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"interchain_tokens": {
"name": "interchain_tokens",
"schema": "",
"columns": {
"token_id": {
"name": "token_id",
"type": "varchar(66)",
"primaryKey": true,
"notNull": true
},
"token_address": {
"name": "token_address",
"type": "varchar(42)",
"primaryKey": false,
"notNull": true
},
"axelar_chain_id": {
"name": "axelar_chain_id",
"type": "varchar(66)",
"primaryKey": false,
"notNull": true
},
"token_name": {
"name": "token_name",
"type": "varchar(100)",
"primaryKey": false,
"notNull": true
},
"token_symbol": {
"name": "token_symbol",
"type": "varchar(100)",
"primaryKey": false,
"notNull": true
},
"token_decimals": {
"name": "token_decimals",
"type": "smallint",
"primaryKey": false,
"notNull": true
},
"deployment_message_id": {
"name": "deployment_message_id",
"type": "varchar(71)",
"primaryKey": false,
"notNull": true
},
"deployer_address": {
"name": "deployer_address",
"type": "varchar(42)",
"primaryKey": false,
"notNull": true
},
"token_manager_address": {
"name": "token_manager_address",
"type": "varchar(42)",
"primaryKey": false,
"notNull": true
},
"original_minter_address": {
"name": "original_minter_address",
"type": "varchar(42)",
"primaryKey": false,
"notNull": false
},
"kind": {
"name": "kind",
"type": "token_kind",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"salt": {
"name": "salt",
"type": "varchar(66)",
"primaryKey": false,
"notNull": true,
"default": "'0x'"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"remote_interchain_tokens": {
"name": "remote_interchain_tokens",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "varchar(128)",
"primaryKey": true,
"notNull": true
},
"token_id": {
"name": "token_id",
"type": "varchar(66)",
"primaryKey": false,
"notNull": true
},
"axelar_chain_id": {
"name": "axelar_chain_id",
"type": "varchar(66)",
"primaryKey": false,
"notNull": true
},
"token_address": {
"name": "token_address",
"type": "varchar(42)",
"primaryKey": false,
"notNull": true
},
"token_manager_address": {
"name": "token_manager_address",
"type": "varchar(42)",
"primaryKey": false,
"notNull": false
},
"deployment_message_id": {
"name": "deployment_message_id",
"type": "varchar(71)",
"primaryKey": false,
"notNull": true
},
"deployment_status": {
"name": "deployment_status",
"type": "deployment_status",
"primaryKey": false,
"notNull": false,
"default": "'pending'"
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {
"remote_interchain_tokens_token_id_interchain_tokens_token_id_fk": {
"name": "remote_interchain_tokens_token_id_interchain_tokens_token_id_fk",
"tableFrom": "remote_interchain_tokens",
"tableTo": "interchain_tokens",
"columnsFrom": [
"token_id"
],
"columnsTo": [
"token_id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {
"audit_log_event_kind": {
"name": "audit_log_event_kind",
"values": {
"unauthorized_access_attempt": "unauthorized_access_attempt"
}
},
"token_kind": {
"name": "token_kind",
"values": {
"canonical": "canonical",
"interchain": "interchain",
"custom": "custom"
}
},
"deployment_status": {
"name": "deployment_status",
"values": {
"confirmed": "confirmed",
"pending": "pending"
}
}
},
"schemas": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}
9 changes: 8 additions & 1 deletion apps/maestro/src/lib/drizzle/migrations/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
"when": 1701957876399,
"tag": "0001_confused_bug",
"breakpoints": true
},
{
"idx": 2,
"version": "5",
"when": 1704908069686,
"tag": "0002_minor_weapon_omega",
"breakpoints": true
}
]
}
}
Loading

0 comments on commit 32f34cc

Please sign in to comment.