From 364a63dcdb5ad863f232b46d56d5b3ce76f77d39 Mon Sep 17 00:00:00 2001 From: Daniel Peng Date: Fri, 13 Nov 2026 16:22:12 -0500 Subject: [PATCH] fix(sdk-lib-safes): omit ecdsaMpc safe slot for zec and tzec Ticket: WCN-4678 --- modules/sdk-core/test/unit/bitgo/safe/safe.ts | 24 ++++++++++++++++++ modules/sdk-lib-safes/src/safeSlot.ts | 21 +++++++++++----- modules/sdk-lib-safes/test/unit/safeSlot.ts | 25 ++++++++++++++++++- 3 files changed, 63 insertions(+), 7 deletions(-) diff --git a/modules/sdk-core/test/unit/bitgo/safe/safe.ts b/modules/sdk-core/test/unit/bitgo/safe/safe.ts index d6536cbedab..705d0220a36 100644 --- a/modules/sdk-core/test/unit/bitgo/safe/safe.ts +++ b/modules/sdk-core/test/unit/bitgo/safe/safe.ts @@ -430,6 +430,30 @@ describe('Safe', function () { mintSend.notCalled.should.be.true(); }); + it('rejects a tzec TSS wallet before any derivation-index call', async function () { + stubCoin('tzec', { getDefaultMultisigType: 'tss' }); + + await safe + .createWallet({ coin: 'tzec', label: 'zec desk', passphrase: 'pw', multisigType: 'tss' }) + .should.be.rejectedWith("Coin 'tzec' is not supported for safe wallet minting"); + mockBitGo.get.notCalled.should.be.true(); + keychainsGet.notCalled.should.be.true(); + mintSend.notCalled.should.be.true(); + }); + + it('still mints a tzec onchain wallet from slot 1', async function () { + stubCoin('tzec'); + derivationQuery.returns({ + result: sinon.stub().resolves({ slot: 'secp256k1Multisig', coinType: 133, account: 0 }), + }); + + await safe.createWallet({ coin: 'tzec', label: 'zec desk', passphrase: 'pw' }); + + derivationQuery.calledOnceWithExactly({ slot: 'secp256k1Multisig', coin: 'tzec' }).should.be.true(); + keychainsAdd.firstCall.args[0].derivedFromParentWithPath.should.equal("m/44'/133'/1'/0'"); + mintSend.firstCall.args[0].should.containEql({ coin: 'tzec', multisigType: 'onchain' }); + }); + it('rejects a peeked derivation account for the wrong slot', async function () { derivationQuery.returns({ result: sinon.stub().resolves({ slot: 'ecdsaMpc', coinType: 0, account: 0 }), diff --git a/modules/sdk-lib-safes/src/safeSlot.ts b/modules/sdk-lib-safes/src/safeSlot.ts index 1002a281605..df70604035c 100644 --- a/modules/sdk-lib-safes/src/safeSlot.ts +++ b/modules/sdk-lib-safes/src/safeSlot.ts @@ -10,7 +10,7 @@ * The multisigType-vs-coin validation stays in sdk-core (it needs IBaseCoin); these * functions take only the chain so this leaf never imports sdk-core. */ -import { coins, CoinFeature, KeyCurve } from '@bitgo/statics'; +import { BaseCoin, coins, CoinFeature, KeyCurve } from '@bitgo/statics'; import type { RootKeyType } from '@bitgo/public-types'; type OnchainSafeRootKeySlot = Extract; @@ -26,6 +26,14 @@ const CURVE_TO_SLOTS: Record): boolean { + return !coin.otherSupportedKeyCurves?.includes(KeyCurve.Pallas); +} + export function onchainSlotForCoin(chain: string): OnchainSafeRootKeySlot { const slot = CURVE_TO_SLOTS[coins.get(chain).primaryKeyCurve].onchain; if (!slot) { @@ -35,7 +43,8 @@ export function onchainSlotForCoin(chain: string): OnchainSafeRootKeySlot { } export function tssSlotForCoin(chain: string): TssSafeRootKeySlot { - const slot = CURVE_TO_SLOTS[coins.get(chain).primaryKeyCurve].tss; + const coin = coins.get(chain); + const slot = hasTssSlot(coin) ? CURVE_TO_SLOTS[coin.primaryKeyCurve].tss : undefined; if (!slot) { throw new Error(`Coin '${chain}' is not supported for safe wallet minting`); } @@ -44,9 +53,9 @@ export function tssSlotForCoin(chain: string): TssSafeRootKeySlot { /** * Every safe root slot a coin can be minted under, in deterministic order (onchain first, - * then tss). Mirrors wallet-platform's mint truth: the onchain slot is included iff the coin - * carries {@link CoinFeature.MULTISIG}, the tss slot iff it carries {@link CoinFeature.TSS}. - * A coin that mints under neither (e.g. a Pallas coin) yields `[]`. + * then tss). The onchain slot is included iff the coin carries {@link CoinFeature.MULTISIG}, + * the tss slot iff it carries {@link CoinFeature.TSS} and is not Pallas-capable (zec, tzec), + * so those are onchain-only. A coin that mints under neither yields `[]`. */ export function safeSlotsForCoin(chain: string): RootKeyType[] { const coin = coins.get(chain); @@ -55,7 +64,7 @@ export function safeSlotsForCoin(chain: string): RootKeyType[] { if (onchain && coin.features.includes(CoinFeature.MULTISIG)) { slots.push(onchain); } - if (tss && coin.features.includes(CoinFeature.TSS)) { + if (tss && coin.features.includes(CoinFeature.TSS) && hasTssSlot(coin)) { slots.push(tss); } return slots; diff --git a/modules/sdk-lib-safes/test/unit/safeSlot.ts b/modules/sdk-lib-safes/test/unit/safeSlot.ts index 7bd015463b6..d4547b4278c 100644 --- a/modules/sdk-lib-safes/test/unit/safeSlot.ts +++ b/modules/sdk-lib-safes/test/unit/safeSlot.ts @@ -1,4 +1,5 @@ import 'should'; +import { coins, KeyCurve } from '@bitgo/statics'; import { onchainSlotForCoin, safeSlotsForCoin, tssSlotForCoin } from '../../src'; describe('safeSlot', function () { @@ -29,6 +30,11 @@ describe('safeSlot', function () { tssSlotForCoin('tsol').should.equal('eddsaMpc'); }); + it('rejects Pallas-capable coins', function () { + (() => tssSlotForCoin('zec')).should.throw("Coin 'zec' is not supported for safe wallet minting"); + (() => tssSlotForCoin('tzec')).should.throw("Coin 'tzec' is not supported for safe wallet minting"); + }); + it('rejects unknown chains', function () { (() => tssSlotForCoin('definitely-not-a-coin')).should.throw(); }); @@ -51,7 +57,24 @@ describe('safeSlot', function () { }); it('returns both slots in order for a coin with both features', function () { - safeSlotsForCoin('zec').should.deepEqual(['secp256k1Multisig', 'ecdsaMpc']); + safeSlotsForCoin('trx').should.deepEqual(['secp256k1Multisig', 'ecdsaMpc']); + safeSlotsForCoin('arbeth').should.deepEqual(['secp256k1Multisig', 'ecdsaMpc']); + }); + + it('omits the tss slot for Pallas-capable coins', function () { + safeSlotsForCoin('zec').should.deepEqual(['secp256k1Multisig']); + safeSlotsForCoin('tzec').should.deepEqual(['secp256k1Multisig']); + }); + + // Pins the Pallas set: a new Pallas coin needs a safe slot decision before it is added here. + it('statics carry Pallas only on zec and tzec', function () { + const pallasCoins: string[] = []; + coins.forEach((coin, name) => { + if (coin.primaryKeyCurve === KeyCurve.Pallas || coin.otherSupportedKeyCurves?.includes(KeyCurve.Pallas)) { + pallasCoins.push(name); + } + }); + pallasCoins.sort().should.deepEqual(['tzec', 'zec']); }); it('returns [] for a coin that mints under no safe slot', function () {