@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
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
|
-
})()
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { Psbt, crypto, Network } from "bitcoinjs-lib"
|
|
2
|
-
// import BIP32Factory from "bip32"
|
|
3
|
-
import ecc from "@bitcoinerlab/secp256k1"
|
|
4
|
-
import * as bitcoinEcPair from "bitcoinjs-ecpair"
|
|
5
|
-
const ECPair = bitcoinEcPair.ECPair
|
|
6
|
-
|
|
7
|
-
function tapTweakHash(pubKey: Buffer, h?: Buffer) {
|
|
8
|
-
return crypto.taggedHash("TapTweak", Buffer.concat(h ? [pubKey, h] : [pubKey]))
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function tweakSigner(
|
|
12
|
-
privateKey: Buffer,
|
|
13
|
-
opts = {} as {
|
|
14
|
-
[key: string]: Buffer
|
|
15
|
-
},
|
|
16
|
-
network: Network,
|
|
17
|
-
) {
|
|
18
|
-
let newPrv = privateKey
|
|
19
|
-
let keyPair = ECPair.fromPrivateKey(privateKey, {
|
|
20
|
-
network: network,
|
|
21
|
-
compressed: true,
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
if (!keyPair.privateKey) throw new Error("private key not exist")
|
|
25
|
-
|
|
26
|
-
if (keyPair.publicKey.toString("hex").startsWith("03")) {
|
|
27
|
-
newPrv = ecc.privateNegate(keyPair.privateKey) as Buffer
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const tweakedPrivateKey = ecc.privateAdd(
|
|
31
|
-
newPrv,
|
|
32
|
-
tapTweakHash(Buffer.from(keyPair.publicKey.toString("hex").slice(2), "hex"), opts?.tweakHash),
|
|
33
|
-
)
|
|
34
|
-
if (!tweakedPrivateKey) {
|
|
35
|
-
throw new Error("Invalid tweaked private key!")
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return ECPair.fromPrivateKey(Buffer.from(tweakedPrivateKey), {
|
|
39
|
-
network: network,
|
|
40
|
-
})
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
class BitcoinLikeSignTransaction {
|
|
44
|
-
network: Network
|
|
45
|
-
constructor(network: Network) {
|
|
46
|
-
this.network = network
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async signPsbt(
|
|
50
|
-
unsignedPsbt: {
|
|
51
|
-
unsignedTransaction: string
|
|
52
|
-
},
|
|
53
|
-
privateKey: Buffer,
|
|
54
|
-
) {
|
|
55
|
-
const { network } = this
|
|
56
|
-
const keyPair = ECPair.fromPrivateKey(privateKey, {
|
|
57
|
-
network,
|
|
58
|
-
compressed: true,
|
|
59
|
-
})
|
|
60
|
-
const psbt = Psbt.fromBase64(unsignedPsbt.unsignedTransaction, {
|
|
61
|
-
network,
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
let numberOfInputs = psbt.inputCount
|
|
65
|
-
|
|
66
|
-
for (let i = 0; i < numberOfInputs; i += 1) {
|
|
67
|
-
let type = psbt.getInputType(i)
|
|
68
|
-
if (type === "nonstandard") {
|
|
69
|
-
let a = tweakSigner(privateKey, undefined, this.network)
|
|
70
|
-
await psbt.signInputAsync(i, a)
|
|
71
|
-
} else {
|
|
72
|
-
await psbt.signInputAsync(i, keyPair)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// psbt.signAllInputs(keyPair)
|
|
77
|
-
const partialSigendPsbt = psbt.toBase64()
|
|
78
|
-
return partialSigendPsbt
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
finalizePsbts(psbtsBase64: string[] = []) {
|
|
82
|
-
const finals = psbtsBase64.map((psbtBase64) =>
|
|
83
|
-
Psbt.fromBase64(psbtBase64, { network: this.network }),
|
|
84
|
-
)
|
|
85
|
-
const psbt =
|
|
86
|
-
finals.length === 1 ? finals[0] : new Psbt({ network: this.network }).combine(...finals)
|
|
87
|
-
|
|
88
|
-
let newPsbt = new Psbt({ network: this.network })
|
|
89
|
-
newPsbt.addOutputs(psbt.txOutputs)
|
|
90
|
-
|
|
91
|
-
// newPsbt.addInputs(
|
|
92
|
-
// psbt.txInputs.map((txIn, i) => ({
|
|
93
|
-
// ...txIn,
|
|
94
|
-
// partialSig: psbt.data.inputs[i].partialSig,
|
|
95
|
-
// witnessUtxo: psbt.data.inputs[i].witnessUtxo,
|
|
96
|
-
// })),
|
|
97
|
-
// )
|
|
98
|
-
newPsbt.addInputs(
|
|
99
|
-
psbt.txInputs.map((txIn, i) => ({
|
|
100
|
-
...txIn,
|
|
101
|
-
...psbt.data.inputs[i],
|
|
102
|
-
})),
|
|
103
|
-
).addInput
|
|
104
|
-
|
|
105
|
-
psbt.finalizeAllInputs()
|
|
106
|
-
|
|
107
|
-
for (let i = 0; i < psbt.txInputs.length; i += 1) {
|
|
108
|
-
// console.log(psbt.data.inputs[i])
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
newPsbt.finalizeAllInputs()
|
|
112
|
-
|
|
113
|
-
let finalizeTx = newPsbt.extractTransaction()
|
|
114
|
-
// console.log(finalizeTx.getId())
|
|
115
|
-
|
|
116
|
-
// console.log(finalizeTx.ins, finalizeTx.outs)
|
|
117
|
-
return finalizeTx.toHex()
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export default BitcoinLikeSignTransaction
|
package/.tmp/rbf.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { sleep } from "../dist/utils/tools"
|
|
2
|
-
import { BitcoinBase, TeleportDaoPayment, TransferRequest } from "@teleportdao/bitcoin"
|
|
3
|
-
import { parseRawTransaction } from "../dist/bitcoin-utils"
|
|
4
|
-
require("dotenv").config()
|
|
5
|
-
;(async () => {
|
|
6
|
-
let btc = new TeleportDaoPayment("bitcoin_testnet", {
|
|
7
|
-
api: {
|
|
8
|
-
enabled: true,
|
|
9
|
-
provider: "MempoolSpace",
|
|
10
|
-
},
|
|
11
|
-
})
|
|
12
|
-
btc.setAccountPrivateKeyByMnemonic({
|
|
13
|
-
mnemonic: process.env.ACCOUNT__MNEMONIC!,
|
|
14
|
-
index: 2,
|
|
15
|
-
addressType: "p2wpkh",
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
console.log(btc.bitcoinAddress)
|
|
19
|
-
let balance = await btc.btcInterface.getBalance(btc.bitcoinAddress!)
|
|
20
|
-
|
|
21
|
-
console.log(balance)
|
|
22
|
-
|
|
23
|
-
let txId = await btc.send({
|
|
24
|
-
receiverAddress: btc.bitcoinAddress!,
|
|
25
|
-
fullAmount: true,
|
|
26
|
-
amount: 0,
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
console.log(txId)
|
|
30
|
-
await sleep(5_000)
|
|
31
|
-
|
|
32
|
-
// const txId = "a4335df47c09cc983d0ba56373212b86c266ea434bb87d610ae5c892da79e1b7"
|
|
33
|
-
|
|
34
|
-
let unsigned = await btc.increaseTransactionFeeUnsignedPsbt(
|
|
35
|
-
txId,
|
|
36
|
-
[btc.signerInfo!],
|
|
37
|
-
[],
|
|
38
|
-
btc.bitcoinAddress!,
|
|
39
|
-
5,
|
|
40
|
-
)
|
|
41
|
-
let signedPsbt = await btc.signer.signPsbt(unsigned, btc.privateKey!)
|
|
42
|
-
let txIdNew = await btc.sendSignedPsbt(signedPsbt)
|
|
43
|
-
|
|
44
|
-
console.log(txIdNew)
|
|
45
|
-
})()
|