@rsksmart/powpeg-sdk 1.3.0-beta → 2.0.0-beta.0
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/README.md +5 -6
- package/dist/index.d.mts +182 -173
- package/dist/index.d.ts +182 -173
- package/dist/index.js +562 -509
- package/dist/index.mjs +556 -508
- package/docs/api.md +15 -8
- package/docs/bitcoin-signers.md +53 -13
- package/docs/setup.md +95 -9
- package/package.json +17 -14
- package/AGENTS.md +0 -23
- package/pnpm-workspace.yaml +0 -2
package/docs/api.md
CHANGED
|
@@ -8,26 +8,25 @@ Public exports of the package's entry point (`src/index.ts`). Each description i
|
|
|
8
8
|
|---|---|---|
|
|
9
9
|
| [`PowPegSDK`](../src/sdk/powpeg.ts) | class | SDK for creating, funding, signing and broadcasting native PowPeg peg-in (BTC -> RBTC) and peg-out (RBTC -> BTC) transactions. |
|
|
10
10
|
|
|
11
|
-
See [`PowPegSDK`](../src/sdk/powpeg.ts) for the full list of methods (`estimatePeginFee`, `createPegin`, `fundPegin`, `createAndFundPegin`, `createAndFundPsbt`, `signAndBroadcastPegin`, `estimatePegoutFees`, `createPegout`, `signAndBroadcastPegout`, `getTransactionStatus`, `getAvailableUtxos`) — each documented in place with its params and return type.
|
|
11
|
+
See [`PowPegSDK`](../src/sdk/powpeg.ts) for the full list of methods (`estimatePeginFee`, `createPegin`, `fundPegin`, `createAndFundPegin`, `createAndFundPsbt`, `signAndBroadcastPegin`, `estimatePegoutFees`, `createPegout`, `signAndBroadcastPegout`, `getTransactionStatus`, `getFeatures`, `getAvailableUtxos`) — each documented in place with its params and return type.
|
|
12
12
|
|
|
13
13
|
## Bitcoin signers
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
| Export | Kind | Description |
|
|
18
|
-
|---|---|---|
|
|
19
|
-
| [`TrezorSigner`](../src/bitcoin-signers/trezor/trezor.ts) | class | `BitcoinSigner` backed by a Trezor hardware wallet, connected via `@trezor/connect-web`. |
|
|
20
|
-
| [`LedgerSigner`](../src/bitcoin-signers/ledger/ledger.ts) | class | `BitcoinSigner` backed by a Ledger hardware wallet, connected over WebUSB. |
|
|
15
|
+
The package ships no `BitcoinSigner` implementations — see [`bitcoin-signers.md`](./bitcoin-signers.md) for the contract and how to supply your own.
|
|
21
16
|
|
|
22
17
|
## Types (`src/types.ts`)
|
|
23
18
|
|
|
24
19
|
| Export | Kind | Description |
|
|
25
20
|
|---|---|---|
|
|
21
|
+
| `Network` | type + value | `'MAIN'` or `'TEST'`. Exported as both, so `Network.TEST` can be used where a network is expected and `Network` can annotate configuration. |
|
|
22
|
+
| `PowPegSDKOptions` | interface | Configuration for `PowPegSDK`; only `network` is required. |
|
|
26
23
|
| `FeeLevel` | type | Priority level used to look up a Bitcoin network fee rate. |
|
|
27
24
|
| `BitcoinSigner` | interface | Contract that a Bitcoin signing backend must implement so `PowPegSDK` can derive addresses and sign peg-in transactions with it. |
|
|
28
25
|
| `BitcoinDataSource` | interface | Contract for a Bitcoin data provider (fee rates, UTXOs, raw transactions, broadcasting). |
|
|
29
26
|
| `AddressWithDetails` | interface | A Bitcoin address together with its current balance and transaction count. |
|
|
30
27
|
| `Utxo` | interface | A spendable Bitcoin unspent transaction output. |
|
|
28
|
+
| `Feature` | interface | A feature flag as reported by the 2WP API. |
|
|
29
|
+
| `SupportedBrowsers` | interface | Browser support flags carried by a `Feature`. |
|
|
31
30
|
| `PegoutFeeEstimation` | interface | Estimated Bitcoin and Rootstock fees for a peg-out. |
|
|
32
31
|
| `TxType` | enum | Distinguishes a peg-in (BTC -> RBTC) from a peg-out (RBTC -> BTC) transaction. |
|
|
33
32
|
| `PegoutStatuses` | enum | Lifecycle status of a peg-out transaction, as reported by the 2WP API. |
|
|
@@ -48,4 +47,12 @@ See [`bitcoin-signers.md`](./bitcoin-signers.md) for the `BitcoinSigner` contrac
|
|
|
48
47
|
| `AmountBelowMinError` | class | Thrown when a requested peg-in or peg-out amount is below the protocol's minimum allowed amount. |
|
|
49
48
|
| `NotEnoughFundsError` | class | Thrown when the available UTXOs/balance can't cover the requested amount plus fees. |
|
|
50
49
|
| `APIError` | class | Thrown when the 2WP API responds with an error, a failed request, or an unexpected failure. |
|
|
51
|
-
| `InvalidAddressError` | class | Thrown when one or more Bitcoin
|
|
50
|
+
| `InvalidAddressError` | class | Thrown when one or more addresses are invalid: a Bitcoin address that doesn't belong to the SDK's configured network, or a malformed Rootstock recipient address. |
|
|
51
|
+
| `FederationAddressError` | class | Thrown when the federation address can't be retrieved from the pegin configuration endpoint or doesn't match the Bridge contract's value. |
|
|
52
|
+
| `SigningError` | class | Thrown when the configured `BitcoinSigner` doesn't return what the SDK asked it for: no derived addresses, or no signed transaction to broadcast. |
|
|
53
|
+
| `PegoutRejectedError` | class | Thrown when the peg-out transaction was mined but the Bridge rejected the release request; carries `reason` (1 below minimum, 2 caller is a contract, 3 fee above value — 1 and 3 are refunded, 2 is not), `txHash` and `amount`. |
|
|
54
|
+
| `UnsupportedSenderError` | class | Thrown when the account asked to send a peg-out is a contract account, which the Bridge refuses to release BTC for. |
|
|
55
|
+
| `TransactionRevertedError` | class | Thrown when the peg-out transaction was mined but reverted, so no release was requested; carries `txHash`. |
|
|
56
|
+
| `UnsupportedAddressTypeError` | class | Thrown when a funding UTXO is held by a P2SH address, whose redeem script the SDK cannot derive; carries `address`. |
|
|
57
|
+
| `WrongNetworkError` | class | Thrown when the signer's chain doesn't match the network the SDK was configured for. |
|
|
58
|
+
| `InvalidFeeRateError` | class | Thrown when a fee rate from the configured `BitcoinDataSource` is missing, non-numeric, non-positive, exceeds the configured bound, or produces a fee disproportionate to the amount being sent. |
|
package/docs/bitcoin-signers.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
`PowPegSDK` doesn't sign transactions itself — it delegates address derivation and PSBT signing to a `BitcoinSigner`, so any Bitcoin key-management backend (hardware wallet, custom key store, etc.) can be plugged in.
|
|
4
4
|
|
|
5
|
+
The package ships no `BitcoinSigner` implementations; supplying one is up to the consumer.
|
|
6
|
+
|
|
5
7
|
## The contract
|
|
6
8
|
|
|
7
9
|
Defined in [`src/types.ts`](../src/types.ts):
|
|
@@ -15,22 +17,60 @@ export interface BitcoinSigner {
|
|
|
15
17
|
```
|
|
16
18
|
|
|
17
19
|
- `getNonChangeAddresses` / `getChangeAddresses` — derive `bundleSize` receive/change addresses the signer controls. `PowPegSDK` uses these to find funded addresses and an unused refund/change address.
|
|
18
|
-
- `signTransaction` — signs a peg-in PSBT and returns the serialized signed transaction. `inputs`/`transactions` carry the UTXOs being spent and their raw hex, for signers
|
|
20
|
+
- `signTransaction` — signs a peg-in PSBT and returns the serialized signed transaction. `inputs`/`transactions` carry the UTXOs being spent and their raw hex, for signers that need to verify each input against its funding transaction. **Throw on failure rather than returning an empty string** — a user declining on a device and a backend outage are different events, and an empty return is rejected with `SigningError` rather than broadcast.
|
|
21
|
+
|
|
22
|
+
## Adding a signer
|
|
23
|
+
|
|
24
|
+
1. Create a class implementing `BitcoinSigner`.
|
|
25
|
+
2. Keep vendor SDK/transport specifics (e.g. a hardware wallet's connection library) private to the class; expose only what the `BitcoinSigner` contract requires plus any signer-specific setup — an async `init` factory, if construction needs to await a connection.
|
|
26
|
+
3. Pass an instance to `PowPegSDK`'s constructor (as the `bitcoinSigner` option), to `createAndFundPegin(...)`'s `signer` argument, or to `createAndFundPsbt(...)`'s `signer` argument. Whichever PSBT-creating method is used, `signAndBroadcastPegin` signs with the signer bound to that specific PSBT — a PSBT created without one cannot be signed later by setting the constructor-level signer alone.
|
|
27
|
+
|
|
28
|
+
## Address types and derivation
|
|
29
|
+
|
|
30
|
+
Addresses passed to `PowPegSDK` may be `'LEGACY'`, `'SEGWIT'` or `'NATIVE SEGWIT'`; deriving them at the
|
|
31
|
+
chosen type is the signer's responsibility. The values the SDK expects for each, and whether a peg-in can
|
|
32
|
+
be funded from UTXOs the address holds:
|
|
33
|
+
|
|
34
|
+
| Address type | BIP | Purpose (`m/<purpose>'`) | Address format | Funding a peg-in |
|
|
35
|
+
|---|---|---|---|---|
|
|
36
|
+
| `'LEGACY'` | BIP 44 | `44'` | P2PKH (`1…` / `m…`, `n…`) | supported |
|
|
37
|
+
| `'SEGWIT'` | BIP 49 | `49'` | P2SH-wrapped P2WPKH (`3…` / `2…`) | **not supported** |
|
|
38
|
+
| `'NATIVE SEGWIT'` | BIP 84 | `84'` | P2WPKH (`bc1…` / `tb1…`) | supported |
|
|
39
|
+
|
|
40
|
+
Funding is allowed for P2PKH and P2WPKH scripts and nothing else, decided from the UTXO's own
|
|
41
|
+
`scriptPubKey` rather than from the shape of the address. That distinction matters for bech32: a P2WSH
|
|
42
|
+
and a taproot address look like a P2WPKH one, and only the script tells them apart.
|
|
43
|
+
|
|
44
|
+
A P2SH input can only be signed with the redeem script behind the address, which is derived from the
|
|
45
|
+
public key. `BitcoinSigner` exposes addresses and a signing method, not public keys, so the SDK cannot
|
|
46
|
+
build that input, and `fundPegin` throws `UnsupportedAddressTypeError` naming the address. Fund from a
|
|
47
|
+
legacy or native segwit address, or pass `selectedUtxos` that exclude the UTXO. The check runs before the
|
|
48
|
+
PSBT is touched, so a refused UTXO leaves it exactly as `createPegin` returned it — no inputs added, no
|
|
49
|
+
change output, and still fundable.
|
|
19
50
|
|
|
20
|
-
|
|
51
|
+
A UTXO held by any other script — P2WSH, taproot, a bare multisig — is refused the same way. Each needs a
|
|
52
|
+
redeem script, a witness script or a key that `BitcoinSigner` does not expose, so the SDK cannot build a
|
|
53
|
+
complete PSBT input for it.
|
|
21
54
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
55
|
+
When `createPegin` discovers UTXOs itself, it looks only at the signer's legacy and native segwit
|
|
56
|
+
addresses, so a wallet holding both types funds a peg-in from the part the SDK can sign. If what remains
|
|
57
|
+
does not cover the amount, `NotEnoughFundsError` says how much was left out. The same preference applies
|
|
58
|
+
to the change address: change goes to the first unused change address the SDK could fund from later,
|
|
59
|
+
falling back to the first unused one, and then to the first funding input's address. `UnsupportedAddressTypeError`
|
|
60
|
+
is therefore reserved for a UTXO the caller named in `selectedUtxos`.
|
|
26
61
|
|
|
27
|
-
|
|
62
|
+
Every funding input carries `witnessUtxo`. A legacy input also carries `nonWitnessUtxo`, the full parent
|
|
63
|
+
transaction, which it needs to be signed; a witness input is signed from `witnessUtxo` alone and does not
|
|
64
|
+
carry it. So a signer built on bitcoinjs-lib can sign either supported type without fetching anything
|
|
65
|
+
itself.
|
|
28
66
|
|
|
29
|
-
|
|
67
|
+
Coin type is `0'` on `MAIN` and `1'` on `TEST`, so a full account path reads
|
|
68
|
+
`m/84'/1'/0'/0/<index>` for a native-segwit receive address on testnet, and `.../1/<index>` for a change
|
|
69
|
+
address. Extended public keys use version bytes `0x0488b21e` on `MAIN` and `0x043587cf` on `TEST`.
|
|
30
70
|
|
|
31
|
-
|
|
71
|
+
Whatever the type, keep the mapping stable: the same address must resolve to the same derivation path
|
|
72
|
+
across calls, since a signer is asked for its addresses and later asked to sign the inputs they own.
|
|
32
73
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
4. Re-export the new class from [`src/index.ts`](../src/index.ts) if it's meant to be part of the public package surface.
|
|
74
|
+
A signer that exposes no change addresses is fine — the refund entry is optional and funding falls back
|
|
75
|
+
to an input's own address. A signer that derives nothing at all can still be used by passing
|
|
76
|
+
`selectedUtxos` to `createPegin`, which skips address-based UTXO discovery entirely.
|
package/docs/setup.md
CHANGED
|
@@ -42,24 +42,110 @@ Install it as a dependency of your own app:
|
|
|
42
42
|
pnpm add @rsksmart/powpeg-sdk
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
`PowPegSDK`'s constructor takes a
|
|
45
|
+
`PowPegSDK`'s constructor takes a single `PowPegSDKOptions` object — there's no `.env` file to configure
|
|
46
|
+
for the SDK itself. Only `network` is required:
|
|
46
47
|
|
|
47
|
-
|
|
48
|
+
```ts
|
|
49
|
+
import { PowPegSDK, Network, type PowPegSDKOptions } from '@rsksmart/powpeg-sdk'
|
|
50
|
+
|
|
51
|
+
const options: PowPegSDKOptions = {
|
|
52
|
+
network: Network.TEST,
|
|
53
|
+
bitcoinSigner: mySigner,
|
|
54
|
+
apiUrl: 'https://api.2wp.testnet.rootstock.io',
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const sdk = new PowPegSDK(options)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`Network` is both a value and a type, so `Network.TEST` can be used where a network is expected and
|
|
61
|
+
`Network` can annotate configuration read from the environment:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
const network: Network = isMainnet ? Network.MAIN : Network.TEST
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The bare strings `'MAIN'` and `'TEST'` are still accepted, so either style works.
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
| Field | Purpose | Default when omitted |
|
|
48
71
|
|---|---|---|
|
|
49
|
-
| `bitcoinSigner` | `BitcoinSigner` used to sign peg-in transactions
|
|
50
|
-
| `bitcoinDataSource` | `BitcoinDataSource` used for fee rates, UTXOs, tx broadcast and tx status |
|
|
51
|
-
| `network` | `
|
|
72
|
+
| `bitcoinSigner` | `BitcoinSigner` used to sign peg-in transactions — supplied by the consumer, see [`bitcoin-signers.md`](./bitcoin-signers.md) | omitted — required only for operations that sign transactions |
|
|
73
|
+
| `bitcoinDataSource` | `BitcoinDataSource` used for fee rates, UTXOs, tx broadcast and tx status | omitted — falls back to the built-in `apiUrl`-backed source |
|
|
74
|
+
| `network` | `Network.MAIN` / `Network.TEST` (or the bare strings) — selects the Bitcoin network params, the Rootstock chain id and the default endpoints | required |
|
|
52
75
|
| `rpcProviderUrl` | Rootstock JSON-RPC endpoint used to read the bridge precompile and send peg-outs | RSK public node for the given network (`https://public-node.rsk.co` / `https://public-node.testnet.rsk.co`) |
|
|
53
76
|
| `apiUrl` | 2WP API endpoint. Used as the default `BitcoinDataSource` when no custom one is supplied, and always used for federation-address verification during peg-in creation regardless of `bitcoinDataSource` — see External dependencies below | production 2WP API for the given network (`https://api.2wp.rootstock.io` / `https://api.2wp.testnet.rootstock.io`) |
|
|
54
77
|
| `maxBundleSize` | Number of addresses to derive per `BitcoinSigner` call while creating a peg-in | `10` |
|
|
55
78
|
| `burnDustValue` | Change amount, in satoshis, below which it's dropped into the fee instead of added as an output | `2000` |
|
|
56
79
|
| `maxFeeRateSatPerByte` | Upper bound, in sat/B, for a fee rate coming from the configured `BitcoinDataSource`; a higher value throws `InvalidFeeRateError` | `1000` |
|
|
57
80
|
| `maxFeeToAmountRatio` | Upper bound for the ratio of total fee to peg-in amount; a higher ratio throws `InvalidFeeRateError` | `0.5` |
|
|
81
|
+
| `requestTimeoutMs` | Milliseconds before a request to the API is aborted; must be a positive integer | `10000` |
|
|
82
|
+
|
|
83
|
+
## Limits and behaviour worth knowing
|
|
84
|
+
|
|
85
|
+
- **Transport limits are adapter-dependent.** Every request carries a wall-clock deadline, enforced with
|
|
86
|
+
an abort signal that all three adapters honour; axios's own `timeout` covers only the connect and idle
|
|
87
|
+
phases on the Node adapter, so a server trickling bytes would otherwise hold a request open past it.
|
|
88
|
+
The response-size cap (10 MB) is enforced by axios's Node adapter only — a browser consumer does not
|
|
89
|
+
get it. Redirects
|
|
90
|
+
are refused on every adapter: `maxRedirects: 0` covers Node, `fetchOptions.redirect: 'error'` covers
|
|
91
|
+
the fetch adapter, and a response served by a host other than the configured one is rejected by an
|
|
92
|
+
interceptor, which is what covers the browser adapter.
|
|
93
|
+
- **Broadcasting gets a longer bound than a read** (60 seconds, or the configured timeout if larger),
|
|
94
|
+
because aborting it cannot un-relay a transaction that may already be in the mempool. The deadline is
|
|
95
|
+
enforced even once the response has started arriving, so a broadcast that exceeds it fails without
|
|
96
|
+
telling you whether the transaction reached the network — check its status rather than re-broadcasting.
|
|
97
|
+
- **The peg-out minimum is derived from the Bridge**, from its fee per kb and the active federation, and
|
|
98
|
+
is taken as the larger of the size rule in force today and the one that activates with RSKIP378. That
|
|
99
|
+
is never below the minimum the Bridge enforces; above a `feePerKb` of roughly 345,000 on mainnet it can
|
|
100
|
+
be up to ~16% above it, which would reject amounts the Bridge would still accept. Today's `feePerKb`
|
|
101
|
+
is 8,000 on both networks, where the two agree exactly.
|
|
102
|
+
- **Peg-outs are refused from contract accounts** before anything is sent, because the Bridge rejects a
|
|
103
|
+
release requested from a contract *without refunding it*.
|
|
104
|
+
- **The provider is pinned to the configured network's chain id**, so a node reporting a different chain
|
|
105
|
+
fails on its first call — including a local regtest or fork node.
|
|
106
|
+
- **The peg-out request carries its `chainId`**, and `signAndBroadcastPegout` hands the request to the
|
|
107
|
+
signer as given, so gas, nonce and fee fields set by the caller are honoured — a replacement for a
|
|
108
|
+
stuck peg-out reaches the node as a replacement. Both the request's `chainId` and
|
|
109
|
+
`signer.getChainId()` are checked against the configured network first, and either mismatch throws
|
|
110
|
+
`WrongNetworkError`; a request that omits `chainId` is stamped with the configured one. What the
|
|
111
|
+
forwarded `chainId` is then worth at send time depends on the signer: ethers asserts it when it signs
|
|
112
|
+
the transaction itself, while `JsonRpcSigner` passes it to the wallet without checking, so a browser
|
|
113
|
+
wallet enforces it only if it chooses to.
|
|
114
|
+
|
|
115
|
+
## Migrating from 1.x
|
|
116
|
+
|
|
117
|
+
- `TrezorSigner` and `LedgerSigner` are no longer exported; supply your own `BitcoinSigner` (see
|
|
118
|
+
[`bitcoin-signers.md`](./bitcoin-signers.md)).
|
|
119
|
+
- A peg-in can only be funded from P2PKH and P2WPKH UTXOs; anything else — P2SH (`2…`/`3…`), P2WSH,
|
|
120
|
+
taproot, a bare multisig — makes `fundPegin` throw `UnsupportedAddressTypeError`. In 1.x such a UTXO was
|
|
121
|
+
accepted and failed later inside the signer, except a bare multisig, which did sign.
|
|
122
|
+
- `maxBundleSize`, `burnDustValue`, `maxFeeRateSatPerByte` and `maxFeeToAmountRatio` are validated at
|
|
123
|
+
construction, and `signAndBroadcastPegout` refuses a request addressed anywhere but the bridge, or one
|
|
124
|
+
carrying calldata.
|
|
125
|
+
Legacy funding inputs now also carry `nonWitnessUtxo`, so they sign without the signer fetching the
|
|
126
|
+
parent transaction itself. Witness inputs do not carry it, so the PSBT does not grow by the size of
|
|
127
|
+
each parent transaction.
|
|
128
|
+
- The constructor takes a single options object instead of nine positional parameters:
|
|
129
|
+
`new PowPegSDK(signer, dataSource, 'TEST', undefined, apiUrl)` becomes
|
|
130
|
+
`new PowPegSDK({ network: Network.TEST, bitcoinSigner: signer, bitcoinDataSource: dataSource, apiUrl })`.
|
|
131
|
+
- `signAndBroadcastPegout`'s first parameter is now the exported `UnsignedPegout` type, which extends
|
|
132
|
+
ethers' `TransactionRequest`. A request built by hand still needs `from`, `to` and `value`; the gas,
|
|
133
|
+
nonce and fee fields ethers serializes are now allowed and forwarded. The request reaches the signer
|
|
134
|
+
as given, so a field ethers does not recognise is no longer dropped in silence — it reaches ethers and
|
|
135
|
+
is rejected there (`invalid transaction key` when the signer signs the transaction itself, `invalid
|
|
136
|
+
object key` through `JsonRpcSigner`). TypeScript catches such a field only when the request is written
|
|
137
|
+
as a literal at the call site, not when it is built in a variable first.
|
|
138
|
+
- Six error types are new — `SigningError`, `WrongNetworkError`, `PegoutRejectedError`,
|
|
139
|
+
`UnsupportedSenderError`, `TransactionRevertedError` and `UnsupportedAddressTypeError` — and
|
|
140
|
+
`APIError.message` now derives from the
|
|
141
|
+
API's own message rather than a
|
|
142
|
+
constant: control characters are replaced with spaces and the text is capped at 300 characters, so a
|
|
143
|
+
message that survives is the API's own wording but not necessarily byte-for-byte. Code that classifies
|
|
144
|
+
SDK failures by message text should be re-checked.
|
|
145
|
+
- `requestTimeoutMs` is validated: it must be a positive integer no greater than 2147483647. `0`, which
|
|
146
|
+
1.x accepted as "no timeout", now throws at construction.
|
|
58
147
|
|
|
59
148
|
## External dependencies
|
|
60
149
|
|
|
61
|
-
- **Rootstock RPC node** — read via `ethers.providers.JsonRpcProvider`, used for the bridge precompile (`Bridge` in `src/bridge.ts`) and to send peg-out transactions.
|
|
150
|
+
- **Rootstock RPC node** — read via `ethers.providers.JsonRpcProvider`, used for the bridge precompile (`Bridge` in `src/bridge.ts`) and to send peg-out transactions. Peg-out estimation additionally reads `getFeePerKb()`, `getActivePowpegRedeemScript()`, `getFederationThreshold()` and `getFederationAddress()` from the Bridge, to derive the minimum amount the Bridge currently enforces rather than assume a fixed one, so a node that cannot serve those calls will fail `estimatePegoutFees` and `createPegout`. The provider is pinned to the configured network's chain id, so a node reporting a different chain fails on the first call.
|
|
62
151
|
- **2WP API** — the SDK's built-in `BitcoinDataSource` implementation (`src/api/api.ts`); the fee-rate/UTXO/broadcast/address-details methods can be replaced with your own `BitcoinDataSource`, but `createPegin` always calls the 2WP API's `/pegin-configuration` endpoint directly (via the internal `ApiService`, independent of `bitcoinDataSource`) to verify the federation address against the Bridge contract — this call cannot be substituted, so the 2WP API stays a required dependency even when every other data source is custom.
|
|
63
|
-
- **Hardware wallets** (only needed if you use the bundled signers — see [`bitcoin-signers.md`](./bitcoin-signers.md)):
|
|
64
|
-
- **Ledger** — via `@ledgerhq/hw-transport-webusb`, requires a browser environment with WebUSB support.
|
|
65
|
-
- **Trezor** — via `@trezor/connect-web`.
|
package/package.json
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsksmart/powpeg-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.0",
|
|
4
4
|
"description": "SDK for creating native peg-in and peg-out transactions following the PowPeg protocol.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist/*.js",
|
|
10
|
+
"dist/*.mjs",
|
|
11
|
+
"dist/*.cjs",
|
|
12
|
+
"dist/*.d.ts",
|
|
13
|
+
"dist/*.d.mts",
|
|
14
|
+
"dist/*.d.cts",
|
|
15
|
+
"dist/*.map",
|
|
16
|
+
"docs/*.md",
|
|
17
|
+
"README.md",
|
|
18
|
+
"SECURITY.md",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
8
21
|
"scripts": {
|
|
9
22
|
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
10
23
|
"build:watch": "pnpm build --watch",
|
|
@@ -35,25 +48,15 @@
|
|
|
35
48
|
"vitest": "^3.0.8"
|
|
36
49
|
},
|
|
37
50
|
"dependencies": {
|
|
38
|
-
"@ledgerhq/hw-app-btc": "^10.11.2",
|
|
39
|
-
"@ledgerhq/hw-transport": "^6.31.12",
|
|
40
|
-
"@ledgerhq/hw-transport-webusb": "^6.29.12",
|
|
41
51
|
"@rsksmart/bridges-core-sdk": "^0.5.0",
|
|
42
52
|
"@rsksmart/rsk-precompiled-abis": "7.1.0-LOVELL",
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"bip32": "5.0.0-rc.0",
|
|
46
|
-
"bitcoinjs-lib": "^6.1.7",
|
|
47
|
-
"tiny-secp256k1": "^2.2.4"
|
|
53
|
+
"axios": "^1.20.0",
|
|
54
|
+
"bitcoinjs-lib": "^6.1.7"
|
|
48
55
|
},
|
|
49
56
|
"packageManager": "pnpm@10.15.1+sha512.34e538c329b5553014ca8e8f4535997f96180a1d0f614339357449935350d924e22f8614682191264ec33d1462ac21561aff97f6bb18065351c162c7e8f6de67",
|
|
50
57
|
"pnpm": {
|
|
51
58
|
"onlyBuiltDependencies": [
|
|
52
|
-
"
|
|
53
|
-
"esbuild",
|
|
54
|
-
"protobufjs",
|
|
55
|
-
"tiny-secp256k1",
|
|
56
|
-
"usb"
|
|
59
|
+
"esbuild"
|
|
57
60
|
]
|
|
58
61
|
}
|
|
59
62
|
}
|
package/AGENTS.md
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# Context for AI coding agents
|
|
2
|
-
|
|
3
|
-
## Commands
|
|
4
|
-
- `pnpm lint` - Check for linting issues.
|
|
5
|
-
- `pnpm lint:fix` - Fix auto-fixable issues.
|
|
6
|
-
- `pnpm test` - Run all tests.
|
|
7
|
-
- `pnpm test -- -t <suite_name>` - Run specific test suite.
|
|
8
|
-
- `pnpm build` - Build the project.
|
|
9
|
-
|
|
10
|
-
## Code style guidelines
|
|
11
|
-
- Prefer descriptive, readable names over short, cryptic abbreviations. Follow existing domain vocabulary for consistency.
|
|
12
|
-
- Only add comments for non-obvious behavior or workarounds.
|
|
13
|
-
- Do not add `eslint-disable` comments to bypass linter errors.
|
|
14
|
-
- Do not add `@ts-ignore` comments to bypass type errors.
|
|
15
|
-
|
|
16
|
-
## TypeScript features
|
|
17
|
-
- Do not introduce new enums into the codebase. Retain existing enums. If you require enum-like behaviour, use an `as const` object.
|
|
18
|
-
- Use discriminated unions to model data with mutually exclusive states and make invalid states unrepresentable.
|
|
19
|
-
- Use optional properties extremely sparingly. Only use them when the property is truly optional, and consider whether bugs may be caused by a failure to pass the property.
|
|
20
|
-
|
|
21
|
-
## Testing instructions
|
|
22
|
-
- Do not assert implementation details. A test must fail if, and only if, the intention behind the system is not met.
|
|
23
|
-
- Never mock anything directly related to the tested intention. Try to introduce mocks at the lowest level possible.
|
package/pnpm-workspace.yaml
DELETED