@totemsdk/txpow 1.0.1 → 1.0.2
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/admission/verify.js +31 -19
- package/package.json +2 -2
package/dist/admission/verify.js
CHANGED
|
@@ -109,33 +109,45 @@ async function verifyWorkAdmission(action, challenge, proof, templateProvider, o
|
|
|
109
109
|
if (!isLessThan(txpowId, admissionTarget)) {
|
|
110
110
|
return { valid: false, reason: 'txpowId does not beat admission target' };
|
|
111
111
|
}
|
|
112
|
-
// 5. Template
|
|
113
|
-
|
|
112
|
+
// 5. Resolve a trusted template. Template fields — notably `blockDifficulty`,
|
|
113
|
+
// which drives the Super-level claim — must come from a freshly-fetched
|
|
114
|
+
// trusted template, never from the prover's copy (RFC-020 H4).
|
|
115
|
+
let trustedTemplate = options?.latestTemplate ?? null;
|
|
116
|
+
if (templateProvider) {
|
|
117
|
+
if (templateProvider.getLatestTemplate) {
|
|
118
|
+
trustedTemplate = await templateProvider.getLatestTemplate();
|
|
119
|
+
}
|
|
120
|
+
else if (options?.latestTemplate) {
|
|
121
|
+
trustedTemplate = options.latestTemplate;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
trustedTemplate = await templateProvider.getCurrentTemplate();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// 5a. Template freshness for admission (uses the proof's capture time).
|
|
128
|
+
const freshness = (0, template_js_1.templateFreshness)(proof.template, trustedTemplate, {
|
|
114
129
|
admissionWindowMs: options?.admissionWindowMs,
|
|
115
130
|
now: options?.now,
|
|
116
131
|
});
|
|
117
132
|
if (!freshness.admissionValid) {
|
|
118
133
|
return { valid: false, reason: 'proof template is stale for admission' };
|
|
119
134
|
}
|
|
120
|
-
//
|
|
121
|
-
//
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
135
|
+
// 5b. The prover's declared block difficulty must byte-match the trusted
|
|
136
|
+
// template — otherwise a prover could set a max difficulty to fake a
|
|
137
|
+
// Minima block.
|
|
138
|
+
if (trustedTemplate && trustedTemplate.blockDifficulty !== proof.template.blockDifficulty) {
|
|
139
|
+
return { valid: false, reason: 'proof template blockDifficulty does not match the trusted template' };
|
|
140
|
+
}
|
|
141
|
+
// 6. Level B: recompute the exact Minima Super level from the TRUSTED block
|
|
142
|
+
// difficulty and the re-derived txpowId. Without a trusted template we
|
|
143
|
+
// cannot claim Minima block contribution (isBlock = false).
|
|
144
|
+
const superLevel = trustedTemplate ? (0, template_js_1.computeSuperLevel)(txpowId, trustedTemplate.blockDifficulty) : -1;
|
|
145
|
+
const isBlock = trustedTemplate ? superLevel >= 0 : false;
|
|
146
|
+
// 7. Level C: broadcastability requires a live template provider, a current
|
|
147
|
+
// template, and isBlock. Offline mode leaves broadcastable undefined.
|
|
126
148
|
let broadcastable;
|
|
127
149
|
if (templateProvider) {
|
|
128
|
-
|
|
129
|
-
if (templateProvider.getLatestTemplate) {
|
|
130
|
-
latest = await templateProvider.getLatestTemplate();
|
|
131
|
-
}
|
|
132
|
-
else if (options?.latestTemplate) {
|
|
133
|
-
latest = options.latestTemplate;
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
latest = await templateProvider.getCurrentTemplate();
|
|
137
|
-
}
|
|
138
|
-
broadcastable = isBlock && latest.templateId === proof.template.templateId;
|
|
150
|
+
broadcastable = isBlock && trustedTemplate !== null && freshness.broadcastable;
|
|
139
151
|
}
|
|
140
152
|
return { valid: true, superLevel, isBlock, broadcastable };
|
|
141
153
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@totemsdk/txpow",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "TxPoW envelope serialization, proof-of-work mining, and Machine Work Admission for the Minima protocol",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"LICENSE"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@totemsdk/core": "^1.2.
|
|
25
|
+
"@totemsdk/core": "^1.2.11"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/jest": "^30.0.0",
|