Skip to content

Commit

Permalink
Don't strip origin field from vault public accounts (#563)
Browse files Browse the repository at this point in the history
* add origin to publicaccount schema

* switch import in account dto

* updated vault client in sdk
  • Loading branch information
Ptroger authored Oct 11, 2024
1 parent 016b14b commit 3a72c9c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 27 deletions.
8 changes: 1 addition & 7 deletions apps/vault/src/shared/type/domain.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,7 @@ export const PrivateAccount = z.object({
})
export type PrivateAccount = z.infer<typeof PrivateAccount>

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<typeof PublicAccount>

export const LocalRootKey = z.object({
Expand Down
32 changes: 21 additions & 11 deletions apps/vault/src/vault/__test__/e2e/account.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
}
]
})
Expand Down Expand Up @@ -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
}
])
})
Expand Down Expand Up @@ -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
}
])
})
Expand Down Expand Up @@ -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
}
])
})
Expand All @@ -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)
})
Expand Down Expand Up @@ -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)
})
Expand Down
6 changes: 4 additions & 2 deletions apps/vault/src/vault/__test__/e2e/wallet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})

Expand Down Expand Up @@ -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'
})
Expand Down
2 changes: 1 addition & 1 deletion apps/vault/src/vault/http/rest/dto/account.dto.ts
Original file line number Diff line number Diff line change
@@ -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) {}
24 changes: 18 additions & 6 deletions packages/armory-sdk/src/lib/http/client/vault/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 3a72c9c

Please sign in to comment.