mainnet-js 2.6.7 → 2.7.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 (98) hide show
  1. package/dist/index.html +1 -1
  2. package/dist/{mainnet-2.6.7.js → mainnet-2.7.0.js} +446 -156
  3. package/dist/module/cli.js +0 -4
  4. package/dist/module/cli.js.map +1 -1
  5. package/dist/module/index.d.ts +1 -3
  6. package/dist/module/index.d.ts.map +1 -1
  7. package/dist/module/index.js +1 -3
  8. package/dist/module/index.js.map +1 -1
  9. package/dist/module/network/ElectrumNetworkProvider.d.ts +21 -27
  10. package/dist/module/network/ElectrumNetworkProvider.d.ts.map +1 -1
  11. package/dist/module/network/ElectrumNetworkProvider.js +92 -102
  12. package/dist/module/network/ElectrumNetworkProvider.js.map +1 -1
  13. package/dist/module/network/NetworkProvider.d.ts +9 -22
  14. package/dist/module/network/NetworkProvider.d.ts.map +1 -1
  15. package/dist/module/network/constant.d.ts +0 -21
  16. package/dist/module/network/constant.d.ts.map +1 -1
  17. package/dist/module/network/constant.js +0 -21
  18. package/dist/module/network/constant.js.map +1 -1
  19. package/dist/module/network/default.d.ts +2 -2
  20. package/dist/module/network/default.d.ts.map +1 -1
  21. package/dist/module/network/default.js +15 -45
  22. package/dist/module/network/default.js.map +1 -1
  23. package/dist/module/network/interface.d.ts +2 -8
  24. package/dist/module/network/interface.d.ts.map +1 -1
  25. package/dist/module/network/util.d.ts.map +1 -1
  26. package/dist/module/network/util.js +4 -5
  27. package/dist/module/network/util.js.map +1 -1
  28. package/dist/module/rate/ExchangeRate.js +2 -1
  29. package/dist/module/rate/ExchangeRate.js.map +1 -1
  30. package/dist/module/transaction/Wif.d.ts.map +1 -1
  31. package/dist/module/transaction/Wif.js +1 -1
  32. package/dist/module/transaction/Wif.js.map +1 -1
  33. package/dist/module/wallet/Base.d.ts +282 -88
  34. package/dist/module/wallet/Base.d.ts.map +1 -1
  35. package/dist/module/wallet/Base.js +1058 -215
  36. package/dist/module/wallet/Base.js.map +1 -1
  37. package/dist/module/wallet/Util.d.ts +7 -54
  38. package/dist/module/wallet/Util.d.ts.map +1 -1
  39. package/dist/module/wallet/Util.js +12 -79
  40. package/dist/module/wallet/Util.js.map +1 -1
  41. package/dist/module/wallet/Wif.d.ts +46 -251
  42. package/dist/module/wallet/Wif.d.ts.map +1 -1
  43. package/dist/module/wallet/Wif.js +126 -1026
  44. package/dist/module/wallet/Wif.js.map +1 -1
  45. package/dist/module/wallet/createWallet.d.ts +2 -1
  46. package/dist/module/wallet/createWallet.d.ts.map +1 -1
  47. package/dist/module/wallet/createWallet.js +2 -3
  48. package/dist/module/wallet/createWallet.js.map +1 -1
  49. package/dist/module/wallet/interface.d.ts +2 -4
  50. package/dist/module/wallet/interface.d.ts.map +1 -1
  51. package/dist/tsconfig.tsbuildinfo +1 -1
  52. package/package.json +6 -12
  53. package/src/cli.ts +0 -4
  54. package/src/index.ts +1 -5
  55. package/src/network/ElectrumNetworkProvider.ts +133 -188
  56. package/src/network/NetworkProvider.ts +9 -30
  57. package/src/network/Rpc.test.ts +14 -5
  58. package/src/network/constant.ts +0 -23
  59. package/src/network/default.ts +26 -66
  60. package/src/network/electrum.test.ts +2 -4
  61. package/src/network/interface.ts +2 -9
  62. package/src/network/util.ts +6 -7
  63. package/src/rate/ExchangeRate.test.ts +1 -1
  64. package/src/rate/ExchangeRate.ts +2 -1
  65. package/{polyfill/json.js → src/test/json.test.ts} +7 -1
  66. package/src/transaction/Wif.ts +2 -1
  67. package/src/wallet/Base.ts +1520 -273
  68. package/src/wallet/Cashtokens.test.headless.js +1 -1
  69. package/src/wallet/Cashtokens.test.ts +7 -8
  70. package/src/wallet/Util.ts +20 -102
  71. package/src/wallet/Wif.bip39.test.ts +3 -3
  72. package/src/wallet/Wif.test.ts +31 -25
  73. package/src/wallet/Wif.ts +174 -1493
  74. package/src/wallet/Wif.watchOnly.test.ts +5 -5
  75. package/src/wallet/createWallet.ts +11 -10
  76. package/src/wallet/interface.ts +3 -4
  77. package/webpack.config.cjs +4 -55
  78. package/dist/module/qr/Qr.d.ts +0 -9
  79. package/dist/module/qr/Qr.d.ts.map +0 -1
  80. package/dist/module/qr/Qr.js +0 -22
  81. package/dist/module/qr/Qr.js.map +0 -1
  82. package/dist/module/qr/interface.d.ts +0 -6
  83. package/dist/module/qr/interface.d.ts.map +0 -1
  84. package/dist/module/qr/interface.js +0 -2
  85. package/dist/module/qr/interface.js.map +0 -1
  86. package/dist/module/util/eventsource.d.ts +0 -3
  87. package/dist/module/util/eventsource.d.ts.map +0 -1
  88. package/dist/module/util/eventsource.js +0 -11
  89. package/dist/module/util/eventsource.js.map +0 -1
  90. package/polyfill/README.md +0 -1
  91. package/polyfill/eventsource.js +0 -6
  92. package/polyfill/support/types.js +0 -286
  93. package/polyfill/util.cjs +0 -249
  94. package/src/network/default.test.ts +0 -37
  95. package/src/qr/Qr.test.ts +0 -14
  96. package/src/qr/Qr.ts +0 -24
  97. package/src/qr/interface.ts +0 -5
  98. package/src/util/eventsource.ts +0 -12
