Skip to content

Commit 18fb95f

Browse files
committed
fix(1540): make supplyKey optional in create-nft and align KeySchema in batch-create-ft-from-file
Signed-off-by: matevszm <mateusz.marcinkowski@blockydevs.com>
1 parent 155e68a commit 18fb95f

File tree

7 files changed

+39
-24
lines changed

7 files changed

+39
-24
lines changed

src/plugins/token/README.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,10 @@ The token file supports aliases and raw keys with optional key type prefixes:
416416

417417
- **Alias**: `"my-account"` - resolved via alias service
418418
- **Account with key**: `"0.0.123456:privateKey"`
419+
- **Account ID only**: `"0.0.123456"`
420+
- **Public key**: `"ed25519:public:hex-key"` or `"ecdsa:public:hex-key"`
421+
- **Private key**: `"ed25519:private:hex-key"` or `"ecdsa:private:hex-key"`
422+
- **Key reference**: `"kr_xxx"` - managed by key manager
419423

420424
**Note**: Token name is automatically registered as an alias after successful creation. Duplicate names are not allowed.
421425

@@ -458,6 +462,10 @@ The NFT file supports aliases and raw keys with optional key type prefixes:
458462

459463
- **Alias**: `"my-account"` - resolved via alias service
460464
- **Account with key**: `"0.0.123456:privateKey"`
465+
- **Account ID only**: `"0.0.123456"`
466+
- **Public key**: `"ed25519:public:hex-key"` or `"ecdsa:public:hex-key"`
467+
- **Private key**: `"ed25519:private:hex-key"` or `"ecdsa:private:hex-key"`
468+
- **Key reference**: `"kr_xxx"` - managed by key manager
461469

462470
**Key Differences from Fungible Token:**
463471

@@ -479,18 +487,17 @@ The plugin supports flexible parameter formats:
479487
- **Account name**: `alice` (resolved via alias service)
480488
- **Amount**: Display units (default) or base units with `t` suffix (e.g., `100t`)
481489

482-
### Private Key Format
490+
### Key Format
483491

484-
Private keys can optionally be prefixed with their key type:
492+
All key parameters accept any of the following formats:
485493

486-
- **With prefix**: `ed25519:12345676543212345` or `ecdsa:12345676543212345`
487-
- **Without prefix**: `12345676543212345` (defaults to `ecdsa`)
488-
489-
This applies to:
490-
491-
- Treasury keys in `create-from-file` command
492-
- Association keys in `create-from-file` command
493-
- Account keys in `treasury-id:key` format
494+
- **Alias**: `"my-account"` - resolved via alias service
495+
- **Account with private key**: `"0.0.123456:privateKey"`
496+
- **Account ID only**: `"0.0.123456"`
497+
- **Public key with type prefix**: `"ed25519:public:hex-key"` or `"ecdsa:public:hex-key"`
498+
- **Private key with type prefix**: `"ed25519:private:hex-key"` or `"ecdsa:private:hex-key"`
499+
- **Key reference**: `"kr_xxx"` - managed by key manager
500+
- **EVM address**: `"0x..."` (where supported)
494501

495502
## 🔧 Core API Integration
496503

src/plugins/token/__tests__/unit/create-nft.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ describe('tokenCreateNftHandler', () => {
132132
},
133133
});
134134

135-
keyResolver.resolveSigningKey.mockResolvedValue({
135+
keyResolver.getPublicKey.mockResolvedValue({
136136
keyRefId: 'supply-key-ref-id',
137137
publicKey: '302a300506032b6570032100' + '0'.repeat(64),
138138
});

src/plugins/token/commands/create-nft/handler.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ import {
2222
buildTokenData,
2323
determineFiniteMaxSupply,
2424
} from '@/plugins/token/utils/token-data-builders';
25-
import { resolveOptionalKey } from '@/plugins/token/utils/token-resolve-optional-key';
25+
import {
26+
resolveOptionalKey,
27+
toPublicKey,
28+
} from '@/plugins/token/utils/token-resolve-optional-key';
2629
import { ZustandTokenStateHelper } from '@/plugins/token/zustand-state-helper';
2730

2831
export const TOKEN_CREATE_NFT_COMMAND_NAME = 'token_create-nft';
@@ -64,10 +67,11 @@ export class TokenCreateNftCommand extends BaseTransactionCommand<
6467
api.keyResolver,
6568
'token:admin',
6669
);
67-
const supply = await api.keyResolver.resolveSigningKey(
70+
const supply = await resolveOptionalKey(
6871
validArgs.supplyKey,
6972
keyManager,
70-
['token:supply'],
73+
api.keyResolver,
74+
'token:supply',
7175
);
7276

7377
let finalMaxSupply: bigint | undefined;
@@ -84,7 +88,7 @@ export class TokenCreateNftCommand extends BaseTransactionCommand<
8488
logger.debug('=== NFT PARAMS DEBUG ===');
8589
logger.debug(`Treasury ID: ${treasury.keyRefId}`);
8690
logger.debug(`Admin Key (keyRefId): ${admin?.keyRefId}`);
87-
logger.debug(`Supply Key (keyRefId): ${supply.keyRefId}`);
91+
logger.debug(`Supply Key (keyRefId): ${supply?.keyRefId}`);
8892
logger.debug(`Use Custom Treasury: ${String(Boolean(treasury))}`);
8993
logger.debug('=========================');
9094

@@ -123,7 +127,7 @@ export class TokenCreateNftCommand extends BaseTransactionCommand<
123127
adminPublicKey: normalisedParams.admin
124128
? PublicKey.fromString(normalisedParams.admin.publicKey)
125129
: undefined,
126-
supplyPublicKey: PublicKey.fromString(normalisedParams.supply.publicKey),
130+
supplyPublicKey: toPublicKey(normalisedParams.supply),
127131
memo: normalisedParams.memo,
128132
});
129133
return { transaction };
@@ -187,7 +191,7 @@ export class TokenCreateNftCommand extends BaseTransactionCommand<
187191
tokenType: normalisedParams.tokenType,
188192
supplyType: normalisedParams.supplyType,
189193
adminPublicKey: normalisedParams.admin?.publicKey,
190-
supplyPublicKey: normalisedParams.supply.publicKey,
194+
supplyPublicKey: normalisedParams.supply?.publicKey,
191195
network: normalisedParams.network,
192196
});
193197

