Skip to content

Commit 7854ed3

Browse files
authored
Merge pull request #7010 from BitGo/BTC-2470-change-accounts-purpose
feat: optional only create addrees accounts lightning
2 parents f5f91d4 + f7a26ad commit 7854ed3

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

modules/abstract-lightning/src/codecs/api/wallet.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,15 @@ export const WatchOnlyAccount = t.type({
5252

5353
export type WatchOnlyAccount = t.TypeOf<typeof WatchOnlyAccount>;
5454

55-
export const WatchOnly = t.type({
56-
master_key_birthday_timestamp: t.string,
57-
master_key_fingerprint: t.string,
58-
accounts: t.array(WatchOnlyAccount),
59-
});
55+
export const WatchOnly = t.intersection([
56+
t.type({
57+
accounts: t.array(WatchOnlyAccount),
58+
}),
59+
t.partial({
60+
master_key_birthday_timestamp: t.string,
61+
master_key_fingerprint: t.string,
62+
}),
63+
]);
6064

6165
export type WatchOnly = t.TypeOf<typeof WatchOnly>;
6266

modules/abstract-lightning/src/lightning/lightningUtils.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,18 @@ function convertXpubPrefix(xpub: string, purpose: ExtendedKeyPurpose, isMainnet:
154154
/**
155155
* Derives watch-only accounts from the master HD node for the given purposes and network.
156156
*/
157-
function deriveWatchOnlyAccounts(masterHDNode: utxolib.BIP32Interface, isMainnet: boolean): WatchOnlyAccount[] {
157+
export function deriveWatchOnlyAccounts(
158+
masterHDNode: utxolib.BIP32Interface,
159+
isMainnet: boolean,
160+
params: { onlyAddressCreationAccounts?: boolean } = { onlyAddressCreationAccounts: false }
161+
): WatchOnlyAccount[] {
158162
// https://github.com/lightningnetwork/lnd/blob/master/docs/remote-signing.md#required-accounts
159163
if (masterHDNode.isNeutered()) {
160164
throw new Error('masterHDNode must not be neutered');
161165
}
162-
163-
const purposes = [PURPOSE_WRAPPED_P2WKH, PURPOSE_P2WKH, PURPOSE_P2TR, PURPOSE_ALL_OTHERS] as const;
164-
166+
const purposes = params.onlyAddressCreationAccounts
167+
? ([PURPOSE_WRAPPED_P2WKH, PURPOSE_P2WKH, PURPOSE_P2TR] as const)
168+
: ([PURPOSE_WRAPPED_P2WKH, PURPOSE_P2WKH, PURPOSE_P2TR, PURPOSE_ALL_OTHERS] as const);
165169
return purposes.flatMap((purpose) => {
166170
const maxAccount = purpose === PURPOSE_ALL_OTHERS ? 255 : 0;
167171
const coinType = purpose !== PURPOSE_ALL_OTHERS || isMainnet ? 0 : 1;

0 commit comments

Comments
 (0)