|
1 | 1 | import { payments, networks } from '@bitgo/utxo-lib'; |
2 | 2 |
|
| 3 | +export const CORE_DAO_DEVNET_CHAIN_ID = Buffer.from('0458', 'hex'); |
3 | 4 | // Source: https://docs.coredao.org/docs/Learn/products/btc-staking/design |
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'); |
@@ -77,7 +78,7 @@ 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 (!(chainId.equals(CORE_DAO_DEVNET_CHAIN_ID) || chainId.equals(CORE_DAO_MAINNET_CHAIN_ID))) { |
81 | 82 | throw new Error('Invalid chain ID'); |
82 | 83 | } |
83 | 84 |
|
@@ -122,7 +123,7 @@ export function createCoreDaoOpReturnOutputScript({ |
122 | 123 |
|
123 | 124 | const payment = payments.embed({ |
124 | 125 | data: [data], |
125 | | - network: chainId.equals(CORE_DAO_TESTNET_CHAIN_ID) ? networks.testnet : networks.bitcoin, |
| 126 | + network: chainId.equals(CORE_DAO_DEVNET_CHAIN_ID) ? networks.testnet : networks.bitcoin, |
126 | 127 | }); |
127 | 128 | if (!payment.output) { |
128 | 129 | throw new Error('Unable to create OP_RETURN output'); |
@@ -166,10 +167,14 @@ export function parseCoreDaoOpReturnOutputScript(script: Buffer): OpReturnParams |
166 | 167 |
|
167 | 168 | // Decode chainId |
168 | 169 | 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))) { |
170 | | - throw new Error( |
171 | | - `Invalid ChainID: ${chainId.toString('hex')}. Must be either 0x045b (testnet) or 0x045c (mainnet).` |
172 | | - ); |
| 170 | + if ( |
| 171 | + !( |
| 172 | + chainId.equals(CORE_DAO_DEVNET_CHAIN_ID) || |
| 173 | + chainId.equals(CORE_DAO_MAINNET_CHAIN_ID) || |
| 174 | + chainId.equals(CORE_DAO_TESTNET_CHAIN_ID) |
| 175 | + ) |
| 176 | + ) { |
| 177 | + throw new Error(`Invalid ChainID: ${chainId.toString('hex')}. Must be either 0x0458 (devnet) or 0x045c (mainnet).`); |
173 | 178 | } |
174 | 179 | offset += 2; |
175 | 180 |
|
|
0 commit comments