@chainflip/bitcoin 1.2.4 → 1.2.6

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/dist/index.cjs CHANGED
@@ -7,7 +7,7 @@ var base58 = require('@chainflip/utils/base58');
7
7
  var chainflip = require('@chainflip/utils/chainflip');
8
8
  var consts = require('@chainflip/utils/consts');
9
9
  var ss58 = require('@chainflip/utils/ss58');
10
- var BigNumber = require('bignumber.js');
10
+ var BigNumber2 = require('bignumber.js');
11
11
  var url = require('@chainflip/utils/url');
12
12
  var zod = require('zod');
13
13
  var scaleTs = require('scale-ts');
@@ -35,7 +35,7 @@ function _interopNamespace(e) {
35
35
  var bitcoin__namespace = /*#__PURE__*/_interopNamespace(bitcoin);
36
36
  var base58__namespace = /*#__PURE__*/_interopNamespace(base58);
37
37
  var ss58__namespace = /*#__PURE__*/_interopNamespace(ss58);
38
- var BigNumber__default = /*#__PURE__*/_interopDefault(BigNumber);
38
+ var BigNumber2__default = /*#__PURE__*/_interopDefault(BigNumber2);
39
39
 
40
40
  // src/address.ts
41
41
 
@@ -133,7 +133,7 @@ var isValidAddressForNetwork = (address2, cfOrBtcNetwork) => {
133
133
  };
134
134
  var hexString = zod.z.string().regex(/^([0-9a-f]{2})+$/, { message: "expected hex string" });
135
135
  var vout = zod.z.object({
136
- value: zod.z.number().transform((n) => BigInt(new BigNumber__default.default(n).shiftedBy(8).toFixed(0))),
136
+ value: zod.z.number().transform((n) => BigInt(new BigNumber2__default.default(n).shiftedBy(8).toFixed(0))),
137
137
  n: zod.z.number()
138
138
  });
139
139
  var nulldataVout = zod.z.object({
@@ -185,7 +185,16 @@ var makeRequest = async (rpcUrl, method, params) => {
185
185
  params
186
186
  })
187
187
  });
188
- const json = await res.json();
188
+ const text = await res.text();
189
+ let json;
190
+ try {
191
+ json = JSON.parse(text);
192
+ } catch {
193
+ if (res.status !== 200) {
194
+ throw new Error(`HTTP error [${res.status}]: ${text || res.statusText}`);
195
+ }
196
+ throw new Error(`Invalid JSON response: ${text}`);
197
+ }
189
198
  const result = rpcResponse.parse(json);
