@teleportdao/bitcoin 1.7.12 → 1.7.14
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/bitcoin-base.d.ts +93 -0
- package/dist/bitcoin-base.d.ts.map +1 -0
- package/dist/bitcoin-base.js +236 -0
- package/dist/bitcoin-base.js.map +1 -0
- package/dist/bitcoin-interface-utils.d.ts.map +1 -1
- package/dist/bitcoin-interface-utils.js +2 -1
- package/dist/bitcoin-interface-utils.js.map +1 -1
- package/dist/helper/burn-request-helper.d.ts +7 -0
- package/dist/helper/burn-request-helper.d.ts.map +1 -0
- package/dist/helper/burn-request-helper.js +26 -0
- package/dist/helper/burn-request-helper.js.map +1 -0
- package/dist/helper/teleport-request-helper.d.ts +47 -0
- package/dist/helper/teleport-request-helper.d.ts.map +1 -0
- package/dist/helper/teleport-request-helper.js +146 -0
- package/dist/helper/teleport-request-helper.js.map +1 -0
- package/dist/helper/teleswap-helper.d.ts.map +1 -1
- package/dist/helper/teleswap-helper.js +1 -2
- package/dist/helper/teleswap-helper.js.map +1 -1
- package/dist/teleport-dao-payments.d.ts +76 -0
- package/dist/teleport-dao-payments.d.ts.map +1 -0
- package/dist/teleport-dao-payments.js +217 -0
- package/dist/teleport-dao-payments.js.map +1 -0
- package/dist/teleswap-wallet.d.ts.map +1 -1
- package/dist/teleswap-wallet.js +4 -1
- package/dist/teleswap-wallet.js.map +1 -1
- package/dist/utils/tools.d.ts.map +1 -1
- package/dist/utils/tools.js.map +1 -1
- package/package.json +4 -4
- package/src/bitcoin-interface-ordinal.ts +181 -181
- package/src/bitcoin-interface-teleswap.ts +252 -252
- package/src/bitcoin-interface-utils.ts +60 -59
- package/src/bitcoin-interface.ts +247 -247
- package/src/bitcoin-utils.ts +591 -591
- package/src/bitcoin-wallet-base.ts +310 -310
- package/src/helper/brc20-helper.ts +181 -181
- package/src/helper/ordinal-helper.ts +118 -118
- package/src/helper/teleswap-helper.ts +2 -4
- package/src/index.ts +15 -15
- package/src/ordinal-wallet.ts +738 -738
- package/src/sign/index.ts +1 -1
- package/src/sign/sign-transaction.ts +108 -108
- package/src/teleswap-wallet.ts +155 -152
- package/src/transaction-builder/bitcoin-transaction-builder.ts +44 -44
- package/src/transaction-builder/index.ts +3 -3
- package/src/transaction-builder/ordinal-transaction-builder.ts +147 -147
- package/src/transaction-builder/transaction-builder.ts +706 -706
- package/src/type.ts +43 -43
- package/src/utils/networks.ts +33 -33
- package/src/utils/tools.ts +90 -89
- package/tsconfig.json +9 -9
- package/webpack.config.js +16 -16
package/src/type.ts
CHANGED
|
@@ -1,43 +1,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
|
-
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
|
+
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
|
+
}
|
package/src/utils/networks.ts
CHANGED
|
@@ -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
|
package/src/utils/tools.ts
CHANGED
|
@@ -1,89 +1,90 @@
|
|
|
1
|
-
import axios from "axios"
|
|
2
|
-
|
|
3
|
-
function sleep(ms: number) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
let
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
+
}
|