|
1 | 1 | import { payments, networks } from '@bitgo/utxo-lib'; |
2 | 2 |
|
3 | 3 | // Source: https://docs.coredao.org/docs/Learn/products/btc-staking/design |
| 4 | +export const CORE_DAO_DEVNET_CHAIN_ID = Buffer.from('0458', 'hex'); |
4 | 5 | export const CORE_DAO_TESTNET_CHAIN_ID = Buffer.from('045b', 'hex'); |
5 | 6 | export const CORE_DAO_MAINNET_CHAIN_ID = Buffer.from('045c', 'hex'); |
6 | 7 | export const CORE_DAO_SATOSHI_PLUS_IDENTIFIER = Buffer.from('5341542b', 'hex'); |
@@ -77,7 +78,13 @@ export function createCoreDaoOpReturnOutputScript({ |
77 | 78 | } |
78 | 79 | const versionBuffer = Buffer.alloc(1, version); |
79 | 80 |
|
80 | | - if (!(chainId.equals(CORE_DAO_TESTNET_CHAIN_ID) || chainId.equals(CORE_DAO_MAINNET_CHAIN_ID))) { |
| 81 | + if ( |
| 82 | + !( |
| 83 | + chainId.equals(CORE_DAO_TESTNET_CHAIN_ID) || |
| 84 | + chainId.equals(CORE_DAO_MAINNET_CHAIN_ID) || |
| 85 | + chainId.equals(CORE_DAO_DEVNET_CHAIN_ID) |
| 86 | + ) |
| 87 | + ) { |
81 | 88 | throw new Error('Invalid chain ID'); |
82 | 89 | } |
83 | 90 |
|
@@ -122,7 +129,7 @@ export function createCoreDaoOpReturnOutputScript({ |
122 | 129 |
|
123 | 130 | const payment = payments.embed({ |
124 | 131 | data: [data], |
125 | | - network: chainId.equals(CORE_DAO_TESTNET_CHAIN_ID) ? networks.testnet : networks.bitcoin, |
| 132 | + network: chainId.equals(CORE_DAO_DEVNET_CHAIN_ID) ? networks.testnet : networks.bitcoin, |
126 | 133 | }); |
127 | 134 | if (!payment.output) { |
128 | 135 | throw new Error('Unable to create OP_RETURN output'); |
@@ -166,9 +173,17 @@ export function parseCoreDaoOpReturnOutputScript(script: Buffer): OpReturnParams |
166 | 173 |
|
167 | 174 | // Decode chainId |
168 | 175 | const chainId = Buffer.from(dataBuffer.subarray(offset, offset + 2)); |
169 | | - if (!(chainId.equals(CORE_DAO_TESTNET_CHAIN_ID) || chainId.equals(CORE_DAO_MAINNET_CHAIN_ID))) { |
| 176 | + if ( |
| 177 | + !( |
| 178 | + chainId.equals(CORE_DAO_DEVNET_CHAIN_ID) || |
| 179 | + chainId.equals(CORE_DAO_TESTNET_CHAIN_ID) || |
| 180 | + chainId.equals(CORE_DAO_MAINNET_CHAIN_ID) |
| 181 | + ) |
| 182 | + ) { |
170 | 183 | throw new Error( |
171 | | - `Invalid ChainID: ${chainId.toString('hex')}. Must be either 0x045b (testnet) or 0x045c (mainnet).` |
| 184 | + `Invalid ChainID: ${chainId.toString( |
| 185 | + 'hex' |
| 186 | + )}. Must be either 0x0458 (devnet), 0x045b (testnet), or 0x045c (mainnet).` |
172 | 187 | ); |
173 | 188 | } |
174 | 189 | offset += 2; |
|
0 commit comments