Skip to content

Commit

Permalink
feat: make key nickname required (#1198)
Browse files Browse the repository at this point in the history
  • Loading branch information
dragosp1011 authored Mar 6, 2024
1 parent 76f8169 commit dc36ba4
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async function (knex) {
return knex.schema.alterTable('walletAddressKeys', async (table) => {
await knex('walletAddressKeys')
.update({ nickname: 'Testnet managed' })
.whereNull('nickname')

table.string('nickname').notNullable().alter()
})
}

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async function (knex) {
return knex.schema.alterTable('walletAddressKeys', async (table) => {
table.string('nickname').nullable().alter()
})
}
1 change: 1 addition & 0 deletions packages/wallet/backend/src/user/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export class UserService implements IUserService {
userId: boutiqueInfo.createdUser.id,
accountId: boutiqueInfo.defaultAccount.id,
walletAddressId: boutiqueWallet.id,
nickname: 'Testnet managed',
keyPair: {
publicKeyPEM: this.env.DEFAULT_BOUTIQUE_KEYS.public_key,
privateKeyPEM: this.env.DEFAULT_BOUTIQUE_KEYS.private_key,
Expand Down
8 changes: 1 addition & 7 deletions packages/wallet/backend/src/walletAddressKeys/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ interface IWalletAddressKeyController {
list: ControllerFunction<WalletAddressKeys[]>
}

interface KeyPair {
publicKey: string
privateKey: string
keyId: string
}

export class WalletAddressKeyController implements IWalletAddressKeyController {
constructor(private walletAddressKeyService: WalletAddressKeyService) {}

Expand Down Expand Up @@ -75,7 +69,7 @@ export class WalletAddressKeyController implements IWalletAddressKeyController {

registerKey = async (
req: Request,
res: CustomResponse<KeyPair>,
res: CustomResponse<KeyResponse>,
next: NextFunction
) => {
try {
Expand Down
2 changes: 1 addition & 1 deletion packages/wallet/backend/src/walletAddressKeys/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { WalletAddress } from '@/walletAddress/model'
export class WalletAddressKeys extends BaseModel {
static tableName = 'walletAddressKeys'

nickname?: string
nickname!: string
readonly walletAddressId!: string
readonly rafikiId!: string
readonly publicKey!: string
Expand Down
4 changes: 2 additions & 2 deletions packages/wallet/backend/src/walletAddressKeys/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type KeyResponse = {
privateKey: string
publicKey: string
keyId: string
nickname?: string
nickname: string
}

interface WalletAddressKeyArgs {
Expand All @@ -21,7 +21,7 @@ interface WalletAddressKeyArgs {
}

interface RegisterKeyArgs extends WalletAddressKeyArgs {
nickname?: string
nickname: string
keyPair?: {
publicKeyPEM: string
privateKeyPEM: string
Expand Down
20 changes: 8 additions & 12 deletions packages/wallet/backend/src/walletAddressKeys/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import { z } from 'zod'

export const generateWalletAddressKey = z.object({
body: z.object({
nickname: z.optional(
z
.string()
.trim()
.min(3, { message: 'Name must be at least 3 characters long' })
)
nickname: z
.string()
.trim()
.min(3, { message: 'Name must be at least 3 characters long' })
})
})
export const patchWalletAddressKey = z.object({
Expand All @@ -21,12 +19,10 @@ export const patchWalletAddressKey = z.object({

export const uploadWalletAddressKey = z.object({
body: z.object({
nickname: z.optional(
z
.string()
.trim()
.min(3, { message: 'Name must be at least 3 characters long' })
),
nickname: z
.string()
.trim()
.min(3, { message: 'Name must be at least 3 characters long' }),
base64Key: z.string()
})
})

0 comments on commit dc36ba4

Please sign in to comment.