Skip to content

Commit d577320

Browse files
committed
feat(1540): Replace outdated key schemas with keySchema
Signed-off-by: matevszm <mateusz.marcinkowski@blockydevs.com>
1 parent 33dc43f commit d577320

File tree

30 files changed

+108
-116
lines changed

30 files changed

+108
-116
lines changed

src/__tests__/integration/token/create-nft.integration.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ describe('Create NFT Integration Tests', () => {
8585
expect(createNftOutput.name).toBe('Test NFT');
8686
expect(createNftOutput.alias).toBe('test-nft');
8787
expect(createNftOutput.treasuryId).toBe(viewAccountOutput.accountId);
88-
expect(createNftOutput.adminAccountId).toBe(viewAccountOutput.accountId);
89-
expect(createNftOutput.supplyAccountId).toBe(viewAccountOutput.accountId);
9088
expect(createNftOutput.symbol).toBe('NFT');
9189
expect(createNftOutput.supplyType).toBe(SupplyType.FINITE);
9290
});

src/__tests__/integration/token/mint-nft.integration.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ describe('Mint NFT Integration Tests', () => {
9090
expect(createNftOutput.name).toBe('Test NFT Collection');
9191
expect(createNftOutput.alias).toBe('test-nft-collection');
9292
expect(createNftOutput.treasuryId).toBe(viewAccountOutput.accountId);
93-
expect(createNftOutput.adminAccountId).toBe(viewAccountOutput.accountId);
94-
expect(createNftOutput.supplyAccountId).toBe(viewAccountOutput.accountId);
9593
expect(createNftOutput.symbol).toBe('TNFT');
9694
expect(createNftOutput.supplyType).toBe(SupplyType.FINITE);
9795

src/__tests__/integration/token/transfer-nft.integration.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,6 @@ describe('Transfer NFT Integration Tests', () => {
106106
expect(createNftOutput.treasuryId).toBe(
107107
createSourceAccountOutput.accountId,
108108
);
109-
expect(createNftOutput.adminAccountId).toBe(
110-
createSourceAccountOutput.accountId,
111-
);
112-
expect(createNftOutput.supplyAccountId).toBe(
113-
createSourceAccountOutput.accountId,
114-
);
115109
expect(createNftOutput.symbol).toBe('TNFTC');
116110
expect(createNftOutput.supplyType).toBe(SupplyType.FINITE);
117111

src/core/services/token/token-service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,11 @@ export class TokenServiceImpl implements TokenService {
112112
.setTokenType(TokenTypeMap[tokenType])
113113
.setInitialSupply(initialSupplyRaw)
114114
.setSupplyType(tokenSupplyType)
115-
.setTreasuryAccountId(AccountId.fromString(treasuryId))
116-
.setAdminKey(adminPublicKey);
115+
.setTreasuryAccountId(AccountId.fromString(treasuryId));
116+
117+
if (adminPublicKey) {
118+
tokenCreateTx.setAdminKey(adminPublicKey);
119+
}
117120

118121
// Set max supply for finite supply tokens
119122
if (supplyType === SupplyType.FINITE && maxSupplyRaw !== undefined) {

src/core/types/token.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export interface TokenCreateParams {
6363
tokenType: HederaTokenType;
6464
supplyType: SupplyType;
6565
maxSupplyRaw?: bigint; // Required for FINITE supply type
66-
adminPublicKey: PublicKey;
66+
adminPublicKey?: PublicKey;
6767
supplyPublicKey?: PublicKey;
6868
wipePublicKey?: PublicKey;
6969
kycPublicKey?: PublicKey;

src/core/utils/resolve-payer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { CoreApi } from '@/core';
22
import type { KeyManagerName } from '@/core/services/kms/kms-types.interface';
33

4-
import { PrivateKeySchema } from '@/core';
4+
import { KeySchema } from '@/core';
55

66
/**
77
* Resolves payer from string (alias or account-id:private-key format)
@@ -17,7 +17,7 @@ export async function resolvePayer(
1717
): Promise<void> {
1818
const keyManager =
1919
coreApi.config.getOption<KeyManagerName>('default_key_manager') || 'local';
20-
const parsedPayer = PrivateKeySchema.parse(payerString);
20+
const parsedPayer = KeySchema.parse(payerString);
2121
const resolvedPayer = await coreApi.keyResolver.resolveAccountCredentials(
2222
parsedPayer,
2323
keyManager,

src/plugins/account/__tests__/unit/import.test.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,14 @@ describe('account plugin - import command (ADR-003)', () => {
6363

6464
const result = await importAccount(args);
6565

66-
expect(kms.importAndValidatePrivateKey).toHaveBeenCalledWith(
67-
KeyAlgorithm.ECDSA,
68-
'abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890',
69-
'0230a1f42abc4794541e4a4389ec7e822666b8a7693c4cc3dedd2746b32f9c015b',
70-
'local',
71-
);
7266
expect(mirrorMock.getAccount).toHaveBeenCalledWith('0.0.9999');
7367
expect(alias.register).toHaveBeenCalledWith(
7468
expect.objectContaining({
7569
alias: 'imported',
7670
type: AliasType.Account,
7771
network: 'testnet',
7872
entityId: '0.0.9999',
79-
publicKey: 'pub-key-test',
73+
publicKey: expect.any(String),
8074
keyRefId: 'kr_test123',
8175
}),
8276
);

src/plugins/account/commands/import/handler.ts

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { KeyManagerName } from '@/core/services/kms/kms-types.interface';
44
import type { AccountData } from '@/plugins/account/schema';
55
import type { ImportAccountOutput } from './output';
66

7-
import { StateError, ValidationError } from '@/core/errors';
7+
import { StateError } from '@/core/errors';
88
import { AliasType } from '@/core/services/alias/alias-service.interface';
99
import { composeKey } from '@/core/utils/key-composer';
1010
import { buildAccountEvmAddress } from '@/plugins/account/utils/account-address';
@@ -20,43 +20,36 @@ export class ImportAccountCommand implements Command {
2020

2121
const validArgs = ImportAccountInputSchema.parse(args.args);
2222

23-
const key = validArgs.key;
2423
const alias = validArgs.name;
2524
const keyManagerArg = validArgs.keyManager;
26-
const accountId = key.accountId;
2725
const network = api.network.getCurrentNetwork();
28-
const accountKey = composeKey(network, accountId);
29-
30-
if (accountState.hasAccount(accountKey)) {
31-
throw new StateError('Account with this ID is already saved in state');
32-
}
3326

3427
const keyManager =
35-
keyManagerArg ||
28+
keyManagerArg ??
3629
api.config.getOption<KeyManagerName>('default_key_manager');
3730

38-
api.alias.availableOrThrow(alias, network);
39-
40-
const accountInfo = await api.mirror.getAccount(key.accountId);
41-
42-
const { keyRefId, publicKey } = api.kms.importAndValidatePrivateKey(
43-
accountInfo.keyAlgorithm,
44-
key.privateKey,
45-
accountInfo.accountPublicKey,
31+
const resolved = await api.keyResolver.resolveAccountCredentials(
32+
validArgs.key,
4633
keyManager,
34+
['account:import'],
4735
);
4836

49-
logger.info(`Importing account: ${accountKey} (${accountId})`);
37+
const accountId = resolved.accountId;
38+
const accountKey = composeKey(network, accountId);
5039

5140
if (accountState.hasAccount(accountKey)) {
52-
throw new ValidationError(
53-
`Account with identifier '${accountKey}' already exists`,
54-
);
41+
throw new StateError('Account with this ID is already saved in state');
5542
}
5643

44+
api.alias.availableOrThrow(alias, network);
45+
46+
const accountInfo = await api.mirror.getAccount(accountId);
47+
48+
logger.info(`Importing account: ${accountKey} (${accountId})`);
49+
5750
const evmAddress = buildAccountEvmAddress({
5851
accountId,
59-
publicKey,
52+
publicKey: resolved.publicKey,
6053
keyType: accountInfo.keyAlgorithm,
6154
existingEvmAddress: accountInfo.evmAddress,
6255
});
@@ -68,8 +61,8 @@ export class ImportAccountCommand implements Command {
6861
network: api.network.getCurrentNetwork(),
6962
entityId: accountId,
7063
evmAddress,
71-
publicKey,
72-
keyRefId,
64+
publicKey: resolved.publicKey,
65+
keyRefId: resolved.keyRefId,
7366
createdAt: new Date().toISOString(),
7467
});
7568
}
@@ -78,9 +71,9 @@ export class ImportAccountCommand implements Command {
7871
name: alias,
7972
accountId,
8073
type: accountInfo.keyAlgorithm,
81-
publicKey: publicKey,
74+
publicKey: resolved.publicKey,
8275
evmAddress,
83-
keyRefId,
76+
keyRefId: resolved.keyRefId,
8477
network: api.network.getCurrentNetwork(),
8578
};
8679

src/plugins/account/commands/import/input.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { z } from 'zod';
22

33
import {
4-
AccountIdWithPrivateKeySchema,
54
AccountNameSchema,
65
KeyManagerTypeSchema,
6+
KeySchema,
77
} from '@/core/schemas';
88

99
/**
1010
* Input schema for account import command
1111
* Validates arguments for importing an existing account
1212
*/
1313
export const ImportAccountInputSchema = z.object({
14-
key: AccountIdWithPrivateKeySchema.describe(
15-
'Account ID with private key in format accountId:privateKey',
14+
key: KeySchema.describe(
15+
'Account credentials. Can be accountId:privateKey pair, key reference or account alias.',
1616
),
1717
name: AccountNameSchema.optional().describe('Optional account name/alias'),
1818
keyManager: KeyManagerTypeSchema.optional().describe(

src/plugins/network/commands/set-operator/input.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import { z } from 'zod';
22

3-
import {
4-
KeyManagerTypeSchema,
5-
NetworkSchema,
6-
PrivateKeyWithAccountIdSchema,
7-
} from '@/core/schemas';
3+
import { KeyManagerTypeSchema, KeySchema, NetworkSchema } from '@/core/schemas';
84

95
/**
106
* Input schema for network set-operator command
117
* Validates arguments for setting operator credentials
128
*/
139
export const SetOperatorInputSchema = z.object({
14-
operator: PrivateKeyWithAccountIdSchema.describe(
10+
operator: KeySchema.describe(
1511
'Operator credentials. Can be accountId:privateKey pair, key reference or account alias.',
1612
),
1713
network: NetworkSchema.optional().describe(

0 commit comments

Comments
 (0)