Skip to content

Commit 4babd8d

Browse files
committed
feat(1590): Change signing key to public key for submit key
Signed-off-by: matevszm <mateusz.marcinkowski@blockydevs.com>
1 parent 2aeea58 commit 4babd8d

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
lines changed

src/__tests__/integration/topic/create-topic.integration.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import '@/core/utils/json-serialize';
88
import { STATE_STORAGE_FILE_PATH } from '@/__tests__/test-constants';
99
import { setDefaultOperatorForNetwork } from '@/__tests__/utils/network-and-operator-setup';
1010
import { createCoreApi } from '@/core';
11+
import { KeyAlgorithm } from '@/core/shared/constants';
1112
import { topicCreate, topicList } from '@/plugins/topic';
1213

1314
describe('Create Topic Integration Tests', () => {
@@ -20,10 +21,18 @@ describe('Create Topic Integration Tests', () => {
2021
network = coreApi.network.getCurrentNetwork();
2122
});
2223
it('should create a topic and verify with list method', async () => {
24+
const operator = coreApi.network.getCurrentOperatorOrThrow();
25+
const operatorKeyEntry = coreApi.kms.get(operator.keyRefId)!;
26+
const algoPrefix =
27+
operatorKeyEntry.keyAlgorithm === KeyAlgorithm.ECDSA
28+
? 'ecdsa:public:'
29+
: 'ed25519:public:';
30+
const operatorPublicKey = `${algoPrefix}${operatorKeyEntry.publicKey}`;
31+
2332
const createTopicArgs: Record<string, unknown> = {
2433
memo: 'Test topic',
2534
adminKey: `${process.env.OPERATOR_ID}:${process.env.OPERATOR_KEY}`,
26-
submitKey: `${process.env.OPERATOR_ID}:${process.env.OPERATOR_KEY}`,
35+
submitKey: operatorPublicKey,
2736
name: 'test-topic',
2837
};
2938
const createTopicResult = await topicCreate({

src/__tests__/mocks/mocks.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,24 @@ export const makeKeyResolverMock = (
613613
return { accountId: credential.accountId };
614614
}
615615

616+
if (credential?.type === CredentialType.PUBLIC_KEY) {
617+
const importResult = options.kms?.importPublicKey
618+
? options.kms.importPublicKey(
619+
credential.keyType,
620+
credential.publicKey,
621+
keyManager,
622+
labels || [],
623+
)
624+
: {
625+
keyRefId: 'imported-pub-key-ref-id',
626+
publicKey: credential.publicKey,
627+
};
628+
return {
629+
keyRefId: importResult.keyRefId,
630+
publicKey: importResult.publicKey,
631+
};
632+
}
633+
616634
if (credential?.type === CredentialType.ALIAS && options.alias) {
617635
const network =
618636
options.network?.getCurrentNetwork() || SupportedNetwork.TESTNET;

src/plugins/topic/__tests__/unit/create.test.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import type { CoreApi, TransactionResult } from '@/core';
22
import type { AliasService } from '@/core/services/alias/alias-service.interface';
33

4-
import { ED25519_DER_PRIVATE_KEY } from '@/__tests__/mocks/fixtures';
4+
import {
5+
ECDSA_HEX_PUBLIC_KEY,
6+
ED25519_DER_PRIVATE_KEY,
7+
} from '@/__tests__/mocks/fixtures';
58
import { createMockTransaction } from '@/__tests__/mocks/hedera-sdk-mocks';
69
import {
710
makeAliasMock,
@@ -55,12 +58,9 @@ const makeApiMocks = ({
5558
[ED25519_DER_PRIVATE_KEY]: 'kr_admin',
5659
'302e020100300506032b6570042204201111111111111111111111111111111111111111111111111111111111111111':
5760
'kr_admin',
58-
'302e020100300506032b6570042204202222222222222222222222222222222222222222222222222222222222222222':
59-
'kr_submit',
6061
'302e020100300506032b6570042204203333333333333333333333333333333333333333333333333333333333333333':
6162
'kr_33333',
6263
'302e020100300506032b657004220420admin': 'kr_admin',
63-
'302e020100300506032b657004220420submit': 'kr_submit',
6464
'302e020100300506032b6570042204204444444444444444444444444444444444444444444444444444444444444444':
6565
'kr_44444',
6666
'302e020100300506032b6570042204205555555555555555555555555555555555555555555555555555555555555555':
@@ -71,6 +71,15 @@ const makeApiMocks = ({
7171
publicKey: 'mock-public-key',
7272
};
7373
});
74+
kms.importPublicKey.mockImplementation((keyType: string, key: string) => {
75+
const keyMap: Record<string, string> = {
76+
[ECDSA_HEX_PUBLIC_KEY]: 'kr_submit',
77+
};
78+
return {
79+
keyRefId: keyMap[key] || `kr_${key.slice(-5)}`,
80+
publicKey: key,
81+
};
82+
});
7483
const alias = makeAliasMock();
7584

7685
return { topicTransactions, txSign, txExecute, networkMock, kms, alias };
@@ -144,8 +153,7 @@ describe('topic plugin - create command', () => {
144153
MockedHelper.mockImplementation(() => ({ saveTopic: saveTopicMock }));
145154

146155
const adminKey = `0.0.123456:${ED25519_DER_PRIVATE_KEY}`;
147-
const submitKey =
148-
'0.0.789012:302e020100300506032b6570042204202222222222222222222222222222222222222222222222222222222222222222';
156+
const submitKey = ECDSA_HEX_PUBLIC_KEY;
149157

150158
const { topicTransactions, txSign, txExecute, networkMock, kms, alias } =
151159
makeApiMocks({
@@ -195,9 +203,9 @@ describe('topic plugin - create command', () => {
195203
'local',
196204
['topic:admin'],
197205
);
198-
expect(kms.importPrivateKey).toHaveBeenCalledWith(
206+
expect(kms.importPublicKey).toHaveBeenCalledWith(
199207
KeyAlgorithm.ECDSA,
200-
'302e020100300506032b6570042204202222222222222222222222222222222222222222222222222222222222222222',
208+
ECDSA_HEX_PUBLIC_KEY,
201209
'local',
202210
['topic:submit'],
203211
);

0 commit comments

Comments
 (0)