Skip to content

Commit 0dcccf8

Browse files
feat(sdk-core): type BitGoBase.wallets() as BitGoApiV1Wallets
Define the full deprecated v1 wallets facade and use it on BitGoBase and BitGoAPI.wallets(). BitGoApiV1BitGo is a leaf type (imports api only) to avoid a bitgoBase/v1Wallets circular dependency. Docs make clear this is v1-only; v2 is coin().wallets() / IWallets. get/getWallet/add still return Promise<any> for the CommonJS v1 Wallet instance so abstract-utxo recovery (recover/sweep, WalletV1) keeps typechecking until v1/wallet.ts is typed. WEB-000
1 parent 47d7f5a commit 0dcccf8

4 files changed

Lines changed: 228 additions & 6 deletions

File tree

modules/sdk-api/src/bitgoAPI.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
bitcoin,
55
BitGoBase,
66
BitGoRequest,
7+
type BitGoApiV1Wallets,
78
CoinConstructor,
89
common,
910
DecryptKeysOptions,
@@ -101,6 +102,9 @@ const PendingApprovals = require('./v1/pendingapprovals');
101102
const TravelRule = require('./v1/travelRule');
102103
const TransactionBuilder = require('./v1/transactionBuilder');
103104

105+
/** Re-export of the deprecated **v1** wallets facade type (`bitgo.wallets()`). Not v2 `IWallets`. */
106+
export type { BitGoApiV1Wallets } from '@bitgo/sdk-core';
107+
104108
function validateDecryptKeysParams(params: DecryptKeysOptions): DecryptKeysOptions {
105109
params = params || {};
106110
if (!params.walletIdEncryptedKeyPairs) {
@@ -231,7 +235,7 @@ function deriveTokenIssuanceEcdhSecret(ecdhXprv: string, derivationPath: string,
231235
export class BitGoAPI implements BitGoBase {
232236
// v1 types
233237
protected _keychains: any;
234-
protected _wallets: any;
238+
protected _wallets: BitGoApiV1Wallets | null;
235239
protected _markets?: any;
236240
protected _blockchain?: any;
237241
protected _travelRule?: any;
@@ -1746,12 +1750,16 @@ export class BitGoAPI implements BitGoBase {
17461750
}
17471751

17481752
/**
1749-
* Get the user's wallets object.
1750-
* @deprecated
1753+
* Get the user's **v1** wallets object (`modules/sdk-api/src/v1/wallets.ts`).
1754+
*
1755+
* Returns {@link BitGoApiV1Wallets}. This is **not** the v2 wallets API —
1756+
* for coin wallets use `this.coin(coinName).wallets()` ({@link IWallets}).
1757+
*
1758+
* @deprecated Prefer `coin(coinName).wallets()`.
17511759
*/
1752-
wallets(): any {
1760+
wallets(): BitGoApiV1Wallets {
17531761
if (!this._wallets) {
1754-
this._wallets = new Wallets(this);
1762+
this._wallets = new Wallets(this) as BitGoApiV1Wallets;
17551763
}
17561764
return this._wallets;
17571765
}

modules/sdk-api/test/unit/bitgoAPI.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,3 +1168,27 @@ describe('Constructor', function () {
11681168
});
11691169
});
11701170
});
1171+
1172+
describe('wallets() v1 facade', function () {
1173+
it('returns BitGoApiV1Wallets with bitgo reference and all prototype methods', function () {
1174+
const bitgo = new BitGoAPI({ env: 'test' });
1175+
const wallets = bitgo.wallets();
1176+
wallets.bitgo.should.equal(bitgo);
1177+
wallets.list.should.be.a.Function();
1178+
wallets.get.should.be.a.Function();
1179+
wallets.getWallet.should.be.a.Function();
1180+
wallets.add.should.be.a.Function();
1181+
wallets.remove.should.be.a.Function();
1182+
wallets.acceptShare.should.be.a.Function();
1183+
wallets.createWalletWithKeychains.should.be.a.Function();
1184+
wallets.createForwardWallet.should.be.a.Function();
1185+
wallets.createKey.should.be.a.Function();
1186+
wallets.listInvites.should.be.a.Function();
1187+
wallets.cancelInvite.should.be.a.Function();
1188+
wallets.listShares.should.be.a.Function();
1189+
wallets.getShare.should.be.a.Function();
1190+
wallets.updateShare.should.be.a.Function();
1191+
wallets.cancelShare.should.be.a.Function();
1192+
wallets.resendShareInvite.should.be.a.Function();
1193+
});
1194+
});

modules/sdk-core/src/bitgo/bitgoBase.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,33 @@ import { IBaseCoin } from './baseCoin';
1111
import { CoinConstructor } from './coinFactory';
1212
import { EnvironmentName } from './environments';
1313
import { EcdhDerivedKeypair, GetSigningKeyApi } from './keychain';
14+
import type { BitGoApiV1Wallets } from './v1Wallets';
15+
16+
export type {
17+
BitGoApiV1AddWalletParams,
18+
BitGoApiV1BitGo,
19+
BitGoApiV1Callback,
20+
BitGoApiV1CreateForwardWalletParams,
21+
BitGoApiV1CreateWalletWithKeychainsParams,
22+
BitGoApiV1GetWalletParams,
23+
BitGoApiV1Keychains,
24+
BitGoApiV1ListWalletsParams,
25+
BitGoApiV1RemoveWalletParams,
26+
BitGoApiV1Wallet,
27+
BitGoApiV1WalletInviteParams,
28+
BitGoApiV1WalletShareParams,
29+
BitGoApiV1Wallets,
30+
} from './v1Wallets';
1431

1532
export interface BitGoBase {
16-
wallets(): any; // TODO - define v1 wallets type
33+
/**
34+
* Deprecated **v1** wallets accessor (`bitgo.wallets()` → {@link BitGoApiV1Wallets}).
35+
*
36+
* Do **not** confuse with v2 coin wallets: `bitgo.coin(name).wallets()` → {@link IWallets}.
37+
*
38+
* @deprecated Prefer `coin(coinName).wallets()`.
39+
*/
40+
wallets(): BitGoApiV1Wallets;
1741
coin(coinName: string): IBaseCoin; // need to change it to BaseCoin once it's moved to @bitgo/sdk-core
1842
decrypt(params: DecryptOptions): Promise<string>;
1943
decryptKeys(params: DecryptKeysOptions): Promise<string[]>;
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
import type { BitGoRequest, DecryptOptions, EncryptionVersion, EncryptOptions } from '../api';
2+
3+
/**
4+
* Minimal BitGo client surface used by the **v1** Wallets facade
5+
* (`modules/sdk-api/src/v1/wallets.ts`).
6+
*
7+
* Intentionally **not** {@link BitGoBase}: importing `BitGoBase` here would
8+
* create a circular module dependency with `bitgoBase.ts`.
9+
* Import graph: `bitgoBase → v1Wallets → api` (acyclic).
10+
*
11+
* @see BitGoApiV1Wallets for the collection returned by `bitgo.wallets()`
12+
* @see IWallets for the **v2** coin wallets API (`bitgo.coin(name).wallets()`)
13+
*/
14+
export type BitGoApiV1BitGo = {
15+
get(url: string): BitGoRequest;
16+
post(url: string): BitGoRequest;
17+
del(url: string): BitGoRequest;
18+
url(path: string, version?: number): string;
19+
encrypt(params: EncryptOptions): Promise<string>;
20+
decrypt(params: DecryptOptions): Promise<string>;
21+
getECDHKeychain(): Promise<{ encryptedXprv?: string; xprv?: string }>;
22+
keychains(): BitGoApiV1Keychains;
23+
};
24+
25+
/**
26+
* v1 keychains surface used by `createWalletWithKeychains` on
27+
* {@link BitGoApiV1Wallets}. Distinct from the v2 `IKeychains` API.
28+
*/
29+
export type BitGoApiV1Keychains = {
30+
create(): { xpub: string; xprv?: string; encryptedXprv?: string };
31+
add(keychainData: Record<string, unknown>): Promise<unknown>;
32+
createBackup(params: { provider: string; disableKRSEmail?: boolean }): Promise<{ xpub: string }>;
33+
createBitGo(): Promise<{ xpub: string }>;
34+
};
35+
36+
/** Legacy Node-style callback used by v1 wallet APIs. */
37+
export type BitGoApiV1Callback<T = unknown> = (err?: Error | null, result?: T) => void;
38+
39+
/**
40+
* Structural hints for a CommonJS v1 Wallet instance
41+
* (`modules/sdk-api/src/v1/wallet.ts`) when used as a **parameter**.
42+
*
43+
* Not the v2 {@link IWallet} / {@link Wallet} class.
44+
*
45+
* Methods that **return** a v1 wallet (`get` / `getWallet` / `add`) still use
46+
* `Promise<any>`: a stub return type with an index signature broke consumers
47+
* (e.g. `abstract-utxo` recovery expects `.recover` / `.sweep` and a local
48+
* `WalletV1` shape). Full typing of `v1/wallet.ts` is a follow-up.
49+
*/
50+
export type BitGoApiV1Wallet = {
51+
id?: string;
52+
createAddress?: (params?: Record<string, unknown>) => Promise<unknown>;
53+
};
54+
55+
/** Params for {@link BitGoApiV1Wallets.list}. */
56+
export type BitGoApiV1ListWalletsParams = {
57+
skip?: number;
58+
prevId?: string;
59+
limit?: number;
60+
getbalances?: boolean;
61+
};
62+
63+
/** Params for {@link BitGoApiV1Wallets.get} / {@link BitGoApiV1Wallets.getWallet}. */
64+
export type BitGoApiV1GetWalletParams = {
65+
id: string;
66+
gpk?: boolean | number;
67+
};
68+
69+
/** Params for {@link BitGoApiV1Wallets.cancelInvite}. */
70+
export type BitGoApiV1WalletInviteParams = {
71+
walletInviteId: string;
72+
};
73+
74+
/** Params for v1 wallet-share methods on {@link BitGoApiV1Wallets}. */
75+
export type BitGoApiV1WalletShareParams = {
76+
walletShareId: string;
77+
state?: string;
78+
encryptedXprv?: string;
79+
userPassword?: string;
80+
newWalletPassphrase?: string;
81+
overrideEncryptedXprv?: string;
82+
encryptionVersion?: EncryptionVersion;
83+
};
84+
85+
/** Params for {@link BitGoApiV1Wallets.createWalletWithKeychains}. */
86+
export type BitGoApiV1CreateWalletWithKeychainsParams = {
87+
passphrase: string;
88+
label?: string;
89+
backupXpub?: string;
90+
backupXpubProvider?: string;
91+
enterprise?: string;
92+
passcodeEncryptionCode?: string;
93+
disableTransactionNotifications?: boolean;
94+
disableKRSEmail?: boolean;
95+
encryptionVersion?: EncryptionVersion;
96+
};
97+
98+
/** Params for {@link BitGoApiV1Wallets.createForwardWallet}. */
99+
export type BitGoApiV1CreateForwardWalletParams = {
100+
privKey: string;
101+
sourceAddress: string;
102+
destinationWallet: BitGoApiV1Wallet;
103+
label?: string;
104+
enterprise?: string;
105+
};
106+
107+
/** Params for {@link BitGoApiV1Wallets.add}. */
108+
export type BitGoApiV1AddWalletParams = {
109+
label?: string;
110+
m: number;
111+
n: number;
112+
keychains: { xpub: string }[];
113+
enterprise?: string;
114+
disableTransactionNotifications?: boolean;
115+
};
116+
117+
/** Params for {@link BitGoApiV1Wallets.remove}. */
118+
export type BitGoApiV1RemoveWalletParams = {
119+
id: string;
120+
};
121+
122+
/**
123+
* **Deprecated v1** wallet collection facade returned by
124+
* {@link BitGoBase.wallets} / `BitGoAPI.wallets()`.
125+
*
126+
* Source of truth: `modules/sdk-api/src/v1/wallets.ts` (CommonJS prototype).
127+
*
128+
* | Accessor | Type | API |
129+
* | --- | --- | --- |
130+
* | `bitgo.wallets()` | {@link BitGoApiV1Wallets} | **v1** (this type) |
131+
* | `bitgo.coin(name).wallets()` | {@link IWallets} | **v2** (not this type) |
132+
*
133+
* Replaces the previous `wallets(): any` on {@link BitGoBase}.
134+
*
135+
* @deprecated Prefer `bitgo.coin(coinName).wallets()` ({@link IWallets}).
136+
*/
137+
export type BitGoApiV1Wallets = {
138+
/** Owning BitGo client (v1 surface only; see {@link BitGoApiV1BitGo}). */
139+
bitgo: BitGoApiV1BitGo;
140+
list(params?: BitGoApiV1ListWalletsParams, callback?: BitGoApiV1Callback): Promise<unknown>;
141+
/**
142+
* Returns a CommonJS v1 Wallet instance.
143+
* Typed as `any` until `sdk-api/src/v1/wallet.ts` is fully typed (call sites
144+
* use `.recover` / `.sweep` / local `WalletV1` shapes).
145+
*/
146+
getWallet(params: BitGoApiV1GetWalletParams, callback?: BitGoApiV1Callback): Promise<any>;
147+
/** Shorthand for {@link BitGoApiV1Wallets.getWallet}. */
148+
get(params: BitGoApiV1GetWalletParams, callback?: BitGoApiV1Callback): Promise<any>;
149+
listInvites(params?: Record<string, unknown>, callback?: BitGoApiV1Callback): Promise<unknown>;
150+
cancelInvite(params: BitGoApiV1WalletInviteParams, callback?: BitGoApiV1Callback): Promise<unknown>;
151+
listShares(params?: Record<string, unknown>, callback?: BitGoApiV1Callback): Promise<unknown>;
152+
resendShareInvite(params: BitGoApiV1WalletShareParams, callback?: BitGoApiV1Callback): Promise<unknown>;
153+
getShare(params: BitGoApiV1WalletShareParams, callback?: BitGoApiV1Callback): Promise<unknown>;
154+
updateShare(params: BitGoApiV1WalletShareParams, callback?: BitGoApiV1Callback): Promise<unknown>;
155+
cancelShare(params: BitGoApiV1WalletShareParams, callback?: BitGoApiV1Callback): Promise<unknown>;
156+
acceptShare(params: BitGoApiV1WalletShareParams, callback?: BitGoApiV1Callback): Promise<unknown>;
157+
createKey(params?: Record<string, unknown>): { address: string; key: string };
158+
createWalletWithKeychains(
159+
params: BitGoApiV1CreateWalletWithKeychainsParams,
160+
callback?: BitGoApiV1Callback
161+
): Promise<unknown>;
162+
createForwardWallet(params: BitGoApiV1CreateForwardWalletParams, callback?: BitGoApiV1Callback): Promise<unknown>;
163+
/** Returns a CommonJS v1 Wallet instance (`any` — see {@link BitGoApiV1Wallets.getWallet}). */
164+
add(params: BitGoApiV1AddWalletParams, callback?: BitGoApiV1Callback): Promise<any>;
165+
remove(params: BitGoApiV1RemoveWalletParams, callback?: BitGoApiV1Callback): Promise<unknown>;
166+
};

0 commit comments

Comments
 (0)