@@ -216,7 +220,7 @@ export class TokenCreateNftCommand extends BaseTransactionCommand<
216220
adminAccountId: undefined,
217221
adminPublicKey: normalisedParams.admin?.publicKey,
218222
supplyAccountId: undefined,
219-
supplyPublicKey: normalisedParams.supply.publicKey,
223+
supplyPublicKey: normalisedParams.supply?.publicKey,
220224
alias: normalisedParams.alias,
221225
network: normalisedParams.network,
222226
};

src/plugins/token/commands/create-nft/input.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ export const TokenCreateNftInputSchema = z
3333
adminKey: KeySchema.optional().describe(
3434
'Admin key. Accepts any key format.',
3535
),
36-
supplyKey: KeySchema.describe('Supply key. Accepts any key format.'),
36+
supplyKey: KeySchema.optional().describe(
37+
'Supply key. Accepts any key format.',
38+
),
3739
name: TokenAliasNameSchema.optional().describe(
3840
'Optional alias to register for the token',
3941
),

src/plugins/token/commands/create-nft/output.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export const TokenCreateNftOutputSchema = z.object({
3131
adminPublicKey:
3232
PublicKeyDefinitionSchema.optional().describe('Admin public key'),
3333
supplyAccountId: EntityIdSchema.optional().describe('Supply account ID'),
34-
supplyPublicKey: PublicKeyDefinitionSchema.describe('Supply public key'),
34+
supplyPublicKey:
35+
PublicKeyDefinitionSchema.optional().describe('Supply public key'),
3536
alias: z.string().describe('Token alias').optional(),
3637
network: NetworkSchema.describe('Network on which token exists'),
3738
});
@@ -53,7 +54,9 @@ export const TOKEN_CREATE_NFT_TEMPLATE = `
5354
{{#if supplyAccountId}}
5455
Supply account: {{hashscanLink supplyAccountId "account" network}}
5556
{{/if}}
57+
{{#if supplyPublicKey}}
5658
Supply public key: {{supplyPublicKey}}
59+
{{/if}}
5760
{{#if alias}}
5861
Alias: {{alias}}
5962
{{/if}}

src/plugins/token/commands/create-nft/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface TokenCreateNftNormalizedParams {
2121
keyManager: KeyManagerName;
2222
treasury: ResolvedAccountCredential;
2323
admin?: ResolvedPublicKey;
24-
supply: ResolvedPublicKey;
24+
supply?: ResolvedPublicKey;
2525
finalMaxSupply?: bigint;
2626
}
2727

src/plugins/token/hooks/batch-create-ft-from-file/types.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
KeySchema,
66
MemoSchema,
77
NetworkSchema,
8-
PrivateKeySchema,
98
PrivateKeyWithAccountIdSchema,
109
ResolvedAccountCredentialSchema,
1110
ResolvedPublicKeySchema,
@@ -24,8 +23,8 @@ export const FungibleTokenFileSchema = z.object({
2423
supplyType: z.union([z.literal('finite'), z.literal('infinite')]),
2524
initialSupply: TinybarSchema,
2625
maxSupply: TinybarSchema,
27-
treasuryKey: PrivateKeyWithAccountIdSchema,
28-
adminKey: PrivateKeySchema,
26+
treasuryKey: KeySchema,
27+
adminKey: KeySchema,
2928
supplyKey: KeySchema.optional(),
3029
wipeKey: KeySchema.optional(),
3130
kycKey: KeySchema.optional(),

0 commit comments

Comments
 (0)