mainnet-js 1.1.34 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.html +1 -1
- package/dist/{mainnet-1.1.34.js → mainnet-2.0.1.js} +26 -338
- package/dist/module/db/SqlProvider.d.ts +2 -2
- package/dist/module/db/SqlProvider.d.ts.map +1 -1
- package/dist/module/db/SqlProvider.js +6 -24
- package/dist/module/db/SqlProvider.js.map +1 -1
- package/dist/module/index.d.ts +0 -3
- package/dist/module/index.d.ts.map +1 -1
- package/dist/module/index.js +3 -6
- package/dist/module/index.js.map +1 -1
- package/dist/module/transaction/Wif.d.ts +4 -8
- package/dist/module/transaction/Wif.d.ts.map +1 -1
- package/dist/module/transaction/Wif.js +6 -10
- package/dist/module/transaction/Wif.js.map +1 -1
- package/dist/module/util/deriveCashaddr.d.ts +1 -0
- package/dist/module/util/deriveCashaddr.d.ts.map +1 -1
- package/dist/module/util/deriveCashaddr.js +8 -1
- package/dist/module/util/deriveCashaddr.js.map +1 -1
- package/dist/module/wallet/Base.d.ts +1 -1
- package/dist/module/wallet/Base.js +1 -1
- package/dist/module/wallet/Bcmr.d.ts +3 -1
- package/dist/module/wallet/Bcmr.d.ts.map +1 -1
- package/dist/module/wallet/Bcmr.js +4 -8
- package/dist/module/wallet/Bcmr.js.map +1 -1
- package/dist/module/wallet/Util.d.ts +2 -2
- package/dist/module/wallet/Util.js +2 -2
- package/dist/module/wallet/Wif.d.ts +0 -28
- package/dist/module/wallet/Wif.d.ts.map +1 -1
- package/dist/module/wallet/Wif.js +2 -109
- package/dist/module/wallet/Wif.js.map +1 -1
- package/dist/module/wallet/createWallet.d.ts +0 -12
- package/dist/module/wallet/createWallet.d.ts.map +1 -1
- package/dist/module/wallet/createWallet.js +0 -43
- package/dist/module/wallet/createWallet.js.map +1 -1
- package/dist/module/wallet/interface.d.ts +0 -2
- package/dist/module/wallet/interface.d.ts.map +1 -1
- package/dist/module/webhook/Webhook.d.ts +1 -6
- package/dist/module/webhook/Webhook.d.ts.map +1 -1
- package/dist/module/webhook/Webhook.js +0 -4
- package/dist/module/webhook/Webhook.js.map +1 -1
- package/dist/module/webhook/index.d.ts +0 -1
- package/dist/module/webhook/index.d.ts.map +1 -1
- package/dist/module/webhook/index.js +0 -1
- package/dist/module/webhook/index.js.map +1 -1
- package/dist/module/webhook/interface.d.ts +0 -1
- package/dist/module/webhook/interface.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -10
- package/src/db/SqlProvider.test.ts +2 -18
- package/src/db/SqlProvider.ts +5 -26
- package/src/index.ts +3 -7
- package/src/transaction/Wif.ts +2 -19
- package/src/util/deriveCashaddr.test.ts +8 -0
- package/src/util/deriveCashaddr.ts +9 -0
- package/src/wallet/Base.ts +1 -1
- package/src/wallet/Bcmr.ts +4 -9
- package/src/wallet/Util.ts +2 -2
- package/src/wallet/Wif.test.ts +0 -23
- package/src/wallet/Wif.ts +2 -148
- package/src/wallet/createWallet.ts +0 -53
- package/src/wallet/interface.ts +0 -2
- package/src/webhook/Webhook.ts +4 -10
- package/src/webhook/index.ts +0 -1
- package/src/webhook/interface.ts +0 -1
- package/webpack.config.cjs +7 -7
- package/dist/module/slp/GsppProvider.d.ts +0 -55
- package/dist/module/slp/GsppProvider.d.ts.map +0 -1
- package/dist/module/slp/GsppProvider.js +0 -204
- package/dist/module/slp/GsppProvider.js.map +0 -1
- package/dist/module/slp/SlpDbProvider.d.ts +0 -52
- package/dist/module/slp/SlpDbProvider.d.ts.map +0 -1
- package/dist/module/slp/SlpDbProvider.js +0 -175
- package/dist/module/slp/SlpDbProvider.js.map +0 -1
- package/dist/module/slp/SlpDbTemplates.d.ts +0 -313
- package/dist/module/slp/SlpDbTemplates.d.ts.map +0 -1
- package/dist/module/slp/SlpDbTemplates.js +0 -375
- package/dist/module/slp/SlpDbTemplates.js.map +0 -1
- package/dist/module/slp/SlpLibAuth.d.ts +0 -210
- package/dist/module/slp/SlpLibAuth.d.ts.map +0 -1
- package/dist/module/slp/SlpLibAuth.js +0 -451
- package/dist/module/slp/SlpLibAuth.js.map +0 -1
- package/dist/module/slp/SlpProvider.d.ts +0 -24
- package/dist/module/slp/SlpProvider.d.ts.map +0 -1
- package/dist/module/slp/SlpProvider.js +0 -29
- package/dist/module/slp/SlpProvider.js.map +0 -1
- package/dist/module/slp/index.d.ts +0 -6
- package/dist/module/slp/index.d.ts.map +0 -1
- package/dist/module/slp/index.js +0 -5
- package/dist/module/slp/index.js.map +0 -1
- package/dist/module/slp/interface.d.ts +0 -114
- package/dist/module/slp/interface.d.ts.map +0 -1
- package/dist/module/slp/interface.js +0 -7
- package/dist/module/slp/interface.js.map +0 -1
- package/dist/module/util/bchaddr.d.ts +0 -2
- package/dist/module/util/bchaddr.d.ts.map +0 -1
- package/dist/module/util/bchaddr.js +0 -16
- package/dist/module/util/bchaddr.js.map +0 -1
- package/dist/module/wallet/Slp.d.ts +0 -431
- package/dist/module/wallet/Slp.d.ts.map +0 -1
- package/dist/module/wallet/Slp.js +0 -770
- package/dist/module/wallet/Slp.js.map +0 -1
- package/dist/module/webhook/WebhookSlp.d.ts +0 -15
- package/dist/module/webhook/WebhookSlp.d.ts.map +0 -1
- package/dist/module/webhook/WebhookSlp.js +0 -100
- package/dist/module/webhook/WebhookSlp.js.map +0 -1
- package/src/slp/GsppProvider.test.ts +0 -40
- package/src/slp/GsppProvider.ts +0 -329
- package/src/slp/SlpDbProvider.test.ts +0 -27
- package/src/slp/SlpDbProvider.ts +0 -291
- package/src/slp/SlpDbTemplates.ts +0 -400
- package/src/slp/SlpLibAuth.test.ts +0 -162
- package/src/slp/SlpLibAuth.ts +0 -532
- package/src/slp/SlpProvider.ts +0 -100
- package/src/slp/index.ts +0 -6
- package/src/slp/interface.ts +0 -128
- package/src/util/bchaddr.test.ts +0 -27
- package/src/util/bchaddr.ts +0 -27
- package/src/wallet/Slp.test.headless.js +0 -120
- package/src/wallet/Slp.test.ts +0 -1000
- package/src/wallet/Slp.ts +0 -1014
- package/src/webhook/WebhookSlp.test.ts +0 -288
- 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": "
|
|
12
|
+
"version": "2.0.1",
|
|
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", "
|
|
283
|
-
await db.addFaucetQueueItem("0x01", "
|
|
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();
|
package/src/db/SqlProvider.ts
CHANGED
|
@@ -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
|
-
|
|
148
|
-
|
|
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,
|
|
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,
|
|
252
|
+
"INSERT into %I (address,value) VALUES ($1, $2);",
|
|
274
253
|
this.faucetQueueTable
|
|
275
254
|
);
|
|
276
|
-
return await this.db.query(text, [address,
|
|
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
|
-
//
|
|
54
|
-
|
|
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
|
+
// }
|
package/src/transaction/Wif.ts
CHANGED
|
@@ -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:
|
|
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
|
package/src/wallet/Base.ts
CHANGED
|
@@ -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
|
|
156
|
+
* @param address cashaddress, token aware cashaddress of a wallet
|
|
157
157
|
*
|
|
158
158
|
* @returns instantiated wallet
|
|
159
159
|
*/
|
package/src/wallet/Bcmr.ts
CHANGED
|
@@ -402,7 +402,9 @@ export class BCMR {
|
|
|
402
402
|
*
|
|
403
403
|
* @param {string} options.chaingraphUrl (required) URL of a chaingraph indexer instance to fetch info from
|
|
404
404
|
* @param {string} options.transactionHash (required) transaction hash from which to build the auth chain
|
|
405
|
-
* @param {string?} options.network (default=
|
|
405
|
+
* @param {string?} options.network (default=undefined) network to query the data from, specific to the queried instance,
|
|
406
|
+
* can be 'mainnet', 'chipnet', or anything else.
|
|
407
|
+
* if left undefined all chaingraph transactions will be looked at, disregarding the chain
|
|
406
408
|
*
|
|
407
409
|
* @returns {AuthChain} returns the resolved authchain
|
|
408
410
|
*/
|
|
@@ -415,10 +417,6 @@ export class BCMR {
|
|
|
415
417
|
throw new Error("Provide `chaingraphUrl` param.");
|
|
416
418
|
}
|
|
417
419
|
|
|
418
|
-
if (options.network === undefined) {
|
|
419
|
-
options.network = "mainnet";
|
|
420
|
-
}
|
|
421
|
-
|
|
422
420
|
const response = await axios.post(
|
|
423
421
|
options.chaingraphUrl,
|
|
424
422
|
{
|
|
@@ -429,10 +427,7 @@ export class BCMR {
|
|
|
429
427
|
transaction(
|
|
430
428
|
where: {
|
|
431
429
|
hash:{_eq:"\\\\x${options.transactionHash}"},
|
|
432
|
-
|
|
433
|
-
{node_validation_timeline:{node:{name:{_ilike:"%${options.network}%"}}}},
|
|
434
|
-
{block_inclusions:{block:{accepted_by:{node:{name:{_ilike:"%${options.network}%"}}}}}},
|
|
435
|
-
]
|
|
430
|
+
${options.network ? `node_validation_timeline:{node:{name:{_ilike:"%${options.network}%"}}}` : ""}
|
|
436
431
|
}
|
|
437
432
|
) {
|
|
438
433
|
hash
|
package/src/wallet/Util.ts
CHANGED
|
@@ -166,7 +166,7 @@ export class Util {
|
|
|
166
166
|
|
|
167
167
|
//#region Specific wallet classes
|
|
168
168
|
/**
|
|
169
|
-
* Class to manage
|
|
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
|
|
178
|
+
* Class to manage a regtest wallet.
|
|
179
179
|
*/
|
|
180
180
|
export class RegTestUtil extends Util {
|
|
181
181
|
static get walletType() {
|
package/src/wallet/Wif.test.ts
CHANGED
|
@@ -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`, () => {
|