Skip to content

Commit

Permalink
fix(sdk-core): set default multisig if empty
Browse files Browse the repository at this point in the history
Ticket: WP-3785
  • Loading branch information
lokesh-bitgo committed Mar 6, 2025
1 parent df5fc48 commit d12605c
Show file tree
Hide file tree
Showing 25 changed files with 148 additions and 0 deletions.
5 changes: 5 additions & 0 deletions modules/abstract-utxo/src/abstractUtxoCoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,11 @@ export abstract class AbstractUtxoCoin extends BaseCoin {
return utxolib.bitgo.outputScripts.isSupportedScriptType(this.network, addressType);
}

/** {@inheritDoc } **/
supportsMultisig(): boolean {
return true;
}

/**
* @param chain
* @return true iff coin supports spending from chain
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-coin-algo/src/algo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,11 @@ export class Algo extends BaseCoin {
return false;
}

/** {@inheritDoc } **/
supportsMultisig(): boolean {
return true;
}

/**
* Gets config for how token enablements work for this coin
* @returns
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-coin-arbeth/src/arbeth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ export class Arbeth extends AbstractEthLikeNewCoins {
}
return userGasLimit;
}

/** {@inheritDoc } **/
supportsMultisig(): boolean {
return true;
}
}
5 changes: 5 additions & 0 deletions modules/sdk-coin-avaxc/src/avaxc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ export class AvaxC extends AbstractEthLikeNewCoins {
return false;
}

/** {@inheritDoc } **/
supportsMultisig(): boolean {
return true;
}

