@chainflip/bitcoin 2.1.0-beta.0 → 2.1.0-beta.1

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.
@@ -1,4 +1,4 @@
1
- import { BitcoinNetwork } from "./consts.js";
1
+ import { BitcoinNetwork } from "./consts.cjs";
2
2
  import { ChainflipNetwork } from "@chainflip/utils/chainflip";
3
3
 
4
4
  //#region src/address.d.ts
@@ -0,0 +1,29 @@
1
+ import { BitcoinNetwork } from "./consts.mjs";
2
+ import { ChainflipNetwork } from "@chainflip/utils/chainflip";
3
+
4
+ //#region src/address.d.ts
5
+ type Bytelike = Uint8Array | number[] | `0x${string}`;
6
+ declare const networkHrp: {
7
+ readonly mainnet: "bc";
8
+ readonly testnet: "tb";
9
+ readonly regtest: "bcrt";
10
+ };
11
+ type HRP = (typeof networkHrp)[keyof typeof networkHrp];
12
+ type Base58AddressType = 'P2SH' | 'P2PKH';
13
+ type DecodedBase58Address = {
14
+ type: Base58AddressType;
15
+ data: Uint8Array;
16
+ version: number;
17
+ };
18
+ type DecodedSegwitAddress = {
19
+ hrp: HRP;
20
+ data: Uint8Array;
21
+ type: SegwitAddressType;
22
+ version: number;
23
+ };
24
+ type SegwitAddressType = 'P2WPKH' | 'P2WSH' | 'Taproot';
25
+ declare const encodeAddress: (data: Bytelike, kind: Base58AddressType | SegwitAddressType, cfOrBtcnetwork: BitcoinNetwork | ChainflipNetwork) => string;
26
+ declare const decodeAddress: (address: string, cfOrBtcNetwork: BitcoinNetwork | ChainflipNetwork) => DecodedBase58Address | DecodedSegwitAddress;
27
+ declare const isValidAddressForNetwork: (address: string, cfOrBtcNetwork: BitcoinNetwork | ChainflipNetwork) => boolean;
28
+ //#endregion
29
+ export { Base58AddressType, Bytelike, DecodedBase58Address, DecodedSegwitAddress, HRP, SegwitAddressType, decodeAddress, encodeAddress, isValidAddressForNetwork };
@@ -1,4 +1,4 @@
1
- import { networkMap } from "./consts.js";
1
+ import { networkMap } from "./consts.mjs";
2
2
  import { assert } from "@chainflip/utils/assertion";
3
3
  import { hexToBytes } from "@chainflip/utils/bytes";
4
4
  import * as bitcoin from "bitcoinjs-lib";
@@ -0,0 +1,7 @@
1
+ import { ChainflipNetwork } from "@chainflip/utils/chainflip";
2
+
3
+ //#region src/consts.d.ts
4
+ type BitcoinNetwork = 'mainnet' | 'testnet' | 'regtest';
5
+ declare const networkMap: Record<ChainflipNetwork | BitcoinNetwork, BitcoinNetwork>;
6
+ //#endregion
7
+ export { BitcoinNetwork, networkMap };
@@ -0,0 +1,9 @@
1
+ import { VaultSwapData } from "@chainflip/utils/types";
2
+
3
+ //#region src/deposit.d.ts
4
+ type BitcoinVaultSwapData = VaultSwapData<null> & {
5
+ depositAddress: string;
6
+ };
7
+ declare const findVaultSwapData: (url: string, txId: string) => Promise<BitcoinVaultSwapData | null>;
8
+ //#endregion
9
+ export { BitcoinVaultSwapData, findVaultSwapData };
@@ -1,5 +1,5 @@
1
- import { makeRequest } from "./rpc.js";
2
- import { createSwapDataCodecV0, createSwapDataCodecV1 } from "./scale.js";
1
+ import { makeRequest } from "./rpc.mjs";
2
+ import { createSwapDataCodecV0, createSwapDataCodecV1 } from "./scale.mjs";
3
3
  import { assert } from "@chainflip/utils/assertion";
4
4
  import { bytesToHex } from "@chainflip/utils/bytes";
5
5
  import * as base58 from "@chainflip/utils/base58";
