@teleportdao/bitcoin 1.7.13 → 1.7.16

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 (50) hide show
  1. package/dist/bitcoin-base.d.ts +93 -0
  2. package/dist/bitcoin-base.d.ts.map +1 -0
  3. package/dist/bitcoin-base.js +236 -0
  4. package/dist/bitcoin-base.js.map +1 -0
  5. package/dist/bitcoin-interface-utils.d.ts.map +1 -1
  6. package/dist/bitcoin-interface-utils.js +2 -1
  7. package/dist/bitcoin-interface-utils.js.map +1 -1
  8. package/dist/bitcoin-interface.d.ts +6 -6
  9. package/dist/bitcoin-interface.d.ts.map +1 -1
  10. package/dist/bitcoin-interface.js +6 -14
  11. package/dist/bitcoin-interface.js.map +1 -1
  12. package/dist/helper/burn-request-helper.d.ts +7 -0
  13. package/dist/helper/burn-request-helper.d.ts.map +1 -0
  14. package/dist/helper/burn-request-helper.js +26 -0
  15. package/dist/helper/burn-request-helper.js.map +1 -0
  16. package/dist/helper/teleport-request-helper.d.ts +47 -0
  17. package/dist/helper/teleport-request-helper.d.ts.map +1 -0
  18. package/dist/helper/teleport-request-helper.js +146 -0
  19. package/dist/helper/teleport-request-helper.js.map +1 -0
  20. package/dist/teleport-dao-payments.d.ts +76 -0
  21. package/dist/teleport-dao-payments.d.ts.map +1 -0
  22. package/dist/teleport-dao-payments.js +217 -0
  23. package/dist/teleport-dao-payments.js.map +1 -0
  24. package/dist/type.d.ts +6 -2
  25. package/dist/type.d.ts.map +1 -1
  26. package/dist/utils/tools.d.ts.map +1 -1
  27. package/dist/utils/tools.js.map +1 -1
  28. package/package.json +4 -4
  29. package/src/bitcoin-interface-ordinal.ts +181 -181
  30. package/src/bitcoin-interface-teleswap.ts +252 -252
  31. package/src/bitcoin-interface-utils.ts +60 -59
  32. package/src/bitcoin-interface.ts +241 -247
  33. package/src/bitcoin-utils.ts +591 -591
  34. package/src/bitcoin-wallet-base.ts +310 -310
  35. package/src/helper/brc20-helper.ts +181 -181
  36. package/src/helper/ordinal-helper.ts +118 -118
  37. package/src/index.ts +15 -15
  38. package/src/ordinal-wallet.ts +738 -738
  39. package/src/sign/index.ts +1 -1
  40. package/src/sign/sign-transaction.ts +108 -108
  41. package/src/teleswap-wallet.ts +155 -155
  42. package/src/transaction-builder/bitcoin-transaction-builder.ts +44 -44
  43. package/src/transaction-builder/index.ts +3 -3
  44. package/src/transaction-builder/ordinal-transaction-builder.ts +147 -147
  45. package/src/transaction-builder/transaction-builder.ts +706 -706
  46. package/src/type.ts +47 -43
  47. package/src/utils/networks.ts +33 -33
  48. package/src/utils/tools.ts +90 -89
  49. package/tsconfig.json +9 -9
  50. package/webpack.config.js +16 -16
package/src/type.ts CHANGED
@@ -1,43 +1,47 @@
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
- rpc?: {
29
- enabled?: boolean
30
- url: string
31
- headers?: {
32
- [key: string]: string
33
- }
34
- auth?: {
35
- username: string
36
- password: string
37
- }
38
- }
39
- api: {
40
- token?: string
41
- provider: string
42
- }
43
- }
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
+ }
32
+ rpc?: {
33
+ enabled?: boolean
34
+ url: string
35
+ headers?: {
36
+ [key: string]: string
37
+ }
38
+ auth?: {
39
+ username: string
40
+ password: string
41
+ }
42
+ }
43
+ utxo?: {
44
+ token?: string
45
+ provider: "BlockStream" | "NowNodes" | "MempoolSpace" | "Unisat"
46
+ }
47
+ }
@@ -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,89 +1,90 @@
1
- import axios from "axios"
2
-
3
- function sleep(ms: number) {
4
- return new Promise((resolve) => setTimeout(resolve, ms))
5
- }
6
-
7
- async function runWithRetries<T>(
8
- action: () => Promise<T>,
9
- config: {
10
- maxTries?: number
11
- retrySleep?: number
12
- } = {
13
- maxTries: 2,
14
- retrySleep: 1000,
15
- },
16
- ): Promise<T> {
17
- const maxTries = config.maxTries ?? 2
18
- const retrySleep = config.retrySleep ?? 1000
19
-
20
- let lastError: any
21
- for (let count = 0; count < maxTries; count += 1) {
22
- try {
23
- return await action()
24
- } catch (error: any) {
25
- console.log(`Attempt ${count + 1} failed: ${error.message}`)
26
- lastError = error
27
- if (count < maxTries - 1) {
28
- await sleep(retrySleep)
29
- }
30
- }
31
- }
32
-
33
- throw lastError || new Error(`Function failed after ${maxTries} retries: ${lastError?.message}`)
34
- }
35
-
36
- function getRandomInteger(min: number, max: number) {
37
- return Math.floor(Math.random() * (max - min)) + min
38
- }
39
-
40
- function getAxiosInstance({
41
- baseUrl,
42
- timeout = 10000,
43
- headers = {},
44
- auth,
45
- }: {
46
- baseUrl: string
47
- timeout?: number
48
- headers?: { [key: string]: string }
49
- auth?: {
50
- username: string
51
- password: string
52
- }
53
- }) {
54
- let host = baseUrl
55
- let instance
56
-
57
- instance = axios.create({
58
- baseURL: host,
59
- timeout,
60
- auth,
61
- headers: {
62
- ...headers,
63
- },
64
- })
65
-
66
- // Add a response interceptor
67
- instance.interceptors.response.use(
68
- (response) => response,
69
- (error) => {
70
- // todo : fix this part
71
- if (error.response) {
72
- const serviceError = new Error(
73
- JSON.stringify({ data: error.response.data, message: error.message }),
74
- )
75
- return Promise.reject(serviceError)
76
- }
77
-
78
- if (error.request) {
79
- const serviceError = new Error(error.message)
80
- return Promise.reject(serviceError)
81
- }
82
- return Promise.reject(error)
83
- },
84
- )
85
-
86
- return instance
87
- }
88
-
89
- 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
+ }