mainnet-js 1.1.34-alpha.1 → 2.0.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 (121) hide show
  1. package/dist/index.html +1 -1
  2. package/dist/{mainnet-1.1.34-alpha.1.js → mainnet-2.0.0.js} +26 -338
  3. package/dist/module/db/SqlProvider.d.ts +2 -2
  4. package/dist/module/db/SqlProvider.d.ts.map +1 -1
  5. package/dist/module/db/SqlProvider.js +6 -24
  6. package/dist/module/db/SqlProvider.js.map +1 -1
  7. package/dist/module/index.d.ts +0 -3
  8. package/dist/module/index.d.ts.map +1 -1
  9. package/dist/module/index.js +3 -6
  10. package/dist/module/index.js.map +1 -1
  11. package/dist/module/transaction/Wif.d.ts +4 -8
  12. package/dist/module/transaction/Wif.d.ts.map +1 -1
  13. package/dist/module/transaction/Wif.js +6 -10
  14. package/dist/module/transaction/Wif.js.map +1 -1
  15. package/dist/module/util/deriveCashaddr.d.ts +1 -0
  16. package/dist/module/util/deriveCashaddr.d.ts.map +1 -1
  17. package/dist/module/util/deriveCashaddr.js +8 -1
  18. package/dist/module/util/deriveCashaddr.js.map +1 -1
  19. package/dist/module/wallet/Base.d.ts +1 -1
  20. package/dist/module/wallet/Base.js +1 -1
  21. package/dist/module/wallet/Bcmr.d.ts.map +1 -1
  22. package/dist/module/wallet/Bcmr.js +0 -1
  23. package/dist/module/wallet/Bcmr.js.map +1 -1
  24. package/dist/module/wallet/Util.d.ts +2 -2
  25. package/dist/module/wallet/Util.js +2 -2
  26. package/dist/module/wallet/Wif.d.ts +0 -28
  27. package/dist/module/wallet/Wif.d.ts.map +1 -1
  28. package/dist/module/wallet/Wif.js +2 -109
  29. package/dist/module/wallet/Wif.js.map +1 -1
  30. package/dist/module/wallet/createWallet.d.ts +0 -12
  31. package/dist/module/wallet/createWallet.d.ts.map +1 -1
  32. package/dist/module/wallet/createWallet.js +0 -43
  33. package/dist/module/wallet/createWallet.js.map +1 -1
  34. package/dist/module/wallet/interface.d.ts +0 -2
  35. package/dist/module/wallet/interface.d.ts.map +1 -1
  36. package/dist/module/webhook/Webhook.d.ts +1 -6
  37. package/dist/module/webhook/Webhook.d.ts.map +1 -1
  38. package/dist/module/webhook/Webhook.js +0 -4
  39. package/dist/module/webhook/Webhook.js.map +1 -1
  40. package/dist/module/webhook/index.d.ts +0 -1
  41. package/dist/module/webhook/index.d.ts.map +1 -1
  42. package/dist/module/webhook/index.js +0 -1
  43. package/dist/module/webhook/index.js.map +1 -1
  44. package/dist/module/webhook/interface.d.ts +0 -1
  45. package/dist/module/webhook/interface.d.ts.map +1 -1
  46. package/dist/tsconfig.tsbuildinfo +1 -1
  47. package/package.json +5 -10
  48. package/src/db/SqlProvider.test.ts +2 -18
  49. package/src/db/SqlProvider.ts +5 -26
  50. package/src/index.ts +3 -7
  51. package/src/transaction/Wif.ts +2 -19
  52. package/src/util/deriveCashaddr.test.ts +8 -0
  53. package/src/util/deriveCashaddr.ts +9 -0
  54. package/src/wallet/Base.ts +1 -1
  55. package/src/wallet/Bcmr.ts +0 -1
  56. package/src/wallet/Util.ts +2 -2
  57. package/src/wallet/Wif.test.ts +0 -23
  58. package/src/wallet/Wif.ts +2 -148
  59. package/src/wallet/createWallet.ts +0 -53
  60. package/src/wallet/interface.ts +0 -2
  61. package/src/webhook/Webhook.ts +4 -10
  62. package/src/webhook/index.ts +0 -1
  63. package/src/webhook/interface.ts +0 -1
  64. package/webpack.config.cjs +7 -7
  65. package/dist/module/slp/GsppProvider.d.ts +0 -55
  66. package/dist/module/slp/GsppProvider.d.ts.map +0 -1
  67. package/dist/module/slp/GsppProvider.js +0 -204
  68. package/dist/module/slp/GsppProvider.js.map +0 -1
  69. package/dist/module/slp/SlpDbProvider.d.ts +0 -52
  70. package/dist/module/slp/SlpDbProvider.d.ts.map +0 -1
  71. package/dist/module/slp/SlpDbProvider.js +0 -175
  72. package/dist/module/slp/SlpDbProvider.js.map +0 -1
  73. package/dist/module/slp/SlpDbTemplates.d.ts +0 -313
  74. package/dist/module/slp/SlpDbTemplates.d.ts.map +0 -1
  75. package/dist/module/slp/SlpDbTemplates.js +0 -375
  76. package/dist/module/slp/SlpDbTemplates.js.map +0 -1
  77. package/dist/module/slp/SlpLibAuth.d.ts +0 -210
  78. package/dist/module/slp/SlpLibAuth.d.ts.map +0 -1
  79. package/dist/module/slp/SlpLibAuth.js +0 -451
  80. package/dist/module/slp/SlpLibAuth.js.map +0 -1
  81. package/dist/module/slp/SlpProvider.d.ts +0 -24
  82. package/dist/module/slp/SlpProvider.d.ts.map +0 -1
  83. package/dist/module/slp/SlpProvider.js +0 -29
  84. package/dist/module/slp/SlpProvider.js.map +0 -1
  85. package/dist/module/slp/index.d.ts +0 -6
  86. package/dist/module/slp/index.d.ts.map +0 -1
  87. package/dist/module/slp/index.js +0 -5
  88. package/dist/module/slp/index.js.map +0 -1
  89. package/dist/module/slp/interface.d.ts +0 -114
  90. package/dist/module/slp/interface.d.ts.map +0 -1
  91. package/dist/module/slp/interface.js +0 -7
  92. package/dist/module/slp/interface.js.map +0 -1
  93. package/dist/module/util/bchaddr.d.ts +0 -2
  94. package/dist/module/util/bchaddr.d.ts.map +0 -1
  95. package/dist/module/util/bchaddr.js +0 -16
  96. package/dist/module/util/bchaddr.js.map +0 -1
  97. package/dist/module/wallet/Slp.d.ts +0 -431
  98. package/dist/module/wallet/Slp.d.ts.map +0 -1
  99. package/dist/module/wallet/Slp.js +0 -770
  100. package/dist/module/wallet/Slp.js.map +0 -1
  101. package/dist/module/webhook/WebhookSlp.d.ts +0 -15
  102. package/dist/module/webhook/WebhookSlp.d.ts.map +0 -1
  103. package/dist/module/webhook/WebhookSlp.js +0 -100
  104. package/dist/module/webhook/WebhookSlp.js.map +0 -1
  105. package/src/slp/GsppProvider.test.ts +0 -40
  106. package/src/slp/GsppProvider.ts +0 -329
  107. package/src/slp/SlpDbProvider.test.ts +0 -27
  108. package/src/slp/SlpDbProvider.ts +0 -291
  109. package/src/slp/SlpDbTemplates.ts +0 -400
  110. package/src/slp/SlpLibAuth.test.ts +0 -162
  111. package/src/slp/SlpLibAuth.ts +0 -532
  112. package/src/slp/SlpProvider.ts +0 -100
  113. package/src/slp/index.ts +0 -6
  114. package/src/slp/interface.ts +0 -128
  115. package/src/util/bchaddr.test.ts +0 -27
  116. package/src/util/bchaddr.ts +0 -27
  117. package/src/wallet/Slp.test.headless.js +0 -120
  118. package/src/wallet/Slp.test.ts +0 -1000
  119. package/src/wallet/Slp.ts +0 -1014
  120. package/src/webhook/WebhookSlp.test.ts +0 -288
  121. package/src/webhook/WebhookSlp.ts +0 -123
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "url": "https://github.com/mainnet-cash/mainnet-js/issues"
10
10
  },