generateKeyPair(seed?: Buffer): KeyPair {
const avaxKeyPair = seed ? new AvaxcKeyPair({ seed }) : new AvaxcKeyPair();
const extendedKeys = avaxKeyPair.getExtendedKeys();
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-coin-avaxp/src/avaxp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ export class AvaxP extends BaseCoin {
return Math.pow(10, this._staticsCoin.decimalPlaces);
}

/** {@inheritDoc } **/
supportsMultisig(): boolean {
return true;
}

/**
* Check if staking txn is valid, based on expected tx params.
*
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-coin-bsc/src/bsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export class Bsc extends AbstractEthLikeNewCoins {
return true;
}

/** {@inheritDoc} */
supportsMultisig(): boolean {
return true;
}

/** @inheritDoc */
getMPCAlgorithm(): MPCAlgorithm {
return 'ecdsa';
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-coin-celo/src/celo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ export class Celo extends AbstractEthLikeCoin {
return valid;
}

/** {@inheritDoc } **/
supportsMultisig(): boolean {
return true;
}

protected getTransactionBuilder(): TransactionBuilder {
return new TransactionBuilder(coins.get(this.getBaseChain()));
}
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-coin-cspr/src/cspr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ export class Cspr extends BaseCoin {
return Math.pow(10, this._staticsCoin.decimalPlaces);
}

/** {@inheritDoc } **/
supportsMultisig(): boolean {
return true;
}

async verifyTransaction(params: VerifyTransactionOptions): Promise<boolean> {
// TODO: Implement when available on the SDK.
return true;
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-coin-eos/src/eos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ export class Eos extends BaseCoin {
return 4;
}

/** {@inheritDoc } **/
supportsMultisig() {
return true;
}

/**
* Flag for sending value of 0
* @returns {boolean} True if okay to send 0 value, false otherwise
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-coin-etc/src/etc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ export class Etc extends AbstractEthLikeCoin {
return valid;
}

/** {@inheritDoc } **/
supportsMultisig() {
return true;
}

/**
* Builds a funds recovery transaction without BitGo
* @param params
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-coin-eth/src/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ export class Eth extends AbstractEthLikeNewCoins {
return true;
}

/** {@inheritDoc } **/
supportsMultisig(): boolean {
return true;
}

getMPCAlgorithm(): MPCAlgorithm {
return 'ecdsa';
}
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-coin-hbar/src/hbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,11 @@ export class Hbar extends BaseCoin {
return false;
}

/** {@inheritDoc } **/
supportsMultisig(): boolean {
return true;
}

public getTokenEnablementConfig(): TokenEnablementConfig {
return {
requiresTokenEnablement: true,
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-coin-opeth/src/opeth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ export class Opeth extends AbstractEthLikeNewCoins {
}
return userGasLimit;
}

/** {@inheritDoc } **/
supportsMultisig(): boolean {
return true;
}
}
5 changes: 5 additions & 0 deletions modules/sdk-coin-polygon/src/polygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ export class Polygon extends AbstractEthLikeNewCoins {
return true;
}

/** {@inheritDoc } **/
supportsMultisig(): boolean {
return true;
}

/** @inheritDoc */
getMPCAlgorithm(): MPCAlgorithm {
return 'ecdsa';
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-coin-rbtc/src/rbtc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export class Rbtc extends AbstractEthLikeCoin {
return valid;
}

/** {@inheritDoc } **/
supportsMultisig() {
return true;
}

protected getTransactionBuilder(): TransactionBuilder {
return new TransactionBuilder(coins.get(this.getBaseChain()));
}
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-coin-stx/src/stx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ export class Stx extends BaseCoin {
return Math.pow(10, this._staticsCoin.decimalPlaces);
}

/** {@inheritDoc } **/
supportsMultisig(): boolean {
return true;
}

async verifyTransaction(params: VerifyTransactionOptions): Promise<boolean> {
const { txParams } = params;
if (Array.isArray(txParams.recipients) && txParams.recipients.length > 1) {
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-coin-trx/src/trx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ export class Trx extends BaseCoin {
return true;
}

/** {@inheritDoc } **/
supportsMultisig(): boolean {
return true;
}

static createInstance(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>): BaseCoin {
return new Trx(bitgo, staticsCoin);
}
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-coin-xlm/src/xlm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ export class Xlm extends BaseCoin {
return false;
}

/** {@inheritDoc } **/
supportsMultisig(): boolean {
return true;
}

/**
* Evaluates whether a memo is valid
*
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-coin-xrp/src/xrp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ export class Xrp extends BaseCoin {
return true;
}

/** {@inheritDoc } **/
supportsMultisig(): boolean {
return true;
}

public getTokenEnablementConfig(): TokenEnablementConfig {
return {
requiresTokenEnablement: true,
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-coin-xtz/src/xtz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ export class Xtz extends BaseCoin {
return Math.pow(10, this._staticsCoin.decimalPlaces);
}

/** {@inheritDoc } **/
supportsMultisig(): boolean {
return true;
}

/**
* Flag for sending value of 0
* @returns {boolean} True if okay to send 0 value, false otherwise
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-coin-zketh/src/zketh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@ export class Zketh extends AbstractEthLikeNewCoins {
const explorerUrl = common.Environments[this.bitgo.getEnv()].zksyncExplorerBaseUrl;
return await recoveryBlockchainExplorerQuery(query, explorerUrl as string);
}

/** {@inheritDoc } **/
supportsMultisig(): boolean {
return true;
}
}
8 changes: 8 additions & 0 deletions modules/sdk-core/src/bitgo/baseCoin/baseCoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@ export abstract class BaseCoin implements IBaseCoin {
return false;
}

/**
* Flag indicating if this coin supports MultiSig wallets.
* @return {boolean} True if MultiSig wallets can be created for this coin
*/
supportsMultisig(): boolean {
return false;
}

/**
* Flag indicating if the coin supports deriving a key with a seed (keyID)
* to the user/backup keys.
Expand Down
1 change: 1 addition & 0 deletions modules/sdk-core/src/bitgo/baseCoin/iBaseCoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ export interface IBaseCoin {
allowsAccountConsolidations(): boolean;
getTokenEnablementConfig(): TokenEnablementConfig;
supportsTss(): boolean;
supportsMultisig(): boolean;
supportsDeriveKeyWithSeed(): boolean;
isEVM(): boolean;
supportsBlsDkg(): boolean;
Expand Down
29 changes: 29 additions & 0 deletions modules/sdk-core/src/bitgo/wallet/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ import { WalletShare } from './iWallet';
import { Wallet } from './wallet';
import { TssSettings } from '@bitgo/public-types';

const multisigTypes = {
onchain: 'onchain',
tss: 'tss',
blsdkg: 'blsdkg',
} as const;

type MultisigType = keyof typeof multisigTypes;

/**
* Check if a wallet is a WalletWithKeychains
*/
Expand Down Expand Up @@ -243,6 +251,11 @@ export class Wallets implements IWallets {
async generateWallet(
params: GenerateWalletOptions = {}
): Promise<WalletWithKeychains | LightningWalletWithKeychains> {
// Assign the default multiSig type value based on the coin
if (!params.multisigType) {
params.multisigType = this.getDefaultMultisigType(this.baseCoin);
}

if (this.baseCoin.getFamily() === 'lnbtc') {
const options = decodeOrElse(
GenerateLightningWalletOptionsCodec.name,
Expand Down Expand Up @@ -605,6 +618,22 @@ export class Wallets implements IWallets {
}
}

/**
* Determine the multisig type based on the coin's capabilities.
* @param baseCoin
* @returns {string | undefined}
*/
private getDefaultMultisigType(baseCoin: IBaseCoin): MultisigType | undefined {
if (baseCoin.supportsMultisig()) {
return multisigTypes.onchain;
} else if (baseCoin.supportsTss()) {
return multisigTypes.tss;
} else if (baseCoin.supportsBlsDkg()) {
return multisigTypes.blsdkg;
}
return undefined;
}

/**
* List the user's wallet shares
* @param params
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-core/src/coins/ofc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ export class Ofc extends BaseCoin {
return 'Offchain';
}

/** {@inheritDoc } **/
supportsMultisig(): boolean {
return true;
}

/**
* Return whether the given m of n wallet signers/ key amounts are valid for the coin
*/
Expand Down

0 comments on commit d12605c

Please sign in to comment.