Skip to content
53 changes: 31 additions & 22 deletions modules/abstract-utxo/src/abstractUtxoCoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ import {
ErrorImplicitExternalOutputs,
} from './transaction/descriptor/verifyTransaction';
import { assertDescriptorWalletAddress, getDescriptorMapFromWallet, isDescriptorWallet } from './descriptor';
import { getChainFromNetwork, getFamilyFromNetwork, getFullNameFromNetwork } from './names';
import {
getFullNameFromCoinName,
getMainnetCoinName,
getNetworkFromCoinName,
UtxoCoinName,
UtxoCoinNameMainnet,
} from './names';
import { assertFixedScriptWalletAddress } from './address/fixedScript';
import { isSdkBackend, ParsedTransaction, SdkBackend } from './transaction/types';
import { decodePsbtWith, encodeTransaction, stringToBufferTryFormats } from './transaction/decode';
Expand Down Expand Up @@ -369,42 +375,37 @@ export abstract class AbstractUtxoCoin
extends BaseCoin
implements Musig2Participant<utxolib.bitgo.UtxoPsbt>, Musig2Participant<fixedScriptWallet.BitGoPsbt>
{
abstract name: UtxoCoinName;

public altScriptHash?: number;
public supportAltScriptDestination?: boolean;
public defaultSdkBackend: SdkBackend = 'utxolib';
public readonly amountType: 'number' | 'bigint';
private readonly _network: utxolib.Network;

protected constructor(bitgo: BitGoBase, network: utxolib.Network, amountType: 'number' | 'bigint' = 'number') {
protected constructor(bitgo: BitGoBase, amountType: 'number' | 'bigint' = 'number') {
super(bitgo);
if (!utxolib.isValidNetwork(network)) {
throw new Error(
'invalid network: please make sure to use the same version of ' +
'@bitgo/utxo-lib as this library when initializing an instance of this class'
);
}
this.amountType = amountType;
this._network = network;
}

get network() {
return this._network;
/** @deprecated - will be removed when we drop support for utxolib */
get network(): utxolib.Network {
return getNetworkFromCoinName(this.name);
}

getChain() {
return getChainFromNetwork(this.network);
getChain(): UtxoCoinName {
return this.name;
}

getFamily() {
return getFamilyFromNetwork(this.network);
getFamily(): UtxoCoinNameMainnet {
return getMainnetCoinName(this.name);
}

getFullName() {
return getFullNameFromNetwork(this.network);
getFullName(): string {
return getFullNameFromCoinName(this.name);
}

/** Indicates whether the coin supports a block target */
supportsBlockTarget() {
supportsBlockTarget(): boolean {
// FIXME: the SDK does not seem to use this anywhere so it is unclear what the purpose of this method is
switch (getMainnet(this.network)) {
case utxolib.networks.bitcoin:
Expand All @@ -428,7 +429,7 @@ export abstract class AbstractUtxoCoin
* Returns the factor between the base unit and its smallest subdivison
* @return {number}
*/
getBaseFactor() {
getBaseFactor(): number {
return 1e8;
}

Expand Down Expand Up @@ -466,7 +467,7 @@ export abstract class AbstractUtxoCoin
* @param {String} pub the pub to be checked
* @returns {Boolean} is it valid?
*/
isValidPub(pub: string) {
isValidPub(pub: string): boolean {
try {
return bip32.fromBase58(pub).isNeutered();
} catch (e) {
Expand Down Expand Up @@ -1056,7 +1057,15 @@ export abstract class AbstractUtxoCoin
}

/** @inheritDoc */
auditDecryptedKey({ multiSigType, publicKey, prv }) {
auditDecryptedKey({
multiSigType,
publicKey,
prv,
}: {
multiSigType: MultisigType;
publicKey: string;
prv: string;
}): void {
if (multiSigType === 'tss') {
throw new Error('tss auditing is not supported for this coin');
}
Expand Down
9 changes: 6 additions & 3 deletions modules/abstract-utxo/src/impl/bch/bch.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { BitGoBase } from '@bitgo/sdk-core';
import * as utxolib from '@bitgo/utxo-lib';

import { AbstractUtxoCoin, UtxoNetwork } from '../../abstractUtxoCoin';
import { AbstractUtxoCoin } from '../../abstractUtxoCoin';
import { UtxoCoinName } from '../../names';
import { isScriptRecipient } from '../../transaction';

export class Bch extends AbstractUtxoCoin {
protected constructor(bitgo: BitGoBase, network?: UtxoNetwork) {
super(bitgo, network || utxolib.networks.bitcoincash);
readonly name: UtxoCoinName = 'bch';

protected constructor(bitgo: BitGoBase) {
super(bitgo);
}

static createInstance(bitgo: BitGoBase): Bch {
Expand Down
7 changes: 5 additions & 2 deletions modules/abstract-utxo/src/impl/bch/tbch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
* @prettier
*/
import { BitGoBase } from '@bitgo/sdk-core';
import * as bitcoin from '@bitgo/utxo-lib';

import { UtxoCoinName } from '../../names';

import { Bch } from './bch';

export class Tbch extends Bch {
readonly name: UtxoCoinName = 'tbch';

constructor(bitgo: BitGoBase) {
super(bitgo, bitcoin.networks.bitcoincashTestnet);
super(bitgo);
}

static createInstance(bitgo: BitGoBase): Tbch {
Expand Down
9 changes: 5 additions & 4 deletions modules/abstract-utxo/src/impl/bcha/bcha.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { BitGoBase } from '@bitgo/sdk-core';
import * as utxolib from '@bitgo/utxo-lib';

import { Bch } from '../bch/bch';
import { UtxoNetwork } from '../../abstractUtxoCoin';
import { UtxoCoinName } from '../../names';

export class Bcha extends Bch {
constructor(bitgo: BitGoBase, network?: UtxoNetwork) {
super(bitgo, network || utxolib.networks.ecash);
readonly name: UtxoCoinName = 'bcha';

constructor(bitgo: BitGoBase) {
super(bitgo);
}

static createInstance(bitgo: BitGoBase): Bcha {
Expand Down
7 changes: 5 additions & 2 deletions modules/abstract-utxo/src/impl/bcha/tbcha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
* @prettier
*/
import { BitGoBase } from '@bitgo/sdk-core';
import * as utxolib from '@bitgo/utxo-lib';

import { UtxoCoinName } from '../../names';

import { Bcha } from './bcha';

export class Tbcha extends Bcha {
readonly name: UtxoCoinName = 'tbcha';

constructor(bitgo: BitGoBase) {
super(bitgo, utxolib.networks.ecashTest);
super(bitgo);
}

static createInstance(bitgo: BitGoBase): Tbcha {
Expand Down
9 changes: 5 additions & 4 deletions modules/abstract-utxo/src/impl/bsv/bsv.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { BitGoBase } from '@bitgo/sdk-core';
import * as utxolib from '@bitgo/utxo-lib';

import { UtxoNetwork } from '../../abstractUtxoCoin';
import { Bch } from '../bch/bch';
import { UtxoCoinName } from '../../names';

export class Bsv extends Bch {
constructor(bitgo: BitGoBase, network?: UtxoNetwork) {
super(bitgo, network || utxolib.networks.bitcoinsv);
readonly name: UtxoCoinName = 'bsv';

constructor(bitgo: BitGoBase) {
super(bitgo);
}

static createInstance(bitgo: BitGoBase): Bsv {
Expand Down
7 changes: 5 additions & 2 deletions modules/abstract-utxo/src/impl/bsv/tbsv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
* @prettier
*/
import { BitGoBase } from '@bitgo/sdk-core';
import * as utxolib from '@bitgo/utxo-lib';

import { UtxoCoinName } from '../../names';

import { Bsv } from './bsv';

export class Tbsv extends Bsv {
readonly name: UtxoCoinName = 'tbsv';

constructor(bitgo: BitGoBase) {
super(bitgo, utxolib.networks.bitcoinsvTestnet);
super(bitgo);
}

static createInstance(bitgo: BitGoBase): Tbsv {
Expand Down
10 changes: 6 additions & 4 deletions modules/abstract-utxo/src/impl/btc/btc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {
VerifyRecoveryTransactionOptions as BaseVerifyRecoveryTransactionOptions,
Wallet,
} from '@bitgo/sdk-core';
import * as utxolib from '@bitgo/utxo-lib';

import { AbstractUtxoCoin, UtxoNetwork } from '../../abstractUtxoCoin';
import { AbstractUtxoCoin } from '../../abstractUtxoCoin';
import { UtxoCoinName } from '../../names';

import { InscriptionBuilder } from './inscriptionBuilder';

Expand All @@ -14,8 +14,10 @@ export interface VerifyRecoveryTransactionOptions extends BaseVerifyRecoveryTran
}

export class Btc extends AbstractUtxoCoin {
constructor(bitgo: BitGoBase, network?: UtxoNetwork) {
super(bitgo, network || utxolib.networks.bitcoin);
readonly name: UtxoCoinName = 'btc';

constructor(bitgo: BitGoBase) {
super(bitgo);
}

static createInstance(bitgo: BitGoBase): Btc {
Expand Down
7 changes: 5 additions & 2 deletions modules/abstract-utxo/src/impl/btc/tbtc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
* @prettier
*/
import { BitGoBase } from '@bitgo/sdk-core';
import * as utxolib from '@bitgo/utxo-lib';

import { UtxoCoinName } from '../../names';

import { Btc } from './btc';

export class Tbtc extends Btc {
readonly name: UtxoCoinName = 'tbtc';

constructor(bitgo: BitGoBase) {
super(bitgo, utxolib.networks.testnet);
super(bitgo);
}

static createInstance(bitgo: BitGoBase): Tbtc {
Expand Down
7 changes: 5 additions & 2 deletions modules/abstract-utxo/src/impl/btc/tbtc4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
* @prettier
*/
import { BitGoBase } from '@bitgo/sdk-core';
import * as utxolib from '@bitgo/utxo-lib';

import { UtxoCoinName } from '../../names';

import { Btc } from './btc';

export class Tbtc4 extends Btc {
readonly name: UtxoCoinName = 'tbtc4';

constructor(bitgo: BitGoBase) {
super(bitgo, utxolib.networks.bitcoinTestnet4);
super(bitgo);
}

static createInstance(bitgo: BitGoBase): Tbtc4 {
Expand Down
7 changes: 5 additions & 2 deletions modules/abstract-utxo/src/impl/btc/tbtcbgsig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
* @prettier
*/
import { BitGoBase } from '@bitgo/sdk-core';
import * as utxolib from '@bitgo/utxo-lib';

import { UtxoCoinName } from '../../names';

import { Btc } from './btc';

export class Tbtcbgsig extends Btc {
readonly name: UtxoCoinName = 'tbtcbgsig';

constructor(bitgo: BitGoBase) {
super(bitgo, utxolib.networks.bitcoinBitGoSignet);
super(bitgo);
}

static createInstance(bitgo: BitGoBase): Tbtcbgsig {
Expand Down
7 changes: 5 additions & 2 deletions modules/abstract-utxo/src/impl/btc/tbtcsig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
* @prettier
*/
import { BitGoBase } from '@bitgo/sdk-core';
import * as utxolib from '@bitgo/utxo-lib';

import { UtxoCoinName } from '../../names';

import { Btc } from './btc';

export class Tbtcsig extends Btc {
readonly name: UtxoCoinName = 'tbtcsig';

constructor(bitgo: BitGoBase) {
super(bitgo, utxolib.networks.bitcoinPublicSignet);
super(bitgo);
}

static createInstance(bitgo: BitGoBase): Tbtcsig {
Expand Down
10 changes: 6 additions & 4 deletions modules/abstract-utxo/src/impl/btg/btg.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { BitGoBase } from '@bitgo/sdk-core';
import * as utxolib from '@bitgo/utxo-lib';

import { AbstractUtxoCoin, UtxoNetwork } from '../../abstractUtxoCoin';
import { AbstractUtxoCoin } from '../../abstractUtxoCoin';
import { UtxoCoinName } from '../../names';

export class Btg extends AbstractUtxoCoin {
constructor(bitgo: BitGoBase, network?: UtxoNetwork) {
super(bitgo, network || utxolib.networks.bitcoingold);
readonly name: UtxoCoinName = 'btg';

constructor(bitgo: BitGoBase) {
super(bitgo);
}

static createInstance(bitgo: BitGoBase): Btg {
Expand Down
10 changes: 6 additions & 4 deletions modules/abstract-utxo/src/impl/dash/dash.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { BitGoBase } from '@bitgo/sdk-core';
import * as utxolib from '@bitgo/utxo-lib';

import { AbstractUtxoCoin, UtxoNetwork } from '../../abstractUtxoCoin';
import { AbstractUtxoCoin } from '../../abstractUtxoCoin';
import { UtxoCoinName } from '../../names';

export class Dash extends AbstractUtxoCoin {
constructor(bitgo: BitGoBase, network?: UtxoNetwork) {
super(bitgo, network || utxolib.networks.dash);
readonly name: UtxoCoinName = 'dash';

constructor(bitgo: BitGoBase) {
super(bitgo);
}

static createInstance(bitgo: BitGoBase): Dash {
Expand Down
7 changes: 5 additions & 2 deletions modules/abstract-utxo/src/impl/dash/tdash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
* @prettier
*/
import { BitGoBase } from '@bitgo/sdk-core';
import * as utxolib from '@bitgo/utxo-lib';

import { UtxoCoinName } from '../../names';

import { Dash } from './dash';

export class Tdash extends Dash {
readonly name: UtxoCoinName = 'tdash';

constructor(bitgo: BitGoBase) {
super(bitgo, utxolib.networks.dashTest);
super(bitgo);
}
static createInstance(bitgo: BitGoBase): Tdash {
return new Tdash(bitgo);
Expand Down
Loading