Skip to content

Commit 3871add

Browse files
OttoAllmendingerllm-git
andcommitted
feat(utxo-staking): update @bitgo/babylonlabs-io-btc-staking-ts to 2.3.4
Updated interfaces to match latest vendor library changes: - Removed `signingStep` parameter from `signMessage` - Updated `signPsbt` to take options with action name - Changed `finalityProviderPkNoCoordHex` to `finalityProviderPksNoCoordHex` - Added `channel` parameter to delegation message functions Issue: BTC-2143 Co-authored-by: llm-git <[email protected]>
1 parent 99f810d commit 3871add

File tree

6 files changed

+21
-23
lines changed

6 files changed

+21
-23
lines changed

modules/utxo-staking/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
},
4444
"dependencies": {
4545
"@babylonlabs-io/babylon-proto-ts": "1.0.0",
46-
"@bitgo/babylonlabs-io-btc-staking-ts": "^1.2.0",
46+
"@bitgo/babylonlabs-io-btc-staking-ts": "^2.3.4",
4747
"@bitgo/unspents": "^0.48.3",
4848
"@bitgo/utxo-core": "^1.11.0",
4949
"@bitgo/utxo-lib": "^11.6.1",

modules/utxo-staking/src/babylon/delegationMessage.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -148,36 +148,30 @@ export function getBtcProviderForECKey(
148148

149149
return {
150150
/**
151-
* @param signingStep
152151
* @param message
153152
* @param type
154153
* @returns Base64 encoded string
155154
*/
156-
async signMessage(
157-
signingStep: vendor.SigningStep,
158-
message: string,
159-
type: 'ecdsa' | 'bip322-simple'
160-
): Promise<string> {
161-
assert(signingStep === 'proof-of-possession');
155+
async signMessage(message: string, type: 'ecdsa' | 'bip322-simple'): Promise<string> {
162156
switch (type) {
163157
case 'ecdsa':
164158
return toBase64(stakerKey.sign(Buffer.from(message, 'hex')));
165159
case 'bip322-simple':
166160
return toBase64(signBip322Simple(message));
167161
default:
168-
throw new Error(`unexpected signing step: ${signingStep}`);
162+
throw new Error(`unexpected type: ${type}`);
169163
}
170164
},
171165

172-
async signPsbt(signingStep: vendor.SigningStep, psbtHex: string): Promise<string> {
166+
async signPsbt(psbtHex: string, options: vendor.SignPsbtOptions): Promise<string> {
173167
const psbt = bitcoinjslib.Psbt.fromHex(psbtHex);
174-
switch (signingStep) {
175-
case 'staking-slashing':
168+
switch (options.action.name) {
169+
case 'sign-btc-slashing-transaction':
176170
return signWithDescriptor(psbt, descriptorBuilder.getStakingDescriptor(), stakerKey).toHex();
177-
case 'unbonding-slashing':
171+
case 'sign-btc-unbonding-slashing-transaction':
178172
return signWithDescriptor(psbt, descriptorBuilder.getUnbondingDescriptor(), stakerKey).toHex();
179173
default:
180-
throw new Error(`unexpected signing step: ${signingStep}`);
174+
throw new Error(`unexpected signing step: ${options.action.name}`);
181175
}
182176
},
183177
};
@@ -225,7 +219,7 @@ export function createStaking(
225219
toBitcoinJsNetwork(network),
226220
stakerBtcInfo,
227221
params,
228-
stakingInput.finalityProviderPkNoCoordHex,
222+
stakingInput.finalityProviderPksNoCoordHex,
229223
stakingInput.stakingTimelock
230224
);
231225
}
@@ -265,6 +259,7 @@ export function toStakingTransaction(tx: TransactionLike): bitcoinjslib.Transact
265259
* The difference is that here we are returning an _unsigned_ delegation message.
266260
*/
267261
export async function createDelegationMessageWithTransaction(
262+
channel: 'delegation:create' | 'delegation:register',
268263
manager: vendor.BabylonBtcStakingManager,
269264
staking: vendor.Staking,
270265
stakingAmountSat: number,
@@ -276,10 +271,11 @@ export async function createDelegationMessageWithTransaction(
276271
}
277272
// Create delegation message without including inclusion proof
278273
return manager.createBtcDelegationMsg(
274+
channel,
279275
staking,
280276
{
281277
stakingTimelock: staking.stakingTimelock,
282-
finalityProviderPkNoCoordHex: staking.finalityProviderPkNoCoordHex,
278+
finalityProviderPksNoCoordHex: staking.finalityProviderPksNoCoordHex,
283279
stakingAmountSat,
284280
},
285281
toStakingTransaction(transaction),
@@ -298,6 +294,7 @@ export async function createUnsignedPreStakeRegistrationBabylonTransactionWithBt
298294
inputUTXOs: vendor.UTXO[],
299295
feeRateSatB: number,
300296
babylonAddress: string,
297+
channel: 'delegation:create' | 'delegation:register',
301298
stakingParams: vendor.VersionedStakingParams[] = getStakingParams(network)
302299
): Promise<Result> {
303300
if (inputUTXOs.length === 0) {
@@ -308,6 +305,7 @@ export async function createUnsignedPreStakeRegistrationBabylonTransactionWithBt
308305
// Create unsigned staking transaction
309306
const { transaction } = staking.createStakingTransaction(stakingInput.stakingAmountSat, inputUTXOs, feeRateSatB);
310307
const unsignedDelegationMsg = await createDelegationMessageWithTransaction(
308+
channel,
311309
manager,
312310
staking,
313311
stakingInput.stakingAmountSat,

modules/utxo-staking/src/babylon/stakingManager.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class BitGoStakingManager extends vendor.BabylonBtcStakingManager {
4040
sigType: BTCSigType
4141
): Promise<ProofOfPossessionBTC> {
4242
const signedBabylonAddress = await this.btcProvider.signMessage(
43-
vendor.SigningStep.PROOF_OF_POSSESSION,
4443
bech32Address,
4544
sigType === BTCSigType.BIP322 ? 'bip322-simple' : 'ecdsa'
4645
);

modules/utxo-staking/src/babylon/stakingParams.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ export function getDescriptorProviderForStakingParams(
126126
stakingParams: DescriptorStakingParams
127127
): BabylonDescriptorBuilder {
128128
const userKey = Buffer.from(stakerBtcInfo.publicKeyNoCoordHex, 'hex');
129-
const finalityProviderKey = Buffer.from(stakingInput.finalityProviderPkNoCoordHex, 'hex');
130-
return getDescriptorBuilderForParams(userKey, [finalityProviderKey], stakingInput.stakingTimelock, stakingParams);
129+
const finalityProviderKeys = stakingInput.finalityProviderPksNoCoordHex.map((pk) => Buffer.from(pk, 'hex'));
130+
return getDescriptorBuilderForParams(userKey, finalityProviderKeys, stakingInput.stakingTimelock, stakingParams);
131131
}
132132

133133
export function getTestnetDescriptorBuilder(

modules/utxo-staking/test/unit/babylon/transactions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ function describeWithKeys(
359359
bitcoinjslib.networks.bitcoin,
360360
toStakerInfo(stakerKey, changeAddress),
361361
stakingParams,
362-
getXOnlyPubkey(finalityProvider).toString('hex'),
362+
[getXOnlyPubkey(finalityProvider).toString('hex')],
363363
stakingParams.minStakingTimeBlocks
364364
);
365365

modules/utxo-staking/test/unit/babylon/vendor.utils.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,15 @@ export async function getBitGoUtxoStakingMsgCreateBtcDelegation(
3939
publicKeyNoCoordHex: getXOnlyPubkey(stakerKey).toString('hex'),
4040
},
4141
{
42-
finalityProviderPkNoCoordHex: getXOnlyPubkey(finalityProvider).toString('hex'),
42+
finalityProviderPksNoCoordHex: [getXOnlyPubkey(finalityProvider).toString('hex')],
4343
stakingAmountSat: amount,
4444
stakingTimelock: getBabylonParamByBtcHeight(blockHeight, stakingParams).minStakingTimeBlocks,
4545
},
4646
800_000,
4747
[utxo],
4848
feeRateSatB,
4949
toBech32(Buffer.from('test'), 0, 'bbn'),
50+
'delegation:create',
5051
stakingParams
5152
);
5253
}
@@ -64,7 +65,7 @@ export async function getVendorMsgCreateBtcDelegation(
6465
blockHeight: number
6566
): Promise<Result> {
6667
const babylonProvider: vendor.BabylonProvider = {
67-
async signTransaction(signingStep, msg) {
68+
async signTransaction(msg) {
6869
// return unsigned payload
6970
return babylonProtobuf.btcstakingtx.MsgCreateBTCDelegation.encode(
7071
msg.value as babylonProtobuf.btcstakingtx.MsgCreateBTCDelegation
@@ -84,7 +85,7 @@ export async function getVendorMsgCreateBtcDelegation(
8485
publicKeyNoCoordHex: getXOnlyPubkey(stakerKey).toString('hex'),
8586
},
8687
{
87-
finalityProviderPkNoCoordHex: getXOnlyPubkey(finalityProvider).toString('hex'),
88+
finalityProviderPksNoCoordHex: [getXOnlyPubkey(finalityProvider).toString('hex')],
8889
stakingAmountSat: amount,
8990
stakingTimelock: getBabylonParamByBtcHeight(blockHeight, stakingParams).minStakingTimeBlocks,
9091
},

0 commit comments

Comments
 (0)