Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/Providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@

## celestia

| nodeURL | https://g.w.lavanet.xyz:443/gateway/celestia/rest/bfdb617358bd786c30374c8799978c27 |
| nodeURL | https://lcd-celestia.imperator.co |

## celestia-testnet

| nodeURL | https://g.w.lavanet.xyz:443/gateway/celestiatm/rest/bfdb617358bd786c30374c8799978c27 |

## dydx

| nodeURL | https://dydx-dao-api.polkachu.com |
| nodeURL | https://dydx-rest.publicnode.com |

## axelar

Expand Down
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,25 @@
"dependencies": {
"@cosmjs/amino": "^0.32.2",
"@cosmjs/crypto": "^0.32.2",
"@cosmjs/encoding": "^0.32.3",
"@cosmjs/encoding": "^0.32.2",
"@cosmjs/proto-signing": "^0.32.2",
"@cosmjs/stargate": "^0.32.2",
"@isaacs/ttlcache": "^1.4.1",
"@ledgerhq/hw-app-algorand": "^6.28.1",
"@ledgerhq/hw-transport-web-ble": "^6.28.4",
"@ledgerhq/hw-transport-webusb": "^6.28.4",
"@t3-oss/env-nextjs": "^0.10.1",
"@vercel/edge-config": "^1.1.0",
"@zondax/ledger-cosmos-js": "^3.0.3",
"algo-msgpack-with-bigint": "^2.1.1",
"algosdk": "^2.7.0",
"bech32": "^2.0.0",
"bignumber.js": "^9.1.2",
"bitcoinjs-lib": "^6.1.6",
"coinselect": "^3.1.13",
"cosmjs-types": "^0.9.0",
"hi-base32": "^0.5.1",
"js-sha512": "^0.8.0",
"next": "14.0.3",
"react": "^18.2.0",
"tiny-secp256k1": "^2.2.3",
"tsx": "^4.7.1",
"tsx": "^4.16.5",
"tweetnacl": "^1.0.3",
"viem": "^2.14.0",
"zod": "^3.23.8",
Expand All @@ -47,7 +44,7 @@
"devDependencies": {
"@types/jest": "^29.5.10",
"@types/node": "^18.19.3",
"@types/react": "18.2.42",
"@types/react": "18.3.3",
"eslint": "^8",
"eslint-config-next": "14.0.3",
"jest": "^29.7.0",
Expand All @@ -56,5 +53,10 @@
"ts-node": "^10.4.0",
"tsconfig-paths": "^4.2.0",
"typescript": "^5"
},
"pnpm": {
"patchedDependencies": {
"coinselect@3.1.13": "patches/coinselect@3.1.13.patch"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have some context about the need for this patch? A link or anything.
Not mandatory just in case, could be useful for future reference.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put those links as context in the description of the PR:

with basic UTXO selection using bitcoinjs coinselect.
⚠️ Known issues:
Because the lib is only published in NPM without its types (bitcoinjs/coinselect#77 (comment)), I've patched the lib using their own definitions.

But your comment makes me think that I should put that context closer to the codebase itself. A recommendation?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose to add the following documentation right next to the patch.

}
}
}
66 changes: 66 additions & 0 deletions patches/coinselect@3.1.13.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
diff --git a/index.d.ts b/index.d.ts
new file mode 100644
index 0000000..20cc98a
--- /dev/null
+++ b/index.d.ts
@@ -0,0 +1,48 @@
+// Declare the main coinselect module
+declare module "coinselect" {
+ export interface UTXO {
+ txid: string | Buffer;
+ vout: number;
+ value: number;
+ nonWitnessUtxo?: Buffer;
+ witnessUtxo?: {
+ script: Buffer;
+ value: number;
+ };
+ }
+
+ export type Target =
+ | {
+ address: string;
+ value: number;
+ }
+ | {
+ address: string;
+ }
+ | {
+ value: number;
+ };
+
+ export interface SelectedUTXO {
+ inputs?: UTXO[];
+ outputs?: Target[];
+ fee: number;
+ }
+
+ export default function coinSelect(
+ utxos: UTXO[],
+ outputs: Target[],
+ feeRate: number
+ ): SelectedUTXO;
+}
+
+// Declare the coinselect/split module
+declare module "coinselect/split.js" {
+ import { UTXO, Target, SelectedUTXO } from "coinselect";
+
+ export default function split(
+ utxos: UTXO[],
+ outputs: Target[],
+ feeRate: number
+ ): SelectedUTXO;
+}
diff --git a/package.json b/package.json
index 6cdef00..337bf4f 100644
--- a/package.json
+++ b/package.json
@@ -31,6 +31,7 @@
"utils.js"
],
"main": "index.js",
+ "types": "index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/bitcoinjs/coinselect.git"
40 changes: 40 additions & 0 deletions patches/how_to.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Why this patch

The library `coinselect.js` is manipulating important and low level objects, it seems important to make sure we don't just send any information to it.
Because the lib is only published in NPM without its types ([because the maintainer doesnt trust NPM](https://github.com/bitcoinjs/coinselect/pull/77#issuecomment-1676430774)), I've patched the lib using their own type definition [their own definitions](https://github.com/bitcoinjs/coinselect/blob/master/index.d.ts), modified to actually reflect the lib's bahaviour.


# How to maintain the patch

Create a temporary copy of the library to patch
```bash
pnpm patch
```

You now have access to a similar folder as: `/private/var/folders/yn/k6gkp3pd7fq4dn71mw1yb8qh0000gn/T/5191b8b733d6bbfd169476c53b6a123b` that I'll refer to as `temp_lib`

Open it on vscode
```bash
code "/temp_lib"
```

Do all the changes that you need.
And then run
```
diff -Naur node_modules/.pnpm/coinselect@3.1.13/node_modules/coinselect/ /temp_lib
```

And copy the changes to `patches/coinselect@3.1.13.patch`, just taking the lines with `+/-` preceeded by the ones with `@@`.

You can now your patch with
```bash
pnpm install --force
```

If all is good, `patches/coinselect@3.1.13.patch` can be commited as any other file.

# Why use `diff` manually and not use `pmpm patch-commit temp_lib` ?

For some reason, it seems pnpm 8 doesn't handle well newly created files (and not just modified ones). This should be better in [pnpm 9](https://github.com/pnpm/pnpm/issues/5686#issuecomment-2272406668)


Loading