zeldhash-miner 0.2.2 → 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/dist/index.d.ts +1 -0
- package/dist/index.js +314 -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 -354
- 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 Z {
|
|
|
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,Ly8gQm9vdHN0cmFwOiBkZWZpbmUgYSBzZW5zaWJsZSBkZWZhdWx0IGZvciBXQVNNIGJhc2UgcGF0aCBpbiB3b3JrZXIgY29udGV4dC4KLy8gV29ya2VycyBkb24ndCBoYXZlIGB3aW5kb3dgLCBidXQgYHNlbGZgIHByb3ZpZGVzIGxvY2F0aW9uLiBUaGlzIG11c3QgcnVuCi8vIGJlZm9yZSBhbnkgaW1wb3J0IHRoYXQgY2FsbHMgcmVzb2x2ZVdhc21CYXNlKCkuCmlmICh0eXBlb2YgKGdsb2JhbFRoaXMgYXMgeyBfX1pFTERNSU5FUl9XQVNNX0JBU0VfXz86IHVua25vd24gfSkuX19aRUxETUlORVJfV0FTTV9CQVNFX18gPT09ICJ1bmRlZmluZWQiKSB7CiAgdHJ5IHsKICAgIGNvbnN0IG9yaWdpbiA9CiAgICAgIHR5cGVvZiBzZWxmICE9PSAidW5kZWZpbmVkIiAmJiAoc2VsZiBh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gICAgIH0gY2F0Y2ggKGVycikgewogICAgICAgIHBvc3RFcnJvcigKICAgICAgICAgIGBJbnZhbGlkIG5vbmNlIHJhbmdlOiAke2Zvcm1hdEVycm9yKGVycil9YCwKICAgICAgICAgIFplbGRNaW5lckVycm9yQ29kZS5JTlZBTElEX0lOUFVUCiAgICAgICAgKTsKICAgICAgICBhYm9ydC5hYm9ydCgpOwogICAgICAgIHJldHVybjsKICAgICAgfQoKICAgICAgbGV0IHRlbXBsYXRlOiBXb3JrZXJUZW1wbGF0ZTsKICAgICAgdHJ5IHsKICAgICAgICB0ZW1wbGF0ZSA9IGF3YWl0IGVuc3VyZVRlbXBsYXRlRm9yU2VnbWVudCgKICAgICAgICAgIHRlbXBsYXRlQ2FjaGUsCiAgICAgICAgICB3YXNtLAogICAgICAgICAgewogICAgICAgICAgICBpbnB1dHM6IG1zZy5pbnB1dHMsCiAgICAgICAgICAgIG91dHB1dHM6IG1zZy5vdXRwdXRzLAogICAgICAgICAgICBzYXRzUGVyVmJ5dGU6IG1zZy5zYXRzUGVyVmJ5dGUsCiAgICAgICAgICAgIGRpc3RyaWJ1dGlvbjogbXNnLmRpc3RyaWJ1dGlvbiwKICAgICAgICAgICAgdXNlQ2Jvck5vbmNlLAogICAgICAgICAgfSwKICAgICAgICAgIHNlZ21lbnQsCiAgICAgICAgICBub3JtYWxpemVkTmV0d29yawogICAgICAgICk7CiAgICAgIH0gY2F0Y2ggKGVycikgewogICAgICAgIHBvc3RFcnJvcigKICAgICAgICAgIGBGYWlsZWQgdG8gYnVpbGQgbWluaW5nIHRlbXBsYXRlOiAke2Zvcm1hdEVycm9yKGVycil9YCwKICAgICAgICAgIFplbGRNaW5lckVycm9yQ29kZS5XT1JLRVJfRVJST1IKICAgICAgICApOwogICAgICAgIGFib3J0LmFib3J0KCk7CiAgICAgICAgcmV0dXJuOwogICAgICB9CgogICAgICBsZXQgb3V0cHV0OiB1bmtub3duOwogICAgICBjb25zdCBiYXRjaFN0YXJ0ZWRBdCA9IHBlcmZvcm1hbmNlLm5vdygpOwogICAgICB0cnkgewogICAgICAgIG91dHB1dCA9IGF3YWl0IHJ1bkJhdGNoKAogICAgICAgICAgd2FzbSwKICAgICAgICAgIGN1cnJlbnRNb2RlLAogICAgICAgICAgdGVtcGxhdGUucHJlZml4LAogICAgICAgICAgdGVtcGxhdGUuc3VmZml4LAogICAgICAgICAgc2VnbWVudC5zdGFydCwKICAgICAgICAgIHNlZ21lbnQuc2l6ZSwKICAgICAgICAgIG1zZy50YXJnZXRaZXJvcywKICAgICAgICAgIHVzZUNib3JOb25jZQogICAgICAgICk7CiAgICAgIH0gY2F0Y2ggKGVycikgewogICAgICAgIGNvbnN0IG1lc3NhZ2UgPSBmb3JtYXRFcnJvcihlcnIpOwogICAgICAgIHBvc3RFcnJvcigKICAgICAgICAgIGBCYXRjaCBtaW5pbmcgZmFpbGVkOiAke21lc3NhZ2V9YCwKICAgICAgICAgIFplbGRNaW5lckVycm9yQ29kZS5XT1JLRVJfRVJST1IKICAgICAgICApOwogICAgICAgIGFib3J0LmFib3J0KCk7CiAgICAgICAgcmV0dXJuOwogICAgICB9CgogICAgICBjb25zdCBiYXRjaER1cmF0aW9uTXMgPSBwZXJmb3JtYW5jZS5ub3coKSAtIGJhdGNoU3RhcnRlZEF0OwoKICAgICAgaWYgKGlzVmFsaWRhdGlvblJlc3VsdChvdXRwdXQpKSB7CiAgICAgICAgaWYgKCFvdXRwdXQub2spIHsKICAgICAgICAgIHBvc3RFcnJvcigKICAgICAgICAgICAgb3V0cHV0LmVycm9yID8/ICJWYWxpZGF0aW9uIGZhaWxlZCIsCiAgICAgICAgICAgIFplbGRNaW5lckVycm9yQ29kZS5JTlZBTElEX0lOUFVUCiAgICAgICAgICApOwogICAgICAgICAgYWJvcnQuYWJvcnQoKTsKICAgICAgICAgIHJldHVybjsKICAgICAgICB9CiAgICAgIH0gZWxzZSBpZiAoaXNNaW5lUmVzdWx0KG91dHB1dCkpIHsKICAgICAgICBjb25zdCBhdHRlbXB0c0JlZm9yZSA9IGhhc2hlc1Byb2Nlc3NlZCArIHByb2Nlc3NlZEluSXRlcmF0aW9uOwogICAgICAgIGNvbnN0IGF0dGVtcHRzSW5TZWdtZW50ID0gQmlnSW50KG91dHB1dC5ub25jZSkgLSBzZWdtZW50LnN0YXJ0ICsgMW47CiAgICAgICAgY29uc3QgdG90YWxBdHRlbXB0cyA9IGF0dGVtcHRzQmVmb3JlICsgYXR0ZW1wdHNJblNlZ21lbnQ7CiAgICAgICAgY29uc3QgZWxhcHNlZE1zID0gcGVyZm9ybWFuY2Uubm93KCkgLSBzdGFydGVkQXQ7CiAgICAgICAgY29uc3QgaGFzaFJhdGUgPQogICAgICAgICAgZWxhcHNlZE1zID4gMAogICAgICAgICAgICA/IHNhZmVCaWdJbnRUb051bWJlcih0b3RhbEF0dGVtcHRzKSAvIChlbGFwc2VkTXMgLyAxMDAwKQogICAgICAgICAgICA6IDA7CiAgICAgICAgY29uc3QgbGFzdE5vbmNlID0gc2VnbWVudC5zdGFydCArIGF0dGVtcHRzSW5TZWdtZW50IC0gMW47CgogICAgICAgIGNvbnN0IHJlc3VsdDogTWluZVJlc3VsdCA9IHsKICAgICAgICAgIHBzYnQ6ICIiLAogICAgICAgICAgdHhpZDogb3V0cHV0LnR4aWQsCiAgICAgICAgICBub25jZTogQmlnSW50KG91dHB1dC5ub25jZSksCiAgICAgICAgICBhdHRlbXB0czogdG90YWxBdHRlbXB0cywKICAgICAgICAgIGR1cmF0aW9uOiBlbGFwc2VkTXMsCiAgICAgICAgICBoYXNoUmF0ZSwKICAgICAgICB9OwoKICAgICAgICBwb3N0KHsKICAgICAgICAgIHR5cGU6ICJmb3VuZCIsCiAgICAgICAgICByZXN1bHQsCiAgICAgICAgICBoYXNoZXNQcm9jZXNzZWQ6IHRvdGFsQXR0ZW1wdHMsCiAgICAgICAgICBoYXNoUmF0ZSwKICAgICAgICAgIGxhc3ROb25jZSwKICAgICAgICB9KTsKICAgICAgICBhYm9ydC5hYm9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G9vcChtc2csIGFib3J0KS5maW5hbGx5KCgpID0+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 Z {
|
|
|
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 Z {
|
|
|
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 Z {
|
|
|
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,30 +191,30 @@ class Z {
|
|
|
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
|
|
217
|
+
const L = {};
|
|
218
218
|
if (typeof globalThis.__ZELDMINER_WASM_BASE__ > "u")
|
|
219
219
|
try {
|
|
220
220
|
const s = typeof window < "u" && window.location?.origin ? window.location.origin : typeof self < "u" && self.location?.origin ? self.location.origin : "http://localhost";
|
|
@@ -222,53 +222,53 @@ if (typeof globalThis.__ZELDMINER_WASM_BASE__ > "u")
|
|
|
222
222
|
} catch {
|
|
223
223
|
globalThis.__ZELDMINER_WASM_BASE__ = "/wasm/";
|
|
224
224
|
}
|
|
225
|
-
let
|
|
226
|
-
const
|
|
227
|
-
if (
|
|
228
|
-
|
|
225
|
+
let B = null, N = null, Y = !1;
|
|
226
|
+
const D = () => {
|
|
227
|
+
if (Y) return;
|
|
228
|
+
Y = !0;
|
|
229
229
|
const s = globalThis.GPUAdapter?.prototype, t = s?.requestDevice;
|
|
230
|
-
!s || typeof t != "function" || (s.requestDevice = function(
|
|
231
|
-
if (
|
|
232
|
-
const
|
|
233
|
-
for (const
|
|
234
|
-
(!(
|
|
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];
|
|
235
235
|
}
|
|
236
|
-
return t.call(this,
|
|
236
|
+
return t.call(this, n);
|
|
237
237
|
});
|
|
238
|
-
},
|
|
238
|
+
}, R = (s) => s.endsWith("/") ? s : `${s}/`, p = (s) => {
|
|
239
239
|
const t = s.trim();
|
|
240
|
-
return t && (typeof window < "u" && typeof window.location?.origin == "string" ?
|
|
241
|
-
},
|
|
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 = () => {
|
|
242
242
|
const s = globalThis.__ZELDMINER_WASM_BASE__;
|
|
243
243
|
if (typeof s == "string" && s.trim())
|
|
244
|
-
return
|
|
245
|
-
const t =
|
|
244
|
+
return p(s);
|
|
245
|
+
const t = L?.VITE_ZELDMINER_WASM_BASE;
|
|
246
246
|
if (typeof t == "string" && t.trim())
|
|
247
|
-
return
|
|
247
|
+
return p(t);
|
|
248
248
|
const e = "./";
|
|
249
|
-
return e.trim() ?
|
|
250
|
-
},
|
|
251
|
-
|
|
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();
|
|
252
252
|
let s;
|
|
253
253
|
try {
|
|
254
|
-
s = await
|
|
254
|
+
s = await x(
|
|
255
255
|
/* @vite-ignore */
|
|
256
|
-
|
|
256
|
+
S
|
|
257
257
|
);
|
|
258
|
-
} catch (
|
|
258
|
+
} catch (n) {
|
|
259
259
|
throw new Error(
|
|
260
|
-
`Failed to import WASM bundle (${
|
|
260
|
+
`Failed to import WASM bundle (${S}). Did you run ./scripts/build-wasm.sh? (${T(n)})`
|
|
261
261
|
);
|
|
262
262
|
}
|
|
263
263
|
const t = s.default;
|
|
264
264
|
if (typeof t != "function")
|
|
265
265
|
throw new Error("WASM init function is missing from the bundle.");
|
|
266
266
|
try {
|
|
267
|
-
const
|
|
268
|
-
await t({ module_or_path:
|
|
269
|
-
} catch (
|
|
267
|
+
const n = new URL(_, import.meta.url);
|
|
268
|
+
await t({ module_or_path: n });
|
|
269
|
+
} catch (n) {
|
|
270
270
|
throw new Error(
|
|
271
|
-
`Failed to initialize WASM bundle: ${
|
|
271
|
+
`Failed to initialize WASM bundle: ${T(n)}`
|
|
272
272
|
);
|
|
273
273
|
}
|
|
274
274
|
const e = s;
|
|
@@ -277,9 +277,9 @@ const q = () => {
|
|
|
277
277
|
} catch {
|
|
278
278
|
}
|
|
279
279
|
return e;
|
|
280
|
-
},
|
|
280
|
+
}, M = async () => B || (N || (N = j().then((s) => (B = s, s)).catch((s) => {
|
|
281
281
|
throw N = null, s;
|
|
282
|
-
})), N),
|
|
282
|
+
})), N), W = (1n << 64n) - 1n, k = (s) => {
|
|
283
283
|
if (s < 0n)
|
|
284
284
|
throw new Error("nonce must be non-negative");
|
|
285
285
|
if (s === 0n) return 1;
|
|
@@ -287,20 +287,20 @@ const q = () => {
|
|
|
287
287
|
for (; e > 0n; )
|
|
288
288
|
t += 1, e >>= 8n;
|
|
289
289
|
return t;
|
|
290
|
-
},
|
|
290
|
+
}, z = (s) => {
|
|
291
291
|
if (s < 0n)
|
|
292
292
|
throw new Error("nonce must be non-negative");
|
|
293
293
|
if (s <= 23n) return 1;
|
|
294
294
|
if (s <= 0xffn) return 2;
|
|
295
295
|
if (s <= 0xffffn) return 3;
|
|
296
296
|
if (s <= 0xffffffffn) return 5;
|
|
297
|
-
if (s <=
|
|
297
|
+
if (s <= W) return 9;
|
|
298
298
|
throw new Error("nonce range exceeds u64");
|
|
299
|
-
},
|
|
299
|
+
}, $ = (s) => {
|
|
300
300
|
if (!Number.isInteger(s) || s <= 0 || s > 8)
|
|
301
301
|
throw new Error("nonceLength must be between 1 and 8");
|
|
302
302
|
return (1n << BigInt(s * 8)) - 1n;
|
|
303
|
-
},
|
|
303
|
+
}, q = (s) => {
|
|
304
304
|
switch (s) {
|
|
305
305
|
case 1:
|
|
306
306
|
return 23n;
|
|
@@ -311,77 +311,77 @@ const q = () => {
|
|
|
311
311
|
case 5:
|
|
312
312
|
return 0xffffffffn;
|
|
313
313
|
case 9:
|
|
314
|
-
return
|
|
314
|
+
return W;
|
|
315
315
|
default:
|
|
316
316
|
throw new Error("cbor nonceLength must be one of 1, 2, 3, 5, 9");
|
|
317
317
|
}
|
|
318
|
-
},
|
|
318
|
+
}, tt = (s, t) => {
|
|
319
319
|
if (s < 0n)
|
|
320
320
|
throw new Error("startNonce must be non-negative");
|
|
321
321
|
if (!Number.isInteger(t) || t <= 0)
|
|
322
322
|
throw new Error("batchSize must be a positive integer");
|
|
323
323
|
const e = s + BigInt(t - 1);
|
|
324
|
-
if (e >
|
|
324
|
+
if (e > W)
|
|
325
325
|
throw new Error("nonce range exceeds u64");
|
|
326
|
-
const
|
|
327
|
-
let
|
|
328
|
-
for (;
|
|
329
|
-
const
|
|
330
|
-
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))
|
|
331
331
|
throw new Error("segment size exceeds safe integer range");
|
|
332
|
-
if (
|
|
333
|
-
start:
|
|
334
|
-
size: Number(
|
|
335
|
-
nonceLength:
|
|
336
|
-
}),
|
|
332
|
+
if (n.push({
|
|
333
|
+
start: i,
|
|
334
|
+
size: Number(a),
|
|
335
|
+
nonceLength: g
|
|
336
|
+
}), c === e)
|
|
337
337
|
break;
|
|
338
|
-
|
|
338
|
+
i = c + 1n;
|
|
339
339
|
}
|
|
340
|
-
return
|
|
341
|
-
},
|
|
340
|
+
return n;
|
|
341
|
+
}, et = (s, t) => {
|
|
342
342
|
if (s < 0n)
|
|
343
343
|
throw new Error("startNonce must be non-negative");
|
|
344
344
|
if (!Number.isInteger(t) || t <= 0)
|
|
345
345
|
throw new Error("batchSize must be a positive integer");
|
|
346
346
|
const e = s + BigInt(t - 1);
|
|
347
|
-
if (e >
|
|
347
|
+
if (e > W)
|
|
348
348
|
throw new Error("nonce range exceeds u64");
|
|
349
|
-
const
|
|
350
|
-
let
|
|
351
|
-
for (;
|
|
352
|
-
const
|
|
353
|
-
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))
|
|
354
354
|
throw new Error("segment size exceeds safe integer range");
|
|
355
|
-
if (
|
|
356
|
-
start:
|
|
357
|
-
size: Number(
|
|
358
|
-
nonceLength:
|
|
359
|
-
}),
|
|
355
|
+
if (n.push({
|
|
356
|
+
start: i,
|
|
357
|
+
size: Number(a),
|
|
358
|
+
nonceLength: g
|
|
359
|
+
}), c === e)
|
|
360
360
|
break;
|
|
361
|
-
|
|
361
|
+
i = c + 1n;
|
|
362
362
|
}
|
|
363
|
-
return
|
|
364
|
-
},
|
|
365
|
-
const
|
|
366
|
-
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(
|
|
367
367
|
o.INSUFFICIENT_FUNDS,
|
|
368
368
|
"Insufficient funds for outputs and fee",
|
|
369
|
-
{ ...e, cause:
|
|
370
|
-
) :
|
|
369
|
+
{ ...e, cause: n }
|
|
370
|
+
) : F(i, ["change would be dust", "output amount below dust limit", "dust"]) ? r(
|
|
371
371
|
o.DUST_OUTPUT,
|
|
372
372
|
"Change would be dust",
|
|
373
|
-
{ ...e, cause:
|
|
374
|
-
) :
|
|
373
|
+
{ ...e, cause: n }
|
|
374
|
+
) : v(s, o.WORKER_ERROR, {
|
|
375
375
|
...e,
|
|
376
376
|
context: t
|
|
377
377
|
});
|
|
378
|
-
},
|
|
379
|
-
class
|
|
378
|
+
}, V = (s) => s === "signet" ? "testnet" : s;
|
|
379
|
+
class It {
|
|
380
380
|
network;
|
|
381
381
|
satsPerVbyte;
|
|
382
382
|
constructor(t, e) {
|
|
383
383
|
if (!Number.isFinite(e) || e <= 0)
|
|
384
|
-
throw
|
|
384
|
+
throw r(
|
|
385
385
|
o.INVALID_INPUT,
|
|
386
386
|
"satsPerVbyte must be a positive number",
|
|
387
387
|
{ field: "satsPerVbyte" }
|
|
@@ -389,38 +389,38 @@ class ot {
|
|
|
389
389
|
this.network = t, this.satsPerVbyte = e;
|
|
390
390
|
}
|
|
391
391
|
async getWasm() {
|
|
392
|
-
return
|
|
392
|
+
return M();
|
|
393
393
|
}
|
|
394
|
-
assertNonceRange(t, e,
|
|
395
|
-
if (t < 0n || t >
|
|
396
|
-
throw
|
|
394
|
+
assertNonceRange(t, e, n) {
|
|
395
|
+
if (t < 0n || t > G)
|
|
396
|
+
throw r(
|
|
397
397
|
o.INVALID_INPUT,
|
|
398
398
|
"startNonce must be between 0 and 2^64 - 1",
|
|
399
399
|
{ startNonce: t }
|
|
400
400
|
);
|
|
401
|
-
if (!Number.isInteger(e) || e <= 0 || e >
|
|
402
|
-
throw
|
|
401
|
+
if (!Number.isInteger(e) || e <= 0 || e > it)
|
|
402
|
+
throw r(
|
|
403
403
|
o.INVALID_INPUT,
|
|
404
404
|
"batchSize must be a positive 32-bit integer",
|
|
405
405
|
{ batchSize: e }
|
|
406
406
|
);
|
|
407
|
-
const
|
|
408
|
-
if (
|
|
409
|
-
throw
|
|
407
|
+
const i = t + BigInt(e - 1);
|
|
408
|
+
if (i > G)
|
|
409
|
+
throw r(
|
|
410
410
|
o.INVALID_INPUT,
|
|
411
411
|
"nonce range exceeds u64",
|
|
412
412
|
{ startNonce: t, batchSize: e }
|
|
413
413
|
);
|
|
414
|
-
const
|
|
415
|
-
if (
|
|
416
|
-
const
|
|
417
|
-
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(
|
|
418
418
|
o.INVALID_INPUT,
|
|
419
|
-
`nonce range crosses ${
|
|
419
|
+
`nonce range crosses ${a} boundary; reduce batch size`,
|
|
420
420
|
{ startNonce: t, batchSize: e }
|
|
421
421
|
);
|
|
422
422
|
}
|
|
423
|
-
return
|
|
423
|
+
return I;
|
|
424
424
|
}
|
|
425
425
|
cloneInputs(t) {
|
|
426
426
|
return t.map((e) => ({ ...e }));
|
|
@@ -430,54 +430,54 @@ class ot {
|
|
|
430
430
|
}
|
|
431
431
|
validateInputs(t) {
|
|
432
432
|
if (!Array.isArray(t) || t.length === 0)
|
|
433
|
-
throw
|
|
433
|
+
throw r(
|
|
434
434
|
o.INVALID_INPUT,
|
|
435
435
|
"At least one input is required"
|
|
436
436
|
);
|
|
437
|
-
t.forEach((e,
|
|
438
|
-
if (!
|
|
439
|
-
throw
|
|
437
|
+
t.forEach((e, n) => {
|
|
438
|
+
if (!st.test(e.txid))
|
|
439
|
+
throw r(
|
|
440
440
|
o.INVALID_INPUT,
|
|
441
|
-
`inputs[${
|
|
442
|
-
{ index:
|
|
441
|
+
`inputs[${n}].txid must be a 64-character hex`,
|
|
442
|
+
{ index: n }
|
|
443
443
|
);
|
|
444
444
|
if (!Number.isInteger(e.vout) || e.vout < 0)
|
|
445
|
-
throw
|
|
445
|
+
throw r(
|
|
446
446
|
o.INVALID_INPUT,
|
|
447
|
-
`inputs[${
|
|
448
|
-
{ index:
|
|
447
|
+
`inputs[${n}].vout must be a non-negative integer`,
|
|
448
|
+
{ index: n }
|
|
449
449
|
);
|
|
450
450
|
if (!Number.isInteger(e.amount) || e.amount <= 0)
|
|
451
|
-
throw
|
|
451
|
+
throw r(
|
|
452
452
|
o.INVALID_INPUT,
|
|
453
|
-
`inputs[${
|
|
454
|
-
{ index:
|
|
453
|
+
`inputs[${n}].amount must be a positive integer`,
|
|
454
|
+
{ index: n }
|
|
455
455
|
);
|
|
456
|
-
if (typeof e.scriptPubKey != "string" || e.scriptPubKey.length === 0 || e.scriptPubKey.length % 2 !== 0 || !
|
|
457
|
-
throw
|
|
456
|
+
if (typeof e.scriptPubKey != "string" || e.scriptPubKey.length === 0 || e.scriptPubKey.length % 2 !== 0 || !nt.test(e.scriptPubKey))
|
|
457
|
+
throw r(
|
|
458
458
|
o.INVALID_INPUT,
|
|
459
|
-
`inputs[${
|
|
460
|
-
{ index:
|
|
459
|
+
`inputs[${n}].scriptPubKey must be valid hex`,
|
|
460
|
+
{ index: n }
|
|
461
461
|
);
|
|
462
462
|
});
|
|
463
463
|
}
|
|
464
|
-
validateAddressResult(t, e,
|
|
464
|
+
validateAddressResult(t, e, n) {
|
|
465
465
|
if (!t.ok) {
|
|
466
|
-
const
|
|
467
|
-
throw
|
|
468
|
-
|
|
469
|
-
`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})`,
|
|
470
470
|
{ index: e }
|
|
471
471
|
);
|
|
472
472
|
}
|
|
473
|
-
if (t.network && t.network !==
|
|
474
|
-
throw
|
|
473
|
+
if (t.network && t.network !== n && !(t.network === "testnet" && n === "signet"))
|
|
474
|
+
throw r(
|
|
475
475
|
o.INVALID_ADDRESS,
|
|
476
476
|
`outputs[${e}].address network mismatch`,
|
|
477
477
|
{ index: e }
|
|
478
478
|
);
|
|
479
479
|
if (t.addressType && t.addressType !== "p2tr" && t.addressType !== "p2wpkh")
|
|
480
|
-
throw
|
|
480
|
+
throw r(
|
|
481
481
|
o.UNSUPPORTED_ADDRESS_TYPE,
|
|
482
482
|
`outputs[${e}].address uses an unsupported type`,
|
|
483
483
|
{ index: e, addressType: t.addressType }
|
|
@@ -485,125 +485,125 @@ class ot {
|
|
|
485
485
|
}
|
|
486
486
|
async validateOutputs(t) {
|
|
487
487
|
if (!Array.isArray(t) || t.length === 0)
|
|
488
|
-
throw
|
|
488
|
+
throw r(
|
|
489
489
|
o.INVALID_INPUT,
|
|
490
490
|
"At least one output is required"
|
|
491
491
|
);
|
|
492
|
-
const e = t.filter((
|
|
492
|
+
const e = t.filter((g) => g.change).length;
|
|
493
493
|
if (e !== 1) {
|
|
494
|
-
const
|
|
495
|
-
throw
|
|
496
|
-
|
|
494
|
+
const g = e === 0 ? o.NO_CHANGE_OUTPUT : o.MULTIPLE_CHANGE_OUTPUTS;
|
|
495
|
+
throw r(
|
|
496
|
+
g,
|
|
497
497
|
"Exactly one change output is required",
|
|
498
498
|
{ changeCount: e }
|
|
499
499
|
);
|
|
500
500
|
}
|
|
501
|
-
const
|
|
502
|
-
t.forEach((
|
|
503
|
-
const
|
|
504
|
-
this.validateAddressResult(
|
|
505
|
-
const
|
|
506
|
-
if (
|
|
507
|
-
if (
|
|
508
|
-
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(
|
|
509
509
|
o.INVALID_INPUT,
|
|
510
|
-
`outputs[${
|
|
511
|
-
{ index:
|
|
510
|
+
`outputs[${I}].amount must be a non-negative integer when provided`,
|
|
511
|
+
{ index: I }
|
|
512
512
|
);
|
|
513
|
-
} else if (!Number.isInteger(
|
|
514
|
-
throw
|
|
513
|
+
} else if (!Number.isInteger(g.amount) || g.amount < a)
|
|
514
|
+
throw r(
|
|
515
515
|
o.DUST_OUTPUT,
|
|
516
|
-
`outputs[${
|
|
517
|
-
{ index:
|
|
516
|
+
`outputs[${I}].amount must be at least ${a} sats`,
|
|
517
|
+
{ index: I, addressType: c.addressType }
|
|
518
518
|
);
|
|
519
519
|
});
|
|
520
520
|
}
|
|
521
521
|
validateDistribution(t, e) {
|
|
522
522
|
if (e !== void 0) {
|
|
523
523
|
if (!Array.isArray(e))
|
|
524
|
-
throw
|
|
524
|
+
throw r(
|
|
525
525
|
o.INVALID_INPUT,
|
|
526
526
|
"distribution must be an array of bigint values"
|
|
527
527
|
);
|
|
528
528
|
if (e.length !== t.length)
|
|
529
|
-
throw
|
|
529
|
+
throw r(
|
|
530
530
|
o.INVALID_INPUT,
|
|
531
531
|
"distribution length must match number of outputs",
|
|
532
532
|
{ expected: t.length, actual: e.length }
|
|
533
533
|
);
|
|
534
|
-
return e.map((
|
|
535
|
-
if (typeof
|
|
536
|
-
throw
|
|
534
|
+
return e.map((n, i) => {
|
|
535
|
+
if (typeof n != "bigint")
|
|
536
|
+
throw r(
|
|
537
537
|
o.INVALID_INPUT,
|
|
538
538
|
"distribution values must be bigint",
|
|
539
|
-
{ index:
|
|
539
|
+
{ index: i }
|
|
540
540
|
);
|
|
541
|
-
if (
|
|
542
|
-
throw
|
|
541
|
+
if (n < 0n)
|
|
542
|
+
throw r(
|
|
543
543
|
o.INVALID_INPUT,
|
|
544
544
|
"distribution values must be non-negative",
|
|
545
|
-
{ index:
|
|
545
|
+
{ index: i }
|
|
546
546
|
);
|
|
547
|
-
return
|
|
547
|
+
return n;
|
|
548
548
|
});
|
|
549
549
|
}
|
|
550
550
|
}
|
|
551
551
|
async buildMiningTemplate(t) {
|
|
552
|
-
const { inputs: e, outputs:
|
|
553
|
-
this.validateInputs(e), await this.validateOutputs(
|
|
554
|
-
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();
|
|
555
555
|
try {
|
|
556
|
-
const
|
|
556
|
+
const l = C.build_mining_template(
|
|
557
557
|
this.cloneInputs(e),
|
|
558
|
-
this.cloneOutputs(
|
|
559
|
-
|
|
558
|
+
this.cloneOutputs(n),
|
|
559
|
+
V(this.network),
|
|
560
560
|
BigInt(this.satsPerVbyte),
|
|
561
|
-
n,
|
|
562
561
|
i,
|
|
563
|
-
|
|
562
|
+
g,
|
|
563
|
+
c ?? null
|
|
564
564
|
);
|
|
565
|
-
if (!
|
|
566
|
-
throw
|
|
565
|
+
if (!l || !(l.prefix instanceof Uint8Array) || !(l.suffix instanceof Uint8Array))
|
|
566
|
+
throw r(
|
|
567
567
|
o.WORKER_ERROR,
|
|
568
568
|
"WASM returned an invalid mining template"
|
|
569
569
|
);
|
|
570
|
-
const
|
|
571
|
-
return { ...
|
|
572
|
-
} catch (
|
|
573
|
-
throw
|
|
574
|
-
startNonce:
|
|
575
|
-
batchSize:
|
|
576
|
-
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
|
|
577
577
|
});
|
|
578
578
|
}
|
|
579
579
|
}
|
|
580
580
|
async buildPsbt(t) {
|
|
581
|
-
const { inputs: e, outputs:
|
|
582
|
-
this.validateInputs(e), await this.validateOutputs(
|
|
583
|
-
const
|
|
584
|
-
if (
|
|
585
|
-
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(
|
|
586
586
|
o.INVALID_INPUT,
|
|
587
587
|
"nonce must be between 0 and 2^64 - 1",
|
|
588
|
-
{ nonce:
|
|
588
|
+
{ nonce: i }
|
|
589
589
|
);
|
|
590
|
-
const
|
|
590
|
+
const c = await this.getWasm();
|
|
591
591
|
try {
|
|
592
|
-
return
|
|
592
|
+
return c.build_psbt(
|
|
593
593
|
this.cloneInputs(e),
|
|
594
|
-
this.cloneOutputs(
|
|
595
|
-
|
|
594
|
+
this.cloneOutputs(n),
|
|
595
|
+
V(this.network),
|
|
596
596
|
BigInt(this.satsPerVbyte),
|
|
597
|
-
|
|
598
|
-
|
|
597
|
+
i,
|
|
598
|
+
I ?? null
|
|
599
599
|
);
|
|
600
|
-
} catch (
|
|
601
|
-
throw
|
|
600
|
+
} catch (a) {
|
|
601
|
+
throw J(a, "build_psbt", { nonce: i, distribution: I });
|
|
602
602
|
}
|
|
603
603
|
}
|
|
604
604
|
}
|
|
605
|
-
const
|
|
606
|
-
class
|
|
605
|
+
const H = 1, U = 32;
|
|
606
|
+
class rt {
|
|
607
607
|
options;
|
|
608
608
|
builder;
|
|
609
609
|
coordinator = null;
|
|
@@ -611,7 +611,7 @@ class at {
|
|
|
611
611
|
state = "idle";
|
|
612
612
|
stopRequested = !1;
|
|
613
613
|
constructor(t) {
|
|
614
|
-
this.options = this.validateOptions(t), this.builder = new
|
|
614
|
+
this.options = this.validateOptions(t), this.builder = new It(t.network, t.satsPerVbyte), this.listeners = {
|
|
615
615
|
progress: /* @__PURE__ */ new Set(),
|
|
616
616
|
found: /* @__PURE__ */ new Set(),
|
|
617
617
|
error: /* @__PURE__ */ new Set(),
|
|
@@ -625,23 +625,23 @@ class at {
|
|
|
625
625
|
this.listeners[t].delete(e);
|
|
626
626
|
}
|
|
627
627
|
emit(t, e) {
|
|
628
|
-
this.listeners[t].forEach((
|
|
628
|
+
this.listeners[t].forEach((n) => n(e));
|
|
629
629
|
}
|
|
630
630
|
validateOptions(t) {
|
|
631
631
|
if (!Number.isInteger(t.batchSize) || t.batchSize <= 0)
|
|
632
|
-
throw
|
|
632
|
+
throw r(
|
|
633
633
|
o.INVALID_INPUT,
|
|
634
634
|
"batchSize must be a positive integer",
|
|
635
635
|
{ field: "batchSize" }
|
|
636
636
|
);
|
|
637
637
|
if (!Number.isInteger(t.workerThreads) || t.workerThreads <= 0)
|
|
638
|
-
throw
|
|
638
|
+
throw r(
|
|
639
639
|
o.INVALID_INPUT,
|
|
640
640
|
"workerThreads must be a positive integer",
|
|
641
641
|
{ field: "workerThreads" }
|
|
642
642
|
);
|
|
643
643
|
if (!Number.isFinite(t.satsPerVbyte) || t.satsPerVbyte <= 0)
|
|
644
|
-
throw
|
|
644
|
+
throw r(
|
|
645
645
|
o.INVALID_INPUT,
|
|
646
646
|
"satsPerVbyte must be a positive number",
|
|
647
647
|
{ field: "satsPerVbyte" }
|
|
@@ -658,106 +658,106 @@ class at {
|
|
|
658
658
|
}
|
|
659
659
|
async mineTransaction(t) {
|
|
660
660
|
if (this.state === "running")
|
|
661
|
-
throw
|
|
661
|
+
throw r(
|
|
662
662
|
o.INVALID_INPUT,
|
|
663
663
|
"Mining is already in progress"
|
|
664
664
|
);
|
|
665
|
-
if (!Number.isInteger(t.targetZeros) || t.targetZeros <
|
|
666
|
-
throw
|
|
665
|
+
if (!Number.isInteger(t.targetZeros) || t.targetZeros < H || t.targetZeros > U)
|
|
666
|
+
throw r(
|
|
667
667
|
o.INVALID_INPUT,
|
|
668
|
-
`targetZeros must be an integer between ${
|
|
668
|
+
`targetZeros must be an integer between ${H} and ${U}`,
|
|
669
669
|
{ targetZeros: t.targetZeros }
|
|
670
670
|
);
|
|
671
|
-
const e = t.startNonce ?? 0n,
|
|
672
|
-
if (!Number.isInteger(
|
|
673
|
-
throw
|
|
671
|
+
const e = t.startNonce ?? 0n, n = t.batchSize ?? this.options.batchSize;
|
|
672
|
+
if (!Number.isInteger(n) || n <= 0)
|
|
673
|
+
throw r(
|
|
674
674
|
o.INVALID_INPUT,
|
|
675
675
|
"batchSize must be a positive integer",
|
|
676
|
-
{ batchSize:
|
|
676
|
+
{ batchSize: n }
|
|
677
677
|
);
|
|
678
678
|
if (t.signal?.aborted)
|
|
679
|
-
throw
|
|
679
|
+
throw r(
|
|
680
680
|
o.MINING_ABORTED,
|
|
681
681
|
"Abort signal already triggered"
|
|
682
682
|
);
|
|
683
|
-
const
|
|
684
|
-
let
|
|
683
|
+
const i = t.distribution, g = !!(i && i.length > 0);
|
|
684
|
+
let I = n;
|
|
685
685
|
try {
|
|
686
|
-
const [
|
|
687
|
-
if (!
|
|
688
|
-
throw
|
|
686
|
+
const [l] = g ? et(e, n) : tt(e, n);
|
|
687
|
+
if (!l)
|
|
688
|
+
throw r(
|
|
689
689
|
o.INVALID_INPUT,
|
|
690
690
|
"Failed to compute nonce segments",
|
|
691
|
-
{ startNonce: e, batchSize:
|
|
691
|
+
{ startNonce: e, batchSize: n }
|
|
692
692
|
);
|
|
693
|
-
|
|
694
|
-
} catch (
|
|
695
|
-
throw
|
|
693
|
+
I = l.size;
|
|
694
|
+
} catch (l) {
|
|
695
|
+
throw r(
|
|
696
696
|
o.INVALID_INPUT,
|
|
697
|
-
|
|
698
|
-
{ startNonce: e, batchSize:
|
|
697
|
+
l instanceof Error ? l.message : String(l),
|
|
698
|
+
{ startNonce: e, batchSize: n }
|
|
699
699
|
);
|
|
700
700
|
}
|
|
701
|
-
const
|
|
701
|
+
const c = await this.selectBackend(), a = await this.builder.buildMiningTemplate({
|
|
702
702
|
inputs: t.inputs,
|
|
703
703
|
outputs: t.outputs,
|
|
704
704
|
startNonce: e,
|
|
705
|
-
batchSize:
|
|
706
|
-
distribution:
|
|
707
|
-
}),
|
|
708
|
-
mode:
|
|
709
|
-
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,
|
|
710
710
|
workerThreads: this.options.workerThreads
|
|
711
711
|
});
|
|
712
|
-
return this.coordinator =
|
|
713
|
-
let
|
|
714
|
-
const
|
|
715
|
-
this.clearCoordinatorHandlers(
|
|
716
|
-
},
|
|
717
|
-
|
|
718
|
-
},
|
|
719
|
-
if (
|
|
720
|
-
|
|
721
|
-
const
|
|
722
|
-
|
|
723
|
-
},
|
|
724
|
-
|
|
725
|
-
this.emit("progress",
|
|
726
|
-
},
|
|
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) => {
|
|
727
727
|
try {
|
|
728
|
-
const
|
|
728
|
+
const m = await this.builder.buildPsbt({
|
|
729
729
|
inputs: t.inputs,
|
|
730
730
|
outputs: t.outputs,
|
|
731
|
-
nonce:
|
|
732
|
-
distribution:
|
|
733
|
-
}),
|
|
734
|
-
this.emit("found",
|
|
735
|
-
} catch (
|
|
736
|
-
|
|
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);
|
|
737
737
|
}
|
|
738
|
-
},
|
|
739
|
-
|
|
740
|
-
},
|
|
741
|
-
if (
|
|
742
|
-
const
|
|
738
|
+
}, b.error = (d) => {
|
|
739
|
+
Z(d);
|
|
740
|
+
}, b.stopped = () => {
|
|
741
|
+
if (h) return;
|
|
742
|
+
const d = this.stopRequested ? r(
|
|
743
743
|
o.MINING_ABORTED,
|
|
744
744
|
"Mining stopped by caller"
|
|
745
|
-
) :
|
|
745
|
+
) : r(
|
|
746
746
|
o.MINING_ABORTED,
|
|
747
747
|
"Mining halted"
|
|
748
748
|
);
|
|
749
|
-
this.emit("stopped", void 0),
|
|
750
|
-
},
|
|
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({
|
|
751
751
|
inputs: t.inputs,
|
|
752
752
|
outputs: t.outputs,
|
|
753
|
-
network:
|
|
753
|
+
network: A,
|
|
754
754
|
satsPerVbyte: this.options.satsPerVbyte,
|
|
755
|
-
template:
|
|
755
|
+
template: a,
|
|
756
756
|
targetZeros: t.targetZeros,
|
|
757
757
|
startNonce: e,
|
|
758
758
|
signal: t.signal,
|
|
759
|
-
distribution:
|
|
760
|
-
}).catch(
|
|
759
|
+
distribution: i
|
|
760
|
+
}).catch(Z);
|
|
761
761
|
});
|
|
762
762
|
}
|
|
763
763
|
stop() {
|
|
@@ -771,12 +771,12 @@ class at {
|
|
|
771
771
|
}
|
|
772
772
|
}
|
|
773
773
|
export {
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
774
|
+
O as MiningCoordinator,
|
|
775
|
+
It as TransactionBuilder,
|
|
776
|
+
rt as ZeldMiner,
|
|
777
|
+
w as ZeldMinerError,
|
|
778
778
|
o as ZeldMinerErrorCode,
|
|
779
|
-
|
|
780
|
-
|
|
779
|
+
r as createMinerError,
|
|
780
|
+
v as toZeldMinerError
|
|
781
781
|
};
|
|
782
782
|
//# sourceMappingURL=index.js.map
|