Skip to content

Commit 5180249

Browse files
authored
Merge pull request #7961 from BitGo/WIN-8664
chore(sdk-coin-polyx): export utils for UI
2 parents 937b0a0 + 186c5d4 commit 5180249

4 files changed

Lines changed: 29 additions & 0 deletions

File tree

modules/sdk-coin-polyx/src/lib/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@ export const POLYX_ADDRESS_FORMAT = 12;
1111
* Tpolyx testnet address format
1212
*/
1313
export const TPOLYX_ADDRESS_FORMAT = 42;
14+
15+
/**
16+
* Regex pattern for validating Polymesh DID (Decentralized Identifier)
17+
* DIDs are 32-byte hex strings (0x prefix + 64 hex characters)
18+
*/
19+
export const POLYX_DID_REGEX = /^0x[a-fA-F0-9]{64}$/;

modules/sdk-coin-polyx/src/lib/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,17 @@ export { BatchStakingBuilder as BatchBuilder } from './batchStakingBuilder';
2121
export { BatchUnstakingBuilder } from './batchUnstakingBuilder';
2222
export { UnbondBuilder } from './unbondBuilder';
2323
export { WithdrawUnbondedBuilder } from './withdrawUnbondedBuilder';
24+
import polyxUtils from './utils';
2425
export { Utils, default as utils } from './utils';
2526
export * from './iface';
2627

2728
export { BondArgs, NominateArgs, BatchCallObject, BatchArgs } from './iface';
29+
30+
/**
31+
* Checks if a string is a valid Polymesh DID (Decentralized Identifier)
32+
* DIDs are 32-byte hex strings (0x prefix + 64 hex characters)
33+
*
34+
* @param {string} did - The string to validate
35+
* @returns {boolean} true if valid DID format, false otherwise
36+
*/
37+
export const isValidDid = (did: string): boolean => polyxUtils.isValidDid(did);

modules/sdk-coin-polyx/src/lib/utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { NetworkType } from '@bitgo/statics';
33
import { TypeRegistry } from '@substrate/txwrapper-core/lib/types';
44
import { mainnetMaterial, testnetMaterial } from '../resources';
55
import { BatchCallObject } from './iface';
6+
import { POLYX_DID_REGEX } from './constants';
67

78
export class Utils extends SubstrateUtils {
89
/**
@@ -17,6 +18,17 @@ export class Utils extends SubstrateUtils {
1718
return isMainnet ? 12 : 42;
1819
}
1920

21+
/**
22+
* Checks if a string is a valid Polymesh DID (Decentralized Identifier)
23+
* DIDs are 32-byte hex strings (0x prefix + 64 hex characters)
24+
*
25+
* @param {string} did - The string to validate
26+
* @returns {boolean} true if valid DID format, false otherwise
27+
*/
28+
isValidDid(did: string): boolean {
29+
return POLYX_DID_REGEX.test(did);
30+
}
31+
2032
getMaterial(networkType: NetworkType): Interface.Material {
2133
return (networkType === NetworkType.MAINNET ? mainnetMaterial : testnetMaterial) as unknown as Interface.Material;
2234
}

modules/statics/src/coinFeatures.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ export const POLYX_FEATURES = [
653653
CoinFeature.STAKING,
654654
CoinFeature.SUPPORTS_TOKENS,
655655
CoinFeature.STUCK_TRANSACTION_MANAGEMENT_TSS,
656+
CoinFeature.ALTERNATIVE_ADDRESS_IDENTIFIER,
656657
];
657658

658659
export const POLYX_TOKEN_FEATURES = [

0 commit comments

Comments
 (0)