nirium-cli 3.2.5 → 3.2.6
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 +8 -0
- package/bin/nirium.js +18 -5
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -114,6 +114,7 @@ nirium verify <cid> --gateway https://gateway.pinata.cloud --gateway https://ipf
|
|
|
114
114
|
| `--json` | machine-readable result | off |
|
|
115
115
|
| `--hash <hex>` | expected evidence hash for a hash-only anchor (`sha-256:` prefix optional) | none |
|
|
116
116
|
| `--evidence <file>` | file whose SHA-256 is compared with the anchored hash | none |
|
|
117
|
+
| `--require-signature` | fail unless the document has a valid agent signature | off |
|
|
117
118
|
|
|
118
119
|
If every gateway comes back 404 after exhausting retries, that's
|
|
119
120
|
reported as **NOT YET AVAILABLE** (`availability: "not_yet_available"`
|
|
@@ -129,6 +130,13 @@ of the two checks actually ran and succeeded, a matching `--hash`/
|
|
|
129
130
|
was verified, so `verify` prints `NOTHING VERIFIED`, exits non-zero, and
|
|
130
131
|
sets `verified: false` in `--json`, instead of reporting a pass.
|
|
131
132
|
|
|
133
|
+
An unsigned record still passes on its recomputed hash, with the
|
|
134
|
+
signature reported as ABSENT. That also means someone can change a
|
|
135
|
+
record, re-hash it and drop the signature, and it still passes. If you
|
|
136
|
+
only trust receipts your agents signed, add `--require-signature`: an
|
|
137
|
+
unsigned document then fails with a "Signature required" error. Same
|
|
138
|
+
rule as the `require-signature` input of the verify-audit-cid Action.
|
|
139
|
+
|
|
132
140
|
## Charge for your API in five minutes
|
|
133
141
|
|
|
134
142
|
```bash
|
package/bin/nirium.js
CHANGED
|
@@ -179,6 +179,7 @@ program
|
|
|
179
179
|
.option('--json', 'Output result as JSON')
|
|
180
180
|
.option('--hash <hex>', 'Expected sha-256 of the evidence (hex, optional sha-256: prefix), for hash-only anchors')
|
|
181
181
|
.option('--evidence <file>', 'Original evidence file; its sha-256 is compared with the anchored hash')
|
|
182
|
+
.option('--require-signature', 'Fail unless the document carries a valid agent signature (an unsigned record otherwise passes on its hash alone)')
|
|
182
183
|
.description('Independently verify IPFS audit document content hash & agent ed25519 signature')
|
|
183
184
|
.action(async (cid, options) => {
|
|
184
185
|
let expectedHash;
|
|
@@ -203,7 +204,7 @@ program
|
|
|
203
204
|
}
|
|
204
205
|
|
|
205
206
|
const gateways = options.gateway.length > 0 ? options.gateway : DEFAULT_GATEWAYS;
|
|
206
|
-
const result = await fetchAndVerifyCid(cid, gateways, globalThis.fetch, { expectedHash, retries, timeoutMs });
|
|
207
|
+
const result = await fetchAndVerifyCid(cid, gateways, globalThis.fetch, { expectedHash, requireSignature: !!options.requireSignature, retries, timeoutMs });
|
|
207
208
|
if (options.json) {
|
|
208
209
|
console.log(JSON.stringify(result, null, 2));
|
|
209
210
|
} else {
|
|
@@ -1642,7 +1643,7 @@ function verifyEd25519Signature(pubKeyGAddress, statement, signature) {
|
|
|
1642
1643
|
}
|
|
1643
1644
|
}
|
|
1644
1645
|
|
|
1645
|
-
function verifyAuditDocument(doc, cid, { expectedHash } = {}) {
|
|
1646
|
+
function verifyAuditDocument(doc, cid, { expectedHash, requireSignature } = {}) {
|
|
1646
1647
|
const fail = (error) => ({ ok: false, verified: false, cid, hashMatch: false, hashStatus: 'mismatch', expectedHash: '', computedHash: '', signatureStatus: 'absent', error });
|
|
1647
1648
|
if (!doc || typeof doc !== 'object') return fail('Invalid audit document format');
|
|
1648
1649
|
const anchoredHash = typeof doc.content_sha256 === 'string' ? doc.content_sha256.toLowerCase() : '';
|
|
@@ -1652,7 +1653,12 @@ function verifyAuditDocument(doc, cid, { expectedHash } = {}) {
|
|
|
1652
1653
|
// hash-only mode: the node stores the submitted hash as content_sha256 and
|
|
1653
1654
|
// has nothing to recompute it from, so compare against --hash/--evidence
|
|
1654
1655
|
// when given, otherwise report the hash as unchecked (not as a mismatch).
|
|
1655
|
-
|
|
1656
|
+
// Hash-only means the `record` field is missing, same rule as the
|
|
1657
|
+
// verify-audit-cid Action. A present but falsy record (null, "", 0) is a
|
|
1658
|
+
// changed document, not a hash-only one: before, `record: null` with the
|
|
1659
|
+
// original hash and signature kept passed here as a hash-only anchor while
|
|
1660
|
+
// the Action rejected it (holistis vector 10).
|
|
1661
|
+
const mode = doc.record === undefined ? 'hash-only' : 'record';
|
|
1656
1662
|
let computedHash = '';
|
|
1657
1663
|
let hashStatus;
|
|
1658
1664
|
if (mode === 'record') {
|
|
@@ -1685,8 +1691,15 @@ function verifyAuditDocument(doc, cid, { expectedHash } = {}) {
|
|
|
1685
1691
|
// signature absent), which is not the same as the evidence being verified.
|
|
1686
1692
|
const anyFailed = hashStatus === 'mismatch' || signatureStatus === 'invalid';
|
|
1687
1693
|
const anyPassed = hashStatus === 'match' || signatureStatus === 'valid';
|
|
1688
|
-
|
|
1689
|
-
|
|
1694
|
+
// --require-signature (opt-in, same as the Action's require-signature
|
|
1695
|
+
// input): an unsigned record otherwise passes on its hash alone, which also
|
|
1696
|
+
// means a record changed, re-hashed and stripped of its signature passes.
|
|
1697
|
+
const signatureMissing = !!requireSignature && signatureStatus === 'absent';
|
|
1698
|
+
const ok = !anyFailed && anyPassed && !signatureMissing;
|
|
1699
|
+
return {
|
|
1700
|
+
ok, verified: ok, cid, mode, hashMatch: hashStatus === 'match', hashStatus, expectedHash: anchoredHash, computedHash, providedHash: expectedHash || '', signatureStatus, signatureScheme, signerKey, statement, declaredStatement, agentId,
|
|
1701
|
+
...(signatureMissing && !anyFailed ? { error: 'Signature required (--require-signature), but this document has no agent signature.' } : {}),
|
|
1702
|
+
};
|
|
1690
1703
|
}
|
|
1691
1704
|
|
|
1692
1705
|
// `gateways` may be a single URL string (back-compat for direct callers)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nirium-cli",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.6",
|
|
4
4
|
"description": "Nirium from the terminal: pay or serve an x402 API on Stellar, anchor and verify receipts, check an agent and export reports.",
|
|
5
5
|
"main": "bin/nirium.js",
|
|
6
6
|
"type": "module",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"prepublishOnly": "node --check bin/nirium.js",
|
|
12
|
-
"test": "node --test test/doctor-seller.test.js test/config-secret.test.js test/serve-api-key.test.js test/verify-hash-only.test.js test/verify-retry-gateway.test.js test/pay-agent-construction.test.js test/pay-status-and-cap.test.js test/pay-payment-response-parsing.test.js test/status.test.js test/anchor.test.js test/anchor-sign.test.js test/report.test.js"
|
|
12
|
+
"test": "node --test test/doctor-seller.test.js test/config-secret.test.js test/serve-api-key.test.js test/verify-hash-only.test.js test/verify-holistis-vectors.test.js test/verify-retry-gateway.test.js test/pay-agent-construction.test.js test/pay-status-and-cap.test.js test/pay-payment-response-parsing.test.js test/status.test.js test/anchor.test.js test/anchor-sign.test.js test/report.test.js"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
|
15
15
|
"stellar",
|