xpi-ts 0.2.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.
Files changed (216) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +516 -0
  3. package/dist/index.d.ts +9 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +8 -0
  6. package/dist/lib/bitcore/address.d.ts +66 -0
  7. package/dist/lib/bitcore/address.d.ts.map +1 -0
  8. package/dist/lib/bitcore/address.js +407 -0
  9. package/dist/lib/bitcore/block/block.d.ts +57 -0
  10. package/dist/lib/bitcore/block/block.d.ts.map +1 -0
  11. package/dist/lib/bitcore/block/block.js +233 -0
  12. package/dist/lib/bitcore/block/blockheader.d.ts +82 -0
  13. package/dist/lib/bitcore/block/blockheader.d.ts.map +1 -0
  14. package/dist/lib/bitcore/block/blockheader.js +323 -0
  15. package/dist/lib/bitcore/block/index.d.ts +5 -0
  16. package/dist/lib/bitcore/block/index.d.ts.map +1 -0
  17. package/dist/lib/bitcore/block/index.js +2 -0
  18. package/dist/lib/bitcore/chunk.d.ts +22 -0
  19. package/dist/lib/bitcore/chunk.d.ts.map +1 -0
  20. package/dist/lib/bitcore/chunk.js +46 -0
  21. package/dist/lib/bitcore/crypto/bn.d.ts +53 -0
  22. package/dist/lib/bitcore/crypto/bn.d.ts.map +1 -0
  23. package/dist/lib/bitcore/crypto/bn.js +238 -0
  24. package/dist/lib/bitcore/crypto/ecdsa.d.ts +46 -0
  25. package/dist/lib/bitcore/crypto/ecdsa.d.ts.map +1 -0
  26. package/dist/lib/bitcore/crypto/ecdsa.js +247 -0
  27. package/dist/lib/bitcore/crypto/hash.d.ts +16 -0
  28. package/dist/lib/bitcore/crypto/hash.d.ts.map +1 -0
  29. package/dist/lib/bitcore/crypto/hash.js +87 -0
  30. package/dist/lib/bitcore/crypto/index.d.ts +9 -0
  31. package/dist/lib/bitcore/crypto/index.d.ts.map +1 -0
  32. package/dist/lib/bitcore/crypto/index.js +8 -0
  33. package/dist/lib/bitcore/crypto/musig2.d.ts +40 -0
  34. package/dist/lib/bitcore/crypto/musig2.d.ts.map +1 -0
  35. package/dist/lib/bitcore/crypto/musig2.js +236 -0
  36. package/dist/lib/bitcore/crypto/point.d.ts +20 -0
  37. package/dist/lib/bitcore/crypto/point.d.ts.map +1 -0
  38. package/dist/lib/bitcore/crypto/point.js +133 -0
  39. package/dist/lib/bitcore/crypto/random.d.ts +7 -0
  40. package/dist/lib/bitcore/crypto/random.d.ts.map +1 -0
  41. package/dist/lib/bitcore/crypto/random.js +30 -0
  42. package/dist/lib/bitcore/crypto/schnorr.d.ts +40 -0
  43. package/dist/lib/bitcore/crypto/schnorr.d.ts.map +1 -0
  44. package/dist/lib/bitcore/crypto/schnorr.js +185 -0
  45. package/dist/lib/bitcore/crypto/signature.d.ts +53 -0
  46. package/dist/lib/bitcore/crypto/signature.d.ts.map +1 -0
  47. package/dist/lib/bitcore/crypto/signature.js +300 -0
  48. package/dist/lib/bitcore/crypto/sigtype.d.ts +5 -0
  49. package/dist/lib/bitcore/crypto/sigtype.d.ts.map +1 -0
  50. package/dist/lib/bitcore/crypto/sigtype.js +18 -0
  51. package/dist/lib/bitcore/encoding/base58.d.ts +16 -0
  52. package/dist/lib/bitcore/encoding/base58.d.ts.map +1 -0
  53. package/dist/lib/bitcore/encoding/base58.js +55 -0
  54. package/dist/lib/bitcore/encoding/base58check.d.ts +9 -0
  55. package/dist/lib/bitcore/encoding/base58check.d.ts.map +1 -0
  56. package/dist/lib/bitcore/encoding/base58check.js +82 -0
  57. package/dist/lib/bitcore/encoding/bufferreader.d.ts +34 -0
  58. package/dist/lib/bitcore/encoding/bufferreader.d.ts.map +1 -0
  59. package/dist/lib/bitcore/encoding/bufferreader.js +198 -0
  60. package/dist/lib/bitcore/encoding/bufferwriter.d.ts +36 -0
  61. package/dist/lib/bitcore/encoding/bufferwriter.d.ts.map +1 -0
  62. package/dist/lib/bitcore/encoding/bufferwriter.js +189 -0
  63. package/dist/lib/bitcore/encoding/varint.d.ts +20 -0
  64. package/dist/lib/bitcore/encoding/varint.d.ts.map +1 -0
  65. package/dist/lib/bitcore/encoding/varint.js +61 -0
  66. package/dist/lib/bitcore/errors.d.ts +28 -0
  67. package/dist/lib/bitcore/errors.d.ts.map +1 -0
  68. package/dist/lib/bitcore/errors.js +325 -0
  69. package/dist/lib/bitcore/hdprivatekey.d.ts +78 -0
  70. package/dist/lib/bitcore/hdprivatekey.d.ts.map +1 -0
  71. package/dist/lib/bitcore/hdprivatekey.js +381 -0
  72. package/dist/lib/bitcore/hdpublickey.d.ts +98 -0
  73. package/dist/lib/bitcore/hdpublickey.d.ts.map +1 -0
  74. package/dist/lib/bitcore/hdpublickey.js +416 -0
  75. package/dist/lib/bitcore/index.d.ts +60 -0
  76. package/dist/lib/bitcore/index.d.ts.map +1 -0
  77. package/dist/lib/bitcore/index.js +44 -0
  78. package/dist/lib/bitcore/message.d.ts +23 -0
  79. package/dist/lib/bitcore/message.d.ts.map +1 -0
  80. package/dist/lib/bitcore/message.js +112 -0
  81. package/dist/lib/bitcore/mnemonic/errors.d.ts +7 -0
  82. package/dist/lib/bitcore/mnemonic/errors.d.ts.map +1 -0
  83. package/dist/lib/bitcore/mnemonic/errors.js +20 -0
  84. package/dist/lib/bitcore/mnemonic/index.d.ts +5 -0
  85. package/dist/lib/bitcore/mnemonic/index.d.ts.map +1 -0
  86. package/dist/lib/bitcore/mnemonic/index.js +4 -0
  87. package/dist/lib/bitcore/mnemonic/mnemonic.d.ts +23 -0
  88. package/dist/lib/bitcore/mnemonic/mnemonic.d.ts.map +1 -0
  89. package/dist/lib/bitcore/mnemonic/mnemonic.js +164 -0
  90. package/dist/lib/bitcore/mnemonic/pbkdf2.d.ts +2 -0
  91. package/dist/lib/bitcore/mnemonic/pbkdf2.d.ts.map +1 -0
  92. package/dist/lib/bitcore/mnemonic/pbkdf2.js +25 -0
  93. package/dist/lib/bitcore/mnemonic/words/english.d.ts +2 -0
  94. package/dist/lib/bitcore/mnemonic/words/english.d.ts.map +1 -0
  95. package/dist/lib/bitcore/mnemonic/words/english.js +2050 -0
  96. package/dist/lib/bitcore/mnemonic/words/index.d.ts +4 -0
  97. package/dist/lib/bitcore/mnemonic/words/index.d.ts.map +1 -0
  98. package/dist/lib/bitcore/mnemonic/words/index.js +4 -0
  99. package/dist/lib/bitcore/musig2/index.d.ts +3 -0
  100. package/dist/lib/bitcore/musig2/index.d.ts.map +1 -0
  101. package/dist/lib/bitcore/musig2/index.js +2 -0
  102. package/dist/lib/bitcore/musig2/session.d.ts +79 -0
  103. package/dist/lib/bitcore/musig2/session.d.ts.map +1 -0
  104. package/dist/lib/bitcore/musig2/session.js +346 -0
  105. package/dist/lib/bitcore/musig2/signer.d.ts +61 -0
  106. package/dist/lib/bitcore/musig2/signer.d.ts.map +1 -0
  107. package/dist/lib/bitcore/musig2/signer.js +146 -0
  108. package/dist/lib/bitcore/networks.d.ts +53 -0
  109. package/dist/lib/bitcore/networks.d.ts.map +1 -0
  110. package/dist/lib/bitcore/networks.js +150 -0
  111. package/dist/lib/bitcore/opcode.d.ts +250 -0
  112. package/dist/lib/bitcore/opcode.d.ts.map +1 -0
  113. package/dist/lib/bitcore/opcode.js +270 -0
  114. package/dist/lib/bitcore/privatekey.d.ts +56 -0
  115. package/dist/lib/bitcore/privatekey.d.ts.map +1 -0
  116. package/dist/lib/bitcore/privatekey.js +237 -0
  117. package/dist/lib/bitcore/publickey.d.ts +59 -0
  118. package/dist/lib/bitcore/publickey.d.ts.map +1 -0
  119. package/dist/lib/bitcore/publickey.js +263 -0
  120. package/dist/lib/bitcore/script/interpreter.d.ts +98 -0
  121. package/dist/lib/bitcore/script/interpreter.d.ts.map +1 -0
  122. package/dist/lib/bitcore/script/interpreter.js +1704 -0
  123. package/dist/lib/bitcore/script.d.ts +111 -0
  124. package/dist/lib/bitcore/script.d.ts.map +1 -0
  125. package/dist/lib/bitcore/script.js +1112 -0
  126. package/dist/lib/bitcore/taproot/musig2.d.ts +29 -0
  127. package/dist/lib/bitcore/taproot/musig2.d.ts.map +1 -0
  128. package/dist/lib/bitcore/taproot/musig2.js +104 -0
  129. package/dist/lib/bitcore/taproot/nft.d.ts +164 -0
  130. package/dist/lib/bitcore/taproot/nft.d.ts.map +1 -0
  131. package/dist/lib/bitcore/taproot/nft.js +407 -0
  132. package/dist/lib/bitcore/taproot.d.ts +65 -0
  133. package/dist/lib/bitcore/taproot.d.ts.map +1 -0
  134. package/dist/lib/bitcore/taproot.js +288 -0
  135. package/dist/lib/bitcore/transaction/index.d.ts +12 -0
  136. package/dist/lib/bitcore/transaction/index.d.ts.map +1 -0
  137. package/dist/lib/bitcore/transaction/index.js +6 -0
  138. package/dist/lib/bitcore/transaction/input.d.ts +202 -0
  139. package/dist/lib/bitcore/transaction/input.d.ts.map +1 -0
  140. package/dist/lib/bitcore/transaction/input.js +911 -0
  141. package/dist/lib/bitcore/transaction/output.d.ts +48 -0
  142. package/dist/lib/bitcore/transaction/output.d.ts.map +1 -0
  143. package/dist/lib/bitcore/transaction/output.js +231 -0
  144. package/dist/lib/bitcore/transaction/sighash.d.ts +32 -0
  145. package/dist/lib/bitcore/transaction/sighash.d.ts.map +1 -0
  146. package/dist/lib/bitcore/transaction/sighash.js +335 -0
  147. package/dist/lib/bitcore/transaction/signature.d.ts +36 -0
  148. package/dist/lib/bitcore/transaction/signature.d.ts.map +1 -0
  149. package/dist/lib/bitcore/transaction/signature.js +130 -0
  150. package/dist/lib/bitcore/transaction/transaction.d.ts +164 -0
  151. package/dist/lib/bitcore/transaction/transaction.d.ts.map +1 -0
  152. package/dist/lib/bitcore/transaction/transaction.js +1016 -0
  153. package/dist/lib/bitcore/transaction/unspentoutput.d.ts +58 -0
  154. package/dist/lib/bitcore/transaction/unspentoutput.d.ts.map +1 -0
  155. package/dist/lib/bitcore/transaction/unspentoutput.js +167 -0
  156. package/dist/lib/bitcore/unit.d.ts +44 -0
  157. package/dist/lib/bitcore/unit.d.ts.map +1 -0
  158. package/dist/lib/bitcore/unit.js +106 -0
  159. package/dist/lib/bitcore/uri.d.ts +29 -0
  160. package/dist/lib/bitcore/uri.d.ts.map +1 -0
  161. package/dist/lib/bitcore/uri.js +163 -0
  162. package/dist/lib/bitcore/util/base32.d.ts +5 -0
  163. package/dist/lib/bitcore/util/base32.d.ts.map +1 -0
  164. package/dist/lib/bitcore/util/base32.js +58 -0
  165. package/dist/lib/bitcore/util/buffer.d.ts +18 -0
  166. package/dist/lib/bitcore/util/buffer.d.ts.map +1 -0
  167. package/dist/lib/bitcore/util/buffer.js +76 -0
  168. package/dist/lib/bitcore/util/convertBits.d.ts +2 -0
  169. package/dist/lib/bitcore/util/convertBits.d.ts.map +1 -0
  170. package/dist/lib/bitcore/util/convertBits.js +26 -0
  171. package/dist/lib/bitcore/util/js.d.ts +9 -0
  172. package/dist/lib/bitcore/util/js.d.ts.map +1 -0
  173. package/dist/lib/bitcore/util/js.js +45 -0
  174. package/dist/lib/bitcore/util/preconditions.d.ts +6 -0
  175. package/dist/lib/bitcore/util/preconditions.d.ts.map +1 -0
  176. package/dist/lib/bitcore/util/preconditions.js +31 -0
  177. package/dist/lib/bitcore/util.d.ts +14 -0
  178. package/dist/lib/bitcore/util.d.ts.map +1 -0
  179. package/dist/lib/bitcore/util.js +13 -0
  180. package/dist/lib/bitcore/xaddress.d.ts +45 -0
  181. package/dist/lib/bitcore/xaddress.d.ts.map +1 -0
  182. package/dist/lib/bitcore/xaddress.js +279 -0
  183. package/dist/lib/rank/api.d.ts +75 -0
  184. package/dist/lib/rank/api.d.ts.map +1 -0
  185. package/dist/lib/rank/api.js +4 -0
  186. package/dist/lib/rank/index.d.ts +127 -0
  187. package/dist/lib/rank/index.d.ts.map +1 -0
  188. package/dist/lib/rank/index.js +421 -0
  189. package/dist/lib/rank/opcode.d.ts +23 -0
  190. package/dist/lib/rank/opcode.d.ts.map +1 -0
  191. package/dist/lib/rank/opcode.js +23 -0
  192. package/dist/lib/rank/script.d.ts +2 -0
  193. package/dist/lib/rank/script.d.ts.map +1 -0
  194. package/dist/lib/rank/script.js +7 -0
  195. package/dist/lib/rank/transaction.d.ts +3 -0
  196. package/dist/lib/rank/transaction.d.ts.map +1 -0
  197. package/dist/lib/rank/transaction.js +12 -0
  198. package/dist/lib/rpc.d.ts +136 -0
  199. package/dist/lib/rpc.d.ts.map +1 -0
  200. package/dist/lib/rpc.js +62 -0
  201. package/dist/utils/constants.d.ts +18 -0
  202. package/dist/utils/constants.d.ts.map +1 -0
  203. package/dist/utils/constants.js +20 -0
  204. package/dist/utils/env.d.ts +3 -0
  205. package/dist/utils/env.d.ts.map +1 -0
  206. package/dist/utils/env.js +8 -0
  207. package/dist/utils/string.d.ts +11 -0
  208. package/dist/utils/string.d.ts.map +1 -0
  209. package/dist/utils/string.js +47 -0
  210. package/dist/utils/types.d.ts +2 -0
  211. package/dist/utils/types.d.ts.map +1 -0
  212. package/dist/utils/types.js +1 -0
  213. package/dist/utils/wallet.d.ts +12 -0
  214. package/dist/utils/wallet.d.ts.map +1 -0
  215. package/dist/utils/wallet.js +28 -0
  216. package/package.json +91 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 The Lotusia Stewardship
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,516 @@
1
+ # xpi-ts
2
+
3
+ > **TypeScript SDK for Lotus (XPI) wallets and other applications**
4
+
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.8-blue)](https://www.typescriptlang.org/)
7
+ [![Node](https://img.shields.io/badge/Node.js->=22-green)](https://nodejs.org/)
8
+
9
+ A comprehensive TypeScript library providing Bitcoin-like transaction primitives, advanced cryptographic protocols, and RANK protocol support for the Lotus (XPI) blockchain ecosystem.
10
+
11
+ ---
12
+
13
+ ## Features
14
+
15
+ ### Cryptography & Signatures
16
+
17
+ - **Bitcore Modules** - Complete Bitcoin-like transaction primitives adapted for Lotus
18
+ - Private/public key management
19
+ - HD wallets (BIP32/BIP39)
20
+ - Transaction building and signing
21
+ - Address generation (P2PKH, P2SH, Taproot)
22
+ - Script interpreter
23
+ - **MuSig2** - Multi-signature Schnorr signatures (BIP327)
24
+ - 2-round non-interactive signing
25
+ - Privacy-preserving multisig (indistinguishable from single-sig)
26
+ - **Taproot** - Pay-to-Taproot address support
27
+ - Script path spending
28
+ - Key path spending
29
+ - MuSig2 integration
30
+ - RANK protocol integration
31
+
32
+ ### RANK Protocol
33
+
34
+ - **Social Ranking System** - On-chain reputation and content ranking
35
+ - Positive/negative/neutral sentiment tracking
36
+ - Multi-platform support (Twitter, Lotusia)
37
+ - Comment system (RNKC)
38
+ - Script builder and parser
39
+ - Fee-based spam prevention
40
+
41
+ ### Utilities
42
+
43
+ - **RPC Client** - Full-featured lotusd RPC interface
44
+ - Network information
45
+ - Block and transaction queries
46
+ - Mining information
47
+ - Mempool management
48
+ - **Constants & Settings** - Lotus-specific network parameters
49
+ - Network configurations
50
+ - Protocol constants
51
+ - Fee calculations
52
+ - **Encoding Utilities** - Base58, Base58Check, Base32, Varint
53
+
54
+ ---
55
+
56
+ ## Installation
57
+
58
+ ```bash
59
+ # Install from npmjs registry
60
+ $ npm install xpi-ts
61
+ ```
62
+
63
+ ### Requirements
64
+
65
+ - Node.js >= 22
66
+ - TypeScript >= 5.0 (for development)
67
+
68
+ ---
69
+
70
+ ## Quick Start
71
+
72
+ ### Basic Transaction
73
+
74
+ ```typescript
75
+ import { Bitcore } from 'xpi-ts'
76
+ import { BIP44_COIN_TYPE } from 'xpi-ts/utils/constants'
77
+
78
+ // Generate mnemonic
79
+ const mnemonic = new Bitcore.Mnemonic()
80
+ const phrase = mnemonic.phrase
81
+
82
+ // Derive HD wallet
83
+ const hdKey = mnemonic.toHDPrivateKey('passphrase')
84
+ const childKey = hdKey.deriveChild(`m/44'/${BIP44_COIN_TYPE}'/0'/0/0`)
85
+
86
+ // Get private key and address
87
+ const privateKey = childKey.privateKey
88
+ const address = privateKey.toAddress()
89
+
90
+ console.log('Address:', address.toString())
91
+
92
+ // Build transaction
93
+ const tx = new Bitcore.Transaction()
94
+ .from(unspentOutput)
95
+ .to(recipientAddress, 100_000_000) // 100 XPI
96
+ .change(changeAddress)
97
+ .sign(privateKey)
98
+
99
+ console.log('Transaction:', tx.serialize())
100
+ ```
101
+
102
+ ### HD Wallet (BIP32/BIP39)
103
+
104
+ ```typescript
105
+ import { Bitcore } from 'xpi-ts'
106
+ import { BIP44_COIN_TYPE } from 'xpi-ts/utils/constants'
107
+
108
+ // Generate mnemonic
109
+ const mnemonic = new Bitcore.Mnemonic()
110
+ const phrase = mnemonic.phrase
111
+
112
+ // Derive HD wallet
113
+ const hdKey = mnemonic.toHDPrivateKey('passphrase')
114
+ const childKey = hdKey.deriveChild(`m/44'/${BIP44_COIN_TYPE}'/0'/0/0`)
115
+
116
+ // Get private key and address
117
+ const privateKey = childKey.privateKey
118
+ const address = privateKey.toAddress()
119
+
120
+ console.log('First address:', address.toString())
121
+
122
+ // Or derive from existing mnemonic
123
+ const existingMnemonic = new Bitcore.Mnemonic(
124
+ 'your twelve word mnemonic phrase here',
125
+ )
126
+ const restoredHdKey = existingMnemonic.toHDPrivateKey()
127
+ ```
128
+
129
+ ### MuSig2 Multi-Signature
130
+
131
+ ```typescript
132
+ import { Bitcore } from 'xpi-ts'
133
+
134
+ // Create MuSig2 signer
135
+ const signer = new Bitcore.MuSig2Signer({
136
+ signers: [alicePubKey, bobPubKey],
137
+ myPrivateKey: alicePrivKey,
138
+ })
139
+
140
+ // Round 1: Generate nonces
141
+ const prepare = signer.prepare(message)
142
+ // Share prepare.myPublicNonces with other signers
143
+
144
+ // Round 2: Collect partial signatures
145
+ const myPartialSig = signer.createPartialSignature(
146
+ prepare,
147
+ allPublicNonces,
148
+ message,
149
+ )
150
+ // Collect partial signatures from other signers
151
+
152
+ // Aggregate final signature
153
+ const result = signer.sign(prepare, allPublicNonces, message, allPartialSigs)
154
+ ```
155
+
156
+ ### RANK Social Ranking
157
+
158
+ ```typescript
159
+ import { Bitcore, RANK } from 'xpi-ts'
160
+
161
+ // Create RANK script
162
+ const rankScript = RANK.toScriptRANK(
163
+ 'positive', // sentiment
164
+ 'twitter', // platform
165
+ '@username', // profileId
166
+ '1234567890', // postId (optional)
167
+ )
168
+
169
+ // Create RNKC script (comment) - returns array of buffers
170
+ const rnkcScripts = RANK.toScriptRNKC({
171
+ platform: 'twitter',
172
+ profileId: '@original_author',
173
+ postId: '0987654321',
174
+ comment: 'Great post!',
175
+ })
176
+
177
+ // Add to transaction
178
+ const tx = new Bitcore.Transaction()
179
+ .from(utxo)
180
+ .addOutput(
181
+ new Bitcore.Output({
182
+ script: rankScript,
183
+ satoshis: 0,
184
+ }),
185
+ )
186
+ // Add RNKC scripts (outIdx 1 and 2)
187
+ .addOutput(
188
+ new Bitcore.Output({
189
+ script: rnkcScripts[0],
190
+ satoshis: 0,
191
+ }),
192
+ )
193
+ .addOutput(
194
+ new Bitcore.Output({
195
+ script: rnkcScripts[1] || Buffer.from('6a', 'hex'), // OP_RETURN if only one script needed
196
+ satoshis: 0,
197
+ }),
198
+ )
199
+ .to(address, amount)
200
+ ```
201
+
202
+ ### Taproot Addresses
203
+
204
+ ```typescript
205
+ import { Bitcore } from 'xpi-ts'
206
+
207
+ // Create simple Taproot address (key-path only)
208
+ const privateKey = new Bitcore.PrivateKey()
209
+ const internalPubKey = privateKey.publicKey
210
+
211
+ const taprootScript = Bitcore.buildKeyPathTaproot(internalPubKey)
212
+ const taprootAddress = taprootScript.toAddress()
213
+
214
+ console.log('Taproot address:', taprootAddress?.toString())
215
+
216
+ // Taproot with script paths
217
+ const script1 = new Bitcore.Script()
218
+ .add(internalPubKey.toBuffer())
219
+ .add(Bitcore.Opcode.OP_CHECKSIG)
220
+
221
+ const script2 = new Bitcore.Script()
222
+ .add(720) // ~1 day timelock (30 blocks per hour (2min average) * 24 hours per day)
223
+ .add(Bitcore.Opcode.OP_CHECKSEQUENCEVERIFY)
224
+ .add(Bitcore.Opcode.OP_DROP)
225
+ .add(internalPubKey.toBuffer())
226
+ .add(Bitcore.Opcode.OP_CHECKSIG)
227
+
228
+ // Build tree with script paths
229
+ const tree = {
230
+ left: { script: script1 },
231
+ right: { script: script2 },
232
+ }
233
+
234
+ const taprootWithScripts = Bitcore.buildScriptPathTaproot(internalPubKey, tree)
235
+ const addressWithScripts = taprootWithScripts.toAddress()
236
+
237
+ console.log('Taproot with scripts:', addressWithScripts?.toString())
238
+ ```
239
+
240
+ ### RPC Client
241
+
242
+ ```typescript
243
+ import { Bitcore } from 'xpi-ts'
244
+ import { type RPCConfig, RPCClient } from 'xpi-ts/lib/rpc'
245
+
246
+ // Configure daemon connection
247
+ const config: RPCConfig = {
248
+ user: 'rpcuser',
249
+ password: 'rpcpass',
250
+ address: '127.0.0.1',
251
+ port: 10604,
252
+ }
253
+
254
+ const rpcClient = new RPCClient(config)
255
+
256
+ // Get blockchain info
257
+ const blockCount = await rpcClient.getBlockCount()
258
+ const blockHash = await rpcClient.getBlockHash(blockCount)
259
+ const block = await rpcClient.getBlock(blockHash)
260
+
261
+ // Get transaction info
262
+ const tx = await rpcClient.getRawTransaction(txid)
263
+
264
+ // Send raw transaction
265
+ const txid = await rpcClient.sendRawTransaction(tx.serialize())
266
+ console.log('Transaction ID:', txid)
267
+ ```
268
+
269
+ ---
270
+
271
+ ## Core Modules
272
+
273
+ ### Bitcore
274
+
275
+ Bitcoin-like transaction primitives adapted for Lotus XPI:
276
+
277
+ - **Transaction building** - Inputs, outputs, signing
278
+ - **Script system** - P2PKH, P2SH, P2TR, custom scripts
279
+ - **Cryptography** - ECDSA, Schnorr signatures
280
+ - **Addresses** - P2PKH, P2SH, P2TR (X-addresses)
281
+ - **HD Wallets** - BIP32 derivation, BIP39 mnemonics
282
+ - **Encoding** - Base58, Base58Check, Varint
283
+
284
+ ```typescript
285
+ import * as Bitcore from 'xpi-ts/lib/bitcore'
286
+ // or
287
+ import { PrivateKey, Transaction, Address } from 'xpi-ts'
288
+ ```
289
+
290
+ ### MuSig2
291
+
292
+ Multi-signature Schnorr signatures:
293
+
294
+ - **2-round signing** - Non-interactive nonce exchange
295
+ - **Security** - Replay protection, nonce aggregation
296
+ - **Privacy** - Indistinguishable from single signatures
297
+
298
+ ```typescript
299
+ import { MuSig2Session, MuSig2Signer } from 'xpi-ts/lib/bitcore/musig2'
300
+ ```
301
+
302
+ ### RANK Protocol
303
+
304
+ On-chain social ranking and reputation system:
305
+
306
+ - **Sentiment tracking** - Positive/negative/neutral
307
+ - **Multi-platform** - Twitter, Lotusia
308
+ - **Comments** - RNKC protocol
309
+ - **Spam prevention** - Fee-based filtering
310
+
311
+ ```typescript
312
+ import { toScriptRANK, toScriptRNKC, ScriptProcessor } from 'xpi-ts/lib/rank'
313
+ ```
314
+
315
+ ### Taproot
316
+
317
+ Pay-to-Taproot support with script paths:
318
+
319
+ - **Key path spending** - Standard Taproot addresses
320
+ - **Script path spending** - MAST-like script trees
321
+ - **MuSig2 integration** - Multi-sig via Taproot
322
+ - **RANK integration** - RANK protocol via Taproot
323
+
324
+ ```typescript
325
+ import { Taproot } from 'xpi-ts/lib/bitcore/taproot'
326
+ ```
327
+
328
+ ### RPC Client
329
+
330
+ Full-featured RPC client for lotusd:
331
+
332
+ - **Network queries** - Get network info, peers, blocks
333
+ - **Transaction handling** - Send raw transactions, query mempool
334
+ - **Mining info** - Get block height, difficulty, hash rate
335
+ - **Type-safe** - Full TypeScript support
336
+
337
+ ```typescript
338
+ import { type RPCConfig, RPCClient } from 'xpi-ts/lib/rpc'
339
+ ```
340
+
341
+ ---
342
+
343
+ ## Examples
344
+
345
+ The library includes comprehensive examples in the [`examples/`](examples/) directory:
346
+
347
+ ### Taproot Examples
348
+
349
+ - `taproot-example.ts` - Basic Taproot usage
350
+ - `taproot-rank-multisig.ts` - RANK protocol with multisig
351
+ - `taproot-rank-timelock.ts` - Timelock scripts
352
+ - `taproot-rnkc-moderation.ts` - Moderation scripts
353
+
354
+ ### MuSig2 Examples
355
+
356
+ - `musig2-example.ts` - Basic 2-of-2 signing
357
+ - `musig2-session-example.ts` - Session management
358
+ - `musig2-browser-compatibility.ts` - Browser usage
359
+
360
+ ### NFT Examples
361
+
362
+ - `nft-class-example.ts` - NFT class usage
363
+ - `nft-examples.ts` - NFT creation and transfer
364
+
365
+ ### Running Examples
366
+
367
+ ```bash
368
+ # Basic example
369
+ npx tsx examples/taproot-example.ts
370
+
371
+ # MuSig2 signing
372
+ npx tsx examples/musig2-example.ts
373
+
374
+ # RANK protocol
375
+ npx tsx examples/rank-example.ts
376
+ ```
377
+
378
+ ---
379
+
380
+ ## Documentation
381
+
382
+ Comprehensive documentation is available in the [`docs/`](docs/) directory:
383
+
384
+ ### Getting Started
385
+
386
+ - [MuSig2 Start Here](docs/MUSIG2_START_HERE.md) - Introduction to MuSig2
387
+ - [MuSig2 Quick Reference](docs/MUSIG2_QUICK_REFERENCE.md) - Quick reference guide
388
+ - [Taproot Quickstart](docs/TAPROOT_QUICKSTART.md) - Taproot introduction
389
+
390
+ ### Architecture & Implementation
391
+
392
+ - [MuSig2 Implementation](docs/MUSIG2_IMPLEMENTATION.md) - MuSig2 design
393
+ - [Taproot Implementation](docs/TAPROOT_IMPLEMENTATION.md) - Taproot details
394
+
395
+ ### Security
396
+
397
+ - [MuSig2 Security Analysis](docs/MUSIG2_SECURITY_ANALYSIS.md) - Security audit
398
+ - [Signature Encoding](docs/SIGNATURE_ENCODING.md) - Signature format
399
+
400
+ ### API References
401
+
402
+ - [Taproot API Reference](docs/taproot/api-reference.md) - Taproot API
403
+
404
+ ---
405
+
406
+ ## Testing
407
+
408
+ ```bash
409
+ # Run all tests
410
+ npm test
411
+
412
+ # Run specific test suite
413
+ npm test -- test/crypto/musig2/
414
+
415
+ # Run with coverage
416
+ npm run test:coverage
417
+ ```
418
+
419
+ ---
420
+
421
+ ## Development
422
+
423
+ ### Build
424
+
425
+ ```bash
426
+ # Compile TypeScript
427
+ npm run build
428
+
429
+ # Watch mode
430
+ npm run build:watch
431
+ ```
432
+
433
+ ### Linting & Formatting
434
+
435
+ ```bash
436
+ # Format code
437
+ npm run format
438
+
439
+ # Lint code
440
+ npm run lint
441
+ ```
442
+
443
+ ---
444
+
445
+ ## Lotus Network Information
446
+
447
+ **Lotus (XPI)** is a Bitcoin-based cryptocurrency with several key differences:
448
+
449
+ - **Decimals**: 6 (1 XPI = 1,000,000 satoshis) vs Bitcoin's 8
450
+ - **Supply**: Inflationary with no hard cap
451
+ - **Consensus**: Proof-of-Work (SHA-256d)
452
+ - **Features**: OP_RETURN data, Taproot, RANK protocol
453
+
454
+ **Network Resources:**
455
+
456
+ - Official Website: https://lotusia.org
457
+ - Documentation: https://lotusia.org/docs
458
+ - Block Explorer: https://explorer.lotusia.org
459
+ - Full Node (lotusd): https://github.com/LotusiaStewardship/lotusd
460
+
461
+ ---
462
+
463
+ ## Community
464
+
465
+ **Discord:** [Lotusia](https://discord.gg/fZrFa3vf)
466
+ **Telegram:** [Lotusia Discourse](https://t.me/LotusiaDiscourse)
467
+ **GitHub:** [LotusiaStewardship](https://github.com/LotusiaStewardship)
468
+
469
+ ---
470
+
471
+ ## Contributing
472
+
473
+ Contributions are welcome! Please:
474
+
475
+ 1. Read the relevant documentation thoroughly
476
+ 2. Follow the existing code style (Prettier + ESLint)
477
+ 3. Add tests for new features
478
+ 4. Update documentation as needed
479
+ 5. Submit a pull request
480
+
481
+ ### Development Setup
482
+
483
+ ```bash
484
+ # Clone repository
485
+ git clone https://github.com/LotusiaStewardship/xpi-ts.git
486
+ cd xpi-ts
487
+
488
+ # Install dependencies
489
+ npm install
490
+
491
+ # Build library
492
+ npm run build
493
+
494
+ # Run tests
495
+ npm test
496
+ ```
497
+
498
+ ---
499
+
500
+ ## License
501
+
502
+ [MIT License](LICENSE) - Copyright (c) 2025 The Lotusia Stewardship
503
+
504
+ ---
505
+
506
+ ## Related Projects
507
+
508
+ - **lotusd** - Lotus full node implementation
509
+ https://github.com/LotusiaStewardship/lotusd
510
+
511
+ - **lotus-web-wallet** - Lotus web wallet with full Taproot support
512
+ https://github.com/LotusiaStewardship/lotus-web-wallet
513
+
514
+ ---
515
+
516
+ **Built with ❤️ for the Lotus Ecosystem** 🌸
@@ -0,0 +1,9 @@
1
+ export * from './lib/rpc.js';
2
+ export * as Bitcore from './lib/bitcore/index.js';
3
+ export * as RANK from './lib/rank/index.js';
4
+ export * from './utils/constants.js';
5
+ export * from './utils/env.js';
6
+ export * from './utils/string.js';
7
+ export * from './utils/types.js';
8
+ export * from './utils/wallet.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAKA,cAAc,cAAc,CAAA;AAC5B,OAAO,KAAK,OAAO,MAAM,wBAAwB,CAAA;AACjD,OAAO,KAAK,IAAI,MAAM,qBAAqB,CAAA;AAC3C,cAAc,sBAAsB,CAAA;AACpC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA;AAChC,cAAc,mBAAmB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ export * from './lib/rpc.js';
2
+ export * as Bitcore from './lib/bitcore/index.js';
3
+ export * as RANK from './lib/rank/index.js';
4
+ export * from './utils/constants.js';
5
+ export * from './utils/env.js';
6
+ export * from './utils/string.js';
7
+ export * from './utils/types.js';
8
+ export * from './utils/wallet.js';
@@ -0,0 +1,66 @@
1
+ import { Network } from './networks.js';
2
+ import { PublicKey } from './publickey.js';
3
+ import { Script } from './script.js';
4
+ export interface AddressData {
5
+ hashBuffer?: Buffer;
6
+ network?: Network;
7
+ type?: string;
8
+ }
9
+ export interface AddressObject {
10
+ hash: string;
11
+ type: string;
12
+ network: string;
13
+ }
14
+ export interface CashAddressDecoding {
15
+ readonly network: Network;
16
+ readonly type: string;
17
+ readonly hashBuffer: Buffer;
18
+ }
19
+ export type AddressInput = string | Buffer | AddressData | PublicKey | PublicKey[] | Script;
20
+ export declare class Address {
21
+ static readonly PayToPublicKeyHash = "pubkeyhash";
22
+ static readonly PayToScriptHash = "scripthash";
23
+ static readonly PayToTaproot = "taproot";
24
+ readonly hashBuffer: Buffer;
25
+ readonly network: Network;
26
+ readonly type: string;
27
+ constructor(data?: AddressInput, network?: Network | string, type?: string);
28
+ private _classifyArguments;
29
+ private static _classifyFromVersion;
30
+ private static _transformString;
31
+ private static _transformLegacyString;
32
+ private static _isXAddress;
33
+ private static _transformXAddressString;
34
+ private static _transformHash;
35
+ private static _transformBuffer;
36
+ private static _transformPublicKey;
37
+ private static _transformScript;
38
+ private static _transformObject;
39
+ static createMultisig(publicKeys: PublicKey[], threshold: number, network?: Network | string): Address;
40
+ static fromPublicKey(data: PublicKey, network?: Network | string): Address;
41
+ static fromPublicKeyHash(hash: Buffer, network?: Network | string): Address;
42
+ static fromScriptHash(hash: Buffer, network?: Network | string): Address;
43
+ static fromTaprootCommitment(commitment: PublicKey | Buffer, network?: Network | string): Address;
44
+ static fromBuffer(buffer: Buffer, network?: Network | string, type?: string): Address;
45
+ static fromString(str: string, network?: Network | string): Address;
46
+ static fromObject(obj: AddressObject): Address;
47
+ static fromScript(script: Script, network?: Network | string): Address;
48
+ static payingTo(script: Script, network?: Network | string): Address;
49
+ static getValidationError(data: AddressInput, network?: Network | string, type?: string): Error | null;
50
+ static isValid(data: AddressInput, network?: Network | string, type?: string): boolean;
51
+ isPayToPublicKeyHash(): boolean;
52
+ isPayToScriptHash(): boolean;
53
+ isPayToTaproot(): boolean;
54
+ toBuffer(): Buffer;
55
+ toFullBuffer(): Buffer;
56
+ toCashBuffer(): Buffer;
57
+ toObject(): AddressObject;
58
+ toJSON(): AddressObject;
59
+ toString(network?: Network | string): string;
60
+ toLegacyAddress(): string;
61
+ toCashAddress(): string;
62
+ toXAddress(network?: Network | string): string;
63
+ static decodeCashAddress(address: string): CashAddressDecoding;
64
+ inspect(): string;
65
+ }
66
+ //# sourceMappingURL=address.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../../lib/bitcore/address.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,OAAO,EAAqC,MAAM,eAAe,CAAA;AAG1E,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,MAAM,WAAW,WAAW;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ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