@rosen-bridge/rosen-extractor 11.1.2-abaa0487 → 11.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -4
- package/README.md +87 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
# @rosen-bridge/rosen-extractor
|
|
2
2
|
|
|
3
|
-
## 11.1.2
|
|
3
|
+
## 11.1.2
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
7
|
- Update dependencies
|
|
8
|
-
-
|
|
9
|
-
- @rosen-bridge/
|
|
10
|
-
- @rosen-bridge/tokens@4.0.2-abaa0487
|
|
8
|
+
- @rosen-bridge/abstract-logger@4.0.0
|
|
9
|
+
- @rosen-bridge/tokens@5.0.0
|
|
11
10
|
|
|
12
11
|
## 11.1.1
|
|
13
12
|
|
package/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# @rosen-bridge/rosen-extractor
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://www.npmjs.com/package/@rosen-bridge/rosen-extractor"><img src="https://img.shields.io/npm/v/@rosen-bridge/rosen-extractor"></a>
|
|
5
|
+
<img src="https://img.shields.io/npm/l/@rosen-bridge/rosen-extractor"></a>
|
|
6
|
+
<p>
|
|
7
|
+
|
|
8
|
+
## Table of contents
|
|
9
|
+
|
|
10
|
+
- [Description](#description)
|
|
11
|
+
- [Installation](#installation)
|
|
12
|
+
- [Usage](#usage)
|
|
13
|
+
|
|
14
|
+
## Description
|
|
15
|
+
|
|
16
|
+
`@rosen-bridge/rosen-extractor` is a core Rosen Bridge module responsible for extracting and validating bridge request data from blockchain transactions. It converts chain-specific transaction data into a standardized bridge request format consumed by Rosen Watcher and Guard services as part of the bridge verification and execution pipeline.
|
|
17
|
+
|
|
18
|
+
The extractor module is responsible for identifying and parsing bridge requests embedded in transactions across supported blockchains. It achieves this through a set of chain-specific extractors (such as `ErgoNodeRosenExtractor`, `CardanoKoiosExtractor`, and others), each of which understands the transaction structure and data formats of its respective chain and provider.
|
|
19
|
+
|
|
20
|
+
In addition to raw data extraction, the module performs several validation and normalization steps required by the bridge protocol (note that these steps are taken in the `AbstractRosenExtractor` class):
|
|
21
|
+
|
|
22
|
+
- Destination addresses are validated against the target chain using `@rosen-bridge/address-codec` package.
|
|
23
|
+
- Tokens are resolved through `TokenMap` to ensure the requested asset is supported on both the source and target chains.
|
|
24
|
+
- Transfer amounts are normalized to account for differing decimal precisions across blockchains using `TokenMap.wrapAmount`.
|
|
25
|
+
|
|
26
|
+
The output of the extractor is a normalized bridge request object containing the target chain and address, source transaction information, token identifiers on both chains, transfer amount, and the bridge and network fees specified in the transaction. This object represents the canonical input used by Rosen Watchers for observation and by Guards for verification and signing.
|
|
27
|
+
|
|
28
|
+
The fees extracted by this package represent the values explicitly declared by the user in the transaction. They do not reflect the effective fees enforced by the protocol. If the specified fees are below the configured minimum fee—defined on-chain on Ergo—the Rosen Guards will apply the minimum fee instead. For more information on fee configuration and enforcement, see the [`@rosen-bridge/minimum-fee`](https://www.npmjs.com/package/@rosen-bridge/minimum-fee) package.
|
|
29
|
+
|
|
30
|
+
The extracted bridge request data includes the following fields:
|
|
31
|
+
|
|
32
|
+
- **`toChain`**: Target blockchain
|
|
33
|
+
- **`toAddress`**: Destination address on the target blockchain
|
|
34
|
+
- **`bridgeFee`**: Bridge fee specified in the transaction
|
|
35
|
+
- **`networkFee`**: Network fee specified in the transaction
|
|
36
|
+
- **`fromAddress`**: Source address transferring assets to the lock address
|
|
37
|
+
- **`sourceChainTokenId`**: Token identifier on the source blockchain
|
|
38
|
+
- **`amount`**: Transfer amount
|
|
39
|
+
- **`targetChainTokenId`**: Token identifier on the target blockchain
|
|
40
|
+
- **`sourceTxId`**: Source transaction identifier
|
|
41
|
+
- **`rawData`**: Raw transaction data from which the request was extracted
|
|
42
|
+
|
|
43
|
+
> Note: The `rawData` field is a small subset of the original transaction data while omitting the irrelevant data. It is included for reference and debugging purposes. For example, on Bitcoin, the `rawData` is the scriptPubKey of OP_RETURN output that contains Rosen data while on Bitcoin-Runes, it is the entire transaction outputs.
|
|
44
|
+
|
|
45
|
+
There are two functions that can be used to extract the bridge request data:
|
|
46
|
+
|
|
47
|
+
1. `extractData`: This function takes a transaction data as input and returns the extracted bridge request data. It is implemented in the child classes based on the chain and provider.
|
|
48
|
+
2. `get`: This function wraps the `extractData` function and adds additional validation and normalization steps (i.e., validate the destination address and normalize the amount). It is recommended to use this function instead of `extractData` as it provides a more consistent and reliable output. It is implemented in the `AbstractRosenExtractor` class.
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
npm i @rosen-bridge/rosen-extractor
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Usage
|
|
57
|
+
|
|
58
|
+
To use the class, The transaction data must be provided in the format expected by the specific extractor class being used. Here's a basic example of how to use this package:
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { ErgoNodeRosenExtractor } from '@rosen-bridge/rosen-extractor';
|
|
62
|
+
import { TokenMap } from '@rosen-bridge/tokens';
|
|
63
|
+
import ergoNodeClientFactory from '@rosen-clients/ergo-node';
|
|
64
|
+
|
|
65
|
+
// generate the Ergo node client
|
|
66
|
+
const ergoNodeUrl = '';
|
|
67
|
+
const nodeClient = ergoNodeClientFactory(ergoNodeUrl);
|
|
68
|
+
|
|
69
|
+
// get the transaction from Ergo node
|
|
70
|
+
const lockTxId =
|
|
71
|
+
'9115d6d6f22269949de1118f1415e7ef8aa717b232f3c6a3710178475a87af05'; // a sample lock transaction
|
|
72
|
+
const tx = await nodeClient.getTxById(lockTxId);
|
|
73
|
+
|
|
74
|
+
// generate the TokenMap
|
|
75
|
+
const tokenMapJson = {}; // you can get the token map json from GitHub releases (https://github.com/rosen-bridge/contract/releases)
|
|
76
|
+
const tokenMap = new TokenMap();
|
|
77
|
+
await tokenMap.updateConfigByJson(tokenMapJson);
|
|
78
|
+
|
|
79
|
+
// generate the Rosen Extractor for Ergo Node provider
|
|
80
|
+
const ergoLockAddress =
|
|
81
|
+
'nB3L2PD3J4rMmyGk7nnNdESpPXxhPRQ4t1chF8LTXtceMQjKCEgL2pFjPY6cehGjyEFZyHEomBTFXZyqfonvxDozrTtK5JzatD8SdmcPeJNWPvdRb5UxEMXE4WQtpAFzt2veT8Z6bmoWN'; // the Rosen lock address on Ergo the time of the sample
|
|
82
|
+
const rosenExtractor = new ErgoNodeRosenExtractor(ergoLockAddress, tokenMap);
|
|
83
|
+
|
|
84
|
+
// extract and display the Rosen data
|
|
85
|
+
const res = rosenExtractor.get(tx);
|
|
86
|
+
console.log(res);
|
|
87
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rosen-bridge/rosen-extractor",
|
|
3
|
-
"version": "11.1.2
|
|
3
|
+
"version": "11.1.2",
|
|
4
4
|
"description": "this project contains methods to get rosen data from blockchain",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"@blockfrost/openapi": "^0.1.80",
|
|
32
32
|
"@cardano-ogmios/schema": "^6.0.3",
|
|
33
33
|
"@emurgo/cardano-serialization-lib-nodejs": "^13.2.1",
|
|
34
|
-
"@rosen-bridge/abstract-logger": "4.0.0
|
|
34
|
+
"@rosen-bridge/abstract-logger": "^4.0.0",
|
|
35
35
|
"@rosen-bridge/address-codec": "^1.0.1",
|
|
36
36
|
"@rosen-bridge/json-bigint": "^1.1.0",
|
|
37
|
-
"@rosen-bridge/tokens": "
|
|
37
|
+
"@rosen-bridge/tokens": "^5.0.0",
|
|
38
38
|
"bitcoinjs-lib": "^6.1.5",
|
|
39
39
|
"ergo-lib-wasm-nodejs": "^0.24.1",
|
|
40
40
|
"ethers": "6.13.2",
|