@multiplechain/bitcoin 0.1.5 → 0.1.7

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.
@@ -0,0 +1,26 @@
1
+ /*!
2
+ * The buffer module from node.js, for the browser.
3
+ *
4
+ * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
5
+ * @license MIT
6
+ */
7
+
8
+ /*!
9
+ * The buffer module from node.js, for the browser.
10
+ *
11
+ * @author Feross Aboukhadijeh <https://feross.org>
12
+ * @license MIT
13
+ */
14
+
15
+ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
16
+
17
+ /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
18
+
19
+ /**
20
+ * [js-sha3]{@link https://github.com/emn178/js-sha3}
21
+ *
22
+ * @version 0.8.0
23
+ * @author Chen, Yi-Cyuan [emn178@gmail.com]
24
+ * @copyright Chen, Yi-Cyuan 2015-2018
25
+ * @license MIT
26
+ */
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "namespace": "multiplechain",
3
3
  "name": "@multiplechain/bitcoin",
4
- "version": "0.1.5",
4
+ "version": "0.1.7",
5
5
  "description": "Bitcoin JS provider",
6
6
  "scripts": {
7
7
  "serve": "parcel test.html --no-cache --dist-dir test",
8
8
  "build": "webpack"
9
9
  },
10
10
  "files": [
11
- "src"
11
+ "src",
12
+ "dist"
12
13
  ],
13
14
  "main": "src/bitcoin-provider.js",
14
15
  "types": "index.d.ts",
@@ -27,9 +27,10 @@ module.exports = unisat = (provider) => {
27
27
  return {
28
28
  key: 'unisat',
29
29
  name: 'UniSat',
30
- type: 'browser',
30
+ supports: ['browser'],
31
31
  wallet,
32
32
  connect,
33
- download: 'https://unisat.io/download'
33
+ download: 'https://unisat.io/download',
34
+ detected: Boolean(typeof window.unisat !== 'undefined' && window.unisat.requestAccounts)
34
35
  }
35
36
  }
package/src/provider.js CHANGED
@@ -69,32 +69,6 @@ class Provider {
69
69
  return 'bitcoin' + ':' + String(address).toUpperCase() + '?amount=' + amount;
70
70
  }
71
71
 
72
- errorCheck(data) {
73
- if (typeof data == 'string') {
74
- if (data == 'Address on invalid network') {
75
- return {
76
- error: 'invalid-address'
77
- }
78
- } else {
79
- return {
80
- error: 'any-error'
81
- }
82
- }
83
- } else if (data.error) {
84
- if (data.error == 'not-found-or-invalid-arg') {
85
- return {
86
- error: 'invalid-address'
87
- }
88
- } else {
89
- return {
90
- error: 'any-error'
91
- }
92
- }
93
- }
94
-
95
- return data;
96
- }
97
-
98
72
  listenTransactions(options, callback) {
99
73
  let receiver = options.receiver;
100
74
  let ws = new WebSocket(this.wsUrl);
@@ -156,13 +130,29 @@ class Provider {
156
130
  }
157
131
 
158
132
  /**
159
- * @param {Array} filter
133
+ * @param {Array|null} filter
134
+ * @returns {Array}
135
+ */
136
+ getSupportedWallets(filter) {
137
+
138
+ const Wallet = require('./wallet');
139
+
140
+ const wallets = {
141
+ unisat: new Wallet('unisat', this)
142
+ };
143
+
144
+ return Object.fromEntries(Object.entries(wallets).filter(([key]) => {
145
+ return !filter ? true : filter.includes(key);
146
+ }));
147
+ }
148
+
149
+ /**
150
+ * @param {Array|null} filter
160
151
  * @returns {Array}
161
152
  */
162
153
  getDetectedWallets(filter) {
163
- if (!filter) return this.detectedWallets;
164
154
  return Object.fromEntries(Object.entries(this.detectedWallets).filter(([key]) => {
165
- return filter.includes(key);
155
+ return !filter ? true : filter.includes(key);
166
156
  }));
167
157
  }
168
158
 
package/src/wallet.js CHANGED
@@ -57,8 +57,8 @@ class Wallet {
57
57
  /**
58
58
  * @returns {String}
59
59
  */
60
- getType() {
61
- return this.adapter.type;
60
+ getSupports() {
61
+ return this.adapter.supports;
62
62
  }
63
63
 
64
64
  /**
@@ -75,21 +75,18 @@ class Wallet {
75
75
  return this.adapter.download;
76
76
  }
77
77
 
78
+ /**
79
+ * @returns {Boolean}
80
+ */
81
+ isDetected() {
82
+ return this.adapter.detected;
83
+ }
84
+
78
85
  /**
79
86
  * @returns {String}
80
87
  */
81
88
  connect() {
82
89
  return new Promise((resolve, reject) => {
83
- let time = 0;
84
- let timeout = 15;
85
- let timer = setInterval(async () => {
86
- time += 1;
87
- if (time > timeout) {
88
- clearInterval(timer);
89
- reject('timeout');
90
- }
91
- }, 1000);
92
-
93
90
  this.adapter.connect()
94
91
  .then(async (connectedAccount) => {
95
92
  let network = await this.wallet.getNetwork();
@@ -102,9 +99,6 @@ class Wallet {
102
99
  })
103
100
  .catch((error) => {
104
101
  utils.rejectMessage(error, reject);
105
- })
106
- .finally(() => {
107
- clearInterval(timer);
108
102
  });
109
103
  });
110
104
  }