@teleportdao/bitcoin 1.7.19 → 1.7.21

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 (44) hide show
  1. package/.tmp/rbf.ts +24 -27
  2. package/dist/helper/teleswap-helper.d.ts.map +1 -1
  3. package/dist/helper/teleswap-helper.js +6 -5
  4. package/dist/helper/teleswap-helper.js.map +1 -1
  5. package/package.json +3 -3
  6. package/src/bitcoin-interface-ordinal.ts +181 -181
  7. package/src/bitcoin-interface-teleswap.ts +252 -252
  8. package/src/bitcoin-interface-utils.ts +60 -60
  9. package/src/bitcoin-interface.ts +241 -241
  10. package/src/bitcoin-utils.ts +591 -591
  11. package/src/bitcoin-wallet-base.ts +310 -310
  12. package/src/helper/brc20-helper.ts +181 -181
  13. package/src/helper/ordinal-helper.ts +118 -118
  14. package/src/helper/teleswap-helper.ts +6 -5
  15. package/src/index.ts +15 -15
  16. package/src/ordinal-wallet.ts +738 -738
  17. package/src/sign/index.ts +1 -1
  18. package/src/sign/sign-transaction.ts +108 -108
  19. package/src/teleswap-wallet.ts +155 -155
  20. package/src/transaction-builder/bitcoin-transaction-builder.ts +44 -44
  21. package/src/transaction-builder/index.ts +3 -3
  22. package/src/transaction-builder/ordinal-transaction-builder.ts +147 -147
  23. package/src/transaction-builder/transaction-builder.ts +706 -706
  24. package/src/type.ts +48 -48
  25. package/src/utils/networks.ts +33 -33
  26. package/src/utils/tools.ts +90 -90
  27. package/tsconfig.json +9 -9
  28. package/webpack.config.js +16 -16
  29. package/dist/bitcoin-base.d.ts +0 -93
  30. package/dist/bitcoin-base.d.ts.map +0 -1
  31. package/dist/bitcoin-base.js +0 -236
  32. package/dist/bitcoin-base.js.map +0 -1
  33. package/dist/helper/burn-request-helper.d.ts +0 -7
  34. package/dist/helper/burn-request-helper.d.ts.map +0 -1
  35. package/dist/helper/burn-request-helper.js +0 -26
  36. package/dist/helper/burn-request-helper.js.map +0 -1
  37. package/dist/helper/teleport-request-helper.d.ts +0 -47
  38. package/dist/helper/teleport-request-helper.d.ts.map +0 -1
  39. package/dist/helper/teleport-request-helper.js +0 -146
  40. package/dist/helper/teleport-request-helper.js.map +0 -1
  41. package/dist/teleport-dao-payments.d.ts +0 -76
  42. package/dist/teleport-dao-payments.d.ts.map +0 -1
  43. package/dist/teleport-dao-payments.js +0 -217
  44. package/dist/teleport-dao-payments.js.map +0 -1