package/polyfill/util.cjs DELETED
@@ -1,249 +0,0 @@
1
- /**
2
- * Echos the value of a value. Trys to print the value out
3
- * in the best way possible given the different types.
4
- *
5
- * @param {Object} obj The object to print out.
6
- * @param {Object} opts Optional options object that alters the output.
7
- */
8
- /* legacy: obj, showHidden, depth, colors*/
9
- function inspect(obj, opts) {
10
- // default options
11
- var ctx = {
12
- seen: [],
13
- stylize: stylizeNoColor,
14
- };
15
- // legacy...
16
- if (arguments.length >= 3) ctx.depth = arguments[2];
17
- if (arguments.length >= 4) ctx.colors = arguments[3];
18
- if (isBoolean(opts)) {
19
- // legacy...
20
- ctx.showHidden = opts;
21
- } else if (opts) {
22
- // got an "options" object
23
- exports._extend(ctx, opts);
24
- }
25
- // set default options
26
- if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
27
- if (isUndefined(ctx.depth)) ctx.depth = 2;
28
- if (isUndefined(ctx.colors)) ctx.colors = false;
29
- if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
30
- if (ctx.colors) ctx.stylize = stylizeWithColor;
31
- return formatValue(ctx, obj, ctx.depth);
32
- }
33
- exports.inspect = inspect;
34
-
35
- function formatValue(ctx, value, recurseTimes) {
36
- // Provide a hook for user-specified inspect functions.
37
- // Check that value is an object with an inspect function on it
38
- if (
39
- ctx.customInspect &&
40
- value &&
41
- isFunction(value.inspect) &&
42
- // Filter out the util module, it's inspect function is special
43
- value.inspect !== exports.inspect &&
44
- // Also filter out any prototype objects using the circular check.
45
- !(value.constructor && value.constructor.prototype === value)
46
- ) {
47
- var ret = value.inspect(recurseTimes, ctx);
48
- if (!isString(ret)) {
49
- ret = formatValue(ctx, ret, recurseTimes);
50
- }
51
- return ret;
52
- }
53
-
54
- // Primitive types cannot have properties
55
- var primitive = formatPrimitive(ctx, value);
56
- if (primitive) {
57
- return primitive;
58
- }
59
-
60
- // Look up the keys of the object.
61
- var keys = Object.keys(value);
62
- var visibleKeys = arrayToHash(keys);
63
-
64
- if (ctx.showHidden) {
65
- keys = Object.getOwnPropertyNames(value);
66
- }
67
-
68
- // IE doesn't make error fields non-enumerable
69
- // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
70
- if (
71
- isError(value) &&
72
- (keys.indexOf("message") >= 0 || keys.indexOf("description") >= 0)
73
- ) {
74
- return formatError(value);
75
- }
76
-
77
- // Some type of object without properties can be shortcutted.
78
- if (keys.length === 0) {
79
- if (isFunction(value)) {
80
- var name = value.name ? ": " + value.name : "";
81
- return ctx.stylize("[Function" + name + "]", "special");
82
- }
83
- if (isRegExp(value)) {
84
- return ctx.stylize(RegExp.prototype.toString.call(value), "regexp");
85
- }
86
- if (isDate(value)) {
87
- return ctx.stylize(Date.prototype.toString.call(value), "date");
88
- }
89
- if (isError(value)) {
90
- return formatError(value);
91
- }
92
- }
93
-
94
- var base = "",
95
- array = false,
96
- braces = ["{", "}"];
97
-
98
- // Make Array say that they are Array
99
- if (isArray(value)) {
100
- array = true;
101
- braces = ["[", "]"];
102
- }
103
-
104
- // Make functions say that they are functions
105
- if (isFunction(value)) {
106
- var n = value.name ? ": " + value.name : "";
107
- base = " [Function" + n + "]";
108
- }
109
-
110
- // Make RegExps say that they are RegExps
111
- if (isRegExp(value)) {
112
- base = " " + RegExp.prototype.toString.call(value);
113
- }
114
-
115
- // Make dates with properties first say the date
116
- if (isDate(value)) {
117
- base = " " + Date.prototype.toUTCString.call(value);
118
- }
119
-
120
- // Make error with message first say the error
121
- if (isError(value)) {
122
- base = " " + formatError(value);
123
- }
124
-
125
- if (keys.length === 0 && (!array || value.length == 0)) {
126
- return braces[0] + base + braces[1];
127
- }
128
-
129
- if (recurseTimes < 0) {
130
- if (isRegExp(value)) {
131
- return ctx.stylize(RegExp.prototype.toString.call(value), "regexp");
132
- } else {
133
- return ctx.stylize("[Object]", "special");
134
- }
135
- }
136
-
137
- ctx.seen.push(value);
138
-
139
- var output;
140
- if (array) {
141
- output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
142
- } else {
143
- output = keys.map(function (key) {
144
- return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
145
- });
146
- }
147
-
148
- ctx.seen.pop();
149
-
150
- return reduceToSingleString(output, base, braces);
151
- }
152
-
153
- function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
154
- var name, str, desc;
155
- desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
156
- if (desc.get) {
157
- if (desc.set) {
158
- str = ctx.stylize("[Getter/Setter]", "special");
159
- } else {
160
- str = ctx.stylize("[Getter]", "special");
161
- }
162
- } else {
163
- if (desc.set) {
164
- str = ctx.stylize("[Setter]", "special");
165
- }
166
- }
167
- if (!hasOwnProperty(visibleKeys, key)) {
168
- name = "[" + key + "]";
169
- }
170
- if (!str) {
171
- if (ctx.seen.indexOf(desc.value) < 0) {
172
- if (isNull(recurseTimes)) {
173
- str = formatValue(ctx, desc.value, null);
174
- } else {
175
- str = formatValue(ctx, desc.value, recurseTimes - 1);
176
- }
177
- if (str.indexOf("\n") > -1) {
178
- if (array) {
179
- str = str
180
- .split("\n")
181
- .map(function (line) {
182
- return " " + line;
183
- })
184
- .join("\n")
185
- .substr(2);
186
- } else {
187
- str =
188
- "\n" +
189
- str
190
- .split("\n")
191
- .map(function (line) {
192
- return " " + line;
193
- })
194
- .join("\n");
195
- }
196
- }
197
- } else {
198
- str = ctx.stylize("[Circular]", "special");
199
- }
200
- }
201
- if (isUndefined(name)) {
202
- if (array && key.match(/^\d+$/)) {
203
- return str;
204
- }
205
- name = JSON.stringify("" + key);
206
- if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
207
- name = name.substr(1, name.length - 2);
208
- name = ctx.stylize(name, "name");
209
- } else {
210
- name = name
211
- .replace(/'/g, "\\'")
212
- .replace(/\\"/g, '"')
213
- .replace(/(^"|"$)/g, "'");
214
- name = ctx.stylize(name, "string");
215
- }
216
- }
217
-
218
- return name + ": " + str;
219
- }
220
-
221
- function reduceToSingleString(output, base, braces) {
222
- var numLinesEst = 0;
223
- var length = output.reduce(function (prev, cur) {
224
- numLinesEst++;
225
- if (cur.indexOf("\n") >= 0) numLinesEst++;
226
- return prev + cur.replace(/\u001b\[\d\d?m/g, "").length + 1;
227
- }, 0);
228
-
229
- if (length > 60) {
230
- return (
231
- braces[0] +
232
- (base === "" ? "" : base + "\n ") +
233
- " " +
234
- output.join(",\n ") +
235
- " " +
236
- braces[1]
237
- );
238
- }
239
-
240
- return braces[0] + base + " " + output.join(", ") + " " + braces[1];
241
- }
242
-
243
- function formatError(value) {
244
- return "[" + Error.prototype.toString.call(value) + "]";
245
- }
246
-
247
- exports.inherits = require("inherits");
248
-
249
- exports.types = require("./support/types");
@@ -1,37 +0,0 @@
1
- import { getNetworkProvider } from "./default";
2
- import { initProviders, disconnectProviders } from "./Connection";
3
-
4
- beforeAll(async () => {
5
- await initProviders();
6
- });
7
-
8
- afterAll(async () => {
9
- await disconnectProviders();
10
- });
11
-
12
- test("Should connect to the default cluster", async () => {
13
- let provider = getNetworkProvider();
14
-
15
- expect(provider.network).toBe("mainnet");
16
- const bal = await provider.getBalance(
17
- "qp6e6enhpy0fwwu7nkvlr8rgl06ru0c9lywalz8st5"
18
- );
19
- expect(bal).toBeGreaterThan(1313545598);
20
- });
21
-
22
- test("Should connect to the default testnet cluster", async () => {
23
- let provider = getNetworkProvider("testnet");
24
-
25
- expect(provider.network).toBe("testnet");
26
- const bal = await provider.getBalance(process.env.ALICE_TESTNET_ADDRESS!);
27
- expect(bal).toBeGreaterThan(100);
28
- });
29
-
30
- // TODO: Fix timeout issue
31
- // test("Should connect to the default regtest client", async () => {
32
- // let provider = getNetworkProvider("regtest");
33
-
34
- // expect(provider.network).toBe("regtest");
35
- // const bal = await provider.getBalance(process.env.ADDRESS!);
36
- // expect(bal).toBeGreaterThan(0);
37
- // });
package/src/qr/Qr.test.ts DELETED
@@ -1,14 +0,0 @@
1
- import { qrAddress } from "./Qr";
2
-
3
- test("Generate a qr address", async () => {
4
- if (process.env.ADDRESS) {
5
- const img = qrAddress(process.env.ADDRESS);
6
- expect(
7
- img.src.startsWith("data:image/svg+xml;base64,PD94bWwgdm")
8
- ).toBeTruthy();
9
- expect(img.title).toBe(process.env.ADDRESS);
10
- expect(img.alt).toBe("a Bitcoin Cash address QR Code");
11
- } else {
12
- throw Error("Cash address not set in env");
13
- }
14
- });
package/src/qr/Qr.ts DELETED
@@ -1,24 +0,0 @@
1
- import QRCode from "qrcode-svg";
2
- import { ImageI } from "./interface.js";
3
- import { btoa } from "../util/base64.js";
4
-
5
- /**
6
- * qrAddress returns a qr code for a given cashaddress as raw utf-8 svg
7
- * @param {string} address
8
- * @param {} size=256 The width and height of the returned image
9
- * @returns Image
10
- */
11
- export function qrAddress(address: string, size = 256): ImageI {
12
- let svg = new QRCode({
13
- content: address,
14
- width: size,
15
- height: size,
16
- }).svg();
17
-
18
- let svgB64 = btoa(svg);
19
- return {
20
- src: `data:image/svg+xml;base64,${svgB64}`,
21
- title: address,
22
- alt: "a Bitcoin Cash address QR Code",
23
- };
24
- }
@@ -1,5 +0,0 @@
1
- export interface ImageI {
2
- src: string;
3
- title: string;
4
- alt: string;
5
- }
@@ -1,12 +0,0 @@
1
- import { getRuntimePlatform } from "./getRuntimePlatform.js";
2
-
3
- import { default as ES } from "eventsource";
4
-
5
- let EventSource;
6
- if (getRuntimePlatform() != "node") {
7
- EventSource = globalThis.EventSource;
8
- } else {
9
- EventSource = ES;
10
- }
11
-
12
- export default EventSource;