mainnet-js 3.1.7 → 4.0.0-next.10

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 (267) hide show
  1. package/dist/module/cache/IndexedDbCache.d.ts +1 -1
  2. package/dist/module/cache/IndexedDbCache.d.ts.map +1 -1
  3. package/dist/module/cache/MemoryCache.d.ts +1 -1
  4. package/dist/module/cache/MemoryCache.d.ts.map +1 -1
  5. package/dist/module/cache/WebStorageCache.d.ts +1 -1
  6. package/dist/module/cache/WebStorageCache.d.ts.map +1 -1
  7. package/dist/module/cache/walletCache.d.ts +16 -6
  8. package/dist/module/cache/walletCache.d.ts.map +1 -1
  9. package/dist/module/cache/walletCache.js +92 -34
  10. package/dist/module/cache/walletCache.js.map +1 -1
  11. package/dist/module/cli.js +1 -2
  12. package/dist/module/cli.js.map +1 -1
  13. package/dist/module/db/index.d.ts +1 -1
  14. package/dist/module/db/index.d.ts.map +1 -1
  15. package/dist/module/db/index.js +1 -1
  16. package/dist/module/db/index.js.map +1 -1
  17. package/dist/module/enum.d.ts +1 -1
  18. package/dist/module/enum.d.ts.map +1 -1
  19. package/dist/module/history/getHistory.d.ts +1 -1
  20. package/dist/module/history/getHistory.d.ts.map +1 -1
  21. package/dist/module/history/getHistory.js +3 -3
  22. package/dist/module/history/getHistory.js.map +1 -1
  23. package/dist/module/index.d.ts +25 -22
  24. package/dist/module/index.d.ts.map +1 -1
  25. package/dist/module/index.js +33 -26
  26. package/dist/module/index.js.map +1 -1
  27. package/dist/module/interface.d.ts +12 -2
  28. package/dist/module/interface.d.ts.map +1 -1
  29. package/dist/module/interface.js.map +1 -1
  30. package/dist/module/libauth.d.ts +1 -1
  31. package/dist/module/libauth.d.ts.map +1 -1
  32. package/dist/module/libauth.js +1 -1
  33. package/dist/module/libauth.js.map +1 -1
  34. package/dist/module/mine/mine.d.ts +2 -7
  35. package/dist/module/mine/mine.d.ts.map +1 -1
  36. package/dist/module/mine/mine.js +6 -27
  37. package/dist/module/mine/mine.js.map +1 -1
  38. package/dist/module/network/Connection.d.ts +1 -12
  39. package/dist/module/network/Connection.d.ts.map +1 -1
  40. package/dist/module/network/Connection.js +24 -33
  41. package/dist/module/network/Connection.js.map +1 -1
  42. package/dist/module/network/ElectrumNetworkProvider.d.ts +16 -17
  43. package/dist/module/network/ElectrumNetworkProvider.d.ts.map +1 -1
  44. package/dist/module/network/ElectrumNetworkProvider.js +91 -93
  45. package/dist/module/network/ElectrumNetworkProvider.js.map +1 -1
  46. package/dist/module/network/MockNetworkProvider.d.ts +28 -0
  47. package/dist/module/network/MockNetworkProvider.d.ts.map +1 -0
  48. package/dist/module/network/MockNetworkProvider.js +74 -0
  49. package/dist/module/network/MockNetworkProvider.js.map +1 -0
  50. package/dist/module/network/NetworkProvider.d.ts +9 -2
  51. package/dist/module/network/NetworkProvider.d.ts.map +1 -1
  52. package/dist/module/network/configuration.d.ts +2 -4
  53. package/dist/module/network/configuration.d.ts.map +1 -1
  54. package/dist/module/network/configuration.js +25 -50
  55. package/dist/module/network/configuration.js.map +1 -1
  56. package/dist/module/network/constant.d.ts +7 -7
  57. package/dist/module/network/constant.d.ts.map +1 -1
  58. package/dist/module/network/constant.js +21 -24
  59. package/dist/module/network/constant.js.map +1 -1
  60. package/dist/module/network/default.d.ts +5 -3
  61. package/dist/module/network/default.d.ts.map +1 -1
  62. package/dist/module/network/default.js +29 -51
  63. package/dist/module/network/default.js.map +1 -1
  64. package/dist/module/network/index.d.ts +4 -4
  65. package/dist/module/network/index.d.ts.map +1 -1
  66. package/dist/module/network/index.js +2 -2
  67. package/dist/module/network/index.js.map +1 -1
  68. package/dist/module/network/interface.d.ts +0 -6
  69. package/dist/module/network/interface.d.ts.map +1 -1
  70. package/dist/module/rate/ExchangeRate.d.ts +1 -1
  71. package/dist/module/rate/ExchangeRate.d.ts.map +1 -1
  72. package/dist/module/rate/ExchangeRate.js +13 -7
  73. package/dist/module/rate/ExchangeRate.js.map +1 -1
  74. package/dist/module/transaction/Wif.d.ts +3 -3
  75. package/dist/module/transaction/Wif.d.ts.map +1 -1
  76. package/dist/module/transaction/Wif.js +4 -4
  77. package/dist/module/transaction/Wif.js.map +1 -1
  78. package/dist/module/transaction/allocateFee.d.ts +1 -1
  79. package/dist/module/transaction/allocateFee.d.ts.map +1 -1
  80. package/dist/module/transaction/allocateFee.js +2 -2
  81. package/dist/module/transaction/allocateFee.js.map +1 -1
  82. package/dist/module/util/deriveCashaddr.js.map +1 -1
  83. package/dist/module/util/deriveNetwork.js +1 -1
  84. package/dist/module/util/deriveNetwork.js.map +1 -1
  85. package/dist/module/util/getAddrsByXpubKey.js +1 -1
  86. package/dist/module/util/getAddrsByXpubKey.js.map +1 -1
  87. package/dist/module/util/getXPubKey.js +1 -1
  88. package/dist/module/util/getXPubKey.js.map +1 -1
  89. package/dist/module/util/hd.d.ts +2 -0
  90. package/dist/module/util/hd.d.ts.map +1 -1
  91. package/dist/module/util/hd.js +41 -0
  92. package/dist/module/util/hd.js.map +1 -1
  93. package/dist/module/util/index.d.ts +7 -9
  94. package/dist/module/util/index.d.ts.map +1 -1
  95. package/dist/module/util/index.js +7 -9
  96. package/dist/module/util/index.js.map +1 -1
  97. package/dist/module/util/transaction.js +1 -1
  98. package/dist/module/util/transaction.js.map +1 -1
  99. package/dist/module/wallet/Base.d.ts +13 -9
  100. package/dist/module/wallet/Base.d.ts.map +1 -1
  101. package/dist/module/wallet/Base.js +54 -58
  102. package/dist/module/wallet/Base.js.map +1 -1
  103. package/dist/module/wallet/HDWallet.d.ts.map +1 -1
  104. package/dist/module/wallet/HDWallet.js +19 -38
  105. package/dist/module/wallet/HDWallet.js.map +1 -1
  106. package/dist/module/wallet/Util.d.ts +4 -22
  107. package/dist/module/wallet/Util.d.ts.map +1 -1
  108. package/dist/module/wallet/Util.js +75 -102
  109. package/dist/module/wallet/Util.js.map +1 -1
  110. package/dist/module/wallet/Watch.d.ts +24 -5
  111. package/dist/module/wallet/Watch.d.ts.map +1 -1
  112. package/dist/module/wallet/Watch.js +141 -17
  113. package/dist/module/wallet/Watch.js.map +1 -1
  114. package/dist/module/wallet/Wif.d.ts +2 -6
  115. package/dist/module/wallet/Wif.d.ts.map +1 -1
  116. package/dist/module/wallet/Wif.js +3 -69
  117. package/dist/module/wallet/Wif.js.map +1 -1
  118. package/dist/module/wallet/createWallet.d.ts +1 -1
  119. package/dist/module/wallet/createWallet.d.ts.map +1 -1
  120. package/dist/module/wallet/createWallet.js +2 -1
  121. package/dist/module/wallet/createWallet.js.map +1 -1
  122. package/dist/module/wallet/interface.d.ts +3 -2
  123. package/dist/module/wallet/interface.d.ts.map +1 -1
  124. package/dist/module/wallet/model.d.ts +2 -1
  125. package/dist/module/wallet/model.d.ts.map +1 -1
  126. package/dist/module/wallet/model.js +1 -1
  127. package/dist/module/wallet/model.js.map +1 -1
  128. package/package.json +17 -29
  129. package/dist/index.html +0 -9
  130. package/dist/mainnet-3.1.7.js +0 -2066
  131. package/dist/module/network/util.d.ts +0 -3
  132. package/dist/module/network/util.d.ts.map +0 -1
  133. package/dist/module/network/util.js +0 -27
  134. package/dist/module/network/util.js.map +0 -1
  135. package/dist/module/test/expect.d.ts +0 -12
  136. package/dist/module/test/expect.d.ts.map +0 -1
  137. package/dist/module/test/expect.js +0 -47
  138. package/dist/module/test/expect.js.map +0 -1
  139. package/dist/module/test/fetch.d.ts +0 -3
  140. package/dist/module/test/fetch.d.ts.map +0 -1
  141. package/dist/module/test/fetch.js +0 -32
  142. package/dist/module/test/fetch.js.map +0 -1
  143. package/dist/module/util/randomBytes.d.ts +0 -2
  144. package/dist/module/util/randomBytes.d.ts.map +0 -1
  145. package/dist/module/util/randomBytes.js +0 -13
  146. package/dist/module/util/randomBytes.js.map +0 -1
  147. package/dist/tsconfig.tsbuildinfo +0 -1
  148. package/src/cache/IndexedDbCache.test.ts +0 -15
  149. package/src/cache/IndexedDbCache.ts +0 -172
  150. package/src/cache/MemoryCache.test.ts +0 -15
  151. package/src/cache/MemoryCache.ts +0 -32
  152. package/src/cache/WebStorageCache.test.ts +0 -15
  153. package/src/cache/WebStorageCache.ts +0 -38
  154. package/src/cache/index.ts +0 -2
  155. package/src/cache/interface.ts +0 -9
  156. package/src/cache/walletCache.ts +0 -254
  157. package/src/chain.ts +0 -3
  158. package/src/cli.ts +0 -32
  159. package/src/config.ts +0 -23
  160. package/src/constant.ts +0 -27
  161. package/src/db/ExchangeRateProvider.ts +0 -28
  162. package/src/db/StorageProvider.ts +0 -64
  163. package/src/db/index.ts +0 -2
  164. package/src/db/interface.ts +0 -11
  165. package/src/enum.ts +0 -34
  166. package/src/history/getHistory.test.ts +0 -290
  167. package/src/history/getHistory.ts +0 -411
  168. package/src/history/interface.ts +0 -24
  169. package/src/index.ts +0 -48
  170. package/src/interface.ts +0 -72
  171. package/src/libauth.ts +0 -11
  172. package/src/message/index.ts +0 -2
  173. package/src/message/interface.ts +0 -40
  174. package/src/message/signed.test.ts +0 -309
  175. package/src/message/signed.ts +0 -201
  176. package/src/mine/index.ts +0 -1
  177. package/src/mine/mine.test.ts +0 -10
  178. package/src/mine/mine.ts +0 -42
  179. package/src/network/Connection.test.ts +0 -51
  180. package/src/network/Connection.ts +0 -73
  181. package/src/network/ElectrumNetworkProvider.ts +0 -657
  182. package/src/network/NetworkProvider.ts +0 -180
  183. package/src/network/Rpc.test.ts +0 -130
  184. package/src/network/configuration.test.ts +0 -59
  185. package/src/network/configuration.ts +0 -72
  186. package/src/network/constant.ts +0 -43
  187. package/src/network/default.ts +0 -120
  188. package/src/network/electrum.test.ts +0 -28
  189. package/src/network/getRelayFeeCache.test.ts +0 -15
  190. package/src/network/getRelayFeeCache.ts +0 -23
  191. package/src/network/index.ts +0 -14
  192. package/src/network/interface.ts +0 -80
  193. package/src/network/util.test.ts +0 -24
  194. package/src/network/util.ts +0 -30
  195. package/src/rate/ExchangeRate.test.headless.js +0 -35
  196. package/src/rate/ExchangeRate.test.ts +0 -51
  197. package/src/rate/ExchangeRate.ts +0 -142
  198. package/src/test/expect.ts +0 -59
  199. package/src/test/fetch.ts +0 -39
  200. package/src/test/json.test.ts +0 -13
  201. package/src/transaction/Wif.ts +0 -680
  202. package/src/transaction/allocateFee.test.ts +0 -298
  203. package/src/transaction/allocateFee.ts +0 -149
  204. package/src/util/amountInSatoshi.test.ts +0 -27
  205. package/src/util/amountInSatoshi.ts +0 -33
  206. package/src/util/asSendRequestObject.ts +0 -81
  207. package/src/util/base64.test.ts +0 -39
  208. package/src/util/base64.ts +0 -12
  209. package/src/util/browserNotSupported.ts +0 -7
  210. package/src/util/checkForEmptySeed.ts +0 -9
  211. package/src/util/checkUtxos.ts +0 -29
  212. package/src/util/checkWifNetwork.ts +0 -24
  213. package/src/util/convert.test.ts +0 -46
  214. package/src/util/convert.ts +0 -50
  215. package/src/util/delay.ts +0 -3
  216. package/src/util/deriveCashaddr.test.ts +0 -164
  217. package/src/util/deriveCashaddr.ts +0 -143
  218. package/src/util/deriveLockscript.ts +0 -16
  219. package/src/util/deriveNetwork.ts +0 -19
  220. package/src/util/derivePublicKeyHash.test.ts +0 -55
  221. package/src/util/derivePublicKeyHash.ts +0 -64
  222. package/src/util/floor.test.ts +0 -21
  223. package/src/util/floor.ts +0 -4
  224. package/src/util/getAddrsByXpubKey.test.ts +0 -115
  225. package/src/util/getAddrsByXpubKey.ts +0 -86
  226. package/src/util/getRuntimePlatform.test.headless.js +0 -40
  227. package/src/util/getRuntimePlatform.test.ts +0 -5
  228. package/src/util/getRuntimePlatform.ts +0 -31
  229. package/src/util/getUsdRate.ts +0 -5
  230. package/src/util/getXPubKey.ts +0 -39
  231. package/src/util/hash160.test.ts +0 -18
  232. package/src/util/hash160.ts +0 -12
  233. package/src/util/hd.ts +0 -16
  234. package/src/util/header.test.ts +0 -34
  235. package/src/util/header.ts +0 -26
  236. package/src/util/index.ts +0 -33
  237. package/src/util/randomBytes.ts +0 -13
  238. package/src/util/randomInt.test.ts +0 -15
  239. package/src/util/randomInt.ts +0 -4
  240. package/src/util/sanitizeAddress.ts +0 -10
  241. package/src/util/sanitizeUnit.ts +0 -11
  242. package/src/util/satoshiToAmount.test.ts +0 -6
  243. package/src/util/satoshiToAmount.ts +0 -33
  244. package/src/util/sumSendRequestAmounts.ts +0 -34
  245. package/src/util/sumUtxoValue.ts +0 -27
  246. package/src/util/transaction.ts +0 -10
  247. package/src/wallet/Base.ts +0 -1563
  248. package/src/wallet/Cashtokens.test.headless.js +0 -730
  249. package/src/wallet/Cashtokens.test.ts +0 -1411
  250. package/src/wallet/HDWallet.test.ts +0 -1086
  251. package/src/wallet/HDWallet.ts +0 -992
  252. package/src/wallet/Util.test.ts +0 -134
  253. package/src/wallet/Util.ts +0 -191
  254. package/src/wallet/WalletCache.test.ts +0 -45
  255. package/src/wallet/Watch.ts +0 -441
  256. package/src/wallet/Wif.bip39.test.ts +0 -48
  257. package/src/wallet/Wif.test.ts +0 -1189
  258. package/src/wallet/Wif.ts +0 -687
  259. package/src/wallet/Wif.watchOnly.test.ts +0 -58
  260. package/src/wallet/createWallet.ts +0 -238
  261. package/src/wallet/enum.ts +0 -18
  262. package/src/wallet/interface.ts +0 -102
  263. package/src/wallet/model.test.ts +0 -24
  264. package/src/wallet/model.ts +0 -352
  265. package/tsconfig.browser.json +0 -11
  266. package/tsconfig.json +0 -33
  267. package/webpack.config.cjs +0 -132
