twzrd-receipt-verifier 1.0.2 → 1.0.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/package.json +1 -6
- package/verify_twzrd_receipt.js +29 -11
package/package.json
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "twzrd-receipt-verifier",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Standalone offline verifier for TWZRD AO-Receipt V5 (Ed25519-signed keccak256 leaf). No trust in TWZRD servers or code.",
|
|
5
5
|
"keywords": ["twzrd", "x402", "solana", "ed25519", "keccak256", "receipt", "verifier", "agent", "attestation"],
|
|
6
6
|
"homepage": "https://intel.twzrd.xyz",
|
|
7
|
-
"repository": {
|
|
8
|
-
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/twzrd-sol/wzrd-final.git",
|
|
10
|
-
"directory": "packages/twzrd-agent-intel/verifier"
|
|
11
|
-
},
|
|
12
7
|
"license": "MIT",
|
|
13
8
|
"author": "TWZRD",
|
|
14
9
|
"bin": {
|
package/verify_twzrd_receipt.js
CHANGED
|
@@ -69,17 +69,35 @@ function recomputeLeaf(pre) {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
function fetchPublishedPubkey(baseUrl) {
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
72
|
+
const base = baseUrl.replace(/\/+$/, '');
|
|
73
|
+
const paths = [
|
|
74
|
+
'/.well-known/twzrd-receipt-pubkey',
|
|
75
|
+
'/v1/intel/pubkey',
|
|
76
|
+
'/.well-known/x402',
|
|
77
|
+
];
|
|
78
|
+
const headers = { 'User-Agent': 'twzrd-receipt-verifier/1.0' };
|
|
79
|
+
|
|
80
|
+
function fetchPath(i) {
|
|
81
|
+
if (i >= paths.length) return Promise.reject(new Error('no pubkey endpoint responded'));
|
|
82
|
+
const path = paths[i];
|
|
83
|
+
return new Promise((resolve, reject) => {
|
|
84
|
+
https.get(base + path, { headers }, (res) => {
|
|
85
|
+
let body = '';
|
|
86
|
+
res.on('data', (c) => (body += c));
|
|
87
|
+
res.on('end', () => {
|
|
88
|
+
try {
|
|
89
|
+
const doc = JSON.parse(body);
|
|
90
|
+
resolve(path.endsWith('/x402')
|
|
91
|
+
? doc.receipt.signature.public_key
|
|
92
|
+
: doc.public_key);
|
|
93
|
+
} catch (e) {
|
|
94
|
+
reject(e);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}).on('error', (err) => fetchPath(i + 1).then(resolve, reject));
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return fetchPath(0);
|
|
83
101
|
}
|
|
84
102
|
|
|
85
103
|
function verify(receipt, trustedPubkey) {
|