Skip to content

Commit 2ac2971

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

File tree

28 files changed

+93
-124
lines changed

28 files changed

+93
-124
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 & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
/**
2-
* Account Import Command Handler
3-
* Handles importing existing accounts using the Core API
4-
* Follows ADR-003 contract: returns CommandExecutionResult
5-
*/
61
import type { CommandHandlerArgs, CommandResult } from '@/core';
72
import type { KeyManagerName } from '@/core/services/kms/kms-types.interface';
83
import type { AccountData } from '@/plugins/account/schema';
94
import type { ImportAccountOutput } from './output';
105

11-
import { StateError, ValidationError } from '@/core/errors';
6+
import { StateError } from '@/core/errors';
127
import { AliasType } from '@/core/services/alias/alias-service.interface';
138
import { composeKey } from '@/core/utils/key-composer';
149
import { buildAccountEvmAddress } from '@/plugins/account/utils/account-address';
@@ -21,53 +16,40 @@ export async function importAccount(
2116
): Promise<CommandResult> {
2217
const { api, logger } = args;
2318

24-
// Initialize Zustand state helper
2519
const accountState = new ZustandAccountStateHelper(api.state, logger);
2620

27-
// Parse and validate command arguments
2821
const validArgs = ImportAccountInputSchema.parse(args.args);
2922

30-
const key = validArgs.key;
3123
const alias = validArgs.name;
3224
const keyManagerArg = validArgs.keyManager;
33-
const accountId = key.accountId;
3425
const network = api.network.getCurrentNetwork();
35-
const accountKey = composeKey(network, accountId);
36-
37-
if (accountState.hasAccount(accountKey)) {
38-
throw new StateError('Account with this ID is already saved in state');
39-
}
4026

41-
// Get keyManager from args or fallback to config
4227
const keyManager =
43-
keyManagerArg ||
28+
keyManagerArg ??
4429
api.config.getOption<KeyManagerName>('default_key_manager');
4530

46-
// Check if account name already exists
47-
api.alias.availableOrThrow(alias, network);
48-
49-
// Get account info from mirror node
50-
const accountInfo = await api.mirror.getAccount(key.accountId);
51-
52-
const { keyRefId, publicKey } = api.kms.importAndValidatePrivateKey(
53-
accountInfo.keyAlgorithm,
54-
key.privateKey,
55-
accountInfo.accountPublicKey,
31+
const resolved = await api.keyResolver.resolveAccountCredentials(
32+
validArgs.key,
5633
keyManager,
34+
['account:import'],
5735
);
5836

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

61-
// Check if account name already exists
6240
if (accountState.hasAccount(accountKey)) {
63-
throw new ValidationError(
64-
`Account with identifier '${accountKey}' already exists`,
65-
);
41+
throw new StateError('Account with this ID is already saved in state');
6642
}
6743

44+
api.alias.availableOrThrow(alias, network);
45+
46+
const accountInfo = await api.mirror.getAccount(accountId);
47+
48+
logger.info(`Importing account: ${accountKey} (${accountId})`);
49+
6850
const evmAddress = buildAccountEvmAddress({
6951
accountId,
70-
publicKey,
52+
publicKey: resolved.publicKey,
7153
keyType: accountInfo.keyAlgorithm,
7254
existingEvmAddress: accountInfo.evmAddress,
7355
});
@@ -79,27 +61,24 @@ export async function importAccount(
7961
network: api.network.getCurrentNetwork(),
8062
entityId: accountId,
8163
evmAddress,
82-
publicKey,
83-
keyRefId,
64+
publicKey: resolved.publicKey,
65+
keyRefId: resolved.keyRefId,
8466
createdAt: new Date().toISOString(),
8567
});
8668
}
8769

88-
// Create account object (no private key in plugin state)
8970
const account: AccountData = {
9071
name: alias,
9172
accountId,
9273
type: accountInfo.keyAlgorithm,
93-
publicKey: publicKey,
74+
publicKey: resolved.publicKey,
9475
evmAddress,
95-
keyRefId,
76+
keyRefId: resolved.keyRefId,
9677
network: api.network.getCurrentNetwork(),
9778
};
9879

99-
// Store account in state using the helper
10080
accountState.saveAccount(accountKey, account);
10181

102-
// Prepare output data
10382
const outputData: ImportAccountOutput = {
10483
accountId,
10584
name: alias,

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)