@teleportdao/bitcoin 1.7.21 → 1.8.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.
Files changed (42) hide show
  1. package/.tmp/ordinal-helper.ts +133 -0
  2. package/.tmp/ordinal.ts +25 -0
  3. package/.tmp/rbf.ts +27 -24
  4. package/dist/bitcoin-base.d.ts +93 -0
  5. package/dist/bitcoin-base.d.ts.map +1 -0
  6. package/dist/bitcoin-base.js +236 -0
  7. package/dist/bitcoin-base.js.map +1 -0
  8. package/dist/helper/burn-request-helper.d.ts +7 -0
  9. package/dist/helper/burn-request-helper.d.ts.map +1 -0
  10. package/dist/helper/burn-request-helper.js +26 -0
  11. package/dist/helper/burn-request-helper.js.map +1 -0
  12. package/dist/helper/teleport-request-helper.d.ts +47 -0
  13. package/dist/helper/teleport-request-helper.d.ts.map +1 -0
  14. package/dist/helper/teleport-request-helper.js +146 -0
  15. package/dist/helper/teleport-request-helper.js.map +1 -0
  16. package/dist/teleport-dao-payments.d.ts +76 -0
  17. package/dist/teleport-dao-payments.d.ts.map +1 -0
  18. package/dist/teleport-dao-payments.js +217 -0
  19. package/dist/teleport-dao-payments.js.map +1 -0
  20. package/package.json +4 -4
  21. package/src/bitcoin-interface-ordinal.ts +181 -181
  22. package/src/bitcoin-interface-teleswap.ts +252 -252
  23. package/src/bitcoin-interface-utils.ts +60 -60
  24. package/src/bitcoin-interface.ts +241 -241
  25. package/src/bitcoin-utils.ts +591 -591
  26. package/src/bitcoin-wallet-base.ts +310 -310
  27. package/src/helper/brc20-helper.ts +181 -181
  28. package/src/helper/ordinal-helper.ts +118 -118
  29. package/src/index.ts +15 -15
  30. package/src/ordinal-wallet.ts +738 -738
  31. package/src/sign/index.ts +1 -1
  32. package/src/sign/sign-transaction.ts +108 -108
  33. package/src/teleswap-wallet.ts +155 -155
  34. package/src/transaction-builder/bitcoin-transaction-builder.ts +44 -44
  35. package/src/transaction-builder/index.ts +3 -3
  36. package/src/transaction-builder/ordinal-transaction-builder.ts +147 -147
  37. package/src/transaction-builder/transaction-builder.ts +706 -706
  38. package/src/type.ts +48 -48
  39. package/src/utils/networks.ts +33 -33
  40. package/src/utils/tools.ts +90 -90
  41. package/tsconfig.json +9 -9
  42. package/webpack.config.js +16 -16