@@ -1,4 +1,4 @@
1
- import { BitcoinNetwork } from "./consts.js";
2
- import { Base58AddressType, Bytelike, DecodedBase58Address, DecodedSegwitAddress, HRP, SegwitAddressType, decodeAddress, encodeAddress, isValidAddressForNetwork } from "./address.js";
3
- import { BitcoinVaultSwapData, findVaultSwapData } from "./deposit.js";
1
+ import { BitcoinNetwork } from "./consts.cjs";
2
+ import { Base58AddressType, Bytelike, DecodedBase58Address, DecodedSegwitAddress, HRP, SegwitAddressType, decodeAddress, encodeAddress, isValidAddressForNetwork } from "./address.cjs";
3
+ import { BitcoinVaultSwapData, findVaultSwapData } from "./deposit.cjs";
4
4
  export { Base58AddressType, type BitcoinNetwork, type BitcoinVaultSwapData, Bytelike, DecodedBase58Address, DecodedSegwitAddress, HRP, SegwitAddressType, decodeAddress, encodeAddress, findVaultSwapData, isValidAddressForNetwork };
@@ -0,0 +1,4 @@
1
+ import { BitcoinNetwork } from "./consts.mjs";
2
+ import { Base58AddressType, Bytelike, DecodedBase58Address, DecodedSegwitAddress, HRP, SegwitAddressType, decodeAddress, encodeAddress, isValidAddressForNetwork } from "./address.mjs";
3
+ import { BitcoinVaultSwapData, findVaultSwapData } from "./deposit.mjs";
4
+ export { Base58AddressType, type BitcoinNetwork, type BitcoinVaultSwapData, Bytelike, DecodedBase58Address, DecodedSegwitAddress, HRP, SegwitAddressType, decodeAddress, encodeAddress, findVaultSwapData, isValidAddressForNetwork };
@@ -1,4 +1,4 @@
1
- import { decodeAddress, encodeAddress, isValidAddressForNetwork } from "./address.js";
2
- import { findVaultSwapData } from "./deposit.js";
1
+ import { decodeAddress, encodeAddress, isValidAddressForNetwork } from "./address.mjs";
2
+ import { findVaultSwapData } from "./deposit.mjs";
3
3
 
4
4
  export { decodeAddress, encodeAddress, findVaultSwapData, isValidAddressForNetwork };
