@@ -3,6 +3,16 @@ export const CORE_DAO_TESTNET_CHAIN_ID = Buffer.alloc(2, 0x1115);
33export const CORE_DAO_MAINNET_CHAIN_ID = Buffer . alloc ( 2 , 0x1116 ) ;
44export const CORE_DAO_SATOSHI_PLUS_IDENTIFIER = Buffer . alloc ( 4 , 0x5341542b ) ;
55
6+ type BaseParams = {
7+ version : number ;
8+ chainId : Buffer ;
9+ delegator : Buffer ;
10+ validator : Buffer ;
11+ fee : number ;
12+ } ;
13+
14+ type OpReturnParams = BaseParams & ( { redeemScript : Buffer } | { timelock : number } ) ;
15+
616/**
717 * Create a CoreDAO OP_RETURN output script
818 *
@@ -21,17 +31,8 @@ export function createCoreDaoOpReturnOutputScript({
2131 delegator,
2232 validator,
2333 fee,
24- redeemScript,
25- timelock,
26- } : {
27- version : number ;
28- chainId : Buffer ;
29- delegator : Buffer ;
30- validator : Buffer ;
31- fee : number ;
32- redeemScript ?: Buffer ;
33- timelock ?: number ;
34- } ) : Buffer {
34+ ...rest
35+ } : OpReturnParams ) : Buffer {
3536 /**
3637 * As of v2, this is the construction of the OP_RETURN:
3738 * Source: https://docs.coredao.org/docs/Learn/products/btc-staking/design#op_return-output
@@ -83,14 +84,11 @@ export function createCoreDaoOpReturnOutputScript({
8384 throw new Error ( 'Invalid fee' ) ;
8485 }
8586
86- if ( ! redeemScript && ! timelock ) {
87- throw new Error ( 'Either redeemScript or timelock must be provided' ) ;
88- }
89- const redeemScriptBuffer = redeemScript ?? Buffer . from ( [ ] ) ;
90- if ( timelock && ( timelock < 0 || timelock > 4294967295 ) ) {
87+ const redeemScriptBuffer = 'redeemScript' in rest ? rest . redeemScript : Buffer . from ( [ ] ) ;
88+ if ( 'timelock' in rest && ( rest . timelock < 0 || rest . timelock > 4294967295 ) ) {
9189 throw new Error ( 'Invalid timelock - out of range' ) ;
9290 }
93- const timelockBuffer = timelock ? Buffer . alloc ( 4 , timelock ) . reverse ( ) : Buffer . from ( [ ] ) ;
91+ const timelockBuffer = ' timelock' in rest ? Buffer . alloc ( 4 , rest . timelock ) . reverse ( ) : Buffer . from ( [ ] ) ;
9492
9593 const totalLength =
9694 CORE_DAO_SATOSHI_PLUS_IDENTIFIER . length +
0 commit comments