zeldhash-miner 0.2.1 → 0.2.3
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/README.md +33 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +321 -314
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/wasm/package.json +1 -1
- package/wasm/zeldhash_miner_wasm_bg.wasm +0 -0
- package/dist/worker.js +0 -339
- package/dist/worker.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
var o = /* @__PURE__ */ ((s) => (s.INVALID_ADDRESS = "INVALID_ADDRESS", s.UNSUPPORTED_ADDRESS_TYPE = "UNSUPPORTED_ADDRESS_TYPE", s.INSUFFICIENT_FUNDS = "INSUFFICIENT_FUNDS", s.NO_CHANGE_OUTPUT = "NO_CHANGE_OUTPUT", s.MULTIPLE_CHANGE_OUTPUTS = "MULTIPLE_CHANGE_OUTPUTS", s.INVALID_INPUT = "INVALID_INPUT", s.WEBGPU_NOT_AVAILABLE = "WEBGPU_NOT_AVAILABLE", s.WORKER_ERROR = "WORKER_ERROR", s.MINING_ABORTED = "MINING_ABORTED", s.DUST_OUTPUT = "DUST_OUTPUT", s))(o || {});
|
|
2
|
-
const
|
|
3
|
-
class
|
|
2
|
+
const P = (s) => s instanceof Error ? s.message : String(s);
|
|
3
|
+
class w extends Error {
|
|
4
4
|
code;
|
|
5
5
|
details;
|
|
6
|
-
constructor(t, e,
|
|
7
|
-
super(e), this.name = "ZeldMinerError", this.code = t, this.details =
|
|
6
|
+
constructor(t, e, n) {
|
|
7
|
+
super(e), this.name = "ZeldMinerError", this.code = t, this.details = n;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
-
const
|
|
11
|
-
if (s instanceof
|
|
10
|
+
const v = (s, t = o.WORKER_ERROR, e) => {
|
|
11
|
+
if (s instanceof w)
|
|
12
12
|
return s;
|
|
13
|
-
const
|
|
14
|
-
return new
|
|
15
|
-
},
|
|
13
|
+
const n = P(s);
|
|
14
|
+
return new w(t, n, e);
|
|
15
|
+
}, r = (s, t, e) => new w(s, t, e), X = (s) => {
|
|
16
16
|
const t = BigInt(Number.MAX_SAFE_INTEGER);
|
|
17
17
|
return s > t ? Number.MAX_SAFE_INTEGER : s < -t ? -Number.MAX_SAFE_INTEGER : Number(s);
|
|
18
18
|
};
|
|
19
|
-
class
|
|
19
|
+
class O {
|
|
20
20
|
mode;
|
|
21
21
|
batchSize;
|
|
22
22
|
workerCount;
|
|
@@ -57,39 +57,39 @@ class C {
|
|
|
57
57
|
this.listeners[t].delete(e);
|
|
58
58
|
}
|
|
59
59
|
emit(t, e) {
|
|
60
|
-
this.listeners[t].forEach((
|
|
60
|
+
this.listeners[t].forEach((n) => n(e));
|
|
61
|
+
}
|
|
62
|
+
resolveWorkerUrl() {
|
|
63
|
+
const t = typeof location < "u" && location.origin ? location.origin : typeof self < "u" && self.location?.origin ? self.location.origin : void 0;
|
|
64
|
+
return t ? `${t}/worker.js` : new URL("data:video/mp2t;base64,Ly8gQm9vdHN0cmFwOiBkZWZpbmUgYSBzZW5zaWJsZSBkZWZhdWx0IGZvciBXQVNNIGJhc2UgcGF0aCBpbiB3b3JrZXIgY29udGV4dC4KLy8gV29ya2VycyBkb24ndCBoYXZlIGB3aW5kb3dgLCBidXQgYHNlbGZgIHByb3ZpZGVzIGxvY2F0aW9uLiBUaGlzIG11c3QgcnVuCi8vIGJlZm9yZSBhbnkgaW1wb3J0IHRoYXQgY2FsbHMgcmVzb2x2ZVdhc21CYXNlKCkuCmlmICh0eXBlb2YgKGdsb2JhbFRoaXMgYXMgeyBfX1pFTERNSU5FUl9XQVNNX0JBU0VfXz86IHVua25vd24gfSkuX19aRUxETUlORVJfV0FTTV9CQVNFX18gPT09ICJ1bmRlZmluZWQiKSB7CiAgdHJ5IHsKICAgIGNvbnN0IG9yaWdpbiA9CiAgICAgIHR5cGVvZiBzZWxmICE9PSAidW5kZWZpbmVkIiAmJ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VudHNbMF07CiAgICAgIH0gY2F0Y2ggKGVycikgewogICAgICAgIHBvc3RFcnJvcigKICAgICAgICAgIGBJbnZhbGlkIG5vbmNlIHJhbmdlOiAke2Zvcm1hdEVycm9yKGVycil9YCwKICAgICAgICAgIFplbGRNaW5lckVycm9yQ29kZS5JTlZBTElEX0lOUFVUCiAgICAgICAgKTsKICAgICAgICBhYm9ydC5hYm9ydCgpOwogICAgICAgIHJldHVybjsKICAgICAgfQoKICAgICAgbGV0IHRlbXBsYXRlOiBXb3JrZXJUZW1wbGF0ZTsKICAgICAgdHJ5IHsKICAgICAgICB0ZW1wbGF0ZSA9IGF3YWl0IGVuc3VyZVRlbXBsYXRlRm9yU2VnbWVudCgKICAgICAgICAgIHRlbXBsYXRlQ2FjaGUsCiAgICAgICAgICB3YXNtLAogICAgICAgICAgewogICAgICAgICAgICBpbnB1dHM6IG1zZy5pbnB1dHMsCiAgICAgICAgICAgIG91dHB1dHM6IG1zZy5vdXRwdXRzLAogICAgICAgICAgICBzYXRzUGVyVmJ5dGU6IG1zZy5zYXRzUGVyVmJ5dGUsCiAgICAgICAgICAgIGRpc3RyaWJ1dGlvbjogbXNnLmRpc3RyaWJ1dGlvbiwKICAgICAgICAgICAgdXNlQ2Jvck5vbmNlLAogICAgICAgICAgfSwKICAgICAgICAgIHNlZ21lbnQsCiAgICAgICAgICBub3JtYWxpemVkTmV0d29yawogICAgICAgICk7CiAgICAgIH0gY2F0Y2ggKGVycikgewogICAgICAgIHBvc3RFcnJvcigKICAgICAgICAgIGBGYWlsZWQgdG8gYnVpbGQgbWluaW5nIHRlbXBsYXRlOiAke2Zvcm1hdEVycm9yKGVycil9YCwKICAgICAgICAgIFplbGRNaW5lckVycm9yQ29kZS5XT1JLRVJfRVJST1IKICAgICAgICApOwogICAgICAgIGFib3J0LmFib3J0KCk7CiAgICAgICAgcmV0dXJuOwogICAgICB9CgogICAgICBsZXQgb3V0cHV0OiB1bmtub3duOwogICAgICBjb25zdCBiYXRjaFN0YXJ0ZWRBdCA9IHBlcmZvcm1hbmNlLm5vdygpOwogICAgICB0cnkgewogICAgICAgIG91dHB1dCA9IGF3YWl0IHJ1bkJhdGNoKAogICAgICAgICAgd2FzbSwKICAgICAgICAgIGN1cnJlbnRNb2RlLAogICAgICAgICAgdGVtcGxhdGUucHJlZml4LAogICAgICAgICAgdGVtcGxhdGUuc3VmZml4LAogICAgICAgICAgc2VnbWVudC5zdGFydCwKICAgICAgICAgIHNlZ21lbnQuc2l6ZSwKICAgICAgICAgIG1zZy50YXJnZXRaZXJvcywKICAgICAgICAgIHVzZUNib3JOb25jZQogICAgICAgICk7CiAgICAgIH0gY2F0Y2ggKGVycikgewogICAgICAgIGNvbnN0IG1lc3NhZ2UgPSBmb3JtYXRFcnJvcihlcnIpOwogICAgICAgIHBvc3RFcnJvcigKICAgICAgICAgIGBCYXRjaCBtaW5pbmcgZmFpbGVkOiAke21lc3NhZ2V9YCwKICAgICAgICAgIFplbGRNaW5lckVycm9yQ29kZS5XT1JLRVJfRVJST1IKICAgICAgICApOwogICAgICAgIGFib3J0LmFib3J0KCk7CiAgICAgICAgcmV0dXJuOwogICAgICB9CgogICAgICBjb25zdCBiYXRjaER1cmF0aW9uTXMgPSBwZXJmb3JtYW5jZS5ub3coKSAtIGJhdGNoU3RhcnRlZEF0OwoKICAgICAgaWYgKGlzVmFsaWRhdGlvblJlc3VsdChvdXRwdXQpKSB7CiAgICAgICAgaWYgKCFvdXRwdXQub2spIHsKICAgICAgICAgIHBvc3RFcnJvcigKICAgICAgICAgICAgb3V0cHV0LmVycm9yID8/ICJWYWxpZGF0aW9uIGZhaWxlZCIsCiAgICAgICAgICAgIFplbGRNaW5lckVycm9yQ29kZS5JTlZBTElEX0lOUFVUCiAgICAgICAgICApOwogICAgICAgICAgYWJvcnQuYWJvcnQoKTsKICAgICAgICAgIHJldHVybjsKICAgICAgICB9CiAgICAgIH0gZWxzZSBpZiAoaXNNaW5lUmVzdWx0KG91dHB1dCkpIHsKICAgICAgICBjb25zdCBhdHRlbXB0c0JlZm9yZSA9IGhhc2hlc1Byb2Nlc3NlZCArIHByb2Nlc3NlZEluSXRlcmF0aW9uOwogICAgICAgIGNvbnN0IGF0dGVtcHRzSW5TZWdtZW50ID0gQmlnSW50KG91dHB1dC5ub25jZSkgLSBzZWdtZW50LnN0YXJ0ICsgMW47CiAgICAgICAgY29uc3QgdG90YWxBdHRlbXB0cyA9IGF0dGVtcHRzQmVmb3JlICsgYXR0ZW1wdHNJblNlZ21lbnQ7CiAgICAgICAgY29uc3QgZWxhcHNlZE1zID0gcGVyZm9ybWFuY2Uubm93KCkgLSBzdGFydGVkQXQ7CiAgICAgICAgY29uc3QgaGFzaFJhdGUgPQogICAgICAgICAgZWxhcHNlZE1zID4gMAogICAgICAgICAgICA/IHNhZmVCaWdJbnRUb051bWJlcih0b3RhbEF0dGVtcHRzKSAvIChlbGFwc2VkTXMgLyAxMDAwKQogICAgICAgICAgICA6IDA7CiAgICAgICAgY29uc3QgbGFzdE5vbmNlID0gc2VnbWVudC5zdGFydCArIGF0dGVtcHRzSW5TZWdtZW50IC0gMW47CgogICAgICAgIGNvbnN0IHJlc3VsdDogTWluZVJlc3VsdCA9IHsKICAgICAgICAgIHBzYnQ6ICIiLAogICAgICAgICAgdHhpZDogb3V0cHV0LnR4aWQsCiAgICAgICAgICBub25jZTogQmlnSW50KG91dHB1dC5ub25jZSksCiAgICAgICAgICBhdHRlbXB0czogdG90YWxBdHRlbXB0cywKICAgICAgICAgIGR1cmF0aW9uOiBlbGFwc2VkTXMsCiAgICAgICAgICBoYXNoUmF0ZSwKICAgICAgICB9OwoKICAgICAgICBwb3N0KHsKICAgICAgICAgIHR5cGU6ICJmb3VuZCIsCiAgICAgICAgICByZXN1bHQsCiAgICAgICAgICBoYXNoZXNQcm9jZXNzZWQ6IHRvdGFsQXR0ZW1wdHMsCiAgICAgICAgICBoYXNoUmF0ZSwKICAgICAgICAgIGxhc3ROb25jZSwKICAgICAgICB9KTsKICAgICAgICBh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UgPSBtaW5lTG9vcChtc2csIGFib3J0KS5maW5hbGx5KCgpID0+IHsKICAgIGlmIChtaW5pbmdBYm9ydCA9PT0gYWJvcnQpIHsKICAgICAgbWluaW5nQWJvcnQgPSBudWxsOwogICAgfQogICAgaWYgKG1pbmluZ1Byb21pc2UgPT09IHByb21pc2UpIHsKICAgICAgbWluaW5nUHJvbWlzZSA9IG51bGw7CiAgICB9CiAgfSk7CgogIG1pbmluZ1Byb21pc2UgPSBwcm9taXNlOwp9OwoKY3R4LmFkZEV2ZW50TGlzdGVuZXIoIm1lc3NhZ2UiLCAoZXZlbnQ6IE1lc3NhZ2VFdmVudDxXb3JrZXJNZXNzYWdlPikgPT4gewogIGNvbnN0IGRhdGEgPSBldmVudC5kYXRhOwoKICBzd2l0Y2ggKGRhdGEudHlwZSkgewogICAgY2FzZSAiaW5pdCI6CiAgICAgIGN1cnJlbnRNb2RlID0gZGF0YS5tb2RlOwogICAgICBwb3N0KHsgdHlwZTogInJlYWR5IiB9KTsKICAgICAgYnJlYWs7CiAgICBjYXNlICJtaW5lIjoKICAgICAgc3RhcnRNaW5pbmcoZGF0YSk7CiAgICAgIGJyZWFrOwogICAgY2FzZSAic3RvcCI6CiAgICAgIG1pbmluZ0Fib3J0Py5hYm9ydCgpOwogICAgICBicmVhazsKICAgIGRlZmF1bHQ6CiAgICAgIHBvc3RFcnJvcigKICAgICAgICBgVW5rbm93biBtZXNzYWdlIHR5cGU6ICR7KGRhdGEgYXMgeyB0eXBlPzogc3RyaW5nIH0pLnR5cGV9YCwKICAgICAgICBaZWxkTWluZXJFcnJvckNvZGUuV09SS0VSX0VSUk9SCiAgICAgICk7CiAgfQp9KTsKCg==", import.meta.url).href;
|
|
61
65
|
}
|
|
62
66
|
async spawnWorkers() {
|
|
63
|
-
const t = [];
|
|
64
|
-
for (let
|
|
65
|
-
const
|
|
66
|
-
/* @vite-ignore */
|
|
67
|
-
"" + new URL("worker.js", import.meta.url).href,
|
|
68
|
-
import.meta.url
|
|
69
|
-
), {
|
|
67
|
+
const t = [], e = this.resolveWorkerUrl();
|
|
68
|
+
for (let n = 0; n < this.workerCount; n += 1) {
|
|
69
|
+
const i = new Worker(e, {
|
|
70
70
|
type: "module",
|
|
71
71
|
/* @vite-ignore */
|
|
72
|
-
name: `zeldminer-worker-${
|
|
73
|
-
}),
|
|
74
|
-
worker:
|
|
72
|
+
name: `zeldminer-worker-${n}`
|
|
73
|
+
}), g = {
|
|
74
|
+
worker: i,
|
|
75
75
|
hashesProcessed: 0n,
|
|
76
76
|
hashRate: 0,
|
|
77
77
|
nextNonce: 0n,
|
|
78
78
|
processedBase: 0n
|
|
79
79
|
};
|
|
80
|
-
this.workers.push(
|
|
81
|
-
new Promise((
|
|
82
|
-
const
|
|
83
|
-
|
|
80
|
+
this.workers.push(g), t.push(
|
|
81
|
+
new Promise((c) => {
|
|
82
|
+
const a = (A) => {
|
|
83
|
+
A.data.type === "ready" && (i.removeEventListener("message", a), c());
|
|
84
84
|
};
|
|
85
|
-
|
|
85
|
+
i.addEventListener("message", a);
|
|
86
86
|
})
|
|
87
|
-
),
|
|
87
|
+
), i.addEventListener(
|
|
88
88
|
"message",
|
|
89
|
-
(
|
|
89
|
+
(c) => this.handleWorkerMessage(g, c.data)
|
|
90
90
|
);
|
|
91
|
-
const
|
|
92
|
-
|
|
91
|
+
const I = { type: "init", mode: this.mode };
|
|
92
|
+
i.postMessage(I);
|
|
93
93
|
}
|
|
94
94
|
await Promise.all(t), this.emit("ready", void 0);
|
|
95
95
|
}
|
|
@@ -105,21 +105,21 @@ class C {
|
|
|
105
105
|
break;
|
|
106
106
|
case "found":
|
|
107
107
|
t.hashesProcessed = t.processedBase + (e.hashesProcessed ?? t.hashesProcessed), t.hashRate = e.hashRate ?? t.hashRate, t.lastNonce = e.lastNonce ?? t.lastNonce;
|
|
108
|
-
const
|
|
109
|
-
(
|
|
108
|
+
const n = this.workers.reduce(
|
|
109
|
+
(c, a) => c + a.hashesProcessed,
|
|
110
110
|
0n
|
|
111
|
-
),
|
|
111
|
+
), i = this.startedAt ? performance.now() - this.startedAt : 0, g = i > 0 ? X(n) / (i / 1e3) : 0, I = {
|
|
112
112
|
...e.result,
|
|
113
|
-
attempts:
|
|
114
|
-
duration:
|
|
115
|
-
hashRate:
|
|
113
|
+
attempts: n,
|
|
114
|
+
duration: i,
|
|
115
|
+
hashRate: g
|
|
116
116
|
};
|
|
117
|
-
this.running = !1, this.paused = !1, this.terminateWorkers(), this.cleanupExternalAbort(), this.emit("found",
|
|
117
|
+
this.running = !1, this.paused = !1, this.terminateWorkers(), this.cleanupExternalAbort(), this.emit("found", I);
|
|
118
118
|
break;
|
|
119
119
|
case "error":
|
|
120
120
|
this.running = !1, this.paused = !1, this.terminateWorkers(), this.cleanupExternalAbort(), this.emit(
|
|
121
121
|
"error",
|
|
122
|
-
new
|
|
122
|
+
new w(
|
|
123
123
|
e.code ?? o.WORKER_ERROR,
|
|
124
124
|
e.message,
|
|
125
125
|
{
|
|
@@ -134,14 +134,14 @@ class C {
|
|
|
134
134
|
emitProgress() {
|
|
135
135
|
if (!this.running) return;
|
|
136
136
|
const t = this.workers.reduce(
|
|
137
|
-
(
|
|
137
|
+
(g, I) => g + I.hashesProcessed,
|
|
138
138
|
0n
|
|
139
|
-
), e = this.startedAt ? performance.now() - this.startedAt : 0,
|
|
139
|
+
), e = this.startedAt ? performance.now() - this.startedAt : 0, n = e > 0 ? X(t) / (e / 1e3) : 0, i = {
|
|
140
140
|
hashesProcessed: t,
|
|
141
|
-
hashRate:
|
|
141
|
+
hashRate: n,
|
|
142
142
|
elapsedMs: e
|
|
143
143
|
};
|
|
144
|
-
this.emit("progress",
|
|
144
|
+
this.emit("progress", i);
|
|
145
145
|
}
|
|
146
146
|
computeNextNonce(t) {
|
|
147
147
|
const e = this.stride - BigInt(this.batchSize);
|
|
@@ -163,25 +163,25 @@ class C {
|
|
|
163
163
|
async start(t) {
|
|
164
164
|
if (await this.readyPromise, this.stopWorkers(), this.running = !0, this.paused = !1, this.startedAt = performance.now(), this.txInputs = t.inputs, this.txOutputs = t.outputs, this.txNetwork = t.network === "signet" ? "testnet" : t.network, this.satsPerVbyte = t.satsPerVbyte, this.template = t.template, this.targetZeros = t.targetZeros, this.startNonce = t.startNonce ?? 0n, this.txDistribution = t.distribution, this.externalAbort && this.externalAbort !== t.signal && this.cleanupExternalAbort(), t.signal && (this.externalAbort = t.signal, t.signal.addEventListener("abort", this.abortHandler, { once: !0 })), !this.template || !this.txInputs || !this.txOutputs || this.targetZeros === void 0 || this.satsPerVbyte === void 0 || !this.txNetwork)
|
|
165
165
|
throw new Error("Mining parameters are missing");
|
|
166
|
-
const e = this.txInputs,
|
|
167
|
-
this.workers.forEach((
|
|
168
|
-
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
const
|
|
166
|
+
const e = this.txInputs, n = this.txOutputs, i = this.txNetwork, g = this.satsPerVbyte, I = this.template, c = this.targetZeros, a = this.txDistribution, A = this.stride;
|
|
167
|
+
this.workers.forEach((C, l) => {
|
|
168
|
+
C.processedBase = 0n, C.hashesProcessed = 0n, C.hashRate = 0, C.lastNonce = void 0;
|
|
169
|
+
const u = this.startNonce + BigInt(l) * BigInt(this.batchSize);
|
|
170
|
+
C.nextNonce = u;
|
|
171
|
+
const h = {
|
|
172
172
|
type: "mine",
|
|
173
173
|
inputs: e,
|
|
174
|
-
outputs:
|
|
175
|
-
network:
|
|
176
|
-
satsPerVbyte:
|
|
177
|
-
template:
|
|
178
|
-
startNonce:
|
|
174
|
+
outputs: n,
|
|
175
|
+
network: i,
|
|
176
|
+
satsPerVbyte: g,
|
|
177
|
+
template: I,
|
|
178
|
+
startNonce: u,
|
|
179
179
|
batchSize: this.batchSize,
|
|
180
|
-
targetZeros:
|
|
181
|
-
nonceStep:
|
|
182
|
-
distribution:
|
|
180
|
+
targetZeros: c,
|
|
181
|
+
nonceStep: A,
|
|
182
|
+
distribution: a
|
|
183
183
|
};
|
|
184
|
-
|
|
184
|
+
C.worker.postMessage(h);
|
|
185
185
|
});
|
|
186
186
|
}
|
|
187
187
|
pause() {
|
|
@@ -191,77 +191,84 @@ class C {
|
|
|
191
191
|
if (!this.paused || !this.template || !this.txInputs || !this.txOutputs || this.targetZeros === void 0 || this.satsPerVbyte === void 0 || !this.txNetwork)
|
|
192
192
|
return;
|
|
193
193
|
await this.readyPromise, this.running = !0, this.paused = !1, this.startedAt || (this.startedAt = performance.now());
|
|
194
|
-
const t = this.txInputs, e = this.txOutputs,
|
|
195
|
-
this.workers.forEach((
|
|
196
|
-
|
|
197
|
-
const
|
|
194
|
+
const t = this.txInputs, e = this.txOutputs, n = this.txNetwork, i = this.satsPerVbyte, g = this.template, I = this.targetZeros, c = this.txDistribution, a = this.stride;
|
|
195
|
+
this.workers.forEach((A, C) => {
|
|
196
|
+
A.processedBase = A.hashesProcessed, A.hashRate = 0;
|
|
197
|
+
const l = A.nextNonce || this.startNonce + BigInt(C) * BigInt(this.batchSize), u = {
|
|
198
198
|
type: "mine",
|
|
199
199
|
inputs: t,
|
|
200
200
|
outputs: e,
|
|
201
|
-
network:
|
|
202
|
-
satsPerVbyte:
|
|
203
|
-
template:
|
|
204
|
-
startNonce:
|
|
201
|
+
network: n,
|
|
202
|
+
satsPerVbyte: i,
|
|
203
|
+
template: g,
|
|
204
|
+
startNonce: l,
|
|
205
205
|
batchSize: this.batchSize,
|
|
206
|
-
targetZeros:
|
|
207
|
-
nonceStep:
|
|
208
|
-
distribution:
|
|
206
|
+
targetZeros: I,
|
|
207
|
+
nonceStep: a,
|
|
208
|
+
distribution: c
|
|
209
209
|
};
|
|
210
|
-
|
|
210
|
+
A.worker.postMessage(u);
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
213
|
stop() {
|
|
214
214
|
!this.running && !this.paused || (this.running = !1, this.paused = !1, this.terminateWorkers(), this.cleanupExternalAbort(), this.emit("stopped", void 0));
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
217
|
+
const L = {};
|
|
218
|
+
if (typeof globalThis.__ZELDMINER_WASM_BASE__ > "u")
|
|
219
|
+
try {
|
|
220
|
+
const s = typeof window < "u" && window.location?.origin ? window.location.origin : typeof self < "u" && self.location?.origin ? self.location.origin : "http://localhost";
|
|
221
|
+
globalThis.__ZELDMINER_WASM_BASE__ = new URL("/wasm/", s).href;
|
|
222
|
+
} catch {
|
|
223
|
+
globalThis.__ZELDMINER_WASM_BASE__ = "/wasm/";
|
|
224
|
+
}
|
|
225
|
+
let B = null, N = null, Y = !1;
|
|
226
|
+
const D = () => {
|
|
227
|
+
if (Y) return;
|
|
228
|
+
Y = !0;
|
|
222
229
|
const s = globalThis.GPUAdapter?.prototype, t = s?.requestDevice;
|
|
223
|
-
!s || typeof t != "function" || (s.requestDevice = function(
|
|
224
|
-
if (
|
|
225
|
-
const
|
|
226
|
-
for (const
|
|
227
|
-
(!(
|
|
230
|
+
!s || typeof t != "function" || (s.requestDevice = function(n) {
|
|
231
|
+
if (n?.requiredLimits && typeof this.limits == "object") {
|
|
232
|
+
const i = n.requiredLimits, g = this.limits;
|
|
233
|
+
for (const I of Object.keys(i))
|
|
234
|
+
(!(I in g) || g[I] === void 0) && delete i[I];
|
|
228
235
|
}
|
|
229
|
-
return t.call(this,
|
|
236
|
+
return t.call(this, n);
|
|
230
237
|
});
|
|
231
|
-
},
|
|
238
|
+
}, R = (s) => s.endsWith("/") ? s : `${s}/`, p = (s) => {
|
|
232
239
|
const t = s.trim();
|
|
233
|
-
return t && (typeof window < "u" && typeof window.location?.origin == "string" ?
|
|
234
|
-
},
|
|
240
|
+
return t && (typeof window < "u" && typeof window.location?.origin == "string" ? R(new URL(t, window.location.origin).href) : R(new URL(t, import.meta.url).href));
|
|
241
|
+
}, Q = () => {
|
|
235
242
|
const s = globalThis.__ZELDMINER_WASM_BASE__;
|
|
236
243
|
if (typeof s == "string" && s.trim())
|
|
237
|
-
return
|
|
238
|
-
const t =
|
|
244
|
+
return p(s);
|
|
245
|
+
const t = L?.VITE_ZELDMINER_WASM_BASE;
|
|
239
246
|
if (typeof t == "string" && t.trim())
|
|
240
|
-
return
|
|
247
|
+
return p(t);
|
|
241
248
|
const e = "./";
|
|
242
|
-
return e.trim() ?
|
|
243
|
-
},
|
|
244
|
-
|
|
249
|
+
return e.trim() ? p(`${R(e.trim())}wasm/`) : p("/wasm/");
|
|
250
|
+
}, K = Q(), S = `${K}zeldhash_miner_wasm.js`, _ = `${K}zeldhash_miner_wasm_bg.wasm`, x = async (s) => (0, eval)("s => import(s)")(s), T = (s) => s instanceof Error ? s.message : String(s), j = async () => {
|
|
251
|
+
D();
|
|
245
252
|
let s;
|
|
246
253
|
try {
|
|
247
|
-
s = await
|
|
254
|
+
s = await x(
|
|
248
255
|
/* @vite-ignore */
|
|
249
|
-
|
|
256
|
+
S
|
|
250
257
|
);
|
|
251
|
-
} catch (
|
|
258
|
+
} catch (n) {
|
|
252
259
|
throw new Error(
|
|
253
|
-
`Failed to import WASM bundle (${
|
|
260
|
+
`Failed to import WASM bundle (${S}). Did you run ./scripts/build-wasm.sh? (${T(n)})`
|
|
254
261
|
);
|
|
255
262
|
}
|
|
256
263
|
const t = s.default;
|
|
257
264
|
if (typeof t != "function")
|
|
258
265
|
throw new Error("WASM init function is missing from the bundle.");
|
|
259
266
|
try {
|
|
260
|
-
const
|
|
261
|
-
await t({ module_or_path:
|
|
262
|
-
} catch (
|
|
267
|
+
const n = new URL(_, import.meta.url);
|
|
268
|
+
await t({ module_or_path: n });
|
|
269
|
+
} catch (n) {
|
|
263
270
|
throw new Error(
|
|
264
|
-
`Failed to initialize WASM bundle: ${
|
|
271
|
+
`Failed to initialize WASM bundle: ${T(n)}`
|
|
265
272
|
);
|
|
266
273
|
}
|
|
267
274
|
const e = s;
|
|
@@ -270,9 +277,9 @@ const Z = () => {
|
|
|
270
277
|
} catch {
|
|
271
278
|
}
|
|
272
279
|
return e;
|
|
273
|
-
},
|
|
280
|
+
}, M = async () => B || (N || (N = j().then((s) => (B = s, s)).catch((s) => {
|
|
274
281
|
throw N = null, s;
|
|
275
|
-
})), N),
|
|
282
|
+
})), N), W = (1n << 64n) - 1n, k = (s) => {
|
|
276
283
|
if (s < 0n)
|
|
277
284
|
throw new Error("nonce must be non-negative");
|
|
278
285
|
if (s === 0n) return 1;
|
|
@@ -280,20 +287,20 @@ const Z = () => {
|
|
|
280
287
|
for (; e > 0n; )
|
|
281
288
|
t += 1, e >>= 8n;
|
|
282
289
|
return t;
|
|
283
|
-
},
|
|
290
|
+
}, z = (s) => {
|
|
284
291
|
if (s < 0n)
|
|
285
292
|
throw new Error("nonce must be non-negative");
|
|
286
293
|
if (s <= 23n) return 1;
|
|
287
294
|
if (s <= 0xffn) return 2;
|
|
288
295
|
if (s <= 0xffffn) return 3;
|
|
289
296
|
if (s <= 0xffffffffn) return 5;
|
|
290
|
-
if (s <=
|
|
297
|
+
if (s <= W) return 9;
|
|
291
298
|
throw new Error("nonce range exceeds u64");
|
|
292
|
-
},
|
|
299
|
+
}, $ = (s) => {
|
|
293
300
|
if (!Number.isInteger(s) || s <= 0 || s > 8)
|
|
294
301
|
throw new Error("nonceLength must be between 1 and 8");
|
|
295
302
|
return (1n << BigInt(s * 8)) - 1n;
|
|
296
|
-
},
|
|
303
|
+
}, q = (s) => {
|
|
297
304
|
switch (s) {
|
|
298
305
|
case 1:
|
|
299
306
|
return 23n;
|
|
@@ -304,77 +311,77 @@ const Z = () => {
|
|
|
304
311
|
case 5:
|
|
305
312
|
return 0xffffffffn;
|
|
306
313
|
case 9:
|
|
307
|
-
return
|
|
314
|
+
return W;
|
|
308
315
|
default:
|
|
309
316
|
throw new Error("cbor nonceLength must be one of 1, 2, 3, 5, 9");
|
|
310
317
|
}
|
|
311
|
-
},
|
|
318
|
+
}, tt = (s, t) => {
|
|
312
319
|
if (s < 0n)
|
|
313
320
|
throw new Error("startNonce must be non-negative");
|
|
314
321
|
if (!Number.isInteger(t) || t <= 0)
|
|
315
322
|
throw new Error("batchSize must be a positive integer");
|
|
316
323
|
const e = s + BigInt(t - 1);
|
|
317
|
-
if (e >
|
|
324
|
+
if (e > W)
|
|
318
325
|
throw new Error("nonce range exceeds u64");
|
|
319
|
-
const
|
|
320
|
-
let
|
|
321
|
-
for (;
|
|
322
|
-
const
|
|
323
|
-
if (
|
|
326
|
+
const n = [];
|
|
327
|
+
let i = s;
|
|
328
|
+
for (; i <= e; ) {
|
|
329
|
+
const g = k(i), I = $(g), c = e < I ? e : I, a = c - i + 1n;
|
|
330
|
+
if (a > BigInt(Number.MAX_SAFE_INTEGER))
|
|
324
331
|
throw new Error("segment size exceeds safe integer range");
|
|
325
|
-
if (
|
|
326
|
-
start:
|
|
327
|
-
size: Number(
|
|
328
|
-
nonceLength:
|
|
329
|
-
}),
|
|
332
|
+
if (n.push({
|
|
333
|
+
start: i,
|
|
334
|
+
size: Number(a),
|
|
335
|
+
nonceLength: g
|
|
336
|
+
}), c === e)
|
|
330
337
|
break;
|
|
331
|
-
|
|
338
|
+
i = c + 1n;
|
|
332
339
|
}
|
|
333
|
-
return
|
|
334
|
-
},
|
|
340
|
+
return n;
|
|
341
|
+
}, et = (s, t) => {
|
|
335
342
|
if (s < 0n)
|
|
336
343
|
throw new Error("startNonce must be non-negative");
|
|
337
344
|
if (!Number.isInteger(t) || t <= 0)
|
|
338
345
|
throw new Error("batchSize must be a positive integer");
|
|
339
346
|
const e = s + BigInt(t - 1);
|
|
340
|
-
if (e >
|
|
347
|
+
if (e > W)
|
|
341
348
|
throw new Error("nonce range exceeds u64");
|
|
342
|
-
const
|
|
343
|
-
let
|
|
344
|
-
for (;
|
|
345
|
-
const
|
|
346
|
-
if (
|
|
349
|
+
const n = [];
|
|
350
|
+
let i = s;
|
|
351
|
+
for (; i <= e; ) {
|
|
352
|
+
const g = z(i), I = q(g), c = e < I ? e : I, a = c - i + 1n;
|
|
353
|
+
if (a > BigInt(Number.MAX_SAFE_INTEGER))
|
|
347
354
|
throw new Error("segment size exceeds safe integer range");
|
|
348
|
-
if (
|
|
349
|
-
start:
|
|
350
|
-
size: Number(
|
|
351
|
-
nonceLength:
|
|
352
|
-
}),
|
|
355
|
+
if (n.push({
|
|
356
|
+
start: i,
|
|
357
|
+
size: Number(a),
|
|
358
|
+
nonceLength: g
|
|
359
|
+
}), c === e)
|
|
353
360
|
break;
|
|
354
|
-
|
|
361
|
+
i = c + 1n;
|
|
355
362
|
}
|
|
356
|
-
return
|
|
357
|
-
},
|
|
358
|
-
const
|
|
359
|
-
throw
|
|
363
|
+
return n;
|
|
364
|
+
}, st = /^[0-9a-fA-F]{64}$/, nt = /^[0-9a-fA-F]+$/, G = (1n << 64n) - 1n, it = 4294967295, gt = (s) => s === "p2tr" ? 330 : s === "p2wpkh" ? 310 : 546, ot = (s) => s instanceof Error ? s.message : String(s), F = (s, t) => t.some((e) => s.includes(e)), J = (s, t, e) => {
|
|
365
|
+
const n = ot(s), i = n.toLowerCase();
|
|
366
|
+
throw F(i, ["insufficient funds", "insufficient_funds"]) ? r(
|
|
360
367
|
o.INSUFFICIENT_FUNDS,
|
|
361
368
|
"Insufficient funds for outputs and fee",
|
|
362
|
-
{ ...e, cause:
|
|
363
|
-
) :
|
|
369
|
+
{ ...e, cause: n }
|
|
370
|
+
) : F(i, ["change would be dust", "output amount below dust limit", "dust"]) ? r(
|
|
364
371
|
o.DUST_OUTPUT,
|
|
365
372
|
"Change would be dust",
|
|
366
|
-
{ ...e, cause:
|
|
367
|
-
) :
|
|
373
|
+
{ ...e, cause: n }
|
|
374
|
+
) : v(s, o.WORKER_ERROR, {
|
|
368
375
|
...e,
|
|
369
376
|
context: t
|
|
370
377
|
});
|
|
371
|
-
},
|
|
372
|
-
class
|
|
378
|
+
}, V = (s) => s === "signet" ? "testnet" : s;
|
|
379
|
+
class It {
|
|
373
380
|
network;
|
|
374
381
|
satsPerVbyte;
|
|
375
382
|
constructor(t, e) {
|
|
376
383
|
if (!Number.isFinite(e) || e <= 0)
|
|
377
|
-
throw
|
|
384
|
+
throw r(
|
|
378
385
|
o.INVALID_INPUT,
|
|
379
386
|
"satsPerVbyte must be a positive number",
|
|
380
387
|
{ field: "satsPerVbyte" }
|
|
@@ -382,38 +389,38 @@ class ot {
|
|
|
382
389
|
this.network = t, this.satsPerVbyte = e;
|
|
383
390
|
}
|
|
384
391
|
async getWasm() {
|
|
385
|
-
return
|
|
392
|
+
return M();
|
|
386
393
|
}
|
|
387
|
-
assertNonceRange(t, e,
|
|
388
|
-
if (t < 0n || t >
|
|
389
|
-
throw
|
|
394
|
+
assertNonceRange(t, e, n) {
|
|
395
|
+
if (t < 0n || t > G)
|
|
396
|
+
throw r(
|
|
390
397
|
o.INVALID_INPUT,
|
|
391
398
|
"startNonce must be between 0 and 2^64 - 1",
|
|
392
399
|
{ startNonce: t }
|
|
393
400
|
);
|
|
394
|
-
if (!Number.isInteger(e) || e <= 0 || e >
|
|
395
|
-
throw
|
|
401
|
+
if (!Number.isInteger(e) || e <= 0 || e > it)
|
|
402
|
+
throw r(
|
|
396
403
|
o.INVALID_INPUT,
|
|
397
404
|
"batchSize must be a positive 32-bit integer",
|
|
398
405
|
{ batchSize: e }
|
|
399
406
|
);
|
|
400
|
-
const
|
|
401
|
-
if (
|
|
402
|
-
throw
|
|
407
|
+
const i = t + BigInt(e - 1);
|
|
408
|
+
if (i > G)
|
|
409
|
+
throw r(
|
|
403
410
|
o.INVALID_INPUT,
|
|
404
411
|
"nonce range exceeds u64",
|
|
405
412
|
{ startNonce: t, batchSize: e }
|
|
406
413
|
);
|
|
407
|
-
const
|
|
408
|
-
if (
|
|
409
|
-
const
|
|
410
|
-
throw
|
|
414
|
+
const g = n ? z : k, I = g(t), c = g(i);
|
|
415
|
+
if (I !== c) {
|
|
416
|
+
const a = n ? "CBOR length" : "byte-length";
|
|
417
|
+
throw r(
|
|
411
418
|
o.INVALID_INPUT,
|
|
412
|
-
`nonce range crosses ${
|
|
419
|
+
`nonce range crosses ${a} boundary; reduce batch size`,
|
|
413
420
|
{ startNonce: t, batchSize: e }
|
|
414
421
|
);
|
|
415
422
|
}
|
|
416
|
-
return
|
|
423
|
+
return I;
|
|
417
424
|
}
|
|
418
425
|
cloneInputs(t) {
|
|
419
426
|
return t.map((e) => ({ ...e }));
|
|
@@ -423,54 +430,54 @@ class ot {
|
|
|
423
430
|
}
|
|
424
431
|
validateInputs(t) {
|
|
425
432
|
if (!Array.isArray(t) || t.length === 0)
|
|
426
|
-
throw
|
|
433
|
+
throw r(
|
|
427
434
|
o.INVALID_INPUT,
|
|
428
435
|
"At least one input is required"
|
|
429
436
|
);
|
|
430
|
-
t.forEach((e,
|
|
431
|
-
if (!
|
|
432
|
-
throw
|
|
437
|
+
t.forEach((e, n) => {
|
|
438
|
+
if (!st.test(e.txid))
|
|
439
|
+
throw r(
|
|
433
440
|
o.INVALID_INPUT,
|
|
434
|
-
`inputs[${
|
|
435
|
-
{ index:
|
|
441
|
+
`inputs[${n}].txid must be a 64-character hex`,
|
|
442
|
+
{ index: n }
|
|
436
443
|
);
|
|
437
444
|
if (!Number.isInteger(e.vout) || e.vout < 0)
|
|
438
|
-
throw
|
|
445
|
+
throw r(
|
|
439
446
|
o.INVALID_INPUT,
|
|
440
|
-
`inputs[${
|
|
441
|
-
{ index:
|
|
447
|
+
`inputs[${n}].vout must be a non-negative integer`,
|
|
448
|
+
{ index: n }
|
|
442
449
|
);
|
|
443
450
|
if (!Number.isInteger(e.amount) || e.amount <= 0)
|
|
444
|
-
throw
|
|
451
|
+
throw r(
|
|
445
452
|
o.INVALID_INPUT,
|
|
446
|
-
`inputs[${
|
|
447
|
-
{ index:
|
|
453
|
+
`inputs[${n}].amount must be a positive integer`,
|
|
454
|
+
{ index: n }
|
|
448
455
|
);
|
|
449
|
-
if (typeof e.scriptPubKey != "string" || e.scriptPubKey.length === 0 || e.scriptPubKey.length % 2 !== 0 || !
|
|
450
|
-
throw
|
|
456
|
+
if (typeof e.scriptPubKey != "string" || e.scriptPubKey.length === 0 || e.scriptPubKey.length % 2 !== 0 || !nt.test(e.scriptPubKey))
|
|
457
|
+
throw r(
|
|
451
458
|
o.INVALID_INPUT,
|
|
452
|
-
`inputs[${
|
|
453
|
-
{ index:
|
|
459
|
+
`inputs[${n}].scriptPubKey must be valid hex`,
|
|
460
|
+
{ index: n }
|
|
454
461
|
);
|
|
455
462
|
});
|
|
456
463
|
}
|
|
457
|
-
validateAddressResult(t, e,
|
|
464
|
+
validateAddressResult(t, e, n) {
|
|
458
465
|
if (!t.ok) {
|
|
459
|
-
const
|
|
460
|
-
throw
|
|
461
|
-
|
|
462
|
-
`outputs[${e}].address is invalid (${
|
|
466
|
+
const i = t.error ?? "invalid address", I = i.toLowerCase().includes("unsupported") ? o.UNSUPPORTED_ADDRESS_TYPE : o.INVALID_ADDRESS;
|
|
467
|
+
throw r(
|
|
468
|
+
I,
|
|
469
|
+
`outputs[${e}].address is invalid (${i})`,
|
|
463
470
|
{ index: e }
|
|
464
471
|
);
|
|
465
472
|
}
|
|
466
|
-
if (t.network && t.network !==
|
|
467
|
-
throw
|
|
473
|
+
if (t.network && t.network !== n && !(t.network === "testnet" && n === "signet"))
|
|
474
|
+
throw r(
|
|
468
475
|
o.INVALID_ADDRESS,
|
|
469
476
|
`outputs[${e}].address network mismatch`,
|
|
470
477
|
{ index: e }
|
|
471
478
|
);
|
|
472
479
|
if (t.addressType && t.addressType !== "p2tr" && t.addressType !== "p2wpkh")
|
|
473
|
-
throw
|
|
480
|
+
throw r(
|
|
474
481
|
o.UNSUPPORTED_ADDRESS_TYPE,
|
|
475
482
|
`outputs[${e}].address uses an unsupported type`,
|
|
476
483
|
{ index: e, addressType: t.addressType }
|
|
@@ -478,125 +485,125 @@ class ot {
|
|
|
478
485
|
}
|
|
479
486
|
async validateOutputs(t) {
|
|
480
487
|
if (!Array.isArray(t) || t.length === 0)
|
|
481
|
-
throw
|
|
488
|
+
throw r(
|
|
482
489
|
o.INVALID_INPUT,
|
|
483
490
|
"At least one output is required"
|
|
484
491
|
);
|
|
485
|
-
const e = t.filter((
|
|
492
|
+
const e = t.filter((g) => g.change).length;
|
|
486
493
|
if (e !== 1) {
|
|
487
|
-
const
|
|
488
|
-
throw
|
|
489
|
-
|
|
494
|
+
const g = e === 0 ? o.NO_CHANGE_OUTPUT : o.MULTIPLE_CHANGE_OUTPUTS;
|
|
495
|
+
throw r(
|
|
496
|
+
g,
|
|
490
497
|
"Exactly one change output is required",
|
|
491
498
|
{ changeCount: e }
|
|
492
499
|
);
|
|
493
500
|
}
|
|
494
|
-
const
|
|
495
|
-
t.forEach((
|
|
496
|
-
const
|
|
497
|
-
this.validateAddressResult(
|
|
498
|
-
const
|
|
499
|
-
if (
|
|
500
|
-
if (
|
|
501
|
-
throw
|
|
501
|
+
const n = await this.getWasm(), i = V(this.network);
|
|
502
|
+
t.forEach((g, I) => {
|
|
503
|
+
const c = n.validate_address(g.address, i);
|
|
504
|
+
this.validateAddressResult(c, I, i);
|
|
505
|
+
const a = gt(c.addressType);
|
|
506
|
+
if (g.change) {
|
|
507
|
+
if (g.amount !== void 0 && (!Number.isInteger(g.amount) || g.amount < 0))
|
|
508
|
+
throw r(
|
|
502
509
|
o.INVALID_INPUT,
|
|
503
|
-
`outputs[${
|
|
504
|
-
{ index:
|
|
510
|
+
`outputs[${I}].amount must be a non-negative integer when provided`,
|
|
511
|
+
{ index: I }
|
|
505
512
|
);
|
|
506
|
-
} else if (!Number.isInteger(
|
|
507
|
-
throw
|
|
513
|
+
} else if (!Number.isInteger(g.amount) || g.amount < a)
|
|
514
|
+
throw r(
|
|
508
515
|
o.DUST_OUTPUT,
|
|
509
|
-
`outputs[${
|
|
510
|
-
{ index:
|
|
516
|
+
`outputs[${I}].amount must be at least ${a} sats`,
|
|
517
|
+
{ index: I, addressType: c.addressType }
|
|
511
518
|
);
|
|
512
519
|
});
|
|
513
520
|
}
|
|
514
521
|
validateDistribution(t, e) {
|
|
515
522
|
if (e !== void 0) {
|
|
516
523
|
if (!Array.isArray(e))
|
|
517
|
-
throw
|
|
524
|
+
throw r(
|
|
518
525
|
o.INVALID_INPUT,
|
|
519
526
|
"distribution must be an array of bigint values"
|
|
520
527
|
);
|
|
521
528
|
if (e.length !== t.length)
|
|
522
|
-
throw
|
|
529
|
+
throw r(
|
|
523
530
|
o.INVALID_INPUT,
|
|
524
531
|
"distribution length must match number of outputs",
|
|
525
532
|
{ expected: t.length, actual: e.length }
|
|
526
533
|
);
|
|
527
|
-
return e.map((
|
|
528
|
-
if (typeof
|
|
529
|
-
throw
|
|
534
|
+
return e.map((n, i) => {
|
|
535
|
+
if (typeof n != "bigint")
|
|
536
|
+
throw r(
|
|
530
537
|
o.INVALID_INPUT,
|
|
531
538
|
"distribution values must be bigint",
|
|
532
|
-
{ index:
|
|
539
|
+
{ index: i }
|
|
533
540
|
);
|
|
534
|
-
if (
|
|
535
|
-
throw
|
|
541
|
+
if (n < 0n)
|
|
542
|
+
throw r(
|
|
536
543
|
o.INVALID_INPUT,
|
|
537
544
|
"distribution values must be non-negative",
|
|
538
|
-
{ index:
|
|
545
|
+
{ index: i }
|
|
539
546
|
);
|
|
540
|
-
return
|
|
547
|
+
return n;
|
|
541
548
|
});
|
|
542
549
|
}
|
|
543
550
|
}
|
|
544
551
|
async buildMiningTemplate(t) {
|
|
545
|
-
const { inputs: e, outputs:
|
|
546
|
-
this.validateInputs(e), await this.validateOutputs(
|
|
547
|
-
const
|
|
552
|
+
const { inputs: e, outputs: n, startNonce: i, batchSize: g, distribution: I } = t;
|
|
553
|
+
this.validateInputs(e), await this.validateOutputs(n);
|
|
554
|
+
const c = this.validateDistribution(n, I), a = Array.isArray(c), A = this.assertNonceRange(i, g, a), C = await this.getWasm();
|
|
548
555
|
try {
|
|
549
|
-
const
|
|
556
|
+
const l = C.build_mining_template(
|
|
550
557
|
this.cloneInputs(e),
|
|
551
|
-
this.cloneOutputs(
|
|
552
|
-
|
|
558
|
+
this.cloneOutputs(n),
|
|
559
|
+
V(this.network),
|
|
553
560
|
BigInt(this.satsPerVbyte),
|
|
554
|
-
n,
|
|
555
561
|
i,
|
|
556
|
-
|
|
562
|
+
g,
|
|
563
|
+
c ?? null
|
|
557
564
|
);
|
|
558
|
-
if (!
|
|
559
|
-
throw
|
|
565
|
+
if (!l || !(l.prefix instanceof Uint8Array) || !(l.suffix instanceof Uint8Array))
|
|
566
|
+
throw r(
|
|
560
567
|
o.WORKER_ERROR,
|
|
561
568
|
"WASM returned an invalid mining template"
|
|
562
569
|
);
|
|
563
|
-
const
|
|
564
|
-
return { ...
|
|
565
|
-
} catch (
|
|
566
|
-
throw
|
|
567
|
-
startNonce:
|
|
568
|
-
batchSize:
|
|
569
|
-
distribution:
|
|
570
|
+
const u = l.useCborNonce ?? a;
|
|
571
|
+
return { ...l, nonceLength: A, useCborNonce: u };
|
|
572
|
+
} catch (l) {
|
|
573
|
+
throw J(l, "build_mining_template", {
|
|
574
|
+
startNonce: i,
|
|
575
|
+
batchSize: g,
|
|
576
|
+
distribution: c
|
|
570
577
|
});
|
|
571
578
|
}
|
|
572
579
|
}
|
|
573
580
|
async buildPsbt(t) {
|
|
574
|
-
const { inputs: e, outputs:
|
|
575
|
-
this.validateInputs(e), await this.validateOutputs(
|
|
576
|
-
const
|
|
577
|
-
if (
|
|
578
|
-
throw
|
|
581
|
+
const { inputs: e, outputs: n, nonce: i, distribution: g } = t;
|
|
582
|
+
this.validateInputs(e), await this.validateOutputs(n);
|
|
583
|
+
const I = this.validateDistribution(n, g);
|
|
584
|
+
if (i < 0n || i > G)
|
|
585
|
+
throw r(
|
|
579
586
|
o.INVALID_INPUT,
|
|
580
587
|
"nonce must be between 0 and 2^64 - 1",
|
|
581
|
-
{ nonce:
|
|
588
|
+
{ nonce: i }
|
|
582
589
|
);
|
|
583
|
-
const
|
|
590
|
+
const c = await this.getWasm();
|
|
584
591
|
try {
|
|
585
|
-
return
|
|
592
|
+
return c.build_psbt(
|
|
586
593
|
this.cloneInputs(e),
|
|
587
|
-
this.cloneOutputs(
|
|
588
|
-
|
|
594
|
+
this.cloneOutputs(n),
|
|
595
|
+
V(this.network),
|
|
589
596
|
BigInt(this.satsPerVbyte),
|
|
590
|
-
|
|
591
|
-
|
|
597
|
+
i,
|
|
598
|
+
I ?? null
|
|
592
599
|
);
|
|
593
|
-
} catch (
|
|
594
|
-
throw
|
|
600
|
+
} catch (a) {
|
|
601
|
+
throw J(a, "build_psbt", { nonce: i, distribution: I });
|
|
595
602
|
}
|
|
596
603
|
}
|
|
597
604
|
}
|
|
598
|
-
const
|
|
599
|
-
class
|
|
605
|
+
const H = 1, U = 32;
|
|
606
|
+
class rt {
|
|
600
607
|
options;
|
|
601
608
|
builder;
|
|
602
609
|
coordinator = null;
|
|
@@ -604,7 +611,7 @@ class at {
|
|
|
604
611
|
state = "idle";
|
|
605
612
|
stopRequested = !1;
|
|
606
613
|
constructor(t) {
|
|
607
|
-
this.options = this.validateOptions(t), this.builder = new
|
|
614
|
+
this.options = this.validateOptions(t), this.builder = new It(t.network, t.satsPerVbyte), this.listeners = {
|
|
608
615
|
progress: /* @__PURE__ */ new Set(),
|
|
609
616
|
found: /* @__PURE__ */ new Set(),
|
|
610
617
|
error: /* @__PURE__ */ new Set(),
|
|
@@ -618,23 +625,23 @@ class at {
|
|
|
618
625
|
this.listeners[t].delete(e);
|
|
619
626
|
}
|
|
620
627
|
emit(t, e) {
|
|
621
|
-
this.listeners[t].forEach((
|
|
628
|
+
this.listeners[t].forEach((n) => n(e));
|
|
622
629
|
}
|
|
623
630
|
validateOptions(t) {
|
|
624
631
|
if (!Number.isInteger(t.batchSize) || t.batchSize <= 0)
|
|
625
|
-
throw
|
|
632
|
+
throw r(
|
|
626
633
|
o.INVALID_INPUT,
|
|
627
634
|
"batchSize must be a positive integer",
|
|
628
635
|
{ field: "batchSize" }
|
|
629
636
|
);
|
|
630
637
|
if (!Number.isInteger(t.workerThreads) || t.workerThreads <= 0)
|
|
631
|
-
throw
|
|
638
|
+
throw r(
|
|
632
639
|
o.INVALID_INPUT,
|
|
633
640
|
"workerThreads must be a positive integer",
|
|
634
641
|
{ field: "workerThreads" }
|
|
635
642
|
);
|
|
636
643
|
if (!Number.isFinite(t.satsPerVbyte) || t.satsPerVbyte <= 0)
|
|
637
|
-
throw
|
|
644
|
+
throw r(
|
|
638
645
|
o.INVALID_INPUT,
|
|
639
646
|
"satsPerVbyte must be a positive number",
|
|
640
647
|
{ field: "satsPerVbyte" }
|
|
@@ -651,106 +658,106 @@ class at {
|
|
|
651
658
|
}
|
|
652
659
|
async mineTransaction(t) {
|
|
653
660
|
if (this.state === "running")
|
|
654
|
-
throw
|
|
661
|
+
throw r(
|
|
655
662
|
o.INVALID_INPUT,
|
|
656
663
|
"Mining is already in progress"
|
|
657
664
|
);
|
|
658
|
-
if (!Number.isInteger(t.targetZeros) || t.targetZeros <
|
|
659
|
-
throw
|
|
665
|
+
if (!Number.isInteger(t.targetZeros) || t.targetZeros < H || t.targetZeros > U)
|
|
666
|
+
throw r(
|
|
660
667
|
o.INVALID_INPUT,
|
|
661
|
-
`targetZeros must be an integer between ${
|
|
668
|
+
`targetZeros must be an integer between ${H} and ${U}`,
|
|
662
669
|
{ targetZeros: t.targetZeros }
|
|
663
670
|
);
|
|
664
|
-
const e = t.startNonce ?? 0n,
|
|
665
|
-
if (!Number.isInteger(
|
|
666
|
-
throw
|
|
671
|
+
const e = t.startNonce ?? 0n, n = t.batchSize ?? this.options.batchSize;
|
|
672
|
+
if (!Number.isInteger(n) || n <= 0)
|
|
673
|
+
throw r(
|
|
667
674
|
o.INVALID_INPUT,
|
|
668
675
|
"batchSize must be a positive integer",
|
|
669
|
-
{ batchSize:
|
|
676
|
+
{ batchSize: n }
|
|
670
677
|
);
|
|
671
678
|
if (t.signal?.aborted)
|
|
672
|
-
throw
|
|
679
|
+
throw r(
|
|
673
680
|
o.MINING_ABORTED,
|
|
674
681
|
"Abort signal already triggered"
|
|
675
682
|
);
|
|
676
|
-
const
|
|
677
|
-
let
|
|
683
|
+
const i = t.distribution, g = !!(i && i.length > 0);
|
|
684
|
+
let I = n;
|
|
678
685
|
try {
|
|
679
|
-
const [
|
|
680
|
-
if (!
|
|
681
|
-
throw
|
|
686
|
+
const [l] = g ? et(e, n) : tt(e, n);
|
|
687
|
+
if (!l)
|
|
688
|
+
throw r(
|
|
682
689
|
o.INVALID_INPUT,
|
|
683
690
|
"Failed to compute nonce segments",
|
|
684
|
-
{ startNonce: e, batchSize:
|
|
691
|
+
{ startNonce: e, batchSize: n }
|
|
685
692
|
);
|
|
686
|
-
|
|
687
|
-
} catch (
|
|
688
|
-
throw
|
|
693
|
+
I = l.size;
|
|
694
|
+
} catch (l) {
|
|
695
|
+
throw r(
|
|
689
696
|
o.INVALID_INPUT,
|
|
690
|
-
|
|
691
|
-
{ startNonce: e, batchSize:
|
|
697
|
+
l instanceof Error ? l.message : String(l),
|
|
698
|
+
{ startNonce: e, batchSize: n }
|
|
692
699
|
);
|
|
693
700
|
}
|
|
694
|
-
const
|
|
701
|
+
const c = await this.selectBackend(), a = await this.builder.buildMiningTemplate({
|
|
695
702
|
inputs: t.inputs,
|
|
696
703
|
outputs: t.outputs,
|
|
697
704
|
startNonce: e,
|
|
698
|
-
batchSize:
|
|
699
|
-
distribution:
|
|
700
|
-
}),
|
|
701
|
-
mode:
|
|
702
|
-
batchSize:
|
|
705
|
+
batchSize: I,
|
|
706
|
+
distribution: i
|
|
707
|
+
}), A = this.options.network === "signet" ? "testnet" : this.options.network, C = new O({
|
|
708
|
+
mode: c,
|
|
709
|
+
batchSize: n,
|
|
703
710
|
workerThreads: this.options.workerThreads
|
|
704
711
|
});
|
|
705
|
-
return this.coordinator =
|
|
706
|
-
let
|
|
707
|
-
const
|
|
708
|
-
this.clearCoordinatorHandlers(
|
|
709
|
-
},
|
|
710
|
-
|
|
711
|
-
},
|
|
712
|
-
if (
|
|
713
|
-
|
|
714
|
-
const
|
|
715
|
-
|
|
716
|
-
},
|
|
717
|
-
|
|
718
|
-
this.emit("progress",
|
|
719
|
-
},
|
|
712
|
+
return this.coordinator = C, this.state = "running", this.stopRequested = !1, new Promise((l, u) => {
|
|
713
|
+
let h = !1;
|
|
714
|
+
const y = () => {
|
|
715
|
+
this.clearCoordinatorHandlers(C, b), this.coordinator === C && (this.coordinator = null), this.state = "idle", this.stopRequested = !1;
|
|
716
|
+
}, E = (d) => {
|
|
717
|
+
h || (h = !0, y(), l(d));
|
|
718
|
+
}, Z = (d) => {
|
|
719
|
+
if (h) return;
|
|
720
|
+
h = !0;
|
|
721
|
+
const m = v(d);
|
|
722
|
+
y(), this.emit("error", m), u(m);
|
|
723
|
+
}, b = {};
|
|
724
|
+
b.progress = (d) => {
|
|
725
|
+
this.emit("progress", d);
|
|
726
|
+
}, b.found = async (d) => {
|
|
720
727
|
try {
|
|
721
|
-
const
|
|
728
|
+
const m = await this.builder.buildPsbt({
|
|
722
729
|
inputs: t.inputs,
|
|
723
730
|
outputs: t.outputs,
|
|
724
|
-
nonce:
|
|
725
|
-
distribution:
|
|
726
|
-
}),
|
|
727
|
-
this.emit("found",
|
|
728
|
-
} catch (
|
|
729
|
-
|
|
731
|
+
nonce: d.nonce,
|
|
732
|
+
distribution: i
|
|
733
|
+
}), f = { ...d, psbt: m };
|
|
734
|
+
this.emit("found", f), E(f);
|
|
735
|
+
} catch (m) {
|
|
736
|
+
Z(m);
|
|
730
737
|
}
|
|
731
|
-
},
|
|
732
|
-
|
|
733
|
-
},
|
|
734
|
-
if (
|
|
735
|
-
const
|
|
738
|
+
}, b.error = (d) => {
|
|
739
|
+
Z(d);
|
|
740
|
+
}, b.stopped = () => {
|
|
741
|
+
if (h) return;
|
|
742
|
+
const d = this.stopRequested ? r(
|
|
736
743
|
o.MINING_ABORTED,
|
|
737
744
|
"Mining stopped by caller"
|
|
738
|
-
) :
|
|
745
|
+
) : r(
|
|
739
746
|
o.MINING_ABORTED,
|
|
740
747
|
"Mining halted"
|
|
741
748
|
);
|
|
742
|
-
this.emit("stopped", void 0),
|
|
743
|
-
},
|
|
749
|
+
this.emit("stopped", void 0), Z(d);
|
|
750
|
+
}, C.on("progress", b.progress), C.on("found", b.found), C.on("error", b.error), C.on("stopped", b.stopped), C.start({
|
|
744
751
|
inputs: t.inputs,
|
|
745
752
|
outputs: t.outputs,
|
|
746
|
-
network:
|
|
753
|
+
network: A,
|
|
747
754
|
satsPerVbyte: this.options.satsPerVbyte,
|
|
748
|
-
template:
|
|
755
|
+
template: a,
|
|
749
756
|
targetZeros: t.targetZeros,
|
|
750
757
|
startNonce: e,
|
|
751
758
|
signal: t.signal,
|
|
752
|
-
distribution:
|
|
753
|
-
}).catch(
|
|
759
|
+
distribution: i
|
|
760
|
+
}).catch(Z);
|
|
754
761
|
});
|
|
755
762
|
}
|
|
756
763
|
stop() {
|
|
@@ -764,12 +771,12 @@ class at {
|
|
|
764
771
|
}
|
|
765
772
|
}
|
|
766
773
|
export {
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
774
|
+
O as MiningCoordinator,
|
|
775
|
+
It as TransactionBuilder,
|
|
776
|
+
rt as ZeldMiner,
|
|
777
|
+
w as ZeldMinerError,
|
|
771
778
|
o as ZeldMinerErrorCode,
|
|
772
|
-
|
|
773
|
-
|
|
779
|
+
r as createMinerError,
|
|
780
|
+
v as toZeldMinerError
|
|
774
781
|
};
|
|
775
782
|
//# sourceMappingURL=index.js.map
|