package/src/type.ts CHANGED
@@ -1,48 +1,48 @@
1
- export type Transaction = {
2
- txId: string
3
- version: number
4
- locktime: number
5
- blockNumber: number
6
- blockHash: string
7
- merkleProof?: {
8
- intermediateNodes: string
9
- transactionIndex: number
10
- }
11
- vout: {
12
- address?: string
13
- script: string
14
- value: number
15
- }[]
16
- vin: {
17
- txId: string
18
- index: number
19
- address?: string
20
- script?: string
21
- value?: number
22
- }[]
23
- address: string
24
- addressScript: string
25
- }
26
-
27
- export type BitcoinConnectionInfo = {
28
- api: {
29
- token?: string
30
- // provider: "BlockStream" | "MempoolSpace"
31
- provider: any
32
- }
33
- rpc?: {
34
- enabled?: boolean
35
- url: string
36
- headers?: {
37
- [key: string]: string
38
- }
39
- auth?: {
40
- username: string
41
- password: string
42
- }
43
- }
44
- utxo?: {
45
- token?: string
46
- provider: "BlockStream" | "NowNodes" | "MempoolSpace" | "Unisat"
47
- }
48
- }
1
+ export type Transaction = {
2
+ txId: string
3
+ version: number
4
+ locktime: number
5
+ blockNumber: number
6
+ blockHash: string
7
+ merkleProof?: {
8
+ intermediateNodes: string
9
+ transactionIndex: number
10
+ }
11
+ vout: {
12
+ address?: string
13
+ script: string
14
+ value: number
15
+ }[]
16
+ vin: {
17
+ txId: string
18
+ index: number
19
+ address?: string
20
+ script?: string
21
+ value?: number
22
+ }[]
23
+ address: string
24
+ addressScript: string
25
+ }
26
+
27
+ export type BitcoinConnectionInfo = {
28
+ api: {
29
+ token?: string
30
+ // provider: "BlockStream" | "MempoolSpace"
31
+ provider: any
32
+ }
33
+ rpc?: {
34
+ enabled?: boolean
35
+ url: string
36
+ headers?: {
37
+ [key: string]: string
38
+ }
39
+ auth?: {
40
+ username: string
41
+ password: string
42
+ }
43
+ }
44
+ utxo?: {
45
+ token?: string
46
+ provider: "BlockStream" | "NowNodes" | "MempoolSpace" | "Unisat"
47
+ }
48
+ }
@@ -1,33 +1,33 @@
1
- import * as bitcoinLib from "bitcoinjs-lib"
2
-
3
- const networks: {
4
- [key: string]: bitcoinLib.Network
5
- } = {
6
- bitcoin: bitcoinLib.networks.bitcoin,
7
- bitcoin_testnet: bitcoinLib.networks.testnet,
8
-
9
- litecoin: {
10
- messagePrefix: "\x19Litecoin Signed Message:\n",
11
- bech32: "ltc",
12
- bip32: {
13
- public: 0x0488b21e,
14
- private: 0x0488ade4,
15
- },
16
- pubKeyHash: 0x30,
17
- scriptHash: 0x32,
18
- wif: 0xb0,
19
- },
20
- litecoin_testnet: {
21
- messagePrefix: "\x18Litecoin Signed Message:\n",
22
- bech32: "tltc",
23
- bip32: {
24
- public: 0x043587cf,
25
- private: 0x04358394,
26
- },
27
- pubKeyHash: 0x6f,
28
- scriptHash: 0x3a, // old 0xc4 -> 2 deprecated
29
- wif: 0xef,
30
- },
31
- }
32
-
33
- export default networks
1
+ import * as bitcoinLib from "bitcoinjs-lib"
2
+
3
+ const networks: {
4
+ [key: string]: bitcoinLib.Network
5
+ } = {
6
+ bitcoin: bitcoinLib.networks.bitcoin,
7
+ bitcoin_testnet: bitcoinLib.networks.testnet,
8
+
9
+ litecoin: {
10
+ messagePrefix: "\x19Litecoin Signed Message:\n",
11
+ bech32: "ltc",
12
+ bip32: {
13
+ public: 0x0488b21e,
14
+ private: 0x0488ade4,
15
+ },
16
+ pubKeyHash: 0x30,
17
+ scriptHash: 0x32,
18
+ wif: 0xb0,
19
+ },
20
+ litecoin_testnet: {
21
+ messagePrefix: "\x18Litecoin Signed Message:\n",
22
+ bech32: "tltc",
23
+ bip32: {
24
+ public: 0x043587cf,
25
+ private: 0x04358394,
26
+ },
27
+ pubKeyHash: 0x6f,
28
+ scriptHash: 0x3a, // old 0xc4 -> 2 deprecated
29
+ wif: 0xef,
30
+ },
31
+ }
32
+
33
+ export default networks
@@ -1,90 +1,90 @@
1
- import axios from "axios"
2
-
3
- function sleep(ms: number) {
4
- // eslint-disable-next-line no-promise-executor-return
5
- return new Promise((resolve) => setTimeout(resolve, ms))
6
- }
7
-
8
- async function runWithRetries<T>(
9
- action: () => Promise<T>,
10
- config: {
11
- maxTries?: number
12
- retrySleep?: number
13
- } = {
14
- maxTries: 2,
15
- retrySleep: 1000,
16
- },
17
- ): Promise<T> {
18
- const maxTries = config.maxTries ?? 2
19
- const retrySleep = config.retrySleep ?? 1000
20
-
21
- let lastError: any
22
- for (let count = 0; count < maxTries; count += 1) {
23
- try {
24
- return await action()
25
- } catch (error: any) {
26
- console.log(`Attempt ${count + 1} failed: ${error.message}`)
27
- lastError = error
28
- if (count < maxTries - 1) {
29
- await sleep(retrySleep)
30
- }
31
- }
32
- }
33
-
34
- throw lastError || new Error(`Function failed after ${maxTries} retries: ${lastError?.message}`)
35
- }
36
-
37
- function getRandomInteger(min: number, max: number) {
38
- return Math.floor(Math.random() * (max - min)) + min
39
- }
40
-
41
- function getAxiosInstance({
42
- baseUrl,
43
- timeout = 10000,
44
- headers = {},
45
- auth,
46
- }: {
47
- baseUrl: string
48
- timeout?: number
49
- headers?: { [key: string]: string }
50
- auth?: {
51
- username: string
52
- password: string
53
- }
54
- }) {
55
- let host = baseUrl
56
- let instance
57
-
58
- instance = axios.create({
59
- baseURL: host,
60
- timeout,
61
- auth,
62
- headers: {
63
- ...headers,
64
- },
65
- })
66
-
67
- // Add a response interceptor
68
- instance.interceptors.response.use(
69
- (response) => response,
70
- (error) => {
71
- // todo : fix this part
72
- if (error.response) {
73
- const serviceError = new Error(
74
- JSON.stringify({ data: error.response.data, message: error.message }),
75
- )
76
- return Promise.reject(serviceError)
77
- }
78
-
79
- if (error.request) {
80
- const serviceError = new Error(error.message)
81
- return Promise.reject(serviceError)
82
- }
83
- return Promise.reject(error)
84
- },
85
- )
86
-
87
- return instance
88
- }
89
-
90
- export { sleep, runWithRetries, getRandomInteger, getAxiosInstance }
1
+ import axios from "axios"
2
+
3
+ function sleep(ms: number) {
4
+ // eslint-disable-next-line no-promise-executor-return
5
+ return new Promise((resolve) => setTimeout(resolve, ms))
6
+ }
7
+
8
+ async function runWithRetries<T>(
9
+ action: () => Promise<T>,
10
+ config: {
11
+ maxTries?: number
12
+ retrySleep?: number
13
+ } = {
14
+ maxTries: 2,
15
+ retrySleep: 1000,
16
+ },
17
+ ): Promise<T> {
18
+ const maxTries = config.maxTries ?? 2
19
+ const retrySleep = config.retrySleep ?? 1000
20
+
21
+ let lastError: any
22
+ for (let count = 0; count < maxTries; count += 1) {
23
+ try {
24
+ return await action()
25
+ } catch (error: any) {
26
+ console.log(`Attempt ${count + 1} failed: ${error.message}`)
27
+ lastError = error
28
+ if (count < maxTries - 1) {
29
+ await sleep(retrySleep)
30
+ }
31
+ }
32
+ }
33
+
34
+ throw lastError || new Error(`Function failed after ${maxTries} retries: ${lastError?.message}`)
35
+ }
36
+
37
+ function getRandomInteger(min: number, max: number) {
38
+ return Math.floor(Math.random() * (max - min)) + min
39
+ }
40
+
41
+ function getAxiosInstance({
42
+ baseUrl,
43
+ timeout = 10000,
44
+ headers = {},
45
+ auth,
46
+ }: {
47
+ baseUrl: string
48
+ timeout?: number
49
+ headers?: { [key: string]: string }
50
+ auth?: {
51
+ username: string
52
+ password: string
53
+ }
54
+ }) {
55
+ let host = baseUrl
56
+ let instance
57
+
58
+ instance = axios.create({
59
+ baseURL: host,
60
+ timeout,
61
+ auth,
62
+ headers: {
63
+ ...headers,
64
+ },
65
+ })
66
+
67
+ // Add a response interceptor
68
+ instance.interceptors.response.use(
69
+ (response) => response,
70
+ (error) => {
71
+ // todo : fix this part
72
+ if (error.response) {
73
+ const serviceError = new Error(
74
+ JSON.stringify({ data: error.response.data, message: error.message }),
75
+ )
76
+ return Promise.reject(serviceError)
77
+ }
78
+
79
+ if (error.request) {
80
+ const serviceError = new Error(error.message)
81
+ return Promise.reject(serviceError)
82
+ }
83
+ return Promise.reject(error)
84
+ },
85
+ )
86
+
87
+ return instance
88
+ }
89
+
90
+ export { sleep, runWithRetries, getRandomInteger, getAxiosInstance }
package/tsconfig.json CHANGED
@@ -1,9 +1,9 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "rootDir": "src" /* Specify the root folder within your source files. */,
5
- "outDir": "dist" /* Specify an output folder for all emitted files. */
6
- },
7
- "include": ["src"],
8
- "exclude": ["node_modules", "dist"]
9
- }
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src" /* Specify the root folder within your source files. */,
5
+ "outDir": "dist" /* Specify an output folder for all emitted files. */
6
+ },
7
+ "include": ["src"],
8
+ "exclude": ["node_modules", "dist"]
9
+ }
package/webpack.config.js CHANGED
@@ -1,16 +1,16 @@
1
- const path = require("path")
2
- // const webpack = require("webpack")
3
-
4
- module.exports = {
5
- mode: "production",
6
- entry: "./dist/index.js",
7
- output: {
8
- filename: "bundle.js",
9
- path: path.resolve(__dirname, "dist"),
10
- libraryTarget: "umd", // Module type
11
- globalObject: "this", // Fix for universal module definition
12
- },
13
- performance: {
14
- hints: false,
15
- },
16
- }
1
+ const path = require("path")
2
+ // const webpack = require("webpack")
3
+
4
+ module.exports = {
5
+ mode: "production",
6
+ entry: "./dist/index.js",
7
+ output: {
8
+ filename: "bundle.js",
9
+ path: path.resolve(__dirname, "dist"),
10
+ libraryTarget: "umd", // Module type
11
+ globalObject: "this", // Fix for universal module definition
12
+ },
13
+ performance: {
14
+ hints: false,
15
+ },
16
+ }