package/dist/rpc.d.mts ADDED
@@ -0,0 +1,167 @@
1
+ import { z } from "zod";
2
+
3
+ //#region src/rpc.d.ts
4
+ type RpcRequest = {
5
+ getrawtransaction: [txId: string, enhanced?: boolean];
6
+ getblock: [blockHash: string, enhanced?: boolean];
7
+ };
8
+ declare const responseSchemas: {
9
+ readonly getrawtransaction: z.ZodObject<{
10
+ vout: z.ZodTuple<[z.ZodIntersection<z.ZodObject<{
11
+ scriptPubKey: z.ZodObject<{
12
+ type: z.ZodEnum<["witness_v1_taproot", "witness_v0_scripthash", "witness_v0_keyhash", "pubkeyhash", "scripthash"]>;
13
+ address: z.ZodString;
14
+ }, "strip", z.ZodTypeAny, {
15
+ type: "witness_v1_taproot" | "witness_v0_scripthash" | "witness_v0_keyhash" | "pubkeyhash" | "scripthash";
16
+ address: string;
17
+ }, {
18
+ type: "witness_v1_taproot" | "witness_v0_scripthash" | "witness_v0_keyhash" | "pubkeyhash" | "scripthash";
19
+ address: string;
20
+ }>;
21
+ }, "strip", z.ZodTypeAny, {
22
+ scriptPubKey: {
23
+ type: "witness_v1_taproot" | "witness_v0_scripthash" | "witness_v0_keyhash" | "pubkeyhash" | "scripthash";
24
+ address: string;
25
+ };
26
+ }, {
27
+ scriptPubKey: {
28
+ type: "witness_v1_taproot" | "witness_v0_scripthash" | "witness_v0_keyhash" | "pubkeyhash" | "scripthash";
29
+ address: string;
30
+ };
31
+ }>, z.ZodObject<{
32
+ value: z.ZodEffects<z.ZodNumber, bigint, number>;
33
+ n: z.ZodNumber;
34
+ }, "strip", z.ZodTypeAny, {
35
+ value: bigint;
36
+ n: number;
37
+ }, {
38
+ value: number;
39
+ n: number;
40
+ }>>, z.ZodIntersection<z.ZodObject<{
41
+ scriptPubKey: z.ZodObject<{
42
+ type: z.ZodLiteral<"nulldata">;
43
+ hex: z.ZodEffects<z.ZodString, Uint8Array<ArrayBufferLike>, string>;
44
+ }, "strip", z.ZodTypeAny, {
45
+ type: "nulldata";
46
+ hex: Uint8Array<ArrayBufferLike>;
47
+ }, {
48
+ type: "nulldata";
49
+ hex: string;
50
+ }>;
51
+ }, "strip", z.ZodTypeAny, {
52
+ scriptPubKey: {
53
+ type: "nulldata";
54
+ hex: Uint8Array<ArrayBufferLike>;
55
+ };
56
+ }, {
57
+ scriptPubKey: {
58
+ type: "nulldata";
59
+ hex: string;
60
+ };
61
+ }>, z.ZodObject<{
62
+ value: z.ZodEffects<z.ZodNumber, bigint, number>;
63
+ n: z.ZodNumber;
64
+ }, "strip", z.ZodTypeAny, {
65
+ value: bigint;
66
+ n: number;
67
+ }, {
68
+ value: number;
69
+ n: number;
70
+ }>>, z.ZodIntersection<z.ZodObject<{
71
+ scriptPubKey: z.ZodObject<{
72
+ type: z.ZodEnum<["witness_v1_taproot", "witness_v0_scripthash", "witness_v0_keyhash", "pubkeyhash", "scripthash"]>;
73
+ address: z.ZodString;
74
+ }, "strip", z.ZodTypeAny, {
75
+ type: "witness_v1_taproot" | "witness_v0_scripthash" | "witness_v0_keyhash" | "pubkeyhash" | "scripthash";
76
+ address: string;
77
+ }, {
78
+ type: "witness_v1_taproot" | "witness_v0_scripthash" | "witness_v0_keyhash" | "pubkeyhash" | "scripthash";
79
+ address: string;
80
+ }>;
81
+ }, "strip", z.ZodTypeAny, {
82
+ scriptPubKey: {
83
+ type: "witness_v1_taproot" | "witness_v0_scripthash" | "witness_v0_keyhash" | "pubkeyhash" | "scripthash";
84
+ address: string;
85
+ };
86
+ }, {
87
+ scriptPubKey: {
88
+ type: "witness_v1_taproot" | "witness_v0_scripthash" | "witness_v0_keyhash" | "pubkeyhash" | "scripthash";
89
+ address: string;
90
+ };
91
+ }>, z.ZodObject<{
92
+ value: z.ZodEffects<z.ZodNumber, bigint, number>;
93
+ n: z.ZodNumber;
94
+ }, "strip", z.ZodTypeAny, {
95
+ value: bigint;
96
+ n: number;
97
+ }, {
98
+ value: number;
99
+ n: number;
100
+ }>>], null>;
101
+ blockhash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
102
+ }, "strip", z.ZodTypeAny, {
103
+ vout: [{
104
+ scriptPubKey: {
105
+ type: "witness_v1_taproot" | "witness_v0_scripthash" | "witness_v0_keyhash" | "pubkeyhash" | "scripthash";
106
+ address: string;
107
+ };
108
+ } & {
109
+ value: bigint;
110
+ n: number;
111
+ }, {
112
+ scriptPubKey: {
113
+ type: "nulldata";
114
+ hex: Uint8Array<ArrayBufferLike>;
115
+ };
116
+ } & {
117
+ value: bigint;
118
+ n: number;
119
+ }, {
120
+ scriptPubKey: {
121
+ type: "witness_v1_taproot" | "witness_v0_scripthash" | "witness_v0_keyhash" | "pubkeyhash" | "scripthash";
122
+ address: string;
123
+ };
124
+ } & {
125
+ value: bigint;
126
+ n: number;
127
+ }];
128
+ blockhash?: string | null | undefined;
129
+ }, {
130
+ vout: [{
131
+ scriptPubKey: {
132
+ type: "witness_v1_taproot" | "witness_v0_scripthash" | "witness_v0_keyhash" | "pubkeyhash" | "scripthash";
133
+ address: string;
134
+ };
135
+ } & {
136
+ value: number;
137
+ n: number;
138
+ }, {
139
+ scriptPubKey: {
140
+ type: "nulldata";
141
+ hex: string;
142
+ };
143
+ } & {
144
+ value: number;
145
+ n: number;
146
+ }, {
147
+ scriptPubKey: {
148
+ type: "witness_v1_taproot" | "witness_v0_scripthash" | "witness_v0_keyhash" | "pubkeyhash" | "scripthash";
149
+ address: string;
150
+ };
151
+ } & {
152
+ value: number;
153
+ n: number;
154
+ }];
155
+ blockhash?: string | null | undefined;
156
+ }>;
157
+ readonly getblock: z.ZodObject<{
158
+ height: z.ZodNumber;
159
+ }, "strip", z.ZodTypeAny, {
160
+ height: number;
161
+ }, {
162
+ height: number;
163
+ }>;
164
+ };
165
+ declare const makeRequest: <T extends keyof RpcRequest & keyof typeof responseSchemas>(rpcUrl: string, method: T, params: RpcRequest[T]) => Promise<z.output<(typeof responseSchemas)[T]> | null>;
166
+ //#endregion
167
+ export { makeRequest };
@@ -0,0 +1,44 @@
1
+ import { ChainflipAsset } from "@chainflip/utils/chainflip";
2
+ import * as scale_ts0 from "scale-ts";
3
+ import { CodecType } from "scale-ts";
4
+
5
+ //#region src/scale.d.ts
6
+ declare const createSwapDataCodecV0: (asset: ChainflipAsset) => scale_ts0.Codec<{
7
+ version: number;
8
+ destinationAsset: number;
9
+ destinationAddress: Uint8Array<ArrayBufferLike>;
10
+ parameters: {
11
+ retryDuration: number;
12
+ minOutputAmount: bigint;
13
+ numberOfChunks: number;
14
+ chunkInterval: number;
15
+ boostFee: number;
16
+ brokerFee: number;
17
+ affiliates: {
18
+ accountIndex: number;
19
+ commissionBps: number;
20
+ }[];
21
+ };
22
+ }>;
23
+ declare const createSwapDataCodecV1: (asset: ChainflipAsset) => scale_ts0.Codec<{
24
+ version: number;
25
+ destinationAsset: number;
26
+ destinationAddress: Uint8Array<ArrayBufferLike>;
27
+ parameters: {
28
+ retryDuration: number;
29
+ minOutputAmount: bigint;
30
+ maxOraclePriceSlippage: number;
31
+ numberOfChunks: number;
32
+ chunkInterval: number;
33
+ boostFee: number;
34
+ brokerFee: number;
35
+ affiliates: {
36
+ accountIndex: number;
37
+ commissionBps: number;
38
+ }[];
39
+ };
40
+ }>;
41
+ type UtxoDataV0 = CodecType<ReturnType<typeof createSwapDataCodecV0>>['parameters'];
42
+ type UtxoDataV1 = CodecType<ReturnType<typeof createSwapDataCodecV1>>['parameters'];
43
+ //#endregion
44
+ export { UtxoDataV0, UtxoDataV1, createSwapDataCodecV0, createSwapDataCodecV1 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainflip/bitcoin",
3
- "version": "2.1.0-beta.0",
3
+ "version": "2.1.0-beta.1",
4
4
  "type": "module",
5
5
  "repository": "https://github.com/chainflip-io/chainflip-product-toolkit.git",
6
6
  "publishConfig": {
@@ -14,12 +14,12 @@
14
14
  "exports": {
15
15
  ".": {
16
16
  "require": {
17
- "types": "./dist/index.d.ts",
17
+ "types": "./dist/index.d.cts",
18
18
  "default": "./dist/index.cjs"
19
19
  },
20
20
  "import": {
21
- "types": "./dist/index.d.ts",
22
- "default": "./dist/index.js"
21
+ "types": "./dist/index.d.mts",
22
+ "default": "./dist/index.mjs"
23
23
  }
24
24
  }
25
25
  },
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes