@teleportdao/bitcoin 1.9.0 → 2.0.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 (70) hide show
  1. package/.tmp/block-parser.ts +58 -0
  2. package/.tmp/ordinal-helper.ts +133 -0
  3. package/.tmp/ordinal.ts +25 -0
  4. package/.tmp/rbf.ts +27 -24
  5. package/dist/bitcoin-interface-ordinal.d.ts +2 -2
  6. package/dist/bitcoin-interface-ordinal.d.ts.map +1 -1
  7. package/dist/bitcoin-interface-ordinal.js +1 -1
  8. package/dist/bitcoin-interface-ordinal.js.map +1 -1
  9. package/dist/bitcoin-interface-teleswap.d.ts +2 -53
  10. package/dist/bitcoin-interface-teleswap.d.ts.map +1 -1
  11. package/dist/bitcoin-interface-teleswap.js +6 -17
  12. package/dist/bitcoin-interface-teleswap.js.map +1 -1
  13. package/dist/bitcoin-interface-wallet.d.ts +29 -0
  14. package/dist/bitcoin-interface-wallet.d.ts.map +1 -0
  15. package/dist/bitcoin-interface-wallet.js +126 -0
  16. package/dist/bitcoin-interface-wallet.js.map +1 -0
  17. package/dist/bitcoin-interface.d.ts +5 -23
  18. package/dist/bitcoin-interface.d.ts.map +1 -1
  19. package/dist/bitcoin-interface.js +13 -92
  20. package/dist/bitcoin-interface.js.map +1 -1
  21. package/dist/bitcoin-wallet-base.d.ts +55 -31
  22. package/dist/bitcoin-wallet-base.d.ts.map +1 -1
  23. package/dist/bitcoin-wallet-base.js +105 -84
  24. package/dist/bitcoin-wallet-base.js.map +1 -1
  25. package/dist/ordinal-wallet.d.ts +29 -71
  26. package/dist/ordinal-wallet.d.ts.map +1 -1
  27. package/dist/ordinal-wallet.js +48 -108
  28. package/dist/ordinal-wallet.js.map +1 -1
  29. package/dist/teleswap-wallet.d.ts +10 -16
  30. package/dist/teleswap-wallet.d.ts.map +1 -1
  31. package/dist/teleswap-wallet.js +10 -30
  32. package/dist/teleswap-wallet.js.map +1 -1
  33. package/dist/transaction-builder/bitcoin-transaction-builder.d.ts +4 -11
  34. package/dist/transaction-builder/bitcoin-transaction-builder.d.ts.map +1 -1
  35. package/dist/transaction-builder/bitcoin-transaction-builder.js +2 -23
  36. package/dist/transaction-builder/bitcoin-transaction-builder.js.map +1 -1
  37. package/dist/transaction-builder/ordinal-transaction-builder.d.ts +3 -2
  38. package/dist/transaction-builder/ordinal-transaction-builder.d.ts.map +1 -1
  39. package/dist/transaction-builder/ordinal-transaction-builder.js +1 -6
  40. package/dist/transaction-builder/ordinal-transaction-builder.js.map +1 -1
  41. package/dist/transaction-builder/transaction-builder.d.ts +3 -7
  42. package/dist/transaction-builder/transaction-builder.d.ts.map +1 -1
  43. package/dist/transaction-builder/transaction-builder.js +22 -49
  44. package/dist/transaction-builder/transaction-builder.js.map +1 -1
  45. package/dist/type.d.ts +33 -18
  46. package/dist/type.d.ts.map +1 -1
  47. package/package.json +4 -4
  48. package/src/bitcoin-interface-ordinal.ts +185 -181
  49. package/src/bitcoin-interface-teleswap.ts +237 -252
  50. package/src/bitcoin-interface-utils.ts +60 -60
  51. package/src/bitcoin-interface-wallet.ts +114 -0
  52. package/src/bitcoin-interface.ts +156 -239
  53. package/src/bitcoin-utils.ts +591 -591
  54. package/src/bitcoin-wallet-base.ts +344 -310
  55. package/src/helper/brc20-helper.ts +179 -179
  56. package/src/helper/ordinal-helper.ts +118 -118
  57. package/src/index.ts +15 -15
  58. package/src/ordinal-wallet.ts +659 -748
  59. package/src/sign/index.ts +1 -1
  60. package/src/sign/sign-transaction.ts +108 -108
  61. package/src/teleswap-wallet.ts +133 -155
  62. package/src/transaction-builder/bitcoin-transaction-builder.ts +26 -44
  63. package/src/transaction-builder/index.ts +3 -3
  64. package/src/transaction-builder/ordinal-transaction-builder.ts +139 -147
  65. package/src/transaction-builder/transaction-builder.ts +690 -706
  66. package/src/type.ts +74 -48
  67. package/src/utils/networks.ts +33 -33
  68. package/src/utils/tools.ts +92 -92
  69. package/tsconfig.json +9 -9
  70. package/webpack.config.js +16 -16
package/src/type.ts CHANGED
@@ -1,48 +1,74 @@
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 UtxoConnectionInfo = {
28
+ token?: string
29
+ provider: "BlockStream" | "MempoolSpace" | "NowNodes" | "Unisat" | "TeleportDao"
30
+ }
31
+
32
+ export type BTCTokenConnectionInfo = {
33
+ token?: string
34
+ provider: "Unisat" | "TeleportDao"
35
+ }
36
+
37
+ export type APIConnectionInfo = {
38
+ provider: "BlockStream" | "MempoolSpace"
39
+ }
40
+
41
+ export type RPCConnectionInfo = {
42
+ url: string
43
+ headers?: {
44
+ [key: string]: string
45
+ }
46
+ auth?: {
47
+ username: string
48
+ password: string
49
+ }
50
+ }
51
+
52
+ export type BitcoinWalletConnectionInfo = {
53
+ utxo?: UtxoConnectionInfo
54
+ // rpc used for getRawTransaction in transaction builder if set (optional)
55
+ rpc?: RPCConnectionInfo
56
+ }
57
+ export type BitcoinWalletInterfaceConnectionInfo = {
58
+ api?: APIConnectionInfo
59
+ // if utxo is not provided, it will use the same provider as the api
60
+ // rpc used for getRawTransaction in transaction builder if set (optional)
61
+ utxo?: UtxoConnectionInfo
62
+ }
63
+
64
+ export type BitcoinInterfaceConnectionInfo = BitcoinWalletInterfaceConnectionInfo & {
65
+ rpc?: RPCConnectionInfo
66
+ }
67
+
68
+ export type BitcoinNodeConnectionInfo = BitcoinWalletInterfaceConnectionInfo & {
69
+ rpc: RPCConnectionInfo
70
+ }
71
+
72
+ export type BitcoinTokenNodeConnectionInfo = BitcoinNodeConnectionInfo & {
73
+ // btcToken: BTCTokenConnectionInfo
74
+ }
@@ -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,92 +1,92 @@
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
- const trace = new Error().stack?.split("\n").slice(5).join("\n")
21
-
22
- let lastError: any
23
- for (let count = 0; count < maxTries; count += 1) {
24
- try {
25
- return await action()
26
- } catch (error: any) {
27
- error.message += `\n${trace}`
28
- console.log(`Attempt ${count + 1} failed: ${error.message}`)
29
- lastError = error
30
- if (count < maxTries - 1) {
31
- await sleep(retrySleep)
32
- }
33
- }
34
- }
35
-
36
- throw lastError || new Error(`Function failed after ${maxTries} retries: ${lastError?.message}`)
37
- }
38
-
39
- function getRandomInteger(min: number, max: number) {
40
- return Math.floor(Math.random() * (max - min)) + min
41
- }
42
-
43
- function getAxiosInstance({
44
- baseUrl,
45
- timeout = 10000,
46
- headers = {},
47
- auth,
48
- }: {
49
- baseUrl: string
50
- timeout?: number
51
- headers?: { [key: string]: string }
52
- auth?: {
53
- username: string
54
- password: string
55
- }
56
- }) {
57
- let host = baseUrl
58
- let instance
59
-
60
- instance = axios.create({
61
- baseURL: host,
62
- timeout,
63
- auth,
64
- headers: {
65
- ...headers,
66
- },
67
- })
68
-
69
- // Add a response interceptor
70
- instance.interceptors.response.use(
71
- (response) => response,
72
- (error) => {
73
- // todo : fix this part
74
- if (error.response) {
75
- const serviceError = new Error(
76
- JSON.stringify({ data: error.response.data, message: error.message }),
77
- )
78
- return Promise.reject(serviceError)
79
- }
80
-
81
- if (error.request) {
82
- const serviceError = new Error(error.message)
83
- return Promise.reject(serviceError)
84
- }
85
- return Promise.reject(error)
86
- },
87
- )
88
-
89
- return instance
90
- }
91
-
92
- 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
+ const trace = new Error().stack?.split("\n").slice(5).join("\n")
21
+
22
+ let lastError: any
23
+ for (let count = 0; count < maxTries; count += 1) {
24
+ try {
25
+ return await action()
26
+ } catch (error: any) {
27
+ error.message += `\n${trace}`
28
+ console.log(`Attempt ${count + 1} failed: ${error.message}`)
29
+ lastError = error
30
+ if (count < maxTries - 1) {
31
+ await sleep(retrySleep)
32
+ }
33
+ }
34
+ }
35
+
36
+ throw lastError || new Error(`Function failed after ${maxTries} retries: ${lastError?.message}`)
37
+ }
38
+
39
+ function getRandomInteger(min: number, max: number) {
40
+ return Math.floor(Math.random() * (max - min)) + min
41
+ }
42
+
43
+ function getAxiosInstance({
44
+ baseUrl,
45
+ timeout = 10000,
46
+ headers = {},
47
+ auth,
48
+ }: {
49
+ baseUrl: string
50
+ timeout?: number
51
+ headers?: { [key: string]: string }
52
+ auth?: {
53
+ username: string
54
+ password: string
55
+ }
56
+ }) {
57
+ let host = baseUrl
58
+ let instance
59
+
60
+ instance = axios.create({
61
+ baseURL: host,
62
+ timeout,
63
+ auth,
64
+ headers: {
65
+ ...headers,
66
+ },
67
+ })
68
+
69
+ // Add a response interceptor
70
+ instance.interceptors.response.use(
71
+ (response) => response,
72
+ (error) => {
73
+ // todo : fix this part
74
+ if (error.response) {
75
+ const serviceError = new Error(
76
+ JSON.stringify({ data: error.response.data, message: error.message }),
77
+ )
78
+ return Promise.reject(serviceError)
79
+ }
80
+
81
+ if (error.request) {
82
+ const serviceError = new Error(error.message)
83
+ return Promise.reject(serviceError)
84
+ }
85
+ return Promise.reject(error)
86
+ },
87
+ )
88
+
89
+ return instance
90
+ }
91
+
92
+ 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
+ }