@@ -1,730 +0,0 @@
1
- const playwright = require("playwright");
2
- const PAGE_URL = "http://localhost:8080";
3
-
4
- describe(`Wallet should function in the browser`, () => {
5
- let browser;
6
- let page;
7
-
8
- /**
9
- * Create the browser and page context
10
- */
11
- beforeAll(async () => {
12
- browser = await playwright["chromium"].launch();
13
- page = await browser.newPage();
14
-
15
- if (!page) {
16
- throw new Error("Connection wasn't established");
17
- }
18
-
19
- // Open the page
20
- await page.goto(PAGE_URL, {
21
- waitUntil: "networkidle0",
22
- });
23
- });
24
-
25
- afterAll(async () => {
26
- await browser.close();
27
- });
28
-
29
- test(`Test fungible cashtoken genesis and sending`, async () => {
30
- await page.evaluate(async (id) => {
31
- const alice = await RegTestWallet.fromId(id);
32
- const bob = await RegTestWallet.newRandom();
33
- const genesisResponse = await alice.tokenGenesis({
34
- amount: 100n,
35
- });
36
-
37
- const category = genesisResponse.categories[0];
38
- const tokenBalance = await alice.getTokenBalance(category);
39
- expect(tokenBalance).toBe(100n);
40
- const tokenUtxos = await alice.getTokenUtxos(category);
41
- expect(tokenUtxos.length).toBe(1);
42
- const response = await alice.send([
43
- new TokenSendRequest({
44
- cashaddr: bob.cashaddr,
45
- amount: 25n,
46
- category: category,
47
- }),
48
- new TokenSendRequest({
49
- cashaddr: alice.cashaddr,
50
- amount: 25n,
51
- category: category,
52
- }),
53
- ]);
54
- const newTokenUtxos = await alice.getTokenUtxos(category);
55
- expect(newTokenUtxos.length).toBe(2);
56
- expect(await alice.getTokenBalance(category)).toBe(75n);
57
- expect(await bob.getTokenBalance(category)).toBe(25n);
58
- }, process.env.ALICE_ID);
59
- });
60
-
61
- test(`Test NFT cashtoken genesis and sending`, async () => {
62
- await page.evaluate(async (id) => {
63
- const alice = await RegTestWallet.fromId(id);
64
- const bob = await RegTestWallet.newRandom();
65
- const genesisResponse = await alice.tokenGenesis({
66
- cashaddr: alice.cashaddr,
67
- nft: {
68
- capability: NFTCapability.mutable,
69
- commitment: "abcd",
70
- },
71
- });
72
-
73
- const category = genesisResponse.categories[0];
74
- const tokenBalance = await alice.getTokenBalance(category);
75
- expect(tokenBalance).toBe(0n);
76
- const tokenUtxos = await alice.getTokenUtxos(category);
77
- expect(tokenUtxos.length).toBe(1);
78
- const response = await alice.send([
79
- new TokenSendRequest({
80
- cashaddr: bob.cashaddr,
81
- category: category,
82
- nft: {
83
- capability: NFTCapability.mutable,
84
- commitment: "abcd",
85
- },
86
- }),
87
- ]);
88
- expect(await alice.getTokenBalance(category)).toBe(0n);
89
- const newTokenUtxos = await alice.getTokenUtxos(category);
90
- expect(newTokenUtxos.length).toBe(0);
91
-
92
- expect(await bob.getTokenBalance(category)).toBe(0n);
93
- const bobTokenUtxos = await bob.getTokenUtxos(category);
94
- expect(bobTokenUtxos.length).toBe(1);
95
- expect(category).toEqual(response.categories[0]);
96
- expect(bobTokenUtxos[0].token?.nft?.commitment).toEqual("abcd");
97
- }, process.env.ALICE_ID);
98
- });
99
-
100
- test("Test immutable NFT cashtoken genesis and sending, error on mutation", async () => {
101
- await page.evaluate(async (id) => {
102
- const alice = await RegTestWallet.fromId(id);
103
- const genesisResponse = await alice.tokenGenesis({
104
- cashaddr: alice.cashaddr,
105
- nft: {
106
- capability: NFTCapability.none,
107
- commitment: "abcd",
108
- },
109
- });
110
-
111
- const category = genesisResponse.categories[0];
112
- const tokenBalance = await alice.getTokenBalance(category);
113
- expect(tokenBalance).toBe(0n);
114
- const tokenUtxos = await alice.getTokenUtxos(category);
115
- expect(tokenUtxos.length).toBe(1);
116
- await expect(
117
- alice.send([
118
- new TokenSendRequest({
119
- cashaddr: alice.cashaddr,
120
- category: category,
121
- nft: {
122
- capability: NFTCapability.none,
123
- commitment: "abcd02",
124
- },
125
- }),
126
- ])
127
- ).rejects.toThrow("No suitable token utxos available to send token");
128
- }, process.env.ALICE_ID);
129
- });
130
-
131
- test("Test mutable NFT cashtoken genesis and mutation", async () => {
132
- await page.evaluate(async (id) => {
133
- const alice = await RegTestWallet.fromId(id);
134
- const genesisResponse = await alice.tokenGenesis({
135
- cashaddr: alice.cashaddr,
136
- nft: {
137
- capability: NFTCapability.mutable,
138
- commitment: "abcd",
139
- },
140
- });
141
-
142
- const category = genesisResponse.categories[0];
143
- const tokenBalance = await alice.getTokenBalance(category);
144
- expect(tokenBalance).toBe(0n);
145
- const tokenUtxos = await alice.getTokenUtxos(category);
146
- expect(tokenUtxos.length).toBe(1);
147
- const response = await alice.send([
148
- new TokenSendRequest({
149
- cashaddr: alice.cashaddr,
150
- category: category,
151
- nft: {
152
- capability: NFTCapability.mutable,
153
- commitment: "abcd02",
154
- },
155
- }),
156
- ]);
157
- expect(await alice.getTokenBalance(category)).toBe(0n);
158
- const newTokenUtxos = await alice.getTokenUtxos(category);
159
- expect(newTokenUtxos.length).toBe(1);
160
- expect(category).toEqual(response.categories[0]);
161
- expect(newTokenUtxos[0].token?.nft?.commitment).toEqual("abcd02");
162
- }, process.env.ALICE_ID);
163
- });
164
-
165
- test("Test minting NFT cashtoken genesis and minting", async () => {
166
- await page.evaluate(async (id) => {
167
- const alice = await RegTestWallet.fromId(id);
168
- const genesisResponse = await alice.tokenGenesis({
169
- cashaddr: alice.cashaddr,
170
- nft: {
171
- capability: NFTCapability.minting,
172
- commitment: "abcd",
173
- },
174
- });
175
-
176
- const category = genesisResponse.categories[0];
177
- const tokenBalance = await alice.getTokenBalance(category);
178
- expect(tokenBalance).toBe(0n);
179
- const tokenUtxos = await alice.getTokenUtxos(category);
180
- expect(tokenUtxos.length).toBe(1);
181
- const response = await alice.tokenMint(category, [
182
- new TokenMintRequest({
183
- cashaddr: alice.cashaddr,
184
- nft: {
185
- capability: NFTCapability.none,
186
- commitment: "test",
187
- },
188
- }),
189
- new TokenMintRequest({
190
- cashaddr: alice.cashaddr,
191
- nft: {
192
- capability: NFTCapability.none,
193
- commitment: "test2",
194
- },
195
- }),
196
- ]);
197
- expect(await alice.getTokenBalance(category)).toBe(0n);
198
- const newTokenUtxos = await alice.getTokenUtxos(category);
199
- expect(newTokenUtxos.length).toBe(3);
200
- expect(category).toEqual(response.categories[0]);
201
- }, process.env.ALICE_ID);
202
- });
203
-
204
- test("Test minting NFT and optionally burning FT cashtoken", async () => {
205
- await page.evaluate(async (id) => {
206
- const alice = await RegTestWallet.fromId(id);
207
- const genesisResponse = await alice.tokenGenesis({
208
- cashaddr: alice.cashaddr,
209
- amount: 4n,
210
- nft: {
211
- capability: NFTCapability.minting,
212
- commitment: "abcd",
213
- },
214
- });
215
-
216
- const category = genesisResponse.categories[0];
217
- const tokenBalance = await alice.getTokenBalance(category);
218
- expect(tokenBalance).toBe(4n);
219
- const tokenUtxos = await alice.getTokenUtxos(category);
220
- expect(tokenUtxos.length).toBe(1);
221
-
222
- // mint 2 NFTs, defaults to amount reducing
223
- const response = await alice.tokenMint(
224
- category,
225
- [
226
- new TokenMintRequest({
227
- cashaddr: alice.cashaddr,
228
- nft: {
229
- capability: NFTCapability.none,
230
- commitment: "0a",
231
- },
232
- }),
233
- new TokenMintRequest({
234
- cashaddr: alice.cashaddr,
235
- nft: {
236
- capability: NFTCapability.none,
237
- commitment: "0b",
238
- },
239
- }),
240
- ],
241
- true
242
- );
243
- expect(await alice.getTokenBalance(category)).toBe(2n);
244
- const newTokenUtxos = await alice.getTokenUtxos(category);
245
- expect(newTokenUtxos.length).toBe(3);
246
- expect(category).toEqual(response.categories[0]);
247
-
248
- // mint 2 more NFTs without amount reducing
249
- const ftResponse = await alice.tokenMint(
250
- category,
251
- [
252
- new TokenMintRequest({
253
- cashaddr: alice.cashaddr,
254
- nft: {
255
- capability: NFTCapability.none,
256
- commitment: "0c",
257
- },
258
- }),
259
- new TokenMintRequest({
260
- cashaddr: alice.cashaddr,
261
- nft: {
262
- capability: NFTCapability.none,
263
- commitment: "0d",
264
- },
265
- }),
266
- ],
267
- false
268
- );
269
- expect(await alice.getTokenBalance(category)).toBe(2n);
270
- const ftTokenUtxos = await alice.getTokenUtxos(category);
271
- expect(ftTokenUtxos.length).toBe(5);
272
- expect(category).toEqual(ftResponse.categories[0]);
273
-
274
- // we are going to hit amount -1, when minting 3 more NFTs
275
- // check that it will stop at 0
276
- const ft2Response = await alice.tokenMint(
277
- category,
278
- [
279
- new TokenMintRequest({
280
- cashaddr: alice.cashaddr,
281
- nft: {
282
- capability: NFTCapability.none,
283
- commitment: "0a",
284
- },
285
- }),
286
- new TokenMintRequest({
287
- cashaddr: alice.cashaddr,
288
- nft: {
289
- capability: NFTCapability.none,
290
- commitment: "0a",
291
- },
292
- }),
293
- new TokenMintRequest({
294
- cashaddr: alice.cashaddr,
295
- nft: {
296
- capability: NFTCapability.none,
297
- commitment: "0a",
298
- },
299
- }),
300
- ],
301
- true
302
- );
303
- expect(await alice.getTokenBalance(category)).toBe(0n);
304
- const ft2TokenUtxos = await alice.getTokenUtxos(category);
305
- expect(ft2TokenUtxos.length).toBe(8);
306
- expect(category).toEqual(ft2Response.categories[0]);
307
- }, process.env.ALICE_ID);
308
- });
309
-
310
- test("Test explicit burning of FT", async () => {
311
- await page.evaluate(async (id) => {
312
- const alice = await RegTestWallet.fromId(id);
313
- const genesisResponse = await alice.tokenGenesis({
314
- cashaddr: alice.cashaddr,
315
- amount: 4n,
316
- });
317
-
318
- const category = genesisResponse.categories[0];
319
- const tokenBalance = await alice.getTokenBalance(category);
320
- expect(tokenBalance).toBe(4n);
321
- const tokenUtxos = await alice.getTokenUtxos(category);
322
- expect(tokenUtxos.length).toBe(1);
323
-
324
- // burn 5 FT
325
- const response = await alice.tokenBurn(
326
- {
327
- category: category,
328
- amount: 5n,
329
- },
330
- "burn"
331
- );
332
-
333
- const rawTx = await alice.provider.getRawTransaction(response.txId, true);
334
- expect(rawTx.vout.length).toEqual(3);
335
- expect(rawTx.vout[0].scriptPubKey.type).toEqual("nulldata");
336
- expect(rawTx.vout[0].scriptPubKey.hex).toContain(
337
- binToHex(utf8ToBin("burn"))
338
- );
339
- expect(await alice.getTokenBalance(category)).toBe(0n);
340
- const newTokenUtxos = await alice.getTokenUtxos(category);
341
- expect(newTokenUtxos.length).toBe(0);
342
- expect(category).toEqual(response.categories[0]);
343
- }, process.env.ALICE_ID);
344
- });
345
-
346
- test("Test explicit burning of FT+NFT", async () => {
347
- await page.evaluate(async (id) => {
348
- const alice = await RegTestWallet.fromId(id);
349
- const genesisResponse = await alice.tokenGenesis({
350
- cashaddr: alice.cashaddr,
351
- amount: 4n,
352
- nft: {
353
- capability: NFTCapability.minting,
354
- commitment: "abcd",
355
- },
356
- });
357
-
358
- const category = genesisResponse.categories[0];
359
- const tokenBalance = await alice.getTokenBalance(category);
360
- expect(tokenBalance).toBe(4n);
361
- const tokenUtxos = await alice.getTokenUtxos(category);
362
- expect(tokenUtxos.length).toBe(1);
363
-
364
- // burn 1 FT
365
- const response = await alice.tokenBurn(
366
- {
367
- category: category,
368
- amount: 1n,
369
- nft: {
370
- capability: NFTCapability.minting,
371
- commitment: "abcd",
372
- },
373
- },
374
- "burn"
375
- );
376
-
377
- const rawTx = await alice.provider.getRawTransaction(response.txId, true);
378
- expect(rawTx.vout.length).toEqual(3);
379
- expect(rawTx.vout[0].scriptPubKey.type).toEqual("nulldata");
380
- expect(rawTx.vout[0].scriptPubKey.hex).toContain(
381
- binToHex(utf8ToBin("burn"))
382
- );
383
- expect(await alice.getTokenBalance(category)).toBe(3n);
384
- expect((await alice.getAllTokenBalances())[category]).toBe(3n);
385
- const newTokenUtxos = await alice.getTokenUtxos(category);
386
- expect(newTokenUtxos.length).toBe(1);
387
- expect(await alice.getNftTokenBalance(category)).toBe(1);
388
- expect((await alice.getAllNftTokenBalances())[category || 0]).toBe(1);
389
- expect(category).toEqual(response.categories[0]);
390
-
391
- // burn the rest FTs
392
- const ftResponse = await alice.tokenBurn(
393
- {
394
- category: category,
395
- amount: 5n,
396
- nft: {
397
- capability: NFTCapability.minting,
398
- commitment: "abcd",
399
- },
400
- },
401
- "burn"
402
- );
403
- expect(await alice.getTokenBalance(category)).toBe(0n);
404
- const ftTokenUtxos = await alice.getTokenUtxos(category);
405
- expect(ftTokenUtxos.length).toBe(1);
406
- expect(category).toEqual(ftResponse.categories[0]);
407
-
408
- // burn the NFT too
409
- const nftResponse = await alice.tokenBurn(
410
- {
411
- category: category,
412
- nft: {
413
- capability: NFTCapability.minting,
414
- commitment: "abcd",
415
- },
416
- },
417
- "burn"
418
- );
419
- expect(await alice.getTokenBalance(category)).toBe(0n);
420
- expect((await alice.getAllTokenBalances())[category] || 0n).toBe(0n);
421
- const nftTokenUtxos = await alice.getTokenUtxos(category);
422
- expect(nftTokenUtxos.length).toBe(0);
423
- expect(category).toEqual(nftResponse.categories[0]);
424
- expect(await alice.getNftTokenBalance(category)).toBe(0);
425
- expect((await alice.getAllNftTokenBalances())[category] || 0n).toBe(0n);
426
- }, process.env.ALICE_ID);
427
- });
428
-
429
- test("Test cashtoken satoshi values and fee calculations", async () => {
430
- await page.evaluate(async (id) => {
431
- const alice = await RegTestWallet.fromId(id);
432
- const bob = await RegTestWallet.newRandom();
433
- const genesisResponse = await alice.tokenGenesis({
434
- amount: 100,
435
- value: 7000n,
436
- cashaddr: bob.cashaddr,
437
- });
438
-
439
- const category = genesisResponse.categories[0];
440
- const tokenBalance = await bob.getTokenBalance(category);
441
- expect(tokenBalance).toBe(100n);
442
- const tokenUtxos = await bob.getTokenUtxos(category);
443
- expect(tokenUtxos.length).toBe(1);
444
- expect(tokenUtxos[0].satoshis).toBe(7000n);
445
-
446
- // lower the token satoshi value
447
- const response = await bob.send([
448
- new TokenSendRequest({
449
- cashaddr: bob.cashaddr,
450
- amount: 100,
451
- category: category,
452
- value: 1500n,
453
- }),
454
- ]);
455
- let newTokenUtxos = await bob.getTokenUtxos(category);
456
- expect(newTokenUtxos.length).toBe(1);
457
- expect(await bob.getTokenBalance(category)).toBe(100n);
458
-
459
- let bobUtxos = await bob.getUtxos();
460
- expect(bobUtxos.length).toBe(2);
461
- expect(bobUtxos[0].satoshis).toBe(1500n);
462
- expect(bobUtxos[1].satoshis).toBe(5245n);
463
-
464
- // raise the token satoshi value
465
- await bob.send([
466
- new TokenSendRequest({
467
- cashaddr: bob.cashaddr,
468
- amount: 100,
469
- category: category,
470
- value: 3000n,
471
- }),
472
- ]);
473
- newTokenUtxos = await bob.getTokenUtxos(category);
474
- expect(newTokenUtxos.length).toBe(1);
475
- expect(await bob.getTokenBalance(category)).toBe(100n);
476
-
477
- bobUtxos = await bob.getUtxos();
478
- expect(bobUtxos.length).toBe(2);
479
- expect(bobUtxos[0].satoshis).toBe(3000n);
480
- expect(bobUtxos[1].satoshis).toBe(3349n);
481
- }, process.env.ALICE_ID);
482
- });
483
-
484
- test("Test cashtoken waiting and watching balance", async () => {
485
- await page.evaluate(async (id) => {
486
- const alice = await RegTestWallet.fromId(id);
487
- const bob = await RegTestWallet.newRandom();
488
-
489
- const genesisResponse = await alice.tokenGenesis({
490
- amount: 100,
491
- value: 5000n,
492
- nft: {
493
- capability: NFTCapability.minting,
494
- commitment: "test",
495
- },
496
- cashaddr: alice.cashaddr,
497
- });
498
-
499
- const category = genesisResponse.categories[0];
500
- const tokenBalance = await alice.getTokenBalance(category);
501
- expect(tokenBalance).toBe(100n);
502
- const tokenUtxos = await alice.getTokenUtxos(category);
503
- expect(tokenUtxos.length).toBe(1);
504
- expect(tokenUtxos[0].satoshis).toBe(5000n);
505
-
506
- let seenBalance = 0;
507
- setTimeout(
508
- () =>
509
- alice.send([
510
- new TokenSendRequest({
511
- cashaddr: bob.cashaddr,
512
- amount: 100,
513
- category: category,
514
- value: 1500n,
515
- nft: {
516
- capability: NFTCapability.minting,
517
- commitment: "test",
518
- },
519
- }),
520
- ]),
521
- 0
522
- );
523
-
524
- const cancel = await bob.watchTokenBalance(category, (balance) => {
525
- seenBalance = balance;
526
- });
527
-
528
- const [balance, _] = await Promise.all([
529
- bob.waitForTokenBalance(category, 100),
530
- delay(1000),
531
- ]);
532
-
533
- expect(balance).toBe(100n);
534
- expect(seenBalance).toBe(100n);
535
-
536
- await Promise.all([cancel(), delay(1000)]);
537
- }, process.env.ALICE_ID);
538
- });
539
-
540
- test("Should encode unsigned transactions", async () => {
541
- await page.evaluate(async (id) => {
542
- const binsAreEqual = (a, b) => {
543
- if (a.length !== b.length) {
544
- return false;
545
- }
546
- // eslint-disable-next-line functional/no-let, functional/no-loop-statement, no-plusplus
547
- for (let i = 0; i < a.length; i++) {
548
- if (a[i] !== b[i]) {
549
- return false;
550
- }
551
- }
552
- return true;
553
- };
554
-
555
- BigInt.prototype.toJSON = function () {
556
- const int = Number.parseInt(this.toString());
557
- return int ?? this.toString();
558
- };
559
-
560
- const aliceWallet = await RegTestWallet.fromId(id);
561
- const aliceWatchWallet = await RegTestWallet.watchOnly(
562
- aliceWallet.cashaddr
563
- );
564
-
565
- let category;
566
- {
567
- const aliceUtxos = await aliceWallet.getUtxos();
568
-
569
- const { unsignedTransaction, sourceOutputs, categories } =
570
- await aliceWatchWallet.tokenGenesis(
571
- {
572
- nft: {
573
- capability: "minting",
574
- commitment: "00",
575
- },
576
- },
577
- undefined,
578
- { buildUnsigned: true }
579
- );
580
- const encodedTransaction = hexToBin(unsignedTransaction);
581
- expect(encodedTransaction.length).toBeGreaterThan(0);
582
-
583
- // check transaction was not submitted
584
- expect(JSON.stringify(aliceUtxos)).toBe(
585
- JSON.stringify(await aliceWallet.getUtxos())
586
- );
587
-
588
- const decoded = libauth.decodeTransaction(encodedTransaction);
589
- if (typeof decoded === "string") {
590
- throw decoded;
591
- }
592
-
593
- expect(
594
- binsAreEqual(decoded.inputs[0].unlockingBytecode, Uint8Array.from([]))
595
- ).toBe(true);
596
- expect(sourceOutputs.length).toBe(decoded.inputs.length);
597
- expect(binToHex(decoded.outputs[0].token?.nft?.commitment)).toBe("00");
598
-
599
- const signed = await aliceWallet.signUnsignedTransaction(
600
- unsignedTransaction,
601
- sourceOutputs
602
- );
603
- await aliceWallet.submitTransaction(signed);
604
-
605
- category = categories[0];
606
-
607
- expect(await aliceWallet.getNftTokenBalance(category)).toBe(1);
608
- const tokenUtxos = await aliceWallet.getTokenUtxos(category);
609
- expect(tokenUtxos.length).toBe(1);
610
- expect(tokenUtxos[0].token?.nft?.capability).toBe(
611
- NFTCapability.minting
612
- );
613
- }
614
-
615
- {
616
- const aliceUtxos = await aliceWallet.getUtxos();
617
-
618
- const { unsignedTransaction, sourceOutputs } =
619
- await aliceWatchWallet.tokenMint(
620
- category,
621
- {
622
- nft: {
623
- capability: "none",
624
- commitment: "0a",
625
- },
626
- },
627
- undefined,
628
- { buildUnsigned: true }
629
- );
630
- const encodedTransaction = hexToBin(unsignedTransaction);
631
- expect(encodedTransaction.length).toBeGreaterThan(0);
632
-
633
- // check transaction was not submitted
634
- expect(JSON.stringify(aliceUtxos)).toBe(
635
- JSON.stringify(await aliceWallet.getUtxos())
636
- );
637
-
638
- const decoded = libauth.decodeTransaction(encodedTransaction);
639
- if (typeof decoded === "string") {
640
- throw decoded;
641
- }
642
-
643
- expect(
644
- binsAreEqual(decoded.inputs[0].unlockingBytecode, Uint8Array.from([]))
645
- ).toBe(true);
646
- expect(sourceOutputs.length).toBe(decoded.inputs.length);
647
- expect(binToHex(sourceOutputs[0].token?.nft?.commitment)).toBe("00");
648
- expect(binToHex(decoded.outputs[0].token?.nft?.commitment)).toBe("00");
649
- expect(binToHex(decoded.outputs[1].token?.nft?.commitment)).toBe("0a");
650
-
651
- const signed = await aliceWallet.signUnsignedTransaction(
652
- unsignedTransaction,
653
- sourceOutputs
654
- );
655
- await aliceWallet.submitTransaction(signed);
656
-
657
- expect(await aliceWallet.getNftTokenBalance(category)).toBe(2);
658
- const tokenUtxos = await aliceWallet.getTokenUtxos(category);
659
- expect(tokenUtxos.length).toBe(2);
660
- expect(
661
- tokenUtxos.filter(
662
- (val) => val.token?.nft?.capability === NFTCapability.minting
663
- ).length
664
- ).toBe(1);
665
- expect(
666
- tokenUtxos.filter(
667
- (val) => val.token?.nft?.capability === NFTCapability.none
668
- ).length
669
- ).toBe(1);
670
- }
671
-
672
- {
673
- const aliceUtxos = await aliceWallet.getUtxos();
674
-
675
- const { unsignedTransaction, sourceOutputs } =
676
- await aliceWatchWallet.send(
677
- [
678
- new TokenSendRequest({
679
- category: category,
680
- nft: {
681
- capability: "none",
682
- commitment: "0a",
683
- },
684
- cashaddr: aliceWallet.cashaddr,
685
- }),
686
- ],
687
- { buildUnsigned: true }
688
- );
689
- const encodedTransaction = hexToBin(unsignedTransaction);
690
- expect(encodedTransaction.length).toBeGreaterThan(0);
691
-
692
- // check transaction was not submitted
693
- expect(JSON.stringify(aliceUtxos)).toBe(
694
- JSON.stringify(await aliceWallet.getUtxos())
695
- );
696
-
697
- const decoded = libauth.decodeTransaction(encodedTransaction);
698
- if (typeof decoded === "string") {
699
- throw decoded;
700
- }
701
-
702
- expect(
703
- binsAreEqual(decoded.inputs[0].unlockingBytecode, Uint8Array.from([]))
704
- ).toBe(true);
705
- expect(sourceOutputs.length).toBe(decoded.inputs.length);
706
- expect(binToHex(sourceOutputs[0].token?.nft?.commitment)).toBe("0a");
707
- expect(binToHex(decoded.outputs[0].token?.nft?.commitment)).toBe("0a");
708
-
709
- const signed = await aliceWallet.signUnsignedTransaction(
710
- unsignedTransaction,
711
- sourceOutputs
712
- );
713
- await aliceWallet.submitTransaction(signed);
714
- expect(await aliceWallet.getNftTokenBalance(category)).toBe(2);
715
- const tokenUtxos = await aliceWallet.getTokenUtxos(category);
716
- expect(tokenUtxos.length).toBe(2);
717
- expect(
718
- tokenUtxos.filter(
719
- (val) => val.token?.nft?.capability === NFTCapability.minting
720
- ).length
721
- ).toBe(1);
722
- expect(
723
- tokenUtxos.filter(
724
- (val) => val.token?.nft?.capability === NFTCapability.none
725
- ).length
726
- ).toBe(1);
727
- }
728
- }, process.env.ALICE_ID);
729
- });
730
- });