@teleportdao/bitcoin 2.0.5 → 2.0.7
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-interface-ordinal.d.ts +108 -108
- package/dist/bitcoin-interface-ordinal.js +140 -140
- package/dist/bitcoin-interface-teleswap.d.ts +101 -101
- package/dist/bitcoin-interface-teleswap.js +176 -176
- package/dist/bitcoin-interface-utils.d.ts +20 -20
- package/dist/bitcoin-interface-utils.js +45 -45
- package/dist/bitcoin-interface-wallet.d.ts +28 -28
- package/dist/bitcoin-interface-wallet.js +125 -125
- package/dist/bitcoin-interface.d.ts +66 -66
- package/dist/bitcoin-interface.js +119 -119
- package/dist/bitcoin-utils.d.ts +96 -96
- package/dist/bitcoin-utils.js +514 -514
- package/dist/bitcoin-wallet-base.d.ts +111 -111
- package/dist/bitcoin-wallet-base.js +258 -258
- package/dist/helper/brc20-helper.d.ts +42 -42
- package/dist/helper/brc20-helper.js +127 -127
- package/dist/helper/index.d.ts +3 -3
- package/dist/helper/index.js +29 -29
- package/dist/helper/ordinal-helper.d.ts +12 -12
- package/dist/helper/ordinal-helper.js +129 -129
- package/dist/helper/teleswap-helper.d.ts +95 -95
- package/dist/helper/teleswap-helper.js +186 -186
- package/dist/index.d.ts +12 -12
- package/dist/index.js +41 -41
- package/dist/ordinal-wallet.d.ts +495 -495
- package/dist/ordinal-wallet.js +386 -386
- package/dist/sign/index.d.ts +1 -1
- package/dist/sign/index.js +8 -8
- package/dist/sign/sign-transaction.d.ts +12 -12
- package/dist/sign/sign-transaction.js +82 -82
- package/dist/teleswap-wallet.d.ts +45 -45
- package/dist/teleswap-wallet.js +68 -68
- package/dist/transaction-builder/bitcoin-transaction-builder.d.ts +9 -9
- package/dist/transaction-builder/bitcoin-transaction-builder.js +54 -54
- package/dist/transaction-builder/index.d.ts +3 -3
- package/dist/transaction-builder/index.js +19 -19
- package/dist/transaction-builder/ordinal-transaction-builder.d.ts +63 -63
- package/dist/transaction-builder/ordinal-transaction-builder.js +125 -125
- package/dist/transaction-builder/transaction-builder.d.ts +223 -223
- package/dist/transaction-builder/transaction-builder.js +447 -447
- package/dist/type.d.ts +61 -61
- package/dist/type.js +2 -2
- package/dist/utils/networks.d.ts +5 -5
- package/dist/utils/networks.js +53 -53
- package/dist/utils/tools.d.ts +18 -18
- package/dist/utils/tools.js +74 -74
- package/package.json +4 -4
- package/src/bitcoin-interface-ordinal.ts +185 -185
- package/src/bitcoin-interface-teleswap.ts +251 -251
- package/src/bitcoin-interface-utils.ts +60 -60
- package/src/bitcoin-interface-wallet.ts +114 -114
- package/src/bitcoin-interface.ts +156 -156
- package/src/bitcoin-utils.ts +591 -591
- package/src/bitcoin-wallet-base.ts +344 -344
- 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 +659 -659
- package/src/sign/index.ts +1 -1
- package/src/sign/sign-transaction.ts +108 -108
- package/src/teleswap-wallet.ts +133 -133
- package/src/transaction-builder/bitcoin-transaction-builder.ts +26 -26
- package/src/transaction-builder/index.ts +3 -3
- package/src/transaction-builder/ordinal-transaction-builder.ts +139 -139
- package/src/transaction-builder/transaction-builder.ts +690 -690
- package/src/type.ts +74 -74
- 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/block-parser.ts +0 -58
- package/.tmp/check.ts +0 -101
- package/.tmp/ordinal-helper.ts +0 -133
- package/.tmp/ordinal.ts +0 -25
- package/.tmp/psbt/sign-transaction.ts +0 -121
- package/.tmp/rbf.ts +0 -45
|
@@ -1,139 +1,139 @@
|
|
|
1
|
-
import * as bitcoin from "bitcoinjs-lib"
|
|
2
|
-
import { LEAF_VERSION_TAPSCRIPT } from "bitcoinjs-lib/src/payments/bip341"
|
|
3
|
-
import { BitcoinTransactionBuilder } from "./bitcoin-transaction-builder"
|
|
4
|
-
import { getOrdinalScript, toXOnly } from "../helper/ordinal-helper"
|
|
5
|
-
import { ExtendedUtxo, Target } from "./transaction-builder"
|
|
6
|
-
|
|
7
|
-
export class OrdinalTransactionBuilder extends BitcoinTransactionBuilder {
|
|
8
|
-
async createNftPsbt({
|
|
9
|
-
extendedUtxo,
|
|
10
|
-
nftExtendedUtxo,
|
|
11
|
-
receiverAddress,
|
|
12
|
-
feeRate,
|
|
13
|
-
changeAddress,
|
|
14
|
-
otherTargets,
|
|
15
|
-
}: {
|
|
16
|
-
nftExtendedUtxo: ExtendedUtxo
|
|
17
|
-
extendedUtxo: ExtendedUtxo[]
|
|
18
|
-
feeRate: number
|
|
19
|
-
changeAddress: string
|
|
20
|
-
receiverAddress: string
|
|
21
|
-
otherTargets?: Target[]
|
|
22
|
-
}) {
|
|
23
|
-
let targets: Target[] = [
|
|
24
|
-
{
|
|
25
|
-
address: receiverAddress,
|
|
26
|
-
value: nftExtendedUtxo.value,
|
|
27
|
-
},
|
|
28
|
-
]
|
|
29
|
-
|
|
30
|
-
if (otherTargets) targets.push(...otherTargets)
|
|
31
|
-
|
|
32
|
-
if (!changeAddress && targets.length === 0) throw new Error("no target")
|
|
33
|
-
let changeObject = {
|
|
34
|
-
address: changeAddress,
|
|
35
|
-
}
|
|
36
|
-
let { inputs, outputs, change, fee } = await this.filterAndConvertTxDataToStandardFormat({
|
|
37
|
-
extendedUtxo: [nftExtendedUtxo, ...extendedUtxo],
|
|
38
|
-
targets,
|
|
39
|
-
changeObject,
|
|
40
|
-
feeRate,
|
|
41
|
-
selectType: "inOrder",
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
let unsignedTx = this.createUnsignedTransaction({
|
|
45
|
-
inputs,
|
|
46
|
-
outputs,
|
|
47
|
-
change,
|
|
48
|
-
fee,
|
|
49
|
-
feeRate,
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
return unsignedTx
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
createOrdinalAddress(
|
|
56
|
-
file: {
|
|
57
|
-
buffer: Buffer
|
|
58
|
-
type: string
|
|
59
|
-
},
|
|
60
|
-
publicKey: Buffer,
|
|
61
|
-
) {
|
|
62
|
-
const internalPublicKey = toXOnly(publicKey).toString("hex")
|
|
63
|
-
let leafScript = getOrdinalScript(file, internalPublicKey)
|
|
64
|
-
|
|
65
|
-
const scriptTree = {
|
|
66
|
-
output: leafScript,
|
|
67
|
-
}
|
|
68
|
-
const redeem = {
|
|
69
|
-
output: leafScript,
|
|
70
|
-
redeemVersion: LEAF_VERSION_TAPSCRIPT,
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const p2trTapOrdinalScript = bitcoin.payments.p2tr({
|
|
74
|
-
internalPubkey: Buffer.from(internalPublicKey, "hex"),
|
|
75
|
-
scriptTree,
|
|
76
|
-
network: this.network,
|
|
77
|
-
redeem,
|
|
78
|
-
})
|
|
79
|
-
let ordinalAddress = p2trTapOrdinalScript.address!
|
|
80
|
-
const controlBlock = p2trTapOrdinalScript.witness![p2trTapOrdinalScript.witness!.length - 1]
|
|
81
|
-
return {
|
|
82
|
-
ordinalAddress,
|
|
83
|
-
ordinalScript: p2trTapOrdinalScript.output!,
|
|
84
|
-
redeem,
|
|
85
|
-
controlBlock,
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
createInscribeUnsignedTx(
|
|
90
|
-
ordinalSpendDetails: {
|
|
91
|
-
ordinalAddress: string
|
|
92
|
-
ordinalScript: Buffer
|
|
93
|
-
redeem: {
|
|
94
|
-
output: Buffer
|
|
95
|
-
redeemVersion: number
|
|
96
|
-
}
|
|
97
|
-
controlBlock: Buffer
|
|
98
|
-
},
|
|
99
|
-
inscribeDeposit: {
|
|
100
|
-
hash: string
|
|
101
|
-
index: number
|
|
102
|
-
value: number
|
|
103
|
-
},
|
|
104
|
-
receiverAddress: string,
|
|
105
|
-
ordinalAmount = 600,
|
|
106
|
-
) {
|
|
107
|
-
const psbt = new bitcoin.Psbt({ network: this.network })
|
|
108
|
-
.addInput({
|
|
109
|
-
...inscribeDeposit,
|
|
110
|
-
witnessUtxo: { value: inscribeDeposit.value, script: ordinalSpendDetails.ordinalScript },
|
|
111
|
-
// tapInternalKey: toXOnly(node.publicKey),
|
|
112
|
-
// tapMerkleRoot: p2trTapOrdinalScript.hash!,
|
|
113
|
-
tapLeafScript: [
|
|
114
|
-
{
|
|
115
|
-
leafVersion: ordinalSpendDetails.redeem.redeemVersion,
|
|
116
|
-
script: ordinalSpendDetails.redeem.output,
|
|
117
|
-
controlBlock: ordinalSpendDetails.controlBlock,
|
|
118
|
-
},
|
|
119
|
-
],
|
|
120
|
-
})
|
|
121
|
-
.addOutput({
|
|
122
|
-
value: ordinalAmount,
|
|
123
|
-
address: receiverAddress,
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
return {
|
|
127
|
-
unsignedTransaction: psbt.toBase64(),
|
|
128
|
-
inputs: [inscribeDeposit],
|
|
129
|
-
outputs: [
|
|
130
|
-
{
|
|
131
|
-
value: ordinalAmount,
|
|
132
|
-
address: receiverAddress,
|
|
133
|
-
},
|
|
134
|
-
],
|
|
135
|
-
fee: inscribeDeposit.value - ordinalAmount,
|
|
136
|
-
possibleTxId: this.getUnsignedPsbtTxId(psbt.toBase64()),
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
1
|
+
import * as bitcoin from "bitcoinjs-lib"
|
|
2
|
+
import { LEAF_VERSION_TAPSCRIPT } from "bitcoinjs-lib/src/payments/bip341"
|
|
3
|
+
import { BitcoinTransactionBuilder } from "./bitcoin-transaction-builder"
|
|
4
|
+
import { getOrdinalScript, toXOnly } from "../helper/ordinal-helper"
|
|
5
|
+
import { ExtendedUtxo, Target } from "./transaction-builder"
|
|
6
|
+
|
|
7
|
+
export class OrdinalTransactionBuilder extends BitcoinTransactionBuilder {
|
|
8
|
+
async createNftPsbt({
|
|
9
|
+
extendedUtxo,
|
|
10
|
+
nftExtendedUtxo,
|
|
11
|
+
receiverAddress,
|
|
12
|
+
feeRate,
|
|
13
|
+
changeAddress,
|
|
14
|
+
otherTargets,
|
|
15
|
+
}: {
|
|
16
|
+
nftExtendedUtxo: ExtendedUtxo
|
|
17
|
+
extendedUtxo: ExtendedUtxo[]
|
|
18
|
+
feeRate: number
|
|
19
|
+
changeAddress: string
|
|
20
|
+
receiverAddress: string
|
|
21
|
+
otherTargets?: Target[]
|
|
22
|
+
}) {
|
|
23
|
+
let targets: Target[] = [
|
|
24
|
+
{
|
|
25
|
+
address: receiverAddress,
|
|
26
|
+
value: nftExtendedUtxo.value,
|
|
27
|
+
},
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
if (otherTargets) targets.push(...otherTargets)
|
|
31
|
+
|
|
32
|
+
if (!changeAddress && targets.length === 0) throw new Error("no target")
|
|
33
|
+
let changeObject = {
|
|
34
|
+
address: changeAddress,
|
|
35
|
+
}
|
|
36
|
+
let { inputs, outputs, change, fee } = await this.filterAndConvertTxDataToStandardFormat({
|
|
37
|
+
extendedUtxo: [nftExtendedUtxo, ...extendedUtxo],
|
|
38
|
+
targets,
|
|
39
|
+
changeObject,
|
|
40
|
+
feeRate,
|
|
41
|
+
selectType: "inOrder",
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
let unsignedTx = this.createUnsignedTransaction({
|
|
45
|
+
inputs,
|
|
46
|
+
outputs,
|
|
47
|
+
change,
|
|
48
|
+
fee,
|
|
49
|
+
feeRate,
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
return unsignedTx
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
createOrdinalAddress(
|
|
56
|
+
file: {
|
|
57
|
+
buffer: Buffer
|
|
58
|
+
type: string
|
|
59
|
+
},
|
|
60
|
+
publicKey: Buffer,
|
|
61
|
+
) {
|
|
62
|
+
const internalPublicKey = toXOnly(publicKey).toString("hex")
|
|
63
|
+
let leafScript = getOrdinalScript(file, internalPublicKey)
|
|
64
|
+
|
|
65
|
+
const scriptTree = {
|
|
66
|
+
output: leafScript,
|
|
67
|
+
}
|
|
68
|
+
const redeem = {
|
|
69
|
+
output: leafScript,
|
|
70
|
+
redeemVersion: LEAF_VERSION_TAPSCRIPT,
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const p2trTapOrdinalScript = bitcoin.payments.p2tr({
|
|
74
|
+
internalPubkey: Buffer.from(internalPublicKey, "hex"),
|
|
75
|
+
scriptTree,
|
|
76
|
+
network: this.network,
|
|
77
|
+
redeem,
|
|
78
|
+
})
|
|
79
|
+
let ordinalAddress = p2trTapOrdinalScript.address!
|
|
80
|
+
const controlBlock = p2trTapOrdinalScript.witness![p2trTapOrdinalScript.witness!.length - 1]
|
|
81
|
+
return {
|
|
82
|
+
ordinalAddress,
|
|
83
|
+
ordinalScript: p2trTapOrdinalScript.output!,
|
|
84
|
+
redeem,
|
|
85
|
+
controlBlock,
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
createInscribeUnsignedTx(
|
|
90
|
+
ordinalSpendDetails: {
|
|
91
|
+
ordinalAddress: string
|
|
92
|
+
ordinalScript: Buffer
|
|
93
|
+
redeem: {
|
|
94
|
+
output: Buffer
|
|
95
|
+
redeemVersion: number
|
|
96
|
+
}
|
|
97
|
+
controlBlock: Buffer
|
|
98
|
+
},
|
|
99
|
+
inscribeDeposit: {
|
|
100
|
+
hash: string
|
|
101
|
+
index: number
|
|
102
|
+
value: number
|
|
103
|
+
},
|
|
104
|
+
receiverAddress: string,
|
|
105
|
+
ordinalAmount = 600,
|
|
106
|
+
) {
|
|
107
|
+
const psbt = new bitcoin.Psbt({ network: this.network })
|
|
108
|
+
.addInput({
|
|
109
|
+
...inscribeDeposit,
|
|
110
|
+
witnessUtxo: { value: inscribeDeposit.value, script: ordinalSpendDetails.ordinalScript },
|
|
111
|
+
// tapInternalKey: toXOnly(node.publicKey),
|
|
112
|
+
// tapMerkleRoot: p2trTapOrdinalScript.hash!,
|
|
113
|
+
tapLeafScript: [
|
|
114
|
+
{
|
|
115
|
+
leafVersion: ordinalSpendDetails.redeem.redeemVersion,
|
|
116
|
+
script: ordinalSpendDetails.redeem.output,
|
|
117
|
+
controlBlock: ordinalSpendDetails.controlBlock,
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
})
|
|
121
|
+
.addOutput({
|
|
122
|
+
value: ordinalAmount,
|
|
123
|
+
address: receiverAddress,
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
unsignedTransaction: psbt.toBase64(),
|
|
128
|
+
inputs: [inscribeDeposit],
|
|
129
|
+
outputs: [
|
|
130
|
+
{
|
|
131
|
+
value: ordinalAmount,
|
|
132
|
+
address: receiverAddress,
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
fee: inscribeDeposit.value - ordinalAmount,
|
|
136
|
+
possibleTxId: this.getUnsignedPsbtTxId(psbt.toBase64()),
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|