Skip to content

Commit

Permalink
Merge pull request #68 from babylonchain/single-pk-for-staking-script
Browse files Browse the repository at this point in the history
chore: babylon only support a single FP for its staking script
  • Loading branch information
jrwbabylonlab authored Jul 8, 2024
2 parents d7d7ec7 + 40b0544 commit 83755f7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "btc-staking-ts",
"version": "0.2.8",
"version": "0.2.9",
"description": "Library exposing methods for the creation and consumption of Bitcoin transactions pertaining to Babylon's Bitcoin Staking protocol. Experimental version, should not be used for production purposes or with real funds.",
"module": "dist/index.js",
"main": "dist/index.cjs",
Expand Down
5 changes: 5 additions & 0 deletions src/utils/stakingScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ export class StakingScriptData {
return false;
}

// Only accept a single finality provider key for now
if (this.#finalityProviderKeys.length != 1) {
return false;
}

return true;
}

Expand Down
20 changes: 18 additions & 2 deletions tests/utils/stakingScript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe("stakingScript", () => {
const pk3 = Buffer.from("17921cf156ccb4e73d428f996ed11b245313e37e27c978ac4d2cc21eca4672e4", "hex");
const pk4 = Buffer.from("76d1ae01f8fb6bf30108731c884cddcf57ef6eef2d9d9559e130894e0e40c62c", "hex");
const pk5 = Buffer.from("49766ccd9e3cd94343e2040474a77fb37cdfd30530d05f9f1e96ae1e2102c86e", "hex");
const pk6 = Buffer.from("063deb187a4bf11c114cf825a4726e4c2c35fea5c4c44a20ff08a30a752ec7e0", "hex");
const invalidPk = Buffer.from("6f13a6d104446520d1757caec13eaf6fbcf29f488c31e0107e7351d4994cd0", "hex");
const emptyBuffer = Buffer.from("", "hex");
const stakingTimeLock = 65535;
Expand All @@ -29,7 +30,7 @@ describe("stakingScript", () => {
expect(() =>
new StakingScriptData(
pk1, // Staker Pk
[pk2, invalidPk], // Finality Provider Pks
[invalidPk], // Finality Provider Pks
[pk3, pk4, pk5], // covenant Pks
2,
stakingTimeLock,
Expand All @@ -38,11 +39,26 @@ describe("stakingScript", () => {
)
).toThrow("Invalid script data provided");
});

it("should fail if more than one finality providers", () => {
expect(() =>
new StakingScriptData(
pk1, // Staker Pk
[pk2, pk6], // More than one FP Pks
[pk3, pk4, pk5], // covenant Pks
2,
stakingTimeLock,
unbondingTimeLock,
magicBytes
)
).toThrow("Invalid script data provided");
});

it("should fail if a covenant emulator key is not 32 bytes", () => {
expect(() =>
new StakingScriptData(
pk1, // Staker Pk
[pk2, pk3], // Finality Provider Pks
[pk2], // Finality Provider Pks
[pk4, invalidPk, pk5], // covenant Pks
2,
stakingTimeLock,
Expand Down

0 comments on commit 83755f7

Please sign in to comment.