190
199
  if (result.error) {
191
200
  if (result.error.code === -5) return null;
@@ -203,7 +212,8 @@ var addressByteLengths = {
203
212
  Arbitrum: 20,
204
213
  Ethereum: 20,
205
214
  Solana: 32,
206
- Polkadot: 32
215
+ Polkadot: 32,
216
+ Assethub: 32
207
217
  };
208
218
  var createSwapDataCodec = (asset) => scaleTs.Struct({
209
219
  version: scaleTs.u8,
@@ -225,6 +235,7 @@ var encodeChainAddress = (data, asset) => {
225
235
  switch (chainflip.assetConstants[asset].chain) {
226
236
  case "Solana":
227
237
  return base58__namespace.encode(data);
238
+ case "Assethub":
228
239
  case "Polkadot":
229
240
  return ss58__namespace.encode({ data, ss58Format: consts.POLKADOT_SS58_PREFIX });
230
241
  case "Ethereum":
@@ -251,7 +262,7 @@ var parseVaultSwapData = (data) => {
251
262
  };
252
263
  };
253
264
  var getX128PriceFromAmounts = (depositAmount, minOutputAmount) => BigInt(
254
- new BigNumber.BigNumber(minOutputAmount.toString()).div(depositAmount.toString()).multipliedBy(new BigNumber.BigNumber(2).pow(128)).toFixed(0, BigNumber.BigNumber.ROUND_FLOOR)
265
+ new BigNumber2__default.default(minOutputAmount.toString()).div(depositAmount.toString()).multipliedBy(new BigNumber2__default.default(2).pow(128)).toFixed(0, BigNumber2__default.default.ROUND_FLOOR)
255
266
  );
256
267
  var findVaultSwapData = async (url, txId) => {
257
268
  const tx = await makeRequest(url, "getrawtransaction", [txId, true]);
package/dist/index.d.cts CHANGED
@@ -1,7 +1,6 @@
1
- import { ChainflipNetwork as ChainflipNetwork$1 } from '@chainflip/utils/chainflip';
1
+ import { ChainflipNetwork } from '@chainflip/utils/chainflip';
2
2
  import { VaultSwapData } from '@chainflip/utils/types';
3
3
 
4
- type ChainflipNetwork = 'mainnet' | 'perseverance' | 'sisyphos' | 'backspin';
5
4
  type BitcoinNetwork = 'mainnet' | 'testnet' | 'regtest';
6
5
 
7
6
  type Bytelike = Uint8Array | number[] | `0x${string}`;
@@ -24,13 +23,13 @@ type DecodedSegwitAddress = {
24
23
  version: number;
25
24
  };
26
25
  type SegwitAddressType = 'P2WPKH' | 'P2WSH' | 'Taproot';
27
- declare const encodeAddress: (data: Bytelike, kind: Base58AddressType | SegwitAddressType, cfOrBtcnetwork: BitcoinNetwork | ChainflipNetwork$1) => string;
28
- declare const decodeAddress: (address: string, cfOrBtcNetwork: BitcoinNetwork | ChainflipNetwork$1) => DecodedBase58Address | DecodedSegwitAddress;
29
- declare const isValidAddressForNetwork: (address: string, cfOrBtcNetwork: BitcoinNetwork | ChainflipNetwork$1) => boolean;
26
+ declare const encodeAddress: (data: Bytelike, kind: Base58AddressType | SegwitAddressType, cfOrBtcnetwork: BitcoinNetwork | ChainflipNetwork) => string;
27
+ declare const decodeAddress: (address: string, cfOrBtcNetwork: BitcoinNetwork | ChainflipNetwork) => DecodedBase58Address | DecodedSegwitAddress;
28
+ declare const isValidAddressForNetwork: (address: string, cfOrBtcNetwork: BitcoinNetwork | ChainflipNetwork) => boolean;
30
29
 
31
30
  type BitcoinVaultSwapData = VaultSwapData<null> & {
32
31
  depositAddress: string;
33
32
  };
34
33
  declare const findVaultSwapData: (url: string, txId: string) => Promise<BitcoinVaultSwapData | null>;
35
34
 
36
- export { type Base58AddressType, type BitcoinNetwork, type BitcoinVaultSwapData, type Bytelike, type ChainflipNetwork, type DecodedBase58Address, type DecodedSegwitAddress, type HRP, type SegwitAddressType, decodeAddress, encodeAddress, findVaultSwapData, isValidAddressForNetwork };
35
+ export { type Base58AddressType, type BitcoinNetwork, type BitcoinVaultSwapData, type Bytelike, type DecodedBase58Address, type DecodedSegwitAddress, type HRP, type SegwitAddressType, decodeAddress, encodeAddress, findVaultSwapData, isValidAddressForNetwork };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { ChainflipNetwork as ChainflipNetwork$1 } from '@chainflip/utils/chainflip';
1
+ import { ChainflipNetwork } from '@chainflip/utils/chainflip';
2
2
  import { VaultSwapData } from '@chainflip/utils/types';
3
3
 
4
- type ChainflipNetwork = 'mainnet' | 'perseverance' | 'sisyphos' | 'backspin';
5
4
  type BitcoinNetwork = 'mainnet' | 'testnet' | 'regtest';
6
5
 
7
6
  type Bytelike = Uint8Array | number[] | `0x${string}`;
@@ -24,13 +23,13 @@ type DecodedSegwitAddress = {
24
23
  version: number;
25
24
  };
26
25
  type SegwitAddressType = 'P2WPKH' | 'P2WSH' | 'Taproot';
27
- declare const encodeAddress: (data: Bytelike, kind: Base58AddressType | SegwitAddressType, cfOrBtcnetwork: BitcoinNetwork | ChainflipNetwork$1) => string;
28
- declare const decodeAddress: (address: string, cfOrBtcNetwork: BitcoinNetwork | ChainflipNetwork$1) => DecodedBase58Address | DecodedSegwitAddress;
29
- declare const isValidAddressForNetwork: (address: string, cfOrBtcNetwork: BitcoinNetwork | ChainflipNetwork$1) => boolean;
26
+ declare const encodeAddress: (data: Bytelike, kind: Base58AddressType | SegwitAddressType, cfOrBtcnetwork: BitcoinNetwork | ChainflipNetwork) => string;
27
+ declare const decodeAddress: (address: string, cfOrBtcNetwork: BitcoinNetwork | ChainflipNetwork) => DecodedBase58Address | DecodedSegwitAddress;
28
+ declare const isValidAddressForNetwork: (address: string, cfOrBtcNetwork: BitcoinNetwork | ChainflipNetwork) => boolean;
30
29
 
31
30
  type BitcoinVaultSwapData = VaultSwapData<null> & {
32
31
  depositAddress: string;
33
32
  };
34
33
  declare const findVaultSwapData: (url: string, txId: string) => Promise<BitcoinVaultSwapData | null>;
35
34
 
36
- export { type Base58AddressType, type BitcoinNetwork, type BitcoinVaultSwapData, type Bytelike, type ChainflipNetwork, type DecodedBase58Address, type DecodedSegwitAddress, type HRP, type SegwitAddressType, decodeAddress, encodeAddress, findVaultSwapData, isValidAddressForNetwork };
35
+ export { type Base58AddressType, type BitcoinNetwork, type BitcoinVaultSwapData, type Bytelike, type DecodedBase58Address, type DecodedSegwitAddress, type HRP, type SegwitAddressType, decodeAddress, encodeAddress, findVaultSwapData, isValidAddressForNetwork };
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import * as base58 from '@chainflip/utils/base58';
5
5
  import { assetContractId, assetConstants } from '@chainflip/utils/chainflip';
6
6
  import { POLKADOT_SS58_PREFIX } from '@chainflip/utils/consts';
7
7
  import * as ss58 from '@chainflip/utils/ss58';
8
- import BigNumber, { BigNumber as BigNumber$1 } from 'bignumber.js';
8
+ import BigNumber2 from 'bignumber.js';
9
9
  import { parseUrlWithBasicAuth } from '@chainflip/utils/url';
10
10
  import { z } from 'zod';
11
11
  import { Struct, Bytes, u8, Vector, u16, u128 } from 'scale-ts';
@@ -106,7 +106,7 @@ var isValidAddressForNetwork = (address2, cfOrBtcNetwork) => {
106
106
  };
107
107
  var hexString = z.string().regex(/^([0-9a-f]{2})+$/, { message: "expected hex string" });
108
108
  var vout = z.object({
109
- value: z.number().transform((n) => BigInt(new BigNumber(n).shiftedBy(8).toFixed(0))),
109
+ value: z.number().transform((n) => BigInt(new BigNumber2(n).shiftedBy(8).toFixed(0))),
110
110
  n: z.number()
111
111
  });
112
112
  var nulldataVout = z.object({
@@ -158,7 +158,16 @@ var makeRequest = async (rpcUrl, method, params) => {
158
158
  params
159
159
  })
160
160
  });
161
- const json = await res.json();
161
+ const text = await res.text();
162
+ let json;
163
+ try {
164
+ json = JSON.parse(text);
165
+ } catch {
166
+ if (res.status !== 200) {
167
+ throw new Error(`HTTP error [${res.status}]: ${text || res.statusText}`);
168
+ }
169
+ throw new Error(`Invalid JSON response: ${text}`);
170
+ }
162
171
  const result = rpcResponse.parse(json);
163
172
  if (result.error) {
164
173
  if (result.error.code === -5) return null;
@@ -176,7 +185,8 @@ var addressByteLengths = {
176
185
  Arbitrum: 20,
177
186
  Ethereum: 20,
178
187
  Solana: 32,
179
- Polkadot: 32
188
+ Polkadot: 32,
189
+ Assethub: 32
180
190
  };
181
191
  var createSwapDataCodec = (asset) => Struct({
182
192
  version: u8,
@@ -198,6 +208,7 @@ var encodeChainAddress = (data, asset) => {
198
208
  switch (assetConstants[asset].chain) {
199
209
  case "Solana":
200
210
  return base58.encode(data);
211
+ case "Assethub":
201
212
  case "Polkadot":
202
213
  return ss58.encode({ data, ss58Format: POLKADOT_SS58_PREFIX });
203
214
  case "Ethereum":
@@ -224,7 +235,7 @@ var parseVaultSwapData = (data) => {
224
235
  };
225
236
  };
226
237
  var getX128PriceFromAmounts = (depositAmount, minOutputAmount) => BigInt(
227
- new BigNumber$1(minOutputAmount.toString()).div(depositAmount.toString()).multipliedBy(new BigNumber$1(2).pow(128)).toFixed(0, BigNumber$1.ROUND_FLOOR)
238
+ new BigNumber2(minOutputAmount.toString()).div(depositAmount.toString()).multipliedBy(new BigNumber2(2).pow(128)).toFixed(0, BigNumber2.ROUND_FLOOR)
228
239
  );
229
240
  var findVaultSwapData = async (url, txId) => {
230
241
  const tx = await makeRequest(url, "getrawtransaction", [txId, true]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainflip/bitcoin",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
4
4
  "type": "module",
5
5
  "repository": "https://github.com/chainflip-io/chainflip-product-toolkit.git",
6
6
  "publishConfig": {
@@ -11,14 +11,24 @@
11
11
  "dist",
12
12
  "README.md"
13
13
  ],
14
- "main": "dist/index.cjs",
15
- "module": "dist/index.js",
14
+ "exports": {
15
+ ".": {
16
+ "require": {
17
+ "types": "./dist/index.d.cts",
18
+ "default": "./dist/index.cjs"
19
+ },
20
+ "import": {
21
+ "types": "./dist/index.d.ts",
22
+ "default": "./dist/index.js"
23
+ }
24
+ }
25
+ },
16
26
  "dependencies": {
17
- "@chainflip/utils": "0.7.2",
18
- "bignumber.js": "^9.1.2",
19
- "bitcoinjs-lib": "^7.0.0-rc.0",
27
+ "@chainflip/utils": "0.8.6",
28
+ "bignumber.js": "^9.3.0",
29
+ "bitcoinjs-lib": "7.0.0-rc.0",
20
30
  "scale-ts": "^1.6.1",
21
- "zod": "^3.24.2"
31
+ "zod": "^3.25.67"
22
32
  },
23
33
  "scripts": {
24
34
  "eslint:check": "pnpm eslint --max-warnings 0 './**/*.ts'",