nirium-cli 3.2.8 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -7
- package/bin/nirium.js +60 -18
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -131,7 +131,8 @@ nirium verify <cid> --gateway https://gateway.pinata.cloud --gateway https://ipf
|
|
|
131
131
|
| `--json` | machine-readable result | off |
|
|
132
132
|
| `--hash <hex>` | expected evidence hash for a hash-only anchor (`sha-256:` prefix optional) | none |
|
|
133
133
|
| `--evidence <file>` | file whose SHA-256 is compared with the anchored hash | none |
|
|
134
|
-
| `--
|
|
134
|
+
| `--allow-unsigned` | accept a document with no agent signature on its hash alone (integrity only) | off |
|
|
135
|
+
| `--require-signature` | fail unless the document has a valid agent signature (the default since 4.0.0, kept for existing scripts) | on |
|
|
135
136
|
|
|
136
137
|
If every gateway comes back 404 after exhausting retries, that's
|
|
137
138
|
reported as **NOT YET AVAILABLE** (`availability: "not_yet_available"`
|
|
@@ -147,12 +148,18 @@ of the two checks actually ran and succeeded, a matching `--hash`/
|
|
|
147
148
|
was verified, so `verify` prints `NOTHING VERIFIED`, exits non-zero, and
|
|
148
149
|
sets `verified: false` in `--json`, instead of reporting a pass.
|
|
149
150
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
record, re-hash it and drop the
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
151
|
+
Since 4.0.0 an unsigned document fails by default ("Not signed ...
|
|
152
|
+
integrity only"): its hash proves the content did not change, not who
|
|
153
|
+
declared it, and someone could change a record, re-hash it and drop the
|
|
154
|
+
signature. Pass `--allow-unsigned` to accept unsigned receipts on their
|
|
155
|
+
hash alone. Same rule as the `require-signature` input of the
|
|
156
|
+
verify-audit-cid Action.
|
|
157
|
+
|
|
158
|
+
`verify` also recomputes the CID from the bytes each gateway serves and
|
|
159
|
+
only reads a document whose bytes match it (`cidMatch` in `--json`), so a
|
|
160
|
+
gateway cannot hand it a different document. A gateway that serves
|
|
161
|
+
anything else is skipped; if none matches, it fails with
|
|
162
|
+
`availability: "cid_mismatch"`.
|
|
156
163
|
|
|
157
164
|
## Charge for your API in five minutes
|
|
158
165
|
|
package/bin/nirium.js
CHANGED
|
@@ -179,7 +179,8 @@ 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('--
|
|
182
|
+
.option('--allow-unsigned', 'Accept a document with no agent signature on its hash alone (integrity only: it does not say who declared it)')
|
|
183
|
+
.option('--require-signature', 'Default since 4.0.0 (kept so existing scripts keep working): fail unless the document carries a valid agent signature')
|
|
183
184
|
.description('Independently verify IPFS audit document content hash & agent ed25519 signature')
|
|
184
185
|
.action(async (cid, options) => {
|
|
185
186
|
let expectedHash;
|
|
@@ -204,7 +205,11 @@ program
|
|
|
204
205
|
}
|
|
205
206
|
|
|
206
207
|
const gateways = options.gateway.length > 0 ? options.gateway : DEFAULT_GATEWAYS;
|
|
207
|
-
|
|
208
|
+
if (options.allowUnsigned && options.requireSignature) {
|
|
209
|
+
console.error('❌ Use either --allow-unsigned or --require-signature, not both');
|
|
210
|
+
process.exit(1);
|
|
211
|
+
}
|
|
212
|
+
const result = await fetchAndVerifyCid(cid, gateways, globalThis.fetch, { expectedHash, requireSignature: !options.allowUnsigned, retries, timeoutMs });
|
|
208
213
|
if (options.json) {
|
|
209
214
|
console.log(JSON.stringify(result, null, 2));
|
|
210
215
|
} else {
|
|
@@ -221,10 +226,10 @@ program
|
|
|
221
226
|
.description('Anchor a sha-256 hash (or a small JSON record) to IPFS via an Audit Trail node')
|
|
222
227
|
.option('--file <path>', 'Anchor the sha-256 of this file - the file itself is never uploaded')
|
|
223
228
|
.option('--hash <hex>', 'sha-256 hex of your evidence (64 chars, optional sha-256: prefix)')
|
|
224
|
-
.option('--record <json>', 'Small JSON object (max 8KB) to anchor verbatim, e.g. \'{"order":"A-12"}\'')
|
|
225
|
-
.option('--tx <hash>', 'Transaction hash to associate with this anchor')
|
|
226
|
-
.option('--tag <tag>', 'Free-form label for this anchor')
|
|
227
|
-
.option('--sign', 'Attach an ed25519 attestation of which key produced this anchor')
|
|
229
|
+
.option('--record <json>', 'Small JSON object (max 8KB) to anchor verbatim, e.g. \'{"order":"A-12"}\'. Put what the payment or action was for here: only the record is covered by its hash and by --sign')
|
|
230
|
+
.option('--tx <hash>', 'Transaction hash to associate with this anchor. Node metadata: not covered by the hash or by --sign')
|
|
231
|
+
.option('--tag <tag>', 'Free-form label for this anchor. Node metadata: not covered by the hash or by --sign')
|
|
232
|
+
.option('--sign', 'Attach an ed25519 attestation of which key produced this anchor (signs the record or hash, not --tx or --tag)')
|
|
228
233
|
.option('--key-env <VAR>', 'Environment variable holding the Stellar secret key to sign with (--sign only; default: the config store\'s secretKey)')
|
|
229
234
|
.option('-u, --url <url>', 'Agent URL', 'https://nirium-agent.fly.dev')
|
|
230
235
|
.option('--save <file>', 'Save your own copy of the anchored document; its bytes give back the same CID if IPFS ever loses it')
|
|
@@ -1655,7 +1660,10 @@ function verifyEd25519Signature(pubKeyGAddress, statement, signature) {
|
|
|
1655
1660
|
}
|
|
1656
1661
|
}
|
|
1657
1662
|
|
|
1658
|
-
|
|
1663
|
+
// requireSignature defaults to true since 4.0.0 (same as the Action's
|
|
1664
|
+
// require-signature, nirium#569): an unsigned receipt only proves its bytes
|
|
1665
|
+
// match its hash, not who declared it. --allow-unsigned turns it off.
|
|
1666
|
+
function verifyAuditDocument(doc, cid, { expectedHash, requireSignature = true } = {}) {
|
|
1659
1667
|
const fail = (error) => ({ ok: false, verified: false, cid, hashMatch: false, hashStatus: 'mismatch', expectedHash: '', computedHash: '', signatureStatus: 'absent', error });
|
|
1660
1668
|
if (!doc || typeof doc !== 'object') return fail('Invalid audit document format');
|
|
1661
1669
|
const anchoredHash = typeof doc.content_sha256 === 'string' ? doc.content_sha256.toLowerCase() : '';
|
|
@@ -1703,14 +1711,14 @@ function verifyAuditDocument(doc, cid, { expectedHash, requireSignature } = {})
|
|
|
1703
1711
|
// signature absent), which is not the same as the evidence being verified.
|
|
1704
1712
|
const anyFailed = hashStatus === 'mismatch' || signatureStatus === 'invalid';
|
|
1705
1713
|
const anyPassed = hashStatus === 'match' || signatureStatus === 'valid';
|
|
1706
|
-
// --
|
|
1707
|
-
//
|
|
1708
|
-
//
|
|
1714
|
+
// Unsigned: with --allow-unsigned a record passes on its hash alone, which
|
|
1715
|
+
// also means a record changed, re-hashed and stripped of its signature
|
|
1716
|
+
// passes. By default it does not.
|
|
1709
1717
|
const signatureMissing = !!requireSignature && signatureStatus === 'absent';
|
|
1710
1718
|
const ok = !anyFailed && anyPassed && !signatureMissing;
|
|
1711
1719
|
return {
|
|
1712
1720
|
ok, verified: ok, cid, mode, hashMatch: hashStatus === 'match', hashStatus, expectedHash: anchoredHash, computedHash, providedHash: expectedHash || '', signatureStatus, signatureScheme, signerKey, statement, declaredStatement, agentId,
|
|
1713
|
-
...(signatureMissing && !anyFailed ? { error: '
|
|
1721
|
+
...(signatureMissing && !anyFailed && anyPassed ? { error: 'Not signed: the content matches its hash (integrity only), but no agent signature says who declared it. Pass --allow-unsigned to accept unsigned receipts.' } : {}),
|
|
1714
1722
|
};
|
|
1715
1723
|
}
|
|
1716
1724
|
|
|
@@ -1728,6 +1736,18 @@ async function fetchAndVerifyCid(cid, gateways = 'https://gateway.pinata.cloud',
|
|
|
1728
1736
|
const sleep = opts.sleepFn || ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
1729
1737
|
const BACKOFF_MS = 300;
|
|
1730
1738
|
|
|
1739
|
+
// The gateway is not trusted to serve the bytes of the CID it was asked
|
|
1740
|
+
// for: the CID is recomputed from the served bytes (cidV0OfSmallFile, the
|
|
1741
|
+
// same check as `nirium cid`). Audit Trail returns CIDv0 (Qm...) only.
|
|
1742
|
+
if (!/^Qm[1-9A-HJ-NP-Za-km-z]{44}$/.test(String(cid))) {
|
|
1743
|
+
return {
|
|
1744
|
+
ok: false, verified: false, cid, hashMatch: false, expectedHash: '', computedHash: '', signatureStatus: 'absent',
|
|
1745
|
+
availability: 'invalid_cid',
|
|
1746
|
+
error: 'Only CIDv0 (Qm...) CIDs, as the Audit Trail node returns them, can be checked against the served bytes',
|
|
1747
|
+
attempts: [],
|
|
1748
|
+
};
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1731
1751
|
const attempts = [];
|
|
1732
1752
|
for (const gatewayUrl of list) {
|
|
1733
1753
|
const url = `${gatewayUrl.replace(/\/$/, '')}/ipfs/${cid}`;
|
|
@@ -1743,8 +1763,20 @@ async function fetchAndVerifyCid(cid, gateways = 'https://gateway.pinata.cloud',
|
|
|
1743
1763
|
attempts.push({ gateway: gatewayUrl, attempt, status: res.status });
|
|
1744
1764
|
break; // a real error from this gateway - try the next one, not more retries here
|
|
1745
1765
|
}
|
|
1746
|
-
const
|
|
1747
|
-
|
|
1766
|
+
const bytes = Buffer.from(await res.arrayBuffer());
|
|
1767
|
+
let served;
|
|
1768
|
+
try {
|
|
1769
|
+
served = cidV0OfSmallFile(bytes);
|
|
1770
|
+
} catch (err) {
|
|
1771
|
+
served = `unreadable (${err?.message || err})`;
|
|
1772
|
+
}
|
|
1773
|
+
if (served !== cid) {
|
|
1774
|
+
// Wrong bytes will not become right on a retry: next gateway.
|
|
1775
|
+
attempts.push({ gateway: gatewayUrl, attempt, status: 200, cidMismatch: true, error: `served bytes do not match the CID (they hash to ${served})` });
|
|
1776
|
+
break;
|
|
1777
|
+
}
|
|
1778
|
+
const doc = JSON.parse(bytes.toString('utf8'));
|
|
1779
|
+
return { ...verifyAuditDocument(doc, cid, opts), cidMatch: true, gateway: gatewayUrl, attempts: [...attempts, { gateway: gatewayUrl, attempt, status: 200 }] };
|
|
1748
1780
|
} catch (err) {
|
|
1749
1781
|
attempts.push({ gateway: gatewayUrl, attempt, error: err?.message || String(err) });
|
|
1750
1782
|
break; // network-level failure (unreachable, timeout) - try the next gateway
|
|
@@ -1758,12 +1790,15 @@ async function fetchAndVerifyCid(cid, gateways = 'https://gateway.pinata.cloud',
|
|
|
1758
1790
|
// which this reports distinctly so a caller doesn't read "not found
|
|
1759
1791
|
// anywhere" as "the hash doesn't match" (it was never fetched at all).
|
|
1760
1792
|
const allNotFound = attempts.length > 0 && attempts.every((a) => a.status === 404);
|
|
1793
|
+
const cidMismatch = attempts.some((a) => a.cidMismatch);
|
|
1761
1794
|
return {
|
|
1762
|
-
ok: false, verified: false, cid, hashMatch: false, expectedHash: '', computedHash: '', signatureStatus: 'absent',
|
|
1763
|
-
availability: allNotFound ? 'not_yet_available' : 'gateway_error',
|
|
1795
|
+
ok: false, verified: false, cid, cidMatch: false, hashMatch: false, expectedHash: '', computedHash: '', signatureStatus: 'absent',
|
|
1796
|
+
availability: allNotFound ? 'not_yet_available' : cidMismatch ? 'cid_mismatch' : 'gateway_error',
|
|
1764
1797
|
error: allNotFound
|
|
1765
1798
|
? `CID not found on ${list.length} gateway(s) after ${retries} retr${retries === 1 ? 'y' : 'ies'} each - it may not be propagated yet, not necessarily wrong`
|
|
1766
|
-
:
|
|
1799
|
+
: cidMismatch
|
|
1800
|
+
? `No gateway served bytes that match the CID - a gateway served different content; see attempts`
|
|
1801
|
+
: `Could not fetch the CID from any of ${list.length} gateway(s) - see attempts for each failure`,
|
|
1767
1802
|
attempts,
|
|
1768
1803
|
};
|
|
1769
1804
|
}
|
|
@@ -1782,7 +1817,9 @@ function formatVerifyOutput(result) {
|
|
|
1782
1817
|
if (result.hashStatus === undefined && result.error) {
|
|
1783
1818
|
lines.push(result.availability === 'not_yet_available'
|
|
1784
1819
|
? `ℹ NOT YET AVAILABLE: ${result.error}`
|
|
1785
|
-
:
|
|
1820
|
+
: result.availability === 'cid_mismatch' || result.availability === 'invalid_cid'
|
|
1821
|
+
? `❌ CID: ${result.error}`
|
|
1822
|
+
: `❌ GATEWAY ERROR: ${result.error}`);
|
|
1786
1823
|
if (Array.isArray(result.attempts) && result.attempts.length > 0) {
|
|
1787
1824
|
lines.push(`--------------------------------------------------`);
|
|
1788
1825
|
lines.push('Attempts:');
|
|
@@ -1793,10 +1830,15 @@ function formatVerifyOutput(result) {
|
|
|
1793
1830
|
lines.push(`--------------------------------------------------`);
|
|
1794
1831
|
lines.push(result.availability === 'not_yet_available'
|
|
1795
1832
|
? `❌ NOT YET AVAILABLE (not a hash mismatch - try again shortly, or add --gateway for another source)`
|
|
1796
|
-
:
|
|
1833
|
+
: result.availability === 'cid_mismatch'
|
|
1834
|
+
? `❌ VERIFICATION FAILED (a gateway served content that is not this CID)`
|
|
1835
|
+
: result.availability === 'invalid_cid'
|
|
1836
|
+
? `❌ VERIFICATION FAILED (not a CIDv0)`
|
|
1837
|
+
: `❌ VERIFICATION FAILED (could not reach the content, not a hash mismatch)`);
|
|
1797
1838
|
return lines.join('\n');
|
|
1798
1839
|
}
|
|
1799
1840
|
|
|
1841
|
+
if (result.cidMatch) lines.push(`✔ CID: MATCH (recomputed from the bytes served by ${result.gateway})`);
|
|
1800
1842
|
if (result.hashStatus === 'unchecked') {
|
|
1801
1843
|
lines.push(`ℹ HASH: NOT CHECKED (hash-only anchor: ${result.expectedHash.slice(0, 16)}...)`);
|
|
1802
1844
|
lines.push(` Pass --hash <hex> or --evidence <file> to compare it with your original evidence.`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nirium-cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
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",
|
|
@@ -48,7 +48,8 @@
|
|
|
48
48
|
"zod": "^4.6.6"
|
|
49
49
|
},
|
|
50
50
|
"viem": {
|
|
51
|
-
"zod": "^4.6.6"
|
|
51
|
+
"zod": "^4.6.6",
|
|
52
|
+
"ws": "^8.23.1"
|
|
52
53
|
}
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|