Skip to content

Commit

Permalink
Merge pull request #76 from babylonchain/move-fp-validaiton-to-embede…
Browse files Browse the repository at this point in the history
…dscript-method-2

Move fp validaiton to embededscript method 2
  • Loading branch information
jrwbabylonlab authored Jul 11, 2024
2 parents 6373b59 + 5135343 commit 2cf5e9e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 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.9",
"version": "0.2.10",
"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
11 changes: 6 additions & 5 deletions src/utils/stakingScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@ 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 Expand Up @@ -235,9 +230,15 @@ export class StakingScriptData {
* OP_RETURN || <serializedStakingData>
* where serializedStakingData is the concatenation of:
* MagicBytes || Version || StakerPublicKey || FinalityProviderPublicKey || StakingTimeLock
* Note: Only a single finality provider key is supported for now in phase 1
* @throws {Error} If the number of finality provider keys is not equal to 1.
* @returns {Buffer} The compiled data embed script.
*/
buildDataEmbedScript(): Buffer {
// Only accept a single finality provider key for now
if (this.#finalityProviderKeys.length != 1) {
throw new Error("Only a single finality provider key is supported");
}
// 1 byte for version
const version = Buffer.alloc(1);
version.writeUInt8(0);
Expand Down
27 changes: 14 additions & 13 deletions tests/utils/stakingScript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe("stakingScript", () => {
expect(() =>
new StakingScriptData(
pk1, // Staker Pk
[invalidPk], // Finality Provider Pks
[pk2, invalidPk], // Finality Provider Pks
[pk3, pk4, pk5], // covenant Pks
2,
stakingTimeLock,
Expand All @@ -41,25 +41,26 @@ describe("stakingScript", () => {
).toThrow("Invalid script data provided");
});

it("should fail if more than one finality providers", () => {
it("should throw if more than one finality providers when building data embed script", () => {
const script = new StakingScriptData(
pk1, // Staker Pk
[pk2, pk6], // More than one FP Pks
[pk3, pk4, pk5], // covenant Pks
2,
stakingTimeLock,
unbondingTimeLock,
magicBytes
);
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");
script.buildDataEmbedScript()
).toThrow("Only a single finality provider key is supported");
});

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

0 comments on commit 2cf5e9e

Please sign in to comment.