Skip to content

Commit 7708f03

Browse files
committed
fix: ensure enum replacement objects are reachable for type resolution
1 parent e369fe2 commit 7708f03

File tree

2 files changed

+47
-32
lines changed

2 files changed

+47
-32
lines changed

src/global/constants.ts

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
/* eslint-disable no-underscore-dangle */
12
import type { FeeMarginPercentage } from '../types';
23
import { ETransactionVersion, RPCSPEC08 } from '../types/api';
4+
import { ValuesType } from '../types/helpers/valuesType';
35
import type { LogLevel } from './logger.type';
46

57
export { IS_BROWSER } from '../utils/encode';
@@ -32,29 +34,6 @@ export const RANGE_FELT = range(ZERO, PRIME - 1n);
3234
export const RANGE_I128 = range(-(2n ** 127n), 2n ** 127n - 1n);
3335
export const RANGE_U128 = range(ZERO, 2n ** 128n - 1n);
3436

35-
export enum BaseUrl {
36-
SN_MAIN = 'https://alpha-mainnet.starknet.io',
37-
SN_SEPOLIA = 'https://alpha-sepolia.starknet.io',
38-
}
39-
40-
export enum NetworkName {
41-
SN_MAIN = 'SN_MAIN',
42-
SN_SEPOLIA = 'SN_SEPOLIA',
43-
}
44-
45-
export enum StarknetChainId {
46-
SN_MAIN = '0x534e5f4d41494e', // encodeShortString('SN_MAIN'),
47-
SN_SEPOLIA = '0x534e5f5345504f4c4941', // encodeShortString('SN_SEPOLIA')
48-
}
49-
50-
export enum TransactionHashPrefix {
51-
DECLARE = '0x6465636c617265', // encodeShortString('declare'),
52-
DEPLOY = '0x6465706c6f79', // encodeShortString('deploy'),
53-
DEPLOY_ACCOUNT = '0x6465706c6f795f6163636f756e74', // encodeShortString('deploy_account'),
54-
INVOKE = '0x696e766f6b65', // encodeShortString('invoke'),
55-
L1_HANDLER = '0x6c315f68616e646c6572', // encodeShortString('l1_handler'),
56-
}
57-
5837
export const UDC = {
5938
ADDRESS: '0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf',
6039
ENTRYPOINT: 'deployContract',
@@ -72,14 +51,48 @@ export const HARDENING_BYTE = 128;
7251
// 0x80000000
7352
export const HARDENING_4BYTES = 2147483648n;
7453

54+
// NOTE: the enum alias exports are made so both the 'const' and 'type' are reachable in the published '.d.ts' file,
55+
// otherwise the last export hides the preceding export with the same name in this file
56+
const _BaseUrl = {
57+
SN_MAIN: 'https://alpha-mainnet.starknet.io',
58+
SN_SEPOLIA: 'https://alpha-sepolia.starknet.io',
59+
} as const;
60+
type _BaseUrl = ValuesType<typeof _BaseUrl>;
61+
export { _BaseUrl as BaseUrl };
62+
63+
const _NetworkName = {
64+
SN_MAIN: 'SN_MAIN',
65+
SN_SEPOLIA: 'SN_SEPOLIA',
66+
} as const;
67+
type _NetworkName = ValuesType<typeof _NetworkName>;
68+
export { _NetworkName as NetworkName };
69+
70+
const _StarknetChainId = {
71+
SN_MAIN: '0x534e5f4d41494e', // encodeShortString('SN_MAIN'),
72+
SN_SEPOLIA: '0x534e5f5345504f4c4941', // encodeShortString('SN_SEPOLIA')
73+
} as const;
74+
type _StarknetChainId = ValuesType<typeof _StarknetChainId>;
75+
export { _StarknetChainId as StarknetChainId };
76+
77+
const _TransactionHashPrefix = {
78+
DECLARE: '0x6465636c617265', // encodeShortString('declare'),
79+
DEPLOY: '0x6465706c6f79', // encodeShortString('deploy'),
80+
DEPLOY_ACCOUNT: '0x6465706c6f795f6163636f756e74', // encodeShortString('deploy_account'),
81+
INVOKE: '0x696e766f6b65', // encodeShortString('invoke'),
82+
L1_HANDLER: '0x6c315f68616e646c6572', // encodeShortString('l1_handler'),
83+
} as const;
84+
type _TransactionHashPrefix = ValuesType<typeof _TransactionHashPrefix>;
85+
export { _TransactionHashPrefix as TransactionHashPrefix };
86+
7587
/**
76-
* dot formate rpc versions
88+
* dot format rpc versions
7789
*/
78-
export const SupportedRpcVersion = {
90+
const _SupportedRpcVersion = {
7991
0.7: '0.7',
8092
0.8: '0.8',
8193
} as const;
82-
export type SupportedRpcVersion = (typeof SupportedRpcVersion)[keyof typeof SupportedRpcVersion];
94+
type _SupportedRpcVersion = ValuesType<typeof _SupportedRpcVersion>;
95+
export { _SupportedRpcVersion as SupportedRpcVersion };
8396

8497
export type SupportedTransactionVersion =
8598
| typeof ETransactionVersion.V2
@@ -89,7 +102,7 @@ export type SupportedTransactionVersion =
89102
export const DEFAULT_GLOBAL_CONFIG: {
90103
legacyMode: boolean;
91104
logLevel: LogLevel;
92-
rpcVersion: SupportedRpcVersion;
105+
rpcVersion: _SupportedRpcVersion;
93106
transactionVersion: SupportedTransactionVersion;
94107
feeMarginPercentage: FeeMarginPercentage;
95108
} = {

src/types/outsideExecution.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ValuesType } from './helpers/valuesType';
12
import { BigNumberish, RawArgs, type Signature } from './lib';
23

34
export interface OutsideExecutionOptions {
@@ -74,8 +75,9 @@ export const OutsideExecutionTypesV2 = {
7475
],
7576
};
7677

77-
export enum OutsideExecutionVersion {
78-
UNSUPPORTED = '0',
79-
V1 = '1',
80-
V2 = '2',
81-
}
78+
export const OutsideExecutionVersion = {
79+
UNSUPPORTED: '0',
80+
V1: '1',
81+
V2: '2',
82+
} as const;
83+
export type OutsideExecutionVersion = ValuesType<typeof OutsideExecutionVersion>;

0 commit comments

Comments
 (0)