@teleportdao/bitcoin 1.8.7 → 1.9.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.
- package/.tmp/rbf.ts +24 -27
- 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 -60
- package/src/bitcoin-interface.ts +239 -239
- package/src/bitcoin-utils.ts +591 -591
- package/src/bitcoin-wallet-base.ts +310 -310
- package/src/helper/brc20-helper.ts +179 -179
- package/src/helper/ordinal-helper.ts +118 -118
- package/src/index.ts +15 -15
- package/src/ordinal-wallet.ts +748 -748
- package/src/sign/index.ts +1 -1
- package/src/sign/sign-transaction.ts +108 -108
- package/src/teleswap-wallet.ts +155 -155
- 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 +48 -48
- package/src/utils/networks.ts +33 -33
- package/src/utils/tools.ts +92 -92
- package/tsconfig.json +9 -9
- package/webpack.config.js +16 -16
- package/.tmp/ordinal-helper.ts +0 -133
- package/.tmp/ordinal.ts +0 -25
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
|
+
}
|
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,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
|
+
}
|
package/.tmp/ordinal-helper.ts
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import * as bitcoin from "bitcoinjs-lib"
|
|
2
|
-
import ecc from "@bitcoinerlab/secp256k1"
|
|
3
|
-
|
|
4
|
-
bitcoin.initEccLib(ecc)
|
|
5
|
-
|
|
6
|
-
// eslint-disable-next-line consistent-return
|
|
7
|
-
export function createAddressObjectByScriptNoType(
|
|
8
|
-
script: Buffer,
|
|
9
|
-
network: bitcoin.Network = bitcoin.networks.bitcoin,
|
|
10
|
-
) {
|
|
11
|
-
let addressObject: bitcoin.payments.Payment
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
addressObject = bitcoin.payments.p2pkh({
|
|
15
|
-
output: script,
|
|
16
|
-
network,
|
|
17
|
-
})
|
|
18
|
-
if (addressObject.address) {
|
|
19
|
-
return {
|
|
20
|
-
addressObject,
|
|
21
|
-
addressType: "p2pkh",
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
} catch (err) {
|
|
25
|
-
/* empty */
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
addressObject = bitcoin.payments.p2wpkh({
|
|
30
|
-
output: script,
|
|
31
|
-
network,
|
|
32
|
-
})
|
|
33
|
-
if (addressObject.address) {
|
|
34
|
-
return {
|
|
35
|
-
addressObject,
|
|
36
|
-
addressType: "p2wpkh",
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
} catch (err) {
|
|
40
|
-
/* empty */
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
addressObject = bitcoin.payments.p2sh({
|
|
45
|
-
output: script,
|
|
46
|
-
network,
|
|
47
|
-
})
|
|
48
|
-
if (addressObject.address) {
|
|
49
|
-
return {
|
|
50
|
-
addressObject,
|
|
51
|
-
addressType: "p2sh",
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
} catch (err) {
|
|
55
|
-
/* empty */
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
try {
|
|
59
|
-
addressObject = bitcoin.payments.p2wsh({
|
|
60
|
-
output: script,
|
|
61
|
-
network,
|
|
62
|
-
})
|
|
63
|
-
if (addressObject.address) {
|
|
64
|
-
return {
|
|
65
|
-
addressObject,
|
|
66
|
-
addressType: "p2wsh",
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
} catch (err) {
|
|
70
|
-
/* empty */
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
try {
|
|
74
|
-
addressObject = bitcoin.payments.p2tr({
|
|
75
|
-
output: script,
|
|
76
|
-
network,
|
|
77
|
-
})
|
|
78
|
-
if (addressObject.address) {
|
|
79
|
-
return {
|
|
80
|
-
addressObject,
|
|
81
|
-
addressType: "p2tr",
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
} catch (err) {
|
|
85
|
-
/* empty */
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export function splitBuffer(buffer: Buffer, partLength: number) {
|
|
90
|
-
const parts: Buffer[] = []
|
|
91
|
-
for (let i = 0; i < buffer.length; i += partLength) {
|
|
92
|
-
const part = buffer.subarray(i, i + partLength)
|
|
93
|
-
parts.push(part)
|
|
94
|
-
}
|
|
95
|
-
return parts
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export function getOrdinalScript(
|
|
99
|
-
file: { buffer: Buffer; type: string },
|
|
100
|
-
internalPublicKeyHex: string,
|
|
101
|
-
) {
|
|
102
|
-
let bufferParts = splitBuffer(file.buffer, 520)
|
|
103
|
-
// const splittedFileHex = bufferParts.map((part) => part.toString("hex")).join(" ")
|
|
104
|
-
// const script = `${internalPublicKeyHex} OP_CHECKSIG OP_FALSE OP_IF ${ORDINAL_ORD_HEX} 00000000000000000000 ${fileTypeHex} OP_0 ${splittedFileHex} OP_ENDIF`
|
|
105
|
-
|
|
106
|
-
// ? bitcoinjs-lib converts "OP_PUSH 1" to "0x51" instead of "0x0101" as required by the ordinal protocol
|
|
107
|
-
// ? so we push 00000000000000000000 instead of 1 and then replace 0a00000000000000000000 with 0101
|
|
108
|
-
let leafScript = bitcoin.script.compile([
|
|
109
|
-
Buffer.from(internalPublicKeyHex, "hex"),
|
|
110
|
-
bitcoin.opcodes.OP_CHECKSIG,
|
|
111
|
-
bitcoin.opcodes.OP_FALSE,
|
|
112
|
-
bitcoin.opcodes.OP_IF,
|
|
113
|
-
Buffer.from("ord", "utf8"),
|
|
114
|
-
// instead of 1 we push 00000000000000000000
|
|
115
|
-
Buffer.from("00000000000000000000", "hex"),
|
|
116
|
-
//
|
|
117
|
-
Buffer.from(file.type!, "utf8"),
|
|
118
|
-
bitcoin.opcodes.OP_0,
|
|
119
|
-
...bufferParts,
|
|
120
|
-
bitcoin.opcodes.OP_ENDIF,
|
|
121
|
-
])
|
|
122
|
-
|
|
123
|
-
leafScript = Buffer.from(
|
|
124
|
-
leafScript.toString("hex").replace("0a00000000000000000000", "0101"),
|
|
125
|
-
"hex",
|
|
126
|
-
)
|
|
127
|
-
|
|
128
|
-
return leafScript
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export function toXOnly(pubKey: Buffer) {
|
|
132
|
-
return pubKey.length === 32 ? pubKey : pubKey.subarray(1, 33)
|
|
133
|
-
}
|
package/.tmp/ordinal.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { OrdinalWallet } from "../"
|
|
2
|
-
import getAndDecryptAccount from "@teleportdao/teleswap-nodes/src/config/account"
|
|
3
|
-
|
|
4
|
-
require("dotenv").config()
|
|
5
|
-
|
|
6
|
-
import blockchainConfig from "@teleportdao/teleswap-nodes/src/config/blockchain.config"
|
|
7
|
-
;(async () => {
|
|
8
|
-
const account = await getAndDecryptAccount()
|
|
9
|
-
|
|
10
|
-
let btc = new OrdinalWallet("bitcoin", "", blockchainConfig.sourceNetwork.connection)
|
|
11
|
-
btc.setAccountPrivateKeyByMnemonic({
|
|
12
|
-
mnemonic: account.mnemonic,
|
|
13
|
-
index: 2,
|
|
14
|
-
addressType: "p2wpkh",
|
|
15
|
-
})
|
|
16
|
-
const x = btc.transactionBuilder.createOrdinalAddress(
|
|
17
|
-
{
|
|
18
|
-
buffer: Buffer.from("Hello World", "utf8"),
|
|
19
|
-
type: "text/plain",
|
|
20
|
-
},
|
|
21
|
-
btc.publicKey!,
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
console.log(x)
|
|
25
|
-
})()
|