@peac/protocol 0.15.0 → 0.15.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/_internal/signature.d.ts +20 -0
- package/dist/_internal/signature.d.ts.map +1 -0
- package/dist/index.cjs +40 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +40 -4
- package/dist/index.mjs.map +1 -1
- package/dist/verify-local-wire01.d.ts.map +1 -1
- package/dist/verify-local.cjs +21 -2
- package/dist/verify-local.cjs.map +1 -1
- package/dist/verify-local.d.ts.map +1 -1
- package/dist/verify-local.mjs +22 -3
- package/dist/verify-local.mjs.map +1 -1
- package/dist/verify.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -2208,6 +2208,18 @@ async function resolveJWKS(issuerUrl, options) {
|
|
|
2208
2208
|
revokedKeys
|
|
2209
2209
|
};
|
|
2210
2210
|
}
|
|
2211
|
+
var ED25519_SIGNATURE_BYTES = 64;
|
|
2212
|
+
function ed25519SignatureByteLength(jws) {
|
|
2213
|
+
const parts = jws.split(".");
|
|
2214
|
+
if (parts.length !== 3) {
|
|
2215
|
+
return null;
|
|
2216
|
+
}
|
|
2217
|
+
try {
|
|
2218
|
+
return base64urlDecode(parts[2]).length;
|
|
2219
|
+
} catch {
|
|
2220
|
+
return null;
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2211
2223
|
|
|
2212
2224
|
// src/verify.ts
|
|
2213
2225
|
function jwkToPublicKey(jwk) {
|
|
@@ -2305,6 +2317,23 @@ async function verifyReceipt(optionsOrJws) {
|
|
|
2305
2317
|
};
|
|
2306
2318
|
}
|
|
2307
2319
|
const publicKey = jwkToPublicKey(jwk);
|
|
2320
|
+
const signatureBytes = ed25519SignatureByteLength(receiptJws);
|
|
2321
|
+
if (signatureBytes !== null && signatureBytes !== ED25519_SIGNATURE_BYTES) {
|
|
2322
|
+
const durationMs = performance.now() - startTime;
|
|
2323
|
+
fireTelemetryHook(telemetry?.onReceiptVerified, {
|
|
2324
|
+
receiptHash: hashReceipt(receiptJws),
|
|
2325
|
+
valid: false,
|
|
2326
|
+
reasonCode: "invalid_signature",
|
|
2327
|
+
issuer: payload.iss,
|
|
2328
|
+
kid: header.kid,
|
|
2329
|
+
durationMs
|
|
2330
|
+
});
|
|
2331
|
+
return {
|
|
2332
|
+
ok: false,
|
|
2333
|
+
reason: "invalid_signature",
|
|
2334
|
+
details: "Ed25519 signature has invalid length"
|
|
2335
|
+
};
|
|
2336
|
+
}
|
|
2308
2337
|
const result = await verify(receiptJws, publicKey);
|
|
2309
2338
|
if (!result.valid) {
|
|
2310
2339
|
const durationMs = performance.now() - startTime;
|
|
@@ -2340,7 +2369,7 @@ async function verifyReceipt(optionsOrJws) {
|
|
|
2340
2369
|
...jwksFetchTime && { jwks_fetch_ms: jwksFetchTime }
|
|
2341
2370
|
}
|
|
2342
2371
|
};
|
|
2343
|
-
} catch
|
|
2372
|
+
} catch {
|
|
2344
2373
|
const durationMs = performance.now() - startTime;
|
|
2345
2374
|
fireTelemetryHook(telemetry?.onReceiptVerified, {
|
|
2346
2375
|
receiptHash: hashReceipt(receiptJws),
|
|
@@ -2351,7 +2380,7 @@ async function verifyReceipt(optionsOrJws) {
|
|
|
2351
2380
|
return {
|
|
2352
2381
|
ok: false,
|
|
2353
2382
|
reason: "verification_error",
|
|
2354
|
-
details:
|
|
2383
|
+
details: "Unexpected verification error."
|
|
2355
2384
|
};
|
|
2356
2385
|
}
|
|
2357
2386
|
}
|
|
@@ -2664,11 +2693,18 @@ async function verifyLocal(jws, publicKey, options = {}) {
|
|
|
2664
2693
|
message: `Invalid receipt payload: ${syntaxMessage}`
|
|
2665
2694
|
};
|
|
2666
2695
|
}
|
|
2667
|
-
const
|
|
2696
|
+
const signatureBytes = ed25519SignatureByteLength(jws);
|
|
2697
|
+
if (signatureBytes !== null && signatureBytes !== ED25519_SIGNATURE_BYTES) {
|
|
2698
|
+
return {
|
|
2699
|
+
valid: false,
|
|
2700
|
+
code: "E_INVALID_SIGNATURE",
|
|
2701
|
+
message: "Ed25519 signature has invalid length"
|
|
2702
|
+
};
|
|
2703
|
+
}
|
|
2668
2704
|
return {
|
|
2669
2705
|
valid: false,
|
|
2670
2706
|
code: "E_INTERNAL",
|
|
2671
|
-
message:
|
|
2707
|
+
message: "Unexpected verification error."
|
|
2672
2708
|
};
|
|
2673
2709
|
}
|
|
2674
2710
|
}
|