Skip to content

Commit 8a75e82

Browse files
feat(statics): add TAT shared secret derivation function
Add deriveTatSharedSecret function for secure communication with the TAT service using the user's private key and the TAT public key. Define tatPubKey in the LightningNetwork interface and implement it in both mainnet and testnet networks. Co-authored-by: llm-git <[email protected]> TICKET: BTC-2202
1 parent 579a9a3 commit 8a75e82

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,20 @@ export function deriveLightningServiceSharedSecret(coinName: 'lnbtc' | 'tlnbtc',
209209

210210
/**
211211
* Derives the shared secret for the middleware using the user's auth extended private key and the middleware's public key.
212-
* This is used for secure communication between the middleware and the user's key.
212+
* This is used for secure communication between the middleware and the user.
213213
*/
214214
export function deriveMiddlewareSharedSecret(coinName: 'lnbtc' | 'tlnbtc', userXprv: string): Buffer {
215215
const publicKey = Buffer.from(getStaticsLightningNetwork(coinName).middlewarePubKey, 'hex');
216216
const userAuthHdNode = utxolib.bip32.fromBase58(userXprv);
217217
return sdkcore.getSharedSecret(userAuthHdNode, publicKey);
218218
}
219+
220+
/**
221+
* Derives the shared secret for TAT service using the user's private key and the TAT public key.
222+
* This is used for secure communication with the TAT service and the user.
223+
*/
224+
export function deriveTatSharedSecret(coinName: 'lnbtc' | 'tlnbtc', userXprv: string): Buffer {
225+
const publicKey = Buffer.from(getStaticsLightningNetwork(coinName).tatPubKey, 'hex');
226+
const userAuthHdNode = utxolib.bip32.fromBase58(userXprv);
227+
return sdkcore.getSharedSecret(userAuthHdNode, publicKey);
228+
}

modules/abstract-lightning/test/unit/lightning/lightningUtils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
addIPCaveatToMacaroon,
1515
deriveLightningServiceSharedSecret,
1616
deriveMiddlewareSharedSecret,
17+
deriveTatSharedSecret,
1718
} from '../../../src/lightning';
1819

1920
import * as sdkcore from '@bitgo/sdk-core';
@@ -115,4 +116,13 @@ describe('lightning utils', function () {
115116

116117
assert.deepStrictEqual(secret, expectedSecret);
117118
});
119+
120+
it(`deriveTatSharedSecret`, function () {
121+
const userXprv =
122+
'xprv9s21ZrQH143K4NPkV8riiTnFf72MRyQDVHMmmpekGF1w5QkS2MfTei9KXYvrZVMop4zQ4arnzSF7TRp3Cy73AWaDdADiYMCi5qpYW1bUa5m';
123+
const tatPubKey = getStaticsLightningNetwork('tlnbtc').tatPubKey;
124+
const expectedSecret = sdkcore.getSharedSecret(utxolib.bip32.fromBase58(userXprv), Buffer.from(tatPubKey, 'hex'));
125+
const secret = deriveTatSharedSecret('tlnbtc', userXprv);
126+
assert.deepStrictEqual(secret, expectedSecret);
127+
});
118128
});

modules/statics/src/networks.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ export interface LightningNetwork extends UtxoNetwork {
3030
* between the user's extended private key and the middleware service.
3131
*/
3232
middlewarePubKey: string;
33+
/**
34+
* The public key of the TAT service, used for deriving the shared Elliptic Curve Diffie-Hellman (ECDH) secret
35+
* between the user's extended private key and the TAT service.
36+
*/
37+
tatPubKey: string;
3338
}
3439

3540
export interface AdaNetwork extends BaseNetwork {
@@ -328,6 +333,8 @@ class LightningBitcoin extends Mainnet implements LightningNetwork {
328333
lightningServicePubKey = '0338508686f978ceffd7ce05404041b1a5b4f75a39bc92a6d355240ccc081f763e';
329334
// TODO - BTC-2202
330335
middlewarePubKey = '';
336+
// TODO - BTC-2211
337+
tatPubKey = '';
331338
}
332339

333340
class LightningBitcoinTestnet extends Testnet implements LightningNetwork {
@@ -337,6 +344,7 @@ class LightningBitcoinTestnet extends Testnet implements LightningNetwork {
337344
explorerUrl = 'https://mempool.space/testnet/lightning';
338345
lightningServicePubKey = '024055021db1e7f019ebb783ab0b0810c21a819207d4cb1ec4a6e2150ac07f1482';
339346
middlewarePubKey = '027cb3bc6b49fc385d282b42a7be232a94ffcbaffc7818b603b17722582bbf539b';
347+
tatPubKey = '02e747c99c371eac9c14fb19913bec8a0e3e46e35ab1a45878e5b9afbb69899c1e';
340348
}
341349

342350
class Bitcoin extends Mainnet implements UtxoNetwork {

0 commit comments

Comments
 (0)