|
| 1 | +import { BaseCoin, BaseUnit, CoinFeature, CoinKind, KeyCurve, UnderlyingAsset } from './base'; |
| 2 | +import { KaspaMainnet, KaspaTestnet } from './networks'; |
| 3 | + |
| 4 | +export interface KaspaConstructorOptions { |
| 5 | + id: string; |
| 6 | + fullName: string; |
| 7 | + name: string; |
| 8 | + network: KaspaMainnet | KaspaTestnet; |
| 9 | + features: CoinFeature[]; |
| 10 | + asset: UnderlyingAsset; |
| 11 | + prefix?: string; |
| 12 | + suffix?: string; |
| 13 | + primaryKeyCurve: KeyCurve; |
| 14 | +} |
| 15 | + |
| 16 | +export class KaspaCoin extends BaseCoin { |
| 17 | + public static readonly DEFAULT_FEATURES = [ |
| 18 | + CoinFeature.UNSPENT_MODEL, |
| 19 | + CoinFeature.TSS, |
| 20 | + CoinFeature.TSS_COLD, |
| 21 | + CoinFeature.CUSTODY, |
| 22 | + CoinFeature.CUSTODY_BITGO_TRUST, |
| 23 | + CoinFeature.CUSTODY_BITGO_INDIA, |
| 24 | + CoinFeature.CUSTODY_BITGO_MENA_FZE, |
| 25 | + CoinFeature.CUSTODY_BITGO_CUSTODY_MENA_FZE, |
| 26 | + CoinFeature.CUSTODY_BITGO_GERMANY, |
| 27 | + CoinFeature.CUSTODY_BITGO_FRANKFURT, |
| 28 | + ]; |
| 29 | + |
| 30 | + public readonly network: KaspaMainnet | KaspaTestnet; |
| 31 | + |
| 32 | + constructor(options: KaspaConstructorOptions) { |
| 33 | + super({ |
| 34 | + ...options, |
| 35 | + kind: CoinKind.CRYPTO, |
| 36 | + isToken: false, |
| 37 | + decimalPlaces: 8, |
| 38 | + baseUnit: BaseUnit.KASPA, |
| 39 | + }); |
| 40 | + |
| 41 | + this.network = options.network; |
| 42 | + } |
| 43 | + |
| 44 | + protected disallowedFeatures(): Set<CoinFeature> { |
| 45 | + return new Set([CoinFeature.ACCOUNT_MODEL]); |
| 46 | + } |
| 47 | + |
| 48 | + protected requiredFeatures(): Set<CoinFeature> { |
| 49 | + return new Set([CoinFeature.UNSPENT_MODEL]); |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +/** |
| 54 | + * Factory function for Kaspa coin instances. |
| 55 | + * |
| 56 | + * @param id uuid v4 |
| 57 | + * @param name unique identifier of the coin |
| 58 | + * @param fullName Complete human-readable name of the coin |
| 59 | + * @param network Network object for this coin |
| 60 | + * @param asset Asset which this coin represents. This is the same for both mainnet and testnet variants of a coin. |
| 61 | + * @param features? Features of this coin. Defaults to the DEFAULT_FEATURES defined in `KaspaCoin` |
| 62 | + * @param prefix? Optional coin prefix. Defaults to empty string |
| 63 | + * @param suffix? Optional coin suffix. Defaults to coin name. |
| 64 | + * @param primaryKeyCurve The elliptic curve for this chain/token |
| 65 | + */ |
| 66 | +export function kaspa( |
| 67 | + id: string, |
| 68 | + name: string, |
| 69 | + fullName: string, |
| 70 | + network: KaspaMainnet | KaspaTestnet, |
| 71 | + asset: UnderlyingAsset, |
| 72 | + features: CoinFeature[] = KaspaCoin.DEFAULT_FEATURES, |
| 73 | + prefix = '', |
| 74 | + suffix: string = name.toUpperCase(), |
| 75 | + primaryKeyCurve: KeyCurve = KeyCurve.Secp256k1 |
| 76 | +) { |
| 77 | + return Object.freeze( |
| 78 | + new KaspaCoin({ |
| 79 | + id, |
| 80 | + name, |
| 81 | + fullName, |
| 82 | + network, |
| 83 | + prefix, |
| 84 | + suffix, |
| 85 | + features, |
| 86 | + asset, |
| 87 | + primaryKeyCurve, |
| 88 | + }) |
| 89 | + ); |
| 90 | +} |
0 commit comments