From 3a72c9c4bfeb7a562e53c330a077f3a26d64e89c Mon Sep 17 00:00:00 2001 From: Ptroger <44851272+Ptroger@users.noreply.github.com> Date: Fri, 11 Oct 2024 21:07:22 +0200 Subject: [PATCH] Don't strip origin field from vault public accounts (#563) * add origin to publicaccount schema * switch import in account dto * updated vault client in sdk --- apps/vault/src/shared/type/domain.type.ts | 8 +---- .../src/vault/__test__/e2e/account.spec.ts | 32 ++++++++++++------- .../src/vault/__test__/e2e/wallet.spec.ts | 6 ++-- .../src/vault/http/rest/dto/account.dto.ts | 2 +- .../src/lib/http/client/vault/api.ts | 24 ++++++++++---- 5 files changed, 45 insertions(+), 27 deletions(-) diff --git a/apps/vault/src/shared/type/domain.type.ts b/apps/vault/src/shared/type/domain.type.ts index f31d1fcae..ee438f024 100644 --- a/apps/vault/src/shared/type/domain.type.ts +++ b/apps/vault/src/shared/type/domain.type.ts @@ -63,13 +63,7 @@ export const PrivateAccount = z.object({ }) export type PrivateAccount = z.infer -export const PublicAccount = z.object({ - id: z.string().min(1), - address: z.string().min(1), - publicKey: hexSchema.refine((val) => val.length === 132, 'Invalid hex publicKey'), - keyId: z.string().min(1).optional(), - derivationPath: z.string().min(1).optional() -}) +export const PublicAccount = PrivateAccount.omit({ privateKey: true }) export type PublicAccount = z.infer export const LocalRootKey = z.object({ diff --git a/apps/vault/src/vault/__test__/e2e/account.spec.ts b/apps/vault/src/vault/__test__/e2e/account.spec.ts index 43d75b962..eccfecbb5 100644 --- a/apps/vault/src/vault/__test__/e2e/account.spec.ts +++ b/apps/vault/src/vault/__test__/e2e/account.spec.ts @@ -23,7 +23,7 @@ import { Config, load } from '../../../main.config' import { REQUEST_HEADER_CLIENT_ID } from '../../../main.constant' import { TestPrismaService } from '../../../shared/module/persistence/service/test-prisma.service' import { getTestRawAesKeyring } from '../../../shared/testing/encryption.testing' -import { Client } from '../../../shared/type/domain.type' +import { Client, Origin } from '../../../shared/type/domain.type' import { AppService } from '../../core/service/app.service' const PRIVATE_KEY = '0x7cfef3303797cbc7515d9ce22ffe849c701b0f2812f999b0847229c47951fca5' @@ -210,7 +210,8 @@ describe('Accounts', () => { keyId, derivationPath: "m/44'/60'/0'/0/1", address: expect.any(String), - publicKey: expect.any(String) + publicKey: expect.any(String), + origin: Origin.GENERATED } ] }) @@ -258,21 +259,24 @@ describe('Accounts', () => { keyId, derivationPath: "m/44'/60'/0'/0/1", address: expect.any(String), - publicKey: expect.any(String) + publicKey: expect.any(String), + origin: Origin.GENERATED }, { id: expect.any(String), keyId, derivationPath: "m/44'/60'/0'/0/2", address: expect.any(String), - publicKey: expect.any(String) + publicKey: expect.any(String), + origin: Origin.GENERATED }, { id: expect.any(String), keyId, derivationPath: "m/44'/60'/0'/0/3", address: expect.any(String), - publicKey: expect.any(String) + publicKey: expect.any(String), + origin: Origin.GENERATED } ]) }) @@ -305,14 +309,16 @@ describe('Accounts', () => { keyId, derivationPath: "m/44'/60'/0'/0/4", address: expect.any(String), - publicKey: expect.any(String) + publicKey: expect.any(String), + origin: Origin.GENERATED }, { id: expect.any(String), keyId, derivationPath: "m/44'/60'/0'/0/5", address: expect.any(String), - publicKey: expect.any(String) + publicKey: expect.any(String), + origin: Origin.GENERATED } ]) }) @@ -346,14 +352,16 @@ describe('Accounts', () => { keyId, derivationPath: "m/44'/60'/0'/0/4", address: expect.any(String), - publicKey: expect.any(String) + publicKey: expect.any(String), + origin: Origin.GENERATED }, { id: expect.any(String), keyId, derivationPath: "m/44'/60'/0'/0/5", address: expect.any(String), - publicKey: expect.any(String) + publicKey: expect.any(String), + origin: Origin.GENERATED } ]) }) @@ -374,7 +382,8 @@ describe('Accounts', () => { expect(body).toEqual({ id: 'eip155:eoa:0x2c4895215973cbbd778c32c456c074b99daf8bf1', address: '0x2c4895215973CbBd778C32c456C074b99daF8Bf1', - publicKey: expect.any(String) + publicKey: expect.any(String), + origin: Origin.IMPORTED }) expect(status).toEqual(HttpStatus.CREATED) }) @@ -402,7 +411,8 @@ describe('Accounts', () => { expect(body).toEqual({ id: 'eip155:eoa:0x2c4895215973cbbd778c32c456c074b99daf8bf1', address: '0x2c4895215973CbBd778C32c456C074b99daF8Bf1', - publicKey: expect.any(String) + publicKey: expect.any(String), + origin: Origin.IMPORTED }) expect(status).toEqual(HttpStatus.CREATED) }) diff --git a/apps/vault/src/vault/__test__/e2e/wallet.spec.ts b/apps/vault/src/vault/__test__/e2e/wallet.spec.ts index 8feba69e6..f0b8f24dd 100644 --- a/apps/vault/src/vault/__test__/e2e/wallet.spec.ts +++ b/apps/vault/src/vault/__test__/e2e/wallet.spec.ts @@ -196,7 +196,8 @@ describe('Generate', () => { derivationPath: "m/44'/60'/0'/0/0", address: expect.any(String), publicKey: expect.any(String), - id: expect.any(String) + id: expect.any(String), + origin: Origin.GENERATED }) }) @@ -277,7 +278,8 @@ describe('Generate', () => { publicKey: expect.any(String), keyId: 'my-imported-rootKey', derivationPath: `m/44'/60'/0'/0/0`, - id: resourceId(body.account.address) + id: resourceId(body.account.address), + origin: Origin.GENERATED }, keyId: 'my-imported-rootKey' }) diff --git a/apps/vault/src/vault/http/rest/dto/account.dto.ts b/apps/vault/src/vault/http/rest/dto/account.dto.ts index 24711a46d..ba8d2aef0 100644 --- a/apps/vault/src/vault/http/rest/dto/account.dto.ts +++ b/apps/vault/src/vault/http/rest/dto/account.dto.ts @@ -1,4 +1,4 @@ -import { PublicAccount } from '@narval/armory-sdk' import { createZodDto } from 'nestjs-zod' +import { PublicAccount } from '../../../../shared/type/domain.type' export class AccountDto extends createZodDto(PublicAccount) {} diff --git a/packages/armory-sdk/src/lib/http/client/vault/api.ts b/packages/armory-sdk/src/lib/http/client/vault/api.ts index b9eedd163..a6893580c 100644 --- a/packages/armory-sdk/src/lib/http/client/vault/api.ts +++ b/packages/armory-sdk/src/lib/http/client/vault/api.ts @@ -37,16 +37,22 @@ export interface AccountDto { 'id': string; /** * - * @type {string} + * @type {any} * @memberof AccountDto */ - 'address': string; + 'publicKey': any; /** * * @type {any} * @memberof AccountDto */ - 'publicKey': any; + 'address': any; + /** + * + * @type {WalletsDtoWalletsInnerOrigin} + * @memberof AccountDto + */ + 'origin': WalletsDtoWalletsInnerOrigin; /** * * @type {string} @@ -1272,16 +1278,22 @@ export interface WalletDtoAccount { 'id': string; /** * - * @type {string} + * @type {any} * @memberof WalletDtoAccount */ - 'address': string; + 'publicKey': any; /** * * @type {any} * @memberof WalletDtoAccount */ - 'publicKey': any; + 'address': any; + /** + * + * @type {WalletsDtoWalletsInnerOrigin} + * @memberof WalletDtoAccount + */ + 'origin': WalletsDtoWalletsInnerOrigin; /** * * @type {string}