11
11
  "name": "mainnet-js",
12
- "version": "1.1.34-alpha.1",
12
+ "version": "2.0.0",
13
13
  "homepage": "https://mainnet.cash",
14
14
  "module": "dist/module/index.js",
15
15
  "browser": {
@@ -40,24 +40,19 @@
40
40
  "dependencies": {
41
41
  "@bitauth/libauth": "^2.0.0-alpha.8",
42
42
  "axios": "^0.21.1",
43
- "bchaddrjs-slp": "^0.2.12",
44
- "bignumber": "^1.1.0",
45
- "bignumber.js": "^9.0.1",
46
43
  "bip39": "^3.0.3",
47
44
  "buffer": "^6.0.3",
48
- "cashaddrjs": "^0.4.4",
49
45
  "electrum-cash": "^2.0.10",
50
46
  "events": "^3.2.0",
51
47
  "eventsource": "^1.0.7",
52
- "qrcode-svg": "1.1.0",
53
- "slp-parser": "^0.0.4"
48
+ "qrcode-svg": "1.1.0"
54
49
  },
55
50
  "devDependencies": {
56
- "fake-indexeddb": "^3.1.2"
51
+ "fake-indexeddb": "^3.1.2",
52
+ "@types/pg": "8.6.0",
53
+ "@types/pg-format": "^1.0.1"
57
54
  },
58
55
  "optionalDependencies": {
59
- "@types/pg": "8.6.0",
60
- "@types/pg-format": "^1.0.1",
61
56
  "dexie": "3.2.2",
62
57
  "dotenv": "^10.0.0",
63
58
  "node-postgres": "^0.6.2",
@@ -103,21 +103,6 @@ test("Should handle basic sql injection", async () => {
103
103
  sh.close();
104
104
  });
105
105
 
106
- test("Should fail registering SLP webhook without tokenId", async () => {
107
- let db = new SqlProvider(`regtest ${Math.random()}`);
108
- await db.init();
109
- await expect(
110
- db.addWebhook({
111
- cashaddr: "",
112
- url: "https://example.com/fail",
113
- type: WebhookType.slpTransactionIn,
114
- recurrence: WebhookRecurrence.recurrent,
115
- })
116
- ).rejects.toThrow();
117
-
118
- db.close();
119
- });
120
-
121
106
  test("Test wallet database name regression", async () => {
122
107
  const name = `test ${Math.random()}`;
123
108
 
@@ -279,14 +264,13 @@ test("Should not have ssl property when unconfigured", async () => {
279
264
  test("Store and retrieve faucet queue items", async () => {
280
265
  let db = new SqlProvider(`testnet ${Math.random()}`);
281
266
  await db.init();
282
- await db.addFaucetQueueItem("0x00", "", "0x0a");
283
- await db.addFaucetQueueItem("0x01", "", "0x0b");
267
+ await db.addFaucetQueueItem("0x00", "0x0a");
268
+ await db.addFaucetQueueItem("0x01", "0x0b");
284
269
 
285
270
  await db.beginTransaction();
286
271
  const items = await db.getFaucetQueue();
287
272
  expect(items.length).toBe(2);
288
273
  expect(items[0].address).toBe("0x00");
289
- expect(items[0].token).toBe("");
290
274
  expect(items[0].value).toBe("0x0a");
291
275
  await db.deleteFaucetQueueItems(items);
292
276
  await db.commitTransaction();
@@ -3,7 +3,6 @@ import { sslConfigI, WalletI, FaucetQueueItemI } from "./interface.js";
3
3
  import { TxI } from "../interface.js";
4
4
  import { Webhook, WebhookRecurrence, WebhookType } from "../webhook/Webhook.js";
5
5
  import { RegisterWebhookParams } from "../webhook/interface.js";
6
- import { isCashAddress } from "../util/bchaddr.js";
7
6
  import { getSslConfig } from "./util.js";
8
7
  import parseDbUrl from "parse-database-url";
9
8
  import pg from "pg";
@@ -64,7 +63,6 @@ export default class SqlProvider implements StorageProvider {
64
63
  "status TEXT," +
65
64
  "tx_seen JSON," +
66
65
  "last_height INTEGER," +
67
- "token_id TEXT," +
68
66
  "expires_at TIMESTAMPTZ" +
69
67
  ");",
70
68
  this.webhookTable
@@ -75,7 +73,6 @@ export default class SqlProvider implements StorageProvider {
75
73
  "CREATE TABLE IF NOT EXISTS %I (" +
76
74
  "id SERIAL PRIMARY KEY," +
77
75
  "address TEXT," +
78
- "token TEXT," +
79
76
  "value TEXT" +
80
77
  ");",
81
78
  this.faucetQueueTable
@@ -144,19 +141,8 @@ export default class SqlProvider implements StorageProvider {
144
141
  }
145
142
 
146
143
  public async webhookFromDb(hook: Webhook) {
147
- // map tokenId field from postgres
148
- hook.tokenId = (hook as any).token_id;
149
- delete (hook as any).token_id;
150
-
151
- if (hook.type.indexOf("slp") === 0) {
152
- const { WebhookSlp } = await import("../webhook/WebhookSlp.js");
153
- return new WebhookSlp(hook);
154
- } else if (isCashAddress(hook.cashaddr)) {
155
- const { WebhookBch } = await import("../webhook/WebhookBch.js");
156
- return new WebhookBch(hook);
157
- }
158
-
159
- throw new Error(`Unsupported or incorrect hook address ${hook.cashaddr}`);
144
+ const { WebhookBch } = await import("../webhook/WebhookBch.js");
145
+ return new WebhookBch(hook);
160
146
  }
161
147
 
162
148
  public async addWebhook(params: RegisterWebhookParams): Promise<Webhook> {
@@ -170,17 +156,12 @@ export default class SqlProvider implements StorageProvider {
170
156
  params.duration_sec = params.duration_sec || expireTimeout;
171
157
  params.duration_sec =
172
158
  params.duration_sec > expireTimeout ? expireTimeout : params.duration_sec;
173
- params.tokenId = params.tokenId || "";
174
-
175
- if (params.type.indexOf("slp") === 0 && !params.tokenId) {
176
- throw new Error("'tokenId' parameter is required for SLP webhooks");
177
- }
178
159
 
179
160
  const expires_at = new Date(
180
161
  new Date().getTime() + params.duration_sec * 1000
181
162
  );
182
163
  let text = this.formatter(
183
- "INSERT into %I (cashaddr,type,recurrence,url,status,tx_seen,last_height,token_id,expires_at) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING *;",
164
+ "INSERT into %I (cashaddr,type,recurrence,url,status,tx_seen,last_height,expires_at) VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING *;",
184
165
  this.webhookTable
185
166
  );
186
167
 
@@ -192,7 +173,6 @@ export default class SqlProvider implements StorageProvider {
192
173
  "",
193
174
  "[]",
194
175
  0,
195
- params.tokenId,
196
176
  expires_at.toISOString(),
197
177
  ]);
198
178
  const hook = await this.webhookFromDb(result.rows[0]);
@@ -266,14 +246,13 @@ export default class SqlProvider implements StorageProvider {
266
246
 
267
247
  public async addFaucetQueueItem(
268
248
  address: string,
269
- tokenId: string,
270
249
  value: string
271
250
  ): Promise<boolean> {
272
251
  let text = this.formatter(
273
- "INSERT into %I (address,token,value) VALUES ($1, $2, $3);",
252
+ "INSERT into %I (address,value) VALUES ($1, $2);",
274
253
  this.faucetQueueTable
275
254
  );
276
- return await this.db.query(text, [address, tokenId, value]);
255
+ return await this.db.query(text, [address, value]);
277
256
  }
278
257
 
279
258
  public async getFaucetQueue(): Promise<Array<FaucetQueueItemI>> {
package/src/index.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export * from "./db/index.js";
2
2
  export * from "./mine/index.js";
3
- export * from "./slp/index.js";
4
3
  export * from "./test/expect.js";
5
4
  export * from "./test/axios.js";
6
5
  export * from "./webhook/index.js";
@@ -50,9 +49,6 @@ export {
50
49
  } from "./message/interface.js";
51
50
  export { WalletRequestI, WalletResponseI } from "./wallet/interface.js";
52
51
 
53
- // TODO move this up to util (Mainnet) ?
54
- export * from "./util/bchaddr.js";
55
-
56
- export function cube(x: number) {
57
- return x * x * x;
58
- }
52
+ // export function cube(x: number) {
53
+ // return x * x * x;
54
+ // }
@@ -39,7 +39,6 @@ export async function buildP2pkhNonHdTransaction({
39
39
  sourceAddress,
40
40
  fee = 0,
41
41
  discardChange = false,
42
- slpOutputs = [],
43
42
  feePaidBy = FeePaidByEnum.change,
44
43
  changeAddress = "",
45
44
  }: {
@@ -49,7 +48,6 @@ export async function buildP2pkhNonHdTransaction({
49
48
  sourceAddress: string;
50
49
  fee?: number;
51
50
  discardChange?: boolean;
52
- slpOutputs?: Output[];
53
51
  feePaidBy?: FeePaidByEnum;
54
52
  changeAddress?: string;
55
53
  }) {
@@ -101,7 +99,7 @@ export async function buildP2pkhNonHdTransaction({
101
99
  const result = generateTransaction({
102
100
  inputs: preparedInputs,
103
101
  locktime: 0,
104
- outputs: [...slpOutputs, ...lockedOutputs],
102
+ outputs: lockedOutputs,
105
103
  version: 2,
106
104
  });
107
105
 
@@ -429,7 +427,6 @@ export async function getFeeAmountSimple({
429
427
  utxos,
430
428
  sendRequests,
431
429
  relayFeePerByteInSatoshi,
432
- slpOutputs,
433
430
  discardChange,
434
431
  }: {
435
432
  utxos: UtxoI[];
@@ -437,7 +434,6 @@ export async function getFeeAmountSimple({
437
434
  privateKey: Uint8Array;
438
435
  sourceAddress: string;
439
436
  relayFeePerByteInSatoshi: number;
440
- slpOutputs: Output[];
441
437
  feePaidBy: FeePaidByEnum;
442
438
  discardChange?: boolean;
443
439
  }) {
@@ -479,15 +475,8 @@ export async function getFeeAmountSimple({
479
475
  const outputTotalSize =
480
476
  sendRequests.reduce((prev, curr) => prev + outputSize(curr), 0) +
481
477
  (discardChange ? 0 : outputSizeP2pkh);
482
- const slpTotalSize = slpOutputs.reduce(
483
- (prev, curr) => prev + curr.lockingBytecode.length,
484
- 0
485
- );
486
478
 
487
- return (
488
- (inputTotalSize + outputTotalSize + slpTotalSize + 16) *
489
- relayFeePerByteInSatoshi
490
- );
479
+ return (inputTotalSize + outputTotalSize + 16) * relayFeePerByteInSatoshi;
491
480
  }
492
481
 
493
482
  // precise fee estimation
@@ -497,7 +486,6 @@ export async function getFeeAmount({
497
486
  privateKey,
498
487
  sourceAddress,
499
488
  relayFeePerByteInSatoshi,
500
- slpOutputs,
501
489
  feePaidBy,
502
490
  discardChange,
503
491
  }: {
@@ -506,7 +494,6 @@ export async function getFeeAmount({
506
494
  privateKey: Uint8Array;
507
495
  sourceAddress: string;
508
496
  relayFeePerByteInSatoshi: number;
509
- slpOutputs: Output[];
510
497
  feePaidBy: FeePaidByEnum;
511
498
  discardChange?: boolean;
512
499
  }) {
@@ -521,7 +508,6 @@ export async function getFeeAmount({
521
508
  sourceAddress,
522
509
  fee: 0, //DUST_UTXO_THRESHOLD
523
510
  discardChange: discardChange ?? false,
524
- slpOutputs,
525
511
  feePaidBy,
526
512
  changeAddress: "",
527
513
  });
@@ -542,7 +528,6 @@ export async function buildEncodedTransaction({
542
528
  sourceAddress,
543
529
  fee = 0,
544
530
  discardChange = false,
545
- slpOutputs = [],
546
531
  feePaidBy = FeePaidByEnum.change,
547
532
  changeAddress = "",
548
533
  buildUnsigned = false,
@@ -553,7 +538,6 @@ export async function buildEncodedTransaction({
553
538
  sourceAddress: string;
554
539
  fee?: number;
555
540
  discardChange?: boolean;
556
- slpOutputs?: Output[];
557
541
  feePaidBy?: FeePaidByEnum;
558
542
  changeAddress?: string;
559
543
  buildUnsigned?: boolean;
@@ -565,7 +549,6 @@ export async function buildEncodedTransaction({
565
549
  sourceAddress,
566
550
  fee,
567
551
  discardChange,
568
- slpOutputs,
569
552
  feePaidBy,
570
553
  changeAddress,
571
554
  });
@@ -3,6 +3,7 @@ import {
3
3
  deriveCashaddr,
4
4
  deriveTokenaddr,
5
5
  isTokenaddr,
6
+ isValidAddress,
6
7
  toCashaddr,
7
8
  toTokenaddr,
8
9
  } from "./deriveCashaddr";
@@ -41,3 +42,10 @@ test("Test address conversion", async () => {
41
42
  expect(isTokenaddr(wallet.cashaddr!)).toBe(false);
42
43
  expect(isTokenaddr(wallet.tokenaddr!)).toBe(true);
43
44
  });
45
+
46
+ test("Test isValidAddress", async () => {
47
+ const wallet = await RegTestWallet.watchOnly(process.env.ADDRESS!);
48
+ expect(isValidAddress(wallet.cashaddr!)).toBe(true);
49
+ expect(isValidAddress(wallet.tokenaddr!)).toBe(true);
50
+ expect(isValidAddress("asdf")).toBe(false);
51
+ });
@@ -13,6 +13,15 @@ import {
13
13
 
14
14
  import { hash160 } from "./hash160.js";
15
15
 
16
+ export function isValidAddress(cashaddr: string): boolean {
17
+ const result = decodeCashAddress(cashaddr);
18
+ if (typeof result === "string") {
19
+ return false;
20
+ }
21
+
22
+ return true;
23
+ }
24
+
16
25
  export function deriveCashaddr(
17
26
  privateKey: Uint8Array,
18
27
  networkPrefix: CashAddressNetworkPrefix
@@ -153,7 +153,7 @@ export class BaseWallet implements WalletI {
153
153
  * such kind of wallet does not have a private key and is unable to spend any funds
154
154
  * however it still allows to use many utility functions such as getting and watching balance, etc.
155
155
  *
156
- * @param address cashaddress, token aware cashaddress or slpaddress of a wallet
156
+ * @param address cashaddress, token aware cashaddress of a wallet
157
157
  *
158
158
  * @returns instantiated wallet
159
159
  */
@@ -470,7 +470,6 @@ export class BCMR {
470
470
  );
471
471
 
472
472
  const result: AuthChain = [];
473
- console.log(response.data)
474
473
  const migrations =
475
474
  response.data.data.transaction[0]?.authchains[0].migrations;
476
475
  if (!migrations) {
@@ -166,7 +166,7 @@ export class Util {
166
166
 
167
167
  //#region Specific wallet classes
168
168
  /**
169
- * Class to manage an slp enabled testnet wallet.
169
+ * Class to manage a testnet wallet.
170
170
  */
171
171
  export class TestNetUtil extends Util {
172
172
  static get walletType() {
@@ -175,7 +175,7 @@ export class TestNetUtil extends Util {
175
175
  }
176
176
 
177
177
  /**
178
- * Class to manage an slp enabled regtest wallet.
178
+ * Class to manage a regtest wallet.
179
179
  */
180
180
  export class RegTestUtil extends Util {
181
181
  static get walletType() {
@@ -887,29 +887,6 @@ describe(`Wallet subscriptions`, () => {
887
887
  delay(3000);
888
888
  expect(response.balance!.sat!).toBe(0);
889
889
  });
890
-
891
- test.skip("Should get testnet slp tokens and send them back", async () => {
892
- let aliceWif = `${process.env.ALICE_TESTNET_WALLET_ID!}`;
893
- let aliceWallet = await TestNetWallet.fromId(aliceWif);
894
-
895
- const wallet = (await TestNetWallet.newRandom()) as TestNetWallet;
896
-
897
- // send bob some bch gas to enable him to send slp
898
- await aliceWallet
899
- .slpAware()
900
- .send([{ cashaddr: wallet.cashaddr!, value: 5000, unit: "sat" }]);
901
-
902
- const txid = await wallet.getTestnetSlp("MNC");
903
- expect(txid.length).toBe(64);
904
- let balance = await wallet.slp.getBalance("MNC");
905
- expect(balance[0].value.toNumber()).toBe(10);
906
-
907
- const tokenId = balance[0].tokenId;
908
- const response = await wallet.returnTestnetSlp(tokenId);
909
- expect(response.balance).toBe(0);
910
-
911
- await wallet.slpAware(false).sendMax(aliceWallet.cashaddr!);
912
- });
913
890
  });
914
891
 
915
892
  describe(`Wallet extrema behavior regression testing`, () => {
package/src/wallet/Wif.ts CHANGED
@@ -77,20 +77,7 @@ import { sumTokenAmounts, sumUtxoValue } from "../util/sumUtxoValue.js";
77
77
  import { sumSendRequestAmounts } from "../util/sumSendRequestAmounts.js";
78
78
  import { ElectrumRawTransaction } from "../network/interface.js";
79
79
  import { getRelayFeeCache } from "../network/getRelayFeeCache.js";
80
- import {
81
- RegTestSlp,
82
- RegTestWatchSlp,
83
- RegTestWifSlp,
84
- Slp,
85
- TestNetSlp,
86
- TestNetWatchSlp,
87
- TestNetWifSlp,
88
- WatchSlp,
89
- WifSlp,
90
- } from "./Slp.js";
91
80
  import axios from "axios";
92
- import { SlpSendResponse } from "../slp/interface.js";
93
- import { toCashAddress } from "../util/bchaddr.js";
94
81
  import {
95
82
  RegTestUtil,
96
83
  RegTestWatchUtil,
@@ -137,28 +124,11 @@ export class Wallet extends BaseWallet {
137
124
  publicKey?: Uint8Array;
138
125
  publicKeyHash?: Uint8Array;
139
126
  networkPrefix: CashAddressNetworkPrefix;
140
- _slp?: Slp;
141
- _slpAware: boolean = false; // a flag which activates utxo checking against an external slp indexer
142
127
  _slpSemiAware: boolean = false; // a flag which requires an utxo to have more than 546 sats to be spendable and counted in the balance
143
128
  _util?: Util;
144
129
  static signedMessage: SignedMessageI = new SignedMessage();
145
130
 
146
131
  //#region Accessors
147
- // interface to slp functions. see Slp.ts
148
- public get slp() {
149
- if (!this._slp) {
150
- this._slp = new Slp(this);
151
- this._slpAware = true;
152
- }
153
-
154
- return this._slp;
155
- }
156
-
157
- // interface to slp functions. see Slp.ts
158
- public static get slp() {
159
- return Slp;
160
- }
161
-
162
132
  // interface to util functions. see Util.ts
163
133
  public get util() {
164
134
  if (!this._util) {
@@ -173,11 +143,6 @@ export class Wallet extends BaseWallet {
173
143
  return Util;
174
144
  }
175
145
 
176
- public slpAware(value: boolean = true): Wallet {
177
- this._slpAware = value;
178
- return this;
179
- }
180
-
181
146
  public slpSemiAware(value: boolean = true): Wallet {
182
147
  this._slpSemiAware = value;
183
148
  return this;
@@ -346,23 +311,6 @@ export class Wallet extends BaseWallet {
346
311
  address
347
312
  ) as InstanceType<T>;
348
313
  }
349
-
350
- /**
351
- * fromSlpaddr - create an SLP aware watch-only wallet in the network derived from the address
352
- *
353
- * such kind of wallet does not have a private key and is unable to spend any funds
354
- * however it still allows to use many utility functions such as getting and watching balance, etc.
355
- *
356
- * @param address slpaddress of a wallet
357
- *
358
- * @returns instantiated wallet
359
- */
360
- public static async fromSlpaddr<T extends typeof Wallet>(
361
- this: T,
362
- address: string
363
- ): Promise<InstanceType<T>> {
364
- return this.fromCashaddr(toCashAddress(address)) as InstanceType<T>;
365
- }
366
314
  //#endregion Constructors and Statics
367
315
 
368
316
  //#region Protected implementations
@@ -639,18 +587,7 @@ export class Wallet extends BaseWallet {
639
587
  address = this.cashaddr!;
640
588
  }
641
589
 
642
- if (this._slpAware) {
643
- const [bchUtxos, slpOutpoints] = await Promise.all([
644
- this.provider!.getUtxos(address),
645
- this.slp.getSlpOutpoints(),
646
- ]);
647
- return bchUtxos.filter(
648
- (bchutxo) =>
649
- slpOutpoints.findIndex(
650
- (slpOutpoint) => `${bchutxo.txid}:${bchutxo.vout}` === slpOutpoint
651
- ) === -1
652
- );
653
- } else if (this._slpSemiAware) {
590
+ if (this._slpSemiAware) {
654
591
  const bchUtxos: UtxoI[] = await this.provider!.getUtxos(address);
655
592
  return bchUtxos.filter(
656
593
  (bchutxo) => bchutxo.satoshis > DUST_UTXO_THRESHOLD
@@ -866,10 +803,6 @@ export class Wallet extends BaseWallet {
866
803
  throw Error("attempted to send without a cashaddr");
867
804
  }
868
805
 
869
- if (params.options && params.options.slpAware) {
870
- this._slpAware = true;
871
- }
872
-
873
806
  if (params.options && params.options.slpSemiAware) {
874
807
  this._slpSemiAware = true;
875
808
  }
@@ -920,7 +853,6 @@ export class Wallet extends BaseWallet {
920
853
  privateKey: this.privateKey ?? Uint8Array.from([]),
921
854
  sourceAddress: this.cashaddr!,
922
855
  relayFeePerByteInSatoshi: relayFeePerByteInSatoshi,
923
- slpOutputs: [],
924
856
  feePaidBy: feePaidBy,
925
857
  });
926
858
  const spendableAmount = sumUtxoValue(fundingUtxos);
@@ -1097,10 +1029,6 @@ export class Wallet extends BaseWallet {
1097
1029
  throw Error("attempted to send without a cashaddr");
1098
1030
  }
1099
1031
 
1100
- if (options && options.slpAware) {
1101
- this._slpAware = true;
1102
- }
1103
-
1104
1032
  if (options && options.slpSemiAware) {
1105
1033
  this._slpSemiAware = true;
1106
1034
  }
@@ -1238,7 +1166,6 @@ export class Wallet extends BaseWallet {
1238
1166
  privateKey: this.privateKey ?? Uint8Array.from([]),
1239
1167
  sourceAddress: this.cashaddr!,
1240
1168
  relayFeePerByteInSatoshi: relayFeePerByteInSatoshi,
1241
- slpOutputs: [],
1242
1169
  feePaidBy: feePaidBy,
1243
1170
  });
1244
1171
 
@@ -1262,7 +1189,6 @@ export class Wallet extends BaseWallet {
1262
1189
  privateKey: this.privateKey ?? Uint8Array.from([]),
1263
1190
  sourceAddress: this.cashaddr!,
1264
1191
  relayFeePerByteInSatoshi: relayFeePerByteInSatoshi,
1265
- slpOutputs: [],
1266
1192
  feePaidBy: feePaidBy,
1267
1193
  });
1268
1194
  const { encodedTransaction, sourceOutputs } = await buildEncodedTransaction(
@@ -1273,7 +1199,6 @@ export class Wallet extends BaseWallet {
1273
1199
  sourceAddress: this.cashaddr!,
1274
1200
  fee,
1275
1201
  discardChange,
1276
- slpOutputs: [],
1277
1202
  feePaidBy,
1278
1203
  changeAddress,
1279
1204
  buildUnsigned: options?.buildUnsigned === true,
@@ -1857,38 +1782,7 @@ export class TestNetWallet extends Wallet {
1857
1782
  `${TestNetWallet.faucetServer}/faucet/get_addresses`
1858
1783
  );
1859
1784
  const data = response.data;
1860
- return await this.slpAware().sendMax(data.bchtest);
1861
- } catch (e: any) {
1862
- console.log(e);
1863
- console.log(e.response ? e.response.data : "");
1864
- throw e;
1865
- }
1866
- }
1867
-
1868
- // will receive 10 testnet tokens, rate limits apply
1869
- async getTestnetSlp(tokenId: string): Promise<string> {
1870
- try {
1871
- const response = await axios.post(
1872
- `${TestNetWallet.faucetServer}/faucet/get_testnet_slp`,
1873
- { slpaddr: this.slp.slpaddr, tokenId: tokenId }
1874
- );
1875
- const data = response.data;
1876
- return data.txId;
1877
- } catch (e) {
1878
- //console.log(e);
1879
- //console.log(e.response ? e.response.data : "");
1880
- throw e;
1881
- }
1882
- }
1883
-
1884
- // be nice and return them back
1885
- async returnTestnetSlp(tokenId: string): Promise<SlpSendResponse> {
1886
- try {
1887
- const response = await axios.post(
1888
- `${TestNetWallet.faucetServer}/faucet/get_addresses`
1889
- );
1890
- const data = response.data;
1891
- return await this.slp.sendMax(data.slptest, tokenId);
1785
+ return await this.sendMax(data.bchtest);
1892
1786
  } catch (e: any) {
1893
1787
  console.log(e);
1894
1788
  console.log(e.response ? e.response.data : "");
@@ -1896,11 +1790,6 @@ export class TestNetWallet extends Wallet {
1896
1790
  }
1897
1791
  }
1898
1792
 
1899
- // interface to static slp functions. see Slp.ts
1900
- public static get slp() {
1901
- return TestNetSlp;
1902
- }
1903
-
1904
1793
  // interface to static util functions. see Util.ts
1905
1794
  public static get util() {
1906
1795
  return TestNetUtil;
@@ -1916,11 +1805,6 @@ export class RegTestWallet extends Wallet {
1916
1805
  super(name, NetworkType.Regtest);
1917
1806
  }
1918
1807
 
1919
- // interface to static slp functions. see Slp.ts
1920
- public static get slp() {
1921
- return RegTestSlp;
1922
- }
1923
-
1924
1808
  // interface to static util functions. see Util.ts
1925
1809
  public static get util() {
1926
1810
  return RegTestUtil;
@@ -1937,11 +1821,6 @@ export class WifWallet extends Wallet {
1937
1821
  super(name, NetworkType.Mainnet, WalletTypeEnum.Wif);
1938
1822
  }
1939
1823
 
1940
- // interface to static slp functions. see Slp.ts
1941
- public static get slp() {
1942
- return WifSlp;
1943
- }
1944
-
1945
1824
  // interface to static util functions. see Util.ts
1946
1825
  public static get util() {
1947
1826
  return WifUtil;
@@ -1958,11 +1837,6 @@ export class TestNetWifWallet extends Wallet {
1958
1837
  super(name, NetworkType.Testnet, WalletTypeEnum.Wif);
1959
1838
  }
1960
1839
 
1961
- // interface to static slp functions. see Slp.ts
1962
- public static get slp() {
1963
- return TestNetWifSlp;
1964
- }
1965
-
1966
1840
  // interface to static util functions. see Util.ts
1967
1841
  public static get util() {
1968
1842
  return TestNetWifUtil;
@@ -1979,11 +1853,6 @@ export class RegTestWifWallet extends Wallet {
1979
1853
  super(name, NetworkType.Regtest, WalletTypeEnum.Wif);
1980
1854
  }
1981
1855
 
1982
- // interface to static slp functions. see Slp.ts
1983
- public static get slp() {
1984
- return RegTestWifSlp;
1985
- }
1986
-
1987
1856
  // interface to static util functions. see Util.ts
1988
1857
  public static get util() {
1989
1858
  return RegTestWifUtil;
@@ -2000,11 +1869,6 @@ export class WatchWallet extends Wallet {
2000
1869
  super(name, NetworkType.Mainnet, WalletTypeEnum.Watch);
2001
1870
  }
2002
1871
 
2003
- // interface to static slp functions. see Slp.ts
2004
- public static get slp() {
2005
- return WatchSlp;
2006
- }
2007
-
2008
1872
  // interface to static util functions. see Util.ts
2009
1873
  public static get util() {
2010
1874
  return WatchUtil;
@@ -2021,11 +1885,6 @@ export class TestNetWatchWallet extends Wallet {
2021
1885
  super(name, NetworkType.Testnet, WalletTypeEnum.Watch);
2022
1886
  }
2023
1887
 
2024
- // interface to static slp functions. see Slp.ts
2025
- public static get slp() {
2026
- return TestNetWatchSlp;
2027
- }
2028
-
2029
1888
  // interface to static util functions. see Util.ts
2030
1889
  public static get util() {
2031
1890
  return TestNetWatchUtil;
@@ -2042,11 +1901,6 @@ export class RegTestWatchWallet extends Wallet {
2042
1901
  super(name, NetworkType.Regtest, WalletTypeEnum.Watch);
2043
1902
  }
2044
1903
 
2045
- // interface to static slp functions. see Slp.ts
2046
- public static get slp() {
2047
- return RegTestWatchSlp;
2048
- }
2049
-
2050
1904
  // interface to static util functions. see Util.ts
2051
1905
  public static get util() {
2052
1906
  return RegTestWatchUtil;