mainnet-js 1.1.26 → 1.1.28

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.
@@ -194,20 +194,23 @@ export class BCMR {
194
194
  continue;
195
195
  }
196
196
 
197
- if (uriString.indexOf("https://") === 0) {
197
+ if (uriString.indexOf("ipfs://") === 0) {
198
+ const ipfsCid = uriString.replace("ipfs://", "");
199
+ result.httpsUrl = `https://dweb.link/ipfs/${ipfsCid}`;
200
+ } else if (uriString.indexOf("https://") === 0) {
198
201
  result.httpsUrl = uriString;
199
202
  } else if (uriString.indexOf("https://") === -1) {
200
203
  result.httpsUrl = uriString;
201
204
 
202
205
  // case for domain name specifier, like example.com
203
206
  if (uriString.indexOf("/") === -1) {
204
- result.httpsUrl = `${result.httpsUrl}/.well-known/bitcoin-cash-metadata-registry.json`;
207
+ const parts = uriString.toLowerCase().split(".");
208
+ if (!(parts?.[0]?.indexOf("baf") === 0 && parts?.[1] === "ipfs")) {
209
+ result.httpsUrl = `${result.httpsUrl}/.well-known/bitcoin-cash-metadata-registry.json`;
210
+ }
205
211
  }
206
212
 
207
213
  result.httpsUrl = `https://${result.httpsUrl}`;
208
- } else if (uriString.indexOf("ipfs://") === 0) {
209
- const ipfsCid = uriString.replace("ipfs://", "");
210
- result.httpsUrl = `https://dweb.link/ipfs/${ipfsCid}`;
211
214
  } else {
212
215
  throw new Error(`Unsupported uri type: ${uriString}`);
213
216
  }
@@ -1,74 +1,84 @@
1
+ import { initProviders, disconnectProviders } from "../network";
1
2
  import { ElectrumRawTransaction } from "../network/interface";
2
3
  import { RegTestWallet, Wallet } from "./Wif";
3
4
 
4
- test("Should compute raw transaction hash", async () => {
5
- const wallet = await RegTestWallet.newRandom();
6
- expect(
7
- await wallet.util.getTransactionHash(
8
- "01000000015bb9142c960a838329694d3fe9ba08c2a6421c5158d8f7044cb7c48006c1b484000000006a4730440220229ea5359a63c2b83a713fcc20d8c41b20d48fe639a639d2a8246a137f29d0fc02201de12de9c056912a4e581a62d12fb5f43ee6c08ed0238c32a1ee769213ca8b8b412103bcf9a004f1f7a9a8d8acce7b51c983233d107329ff7c4fb53e44c855dbe1f6a4feffffff02c6b68200000000001976a9141041fb024bd7a1338ef1959026bbba860064fe5f88ac50a8cf00000000001976a91445dac110239a7a3814535c15858b939211f8529888ac61ee0700"
9
- )
10
- ).toBe("36a3692a41a8ac60b73f7f41ee23f5c917413e5b2fad9e44b34865bd0d601a3d");
11
-
12
- // test static accessor
13
- expect(
14
- await RegTestWallet.util.getTransactionHash(
15
- "01000000015bb9142c960a838329694d3fe9ba08c2a6421c5158d8f7044cb7c48006c1b484000000006a4730440220229ea5359a63c2b83a713fcc20d8c41b20d48fe639a639d2a8246a137f29d0fc02201de12de9c056912a4e581a62d12fb5f43ee6c08ed0238c32a1ee769213ca8b8b412103bcf9a004f1f7a9a8d8acce7b51c983233d107329ff7c4fb53e44c855dbe1f6a4feffffff02c6b68200000000001976a9141041fb024bd7a1338ef1959026bbba860064fe5f88ac50a8cf00000000001976a91445dac110239a7a3814535c15858b939211f8529888ac61ee0700"
16
- )
17
- ).toBe("36a3692a41a8ac60b73f7f41ee23f5c917413e5b2fad9e44b34865bd0d601a3d");
5
+ beforeAll(async () => {
6
+ await initProviders();
18
7
  });
19
-
20
- test("Should throw on non-existent transaction and invalid hash", async () => {
21
- const wallet = await RegTestWallet.newRandom();
22
- await expect(
23
- wallet.util.decodeTransaction(
24
- "36a3692a41a8ac60b73f7f41ee23f5c917413e5b2fad9e44b34865bd0d601a3d"
25
- )
26
- ).rejects.toThrowError("might not exist");
27
- await expect(wallet.util.decodeTransaction("test")).rejects.toThrowError(
28
- "Invalid tx hash"
29
- );
8
+ afterAll(async () => {
9
+ await disconnectProviders();
30
10
  });
31
11
 
32
- test("Should get raw transaction", async () => {
33
- let wallet = await RegTestWallet.fromId(process.env.ALICE_ID!);
34
- const utxo = (await wallet.getUtxos())[0];
35
- const transaction = (await wallet.provider!.getRawTransactionObject(
36
- utxo.txid
37
- )) as ElectrumRawTransaction;
38
- expect((await wallet.util.decodeTransaction(transaction.hash)).hash).toBe(
39
- utxo.txid
40
- );
41
- expect((await wallet.util.decodeTransaction(transaction.hex)).txid).toBe(
42
- utxo.txid
43
- );
12
+ describe("Utility tests", () => {
13
+ test("Should compute raw transaction hash", async () => {
14
+ const wallet = await RegTestWallet.newRandom();
15
+ expect(
16
+ await wallet.util.getTransactionHash(
17
+ "01000000015bb9142c960a838329694d3fe9ba08c2a6421c5158d8f7044cb7c48006c1b484000000006a4730440220229ea5359a63c2b83a713fcc20d8c41b20d48fe639a639d2a8246a137f29d0fc02201de12de9c056912a4e581a62d12fb5f43ee6c08ed0238c32a1ee769213ca8b8b412103bcf9a004f1f7a9a8d8acce7b51c983233d107329ff7c4fb53e44c855dbe1f6a4feffffff02c6b68200000000001976a9141041fb024bd7a1338ef1959026bbba860064fe5f88ac50a8cf00000000001976a91445dac110239a7a3814535c15858b939211f8529888ac61ee0700"
18
+ )
19
+ ).toBe("36a3692a41a8ac60b73f7f41ee23f5c917413e5b2fad9e44b34865bd0d601a3d");
44
20
 
45
- // test static accessor
46
- expect(
47
- (await RegTestWallet.util.decodeTransaction(transaction.hex)).txid
48
- ).toBe(utxo.txid);
49
- });
21
+ // test static accessor
22
+ expect(
23
+ await RegTestWallet.util.getTransactionHash(
24
+ "01000000015bb9142c960a838329694d3fe9ba08c2a6421c5158d8f7044cb7c48006c1b484000000006a4730440220229ea5359a63c2b83a713fcc20d8c41b20d48fe639a639d2a8246a137f29d0fc02201de12de9c056912a4e581a62d12fb5f43ee6c08ed0238c32a1ee769213ca8b8b412103bcf9a004f1f7a9a8d8acce7b51c983233d107329ff7c4fb53e44c855dbe1f6a4feffffff02c6b68200000000001976a9141041fb024bd7a1338ef1959026bbba860064fe5f88ac50a8cf00000000001976a91445dac110239a7a3814535c15858b939211f8529888ac61ee0700"
25
+ )
26
+ ).toBe("36a3692a41a8ac60b73f7f41ee23f5c917413e5b2fad9e44b34865bd0d601a3d");
27
+ });
50
28
 
51
- test("Should decode a transaction from fist block", async () => {
52
- let wallet = await Wallet.newRandom();
53
- const decoded = await wallet.util.decodeTransaction(
54
- "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098"
55
- );
29
+ test("Should throw on non-existent transaction and invalid hash", async () => {
30
+ const wallet = await RegTestWallet.newRandom();
31
+ await expect(
32
+ wallet.util.decodeTransaction(
33
+ "36a3692a41a8ac60b73f7f41ee23f5c917413e5b2fad9e44b34865bd0d601a3d"
34
+ )
35
+ ).rejects.toThrowError("might not exist");
36
+ await expect(wallet.util.decodeTransaction("test")).rejects.toThrowError(
37
+ "Invalid tx hash"
38
+ );
39
+ });
56
40
 
57
- expect(decoded.txid).toBe(
58
- "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098"
59
- );
41
+ test("Should get raw transaction", async () => {
42
+ let wallet = await RegTestWallet.fromId(process.env.ALICE_ID!);
43
+ const utxo = (await wallet.getUtxos())[0];
44
+ const transaction = (await wallet.provider!.getRawTransactionObject(
45
+ utxo.txid
46
+ )) as ElectrumRawTransaction;
47
+ expect((await wallet.util.decodeTransaction(transaction.hash)).hash).toBe(
48
+ utxo.txid
49
+ );
50
+ expect((await wallet.util.decodeTransaction(transaction.hex)).txid).toBe(
51
+ utxo.txid
52
+ );
60
53
 
61
- expect(decoded.vin[0].address).toBeUndefined();
62
- expect(decoded.vin[0].value).toBeUndefined();
63
- });
54
+ // test static accessor
55
+ expect(
56
+ (await RegTestWallet.util.decodeTransaction(transaction.hex)).txid
57
+ ).toBe(utxo.txid);
58
+ });
59
+
60
+ test("Should decode a transaction from fist block", async () => {
61
+ let wallet = await Wallet.newRandom();
62
+ const decoded = await wallet.util.decodeTransaction(
63
+ "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098"
64
+ );
65
+
66
+ expect(decoded.txid).toBe(
67
+ "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098"
68
+ );
69
+
70
+ expect(decoded.vin[0].address).toBeUndefined();
71
+ expect(decoded.vin[0].value).toBeUndefined();
72
+ });
64
73
 
65
- test("Should decode a transaction and fetch input values and addresses", async () => {
66
- const txHash =
67
- "dc8f059900807c36941313f10b43ec049e23dfede4e09f8fbccc3871ed359fbe";
68
- const decoded = await Wallet.util.decodeTransaction(txHash, true);
69
- expect(decoded.vin[0].address).toBeDefined();
70
- expect(decoded.vin[0].value).toBeDefined();
74
+ test("Should decode a transaction and fetch input values and addresses", async () => {
75
+ const txHash =
76
+ "dc8f059900807c36941313f10b43ec049e23dfede4e09f8fbccc3871ed359fbe";
77
+ const decoded = await Wallet.util.decodeTransaction(txHash, true);
78
+ expect(decoded.vin[0].address).toBeDefined();
79
+ expect(decoded.vin[0].value).toBeDefined();
71
80
 
72
- // uncomment next line
73
- // expect(await Wallet.util.decodeTransaction(txHash)).toBe(await new Wallet().provider!.getRawTransactionObject(txHash));
81
+ // uncomment next line
82
+ // expect(await Wallet.util.decodeTransaction(txHash)).toBe(await new Wallet().provider!.getRawTransactionObject(txHash));
83
+ });
74
84
  });