@@ -1,181 +1,181 @@
1
- import BigNumber from "bignumber.js"
2
- import { brc20 } from "@teleportdao/configs"
3
-
4
- export type WrapOpReturn = {
5
- chainId: number
6
- appId: number
7
- brc20TokenId: number
8
- recipientAddress: string
9
- inputAmount: string
10
- outputAmount?: string
11
- outputToken?: string
12
- thirdPartyId?: number
13
- }
14
- export type WrapOpReturnAndType = WrapOpReturn & {
15
- requestType: "wrap" | "wrapAndExchange"
16
- }
17
-
18
- const brc20WrapRequests = brc20.requestAppId
19
-
20
- export function generateBrc2OpReturn({
21
- chainId,
22
- appId,
23
- brc20TokenId,
24
- inputAmount,
25
- recipientAddress,
26
- thirdPartyId = 0,
27
- isExchange = false,
28
- outputToken,
29
- outputAmount,
30
- }: WrapOpReturn & {
31
- isExchange?: boolean
32
- }) {
33
- let data = ""
34
- if (chainId.toString(16).length > 4) throw new Error("chainId should be less than 2 bytes")
35
- data += chainId.toString(16).padStart(4, "0") // 2 bytes
36
- data += appId.toString(16).padStart(2, "0") // 1 bytes
37
- data += brc20TokenId.toString(16).padStart(4, "0") // 2 bytes
38
- data += BigNumber(inputAmount).toString(16).padStart(26, "0") // 13 bytes
39
- data += recipientAddress.replace("0x", "").toLowerCase().padStart(40, "0") // 20 bytes
40
- data += BigNumber(thirdPartyId).toString(16).padStart(2, "0") // 1 bytes
41
- if (isExchange) {
42
- if (!outputAmount || !outputToken) {
43
- throw new Error("outputAmount and outputToken are required for exchange")
44
- }
45
- data += outputToken.replace("0x", "").toLowerCase().padStart(40, "0") // 20 bytes
46
- data += BigNumber(outputAmount).toString(16).padStart(26, "0") // 13 bytes
47
- }
48
- return data
49
- }
50
-
51
- export function parseBrc20OpReturn(data: string) {
52
- let parsedData: any = {}
53
- parsedData.chainId = Number(`0x${data.slice(0, 4)}`) // 2 bytes
54
- parsedData.appId = Number(`0x${data.slice(4, 6)}`) // 1 bytes
55
- parsedData.brc20TokenId = Number(`0x${data.slice(6, 10)}`) // 2 bytes
56
- parsedData.inputAmount = new BigNumber(`0x${data.slice(10, 36)}`).toFixed(0) // 11 bytes
57
- parsedData.recipientAddress = `0x${data.slice(36, 76)}` // 20 bytes
58
- parsedData.thirdPartyId = `0x${data.slice(76, 78)}` // 20 bytes
59
- if (data.length === 78) {
60
- parsedData.requestType = "wrap"
61
- return {
62
- status: true,
63
- data: parsedData as WrapOpReturnAndType,
64
- }
65
- }
66
- parsedData.outputToken = `0x${data.slice(78, 118)}` // 20 bytes
67
- parsedData.outputAmount = new BigNumber(`0x${data.slice(118, 144)}`).toFixed(0) // 20 bytes
68
- if (data.length === 144) {
69
- parsedData.requestType = "swapAndWrap"
70
- return {
71
- status: true,
72
- data: parsedData as WrapOpReturnAndType,
73
- }
74
- }
75
-
76
- return {
77
- status: false,
78
- message: `invalid OP_RETURN data for requestType: 'wrap or exchange'. invalid data length : ${data.length} - valid length : 144 , 78`,
79
- code: "INVALID_OP_RETURN",
80
- }
81
- }
82
-
83
- function parseBrc20RawRequest(opReturnData: string): {
84
- status: boolean
85
- data?: WrapOpReturnAndType
86
- message?: string
87
- code?: string
88
- } {
89
- let data = opReturnData.slice(2, 4) === "4c" ? opReturnData.slice(6) : opReturnData.slice(4)
90
- // eslint-disable-next-line no-unused-vars
91
- let appIdHex = data.slice(4, 6) // 2 bytes
92
- if (!appIdHex) {
93
- return {
94
- status: false,
95
- message: `invalid OP_RETURN data : ${data}`,
96
- code: "INVALID_APP_ID",
97
- }
98
- }
99
-
100
- let appId = Number(`0x${appIdHex}`) // 2 bytes
101
-
102
- // get type base on appId
103
- let requestType = Object.keys(brc20WrapRequests).find(
104
- (key) =>
105
- appId >= brc20WrapRequests[key as keyof typeof brc20WrapRequests].appIdRange[0] &&
106
- appId <= brc20WrapRequests[key as keyof typeof brc20WrapRequests].appIdRange[1],
107
- )
108
-
109
- switch (requestType) {
110
- case "wrap":
111
- case "wrapAndExchange":
112
- return parseBrc20OpReturn(data)
113
- default:
114
- return {
115
- status: false,
116
- message: `invalid appId : ${appId}`,
117
- code: "INVALID_OP_RETURN",
118
- }
119
- }
120
- }
121
-
122
- export function checkAndParseBrc20Request(
123
- vouts: {
124
- address?: string
125
- script: string
126
- value: number
127
- }[],
128
- address: string,
129
- ): {
130
- status: boolean
131
- data?: WrapOpReturnAndType
132
- dataOutputIndex?: number
133
- lockerFeeValue?: number
134
- lockerFeeOutputIndex?: number
135
- brc20OutputIndex?: number
136
- brc20OutputValue?: number
137
- message?: string
138
- code?: string
139
- } {
140
- let requestOutputIndex = vouts.findIndex((vout_) => vout_.script.startsWith("6a"))
141
- if (requestOutputIndex >= 0) {
142
- let opReturnData = vouts[requestOutputIndex]?.script
143
- if (!opReturnData) {
144
- return {
145
- status: false,
146
- message: "invalid OP_RETURN",
147
- code: "INVALID_OP_RETURN",
148
- }
149
- }
150
-
151
- let brc20Transfer = vouts[0]
152
- if (brc20Transfer.address !== address || brc20Transfer.value < 546) {
153
- return {
154
- status: false,
155
- message: "no brc20 transfer output",
156
- code: "NO_BRC20_TRANSFER",
157
- }
158
- }
159
-
160
- let dataResponse = parseBrc20RawRequest(opReturnData)
161
- if (dataResponse.status) {
162
- let lockerFeeOutputIndex = vouts.findIndex((vout_, i) => vout_.address === address && +i > 0)
163
- let lockerFeeValue = lockerFeeOutputIndex >= 0 ? vouts[lockerFeeOutputIndex].value : 0
164
- return {
165
- status: true,
166
- data: dataResponse.data!,
167
- dataOutputIndex: requestOutputIndex,
168
- lockerFeeValue,
169
- lockerFeeOutputIndex,
170
- brc20OutputIndex: 0,
171
- brc20OutputValue: brc20Transfer.value,
172
- }
173
- }
174
- return dataResponse
175
- }
176
- return {
177
- status: false,
178
- message: "transaction outputs should contain OP_RETURN",
179
- code: "NO_OP_RETURN",
180
- }
181
- }
1
+ import BigNumber from "bignumber.js"
2
+ import { brc20 } from "@teleportdao/configs"
3
+
4
+ export type WrapOpReturn = {
5
+ chainId: number
6
+ appId: number
7
+ brc20TokenId: number
8
+ recipientAddress: string
9
+ inputAmount: string
10
+ outputAmount?: string
11
+ outputToken?: string
12
+ thirdPartyId?: number
13
+ }
14
+ export type WrapOpReturnAndType = WrapOpReturn & {
15
+ requestType: "wrap" | "wrapAndExchange"
16
+ }
17
+
18
+ const brc20WrapRequests = brc20.requestAppId
19
+
20
+ export function generateBrc2OpReturn({
21
+ chainId,
22
+ appId,
23
+ brc20TokenId,
24
+ inputAmount,
25
+ recipientAddress,
26
+ thirdPartyId = 0,
27
+ isExchange = false,
28
+ outputToken,
29
+ outputAmount,
30
+ }: WrapOpReturn & {
31
+ isExchange?: boolean
32
+ }) {
33
+ let data = ""
34
+ if (chainId.toString(16).length > 4) throw new Error("chainId should be less than 2 bytes")
35
+ data += chainId.toString(16).padStart(4, "0") // 2 bytes
36
+ data += appId.toString(16).padStart(2, "0") // 1 bytes
37
+ data += brc20TokenId.toString(16).padStart(4, "0") // 2 bytes
38
+ data += BigNumber(inputAmount).toString(16).padStart(26, "0") // 13 bytes
39
+ data += recipientAddress.replace("0x", "").toLowerCase().padStart(40, "0") // 20 bytes
40
+ data += BigNumber(thirdPartyId).toString(16).padStart(2, "0") // 1 bytes
41
+ if (isExchange) {
42
+ if (!outputAmount || !outputToken) {
43
+ throw new Error("outputAmount and outputToken are required for exchange")
44
+ }
45
+ data += outputToken.replace("0x", "").toLowerCase().padStart(40, "0") // 20 bytes
46
+ data += BigNumber(outputAmount).toString(16).padStart(26, "0") // 13 bytes
47
+ }
48
+ return data
49
+ }
50
+
51
+ export function parseBrc20OpReturn(data: string) {
52
+ let parsedData: any = {}
53
+ parsedData.chainId = Number(`0x${data.slice(0, 4)}`) // 2 bytes
54
+ parsedData.appId = Number(`0x${data.slice(4, 6)}`) // 1 bytes
55
+ parsedData.brc20TokenId = Number(`0x${data.slice(6, 10)}`) // 2 bytes
56
+ parsedData.inputAmount = new BigNumber(`0x${data.slice(10, 36)}`).toFixed(0) // 11 bytes
57
+ parsedData.recipientAddress = `0x${data.slice(36, 76)}` // 20 bytes
58
+ parsedData.thirdPartyId = `0x${data.slice(76, 78)}` // 20 bytes
59
+ if (data.length === 78) {
60
+ parsedData.requestType = "wrap"
61
+ return {
62
+ status: true,
63
+ data: parsedData as WrapOpReturnAndType,
64
+ }
65
+ }
66
+ parsedData.outputToken = `0x${data.slice(78, 118)}` // 20 bytes
67
+ parsedData.outputAmount = new BigNumber(`0x${data.slice(118, 144)}`).toFixed(0) // 20 bytes
68
+ if (data.length === 144) {
69
+ parsedData.requestType = "swapAndWrap"
70
+ return {
71
+ status: true,
72
+ data: parsedData as WrapOpReturnAndType,
73
+ }
74
+ }
75
+
76
+ return {
77
+ status: false,
78
+ message: `invalid OP_RETURN data for requestType: 'wrap or exchange'. invalid data length : ${data.length} - valid length : 144 , 78`,
79
+ code: "INVALID_OP_RETURN",
80
+ }
81
+ }
82
+
83
+ function parseBrc20RawRequest(opReturnData: string): {
84
+ status: boolean
85
+ data?: WrapOpReturnAndType
86
+ message?: string
87
+ code?: string
88
+ } {
89
+ let data = opReturnData.slice(2, 4) === "4c" ? opReturnData.slice(6) : opReturnData.slice(4)
90
+ // eslint-disable-next-line no-unused-vars
91
+ let appIdHex = data.slice(4, 6) // 2 bytes
92
+ if (!appIdHex) {
93
+ return {
94
+ status: false,
95
+ message: `invalid OP_RETURN data : ${data}`,
96
+ code: "INVALID_APP_ID",
97
+ }
98
+ }
99
+
100
+ let appId = Number(`0x${appIdHex}`) // 2 bytes
101
+
102
+ // get type base on appId
103
+ let requestType = Object.keys(brc20WrapRequests).find(
104
+ (key) =>
105
+ appId >= brc20WrapRequests[key as keyof typeof brc20WrapRequests].appIdRange[0] &&
106
+ appId <= brc20WrapRequests[key as keyof typeof brc20WrapRequests].appIdRange[1],
107
+ )
108
+
109
+ switch (requestType) {
110
+ case "wrap":
111
+ case "wrapAndExchange":
112
+ return parseBrc20OpReturn(data)
113
+ default:
114
+ return {
115
+ status: false,
116
+ message: `invalid appId : ${appId}`,
117
+ code: "INVALID_OP_RETURN",
118
+ }
119
+ }
120
+ }
121
+
122
+ export function checkAndParseBrc20Request(
123
+ vouts: {
124
+ address?: string
125
+ script: string
126
+ value: number
127
+ }[],
128
+ address: string,
129
+ ): {
130
+ status: boolean
131
+ data?: WrapOpReturnAndType
132
+ dataOutputIndex?: number
133
+ lockerFeeValue?: number
134
+ lockerFeeOutputIndex?: number
135
+ brc20OutputIndex?: number
136
+ brc20OutputValue?: number
137
+ message?: string
138
+ code?: string
139
+ } {
140
+ let requestOutputIndex = vouts.findIndex((vout_) => vout_.script.startsWith("6a"))
141
+ if (requestOutputIndex >= 0) {
142
+ let opReturnData = vouts[requestOutputIndex]?.script
143
+ if (!opReturnData) {
144
+ return {
145
+ status: false,
146
+ message: "invalid OP_RETURN",
147
+ code: "INVALID_OP_RETURN",
148
+ }
149
+ }
150
+
151
+ let brc20Transfer = vouts[0]
152
+ if (brc20Transfer.address !== address || brc20Transfer.value < 546) {
153
+ return {
154
+ status: false,
155
+ message: "no brc20 transfer output",
156
+ code: "NO_BRC20_TRANSFER",
157
+ }
158
+ }
159
+
160
+ let dataResponse = parseBrc20RawRequest(opReturnData)
161
+ if (dataResponse.status) {
162
+ let lockerFeeOutputIndex = vouts.findIndex((vout_, i) => vout_.address === address && +i > 0)
163
+ let lockerFeeValue = lockerFeeOutputIndex >= 0 ? vouts[lockerFeeOutputIndex].value : 0
164
+ return {
165
+ status: true,
166
+ data: dataResponse.data!,
167
+ dataOutputIndex: requestOutputIndex,
168
+ lockerFeeValue,
169
+ lockerFeeOutputIndex,
170
+ brc20OutputIndex: 0,
171
+ brc20OutputValue: brc20Transfer.value,
172
+ }
173
+ }
174
+ return dataResponse
175
+ }
176
+ return {
177
+ status: false,
178
+ message: "transaction outputs should contain OP_RETURN",
179
+ code: "NO_OP_RETURN",
180
+ }
181
+ }
@@ -1,118 +1,118 @@
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 fileTypeHex = Buffer.from(file.type!, "utf8").toString("hex")
105
- const ORDINAL_ORD_HEX = Buffer.from("ord", "utf8").toString("hex")
106
- const script = `${internalPublicKeyHex} OP_CHECKSIG OP_FALSE OP_IF ${ORDINAL_ORD_HEX} 00000000000000000000 ${fileTypeHex} OP_0 ${splittedFileHex} OP_ENDIF`
107
-
108
- // we add 00000000000000000000 so we can modify INCORRECT OPCODE
109
- const leafScript = Buffer.from(
110
- bitcoin.script.fromASM(script).toString("hex").replace("0a00000000000000000000", "0101"),
111
- "hex",
112
- )
113
- return leafScript
114
- }
115
-
116
- export function toXOnly(pubKey: Buffer) {
117
- return pubKey.length === 32 ? pubKey : pubKey.subarray(1, 33)
118
- }
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 fileTypeHex = Buffer.from(file.type!, "utf8").toString("hex")
105
+ const ORDINAL_ORD_HEX = Buffer.from("ord", "utf8").toString("hex")
106
+ const script = `${internalPublicKeyHex} OP_CHECKSIG OP_FALSE OP_IF ${ORDINAL_ORD_HEX} 00000000000000000000 ${fileTypeHex} OP_0 ${splittedFileHex} OP_ENDIF`
107
+
108
+ // we add 00000000000000000000 so we can modify INCORRECT OPCODE
109
+ const leafScript = Buffer.from(
110
+ bitcoin.script.fromASM(script).toString("hex").replace("0a00000000000000000000", "0101"),
111
+ "hex",
112
+ )
113
+ return leafScript
114
+ }
115
+
116
+ export function toXOnly(pubKey: Buffer) {
117
+ return pubKey.length === 32 ? pubKey : pubKey.subarray(1, 33)
118
+ }
@@ -103,8 +103,9 @@ export function generateWrapOpReturn({
103
103
  }
104
104
  if (
105
105
  (bridgePercentageFee || 0) > 100 ||
106
- BigNumber(bridgePercentageFee || 0)
107
- .multipliedBy(1e7)
106
+ (bridgePercentageFee && bridgePercentageFee < 0.00001) ||
107
+ BigNumber(bridgePercentageFee?.toFixed(5) || 0)
108
+ .multipliedBy(1e5) // bridgePercentageFee is in %. 100 = 100% = 1e7
108
109
  .toString(16).length > wrapOpReturnLength.bridgePercentageFee
109
110
  ) {
110
111
  throw new Error("invalid percentageFee")
@@ -112,8 +113,8 @@ export function generateWrapOpReturn({
112
113
  data += outputToken.replace("0x", "").toLowerCase().padStart(40, "0")
113
114
  data += BigNumber(outputAmount).toString(16).padStart(wrapOpReturnLength.outputAmount, "0")
114
115
 
115
- data += BigNumber(bridgePercentageFee || 0)
116
- .multipliedBy(1e7)
116
+ data += BigNumber(bridgePercentageFee?.toFixed(5) || 0)
117
+ .multipliedBy(1e5)
117
118
  .toString(16)
118
119
  .padStart(wrapOpReturnLength.bridgePercentageFee, "0")
119
120
  if (data.length !== 65 * 2) throw new Error("invalid data length")
@@ -181,7 +182,7 @@ export function parseWrapRequest(data: string) {
181
182
  parsedData.bridgePercentageFee = new BigNumber(
182
183
  `0x${data.slice(offset, (offset += wrapOpReturnLength.bridgePercentageFee))}`,
183
184
  )
184
- .dividedBy(1e7)
185
+ .dividedBy(1e5)
185
186
  .toNumber()
186
187
 
187
188
  if (parsedData.bridgePercentageFee > 100) {
package/src/index.ts CHANGED
@@ -1,15 +1,15 @@
1
- export * as bitcoinUtils from "./bitcoin-utils"
2
- export * from "./helper"
3
- export * from "./type"
4
- //
5
- export * from "./teleswap-wallet"
6
- export * from "./ordinal-wallet"
7
- export * from "./bitcoin-wallet-base"
8
- //
9
- export * from "./bitcoin-interface-utils"
10
- export * from "./bitcoin-interface"
11
- export * from "./bitcoin-interface-teleswap"
12
- export * from "./bitcoin-interface-ordinal"
13
- //
14
- export * from "./transaction-builder"
15
- export * from "./sign"
1
+ export * as bitcoinUtils from "./bitcoin-utils"
2
+ export * from "./helper"
3
+ export * from "./type"
4
+ //
5
+ export * from "./teleswap-wallet"
6
+ export * from "./ordinal-wallet"
7
+ export * from "./bitcoin-wallet-base"
8
+ //
9
+ export * from "./bitcoin-interface-utils"
10
+ export * from "./bitcoin-interface"
11
+ export * from "./bitcoin-interface-teleswap"
12
+ export * from "./bitcoin-interface-ordinal"
13
+ //
14
+ export * from "./transaction-builder"
15
+ export * from "./sign"