@chipi-stack/core 0.6.1 → 0.6.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/index.cjs +15 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +15 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -767,12 +767,24 @@ function generateNonce() {
|
|
|
767
767
|
}
|
|
768
768
|
return `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
|
|
769
769
|
}
|
|
770
|
+
function feltEquals(value, expected) {
|
|
771
|
+
try {
|
|
772
|
+
return BigInt(value) === expected;
|
|
773
|
+
} catch {
|
|
774
|
+
return false;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
770
777
|
function normalizeX402Signature(signature) {
|
|
771
778
|
if (Array.isArray(signature)) {
|
|
772
|
-
if (signature.length
|
|
773
|
-
|
|
779
|
+
if (signature.length === 2) {
|
|
780
|
+
return { r: String(signature[0]), s: String(signature[1]) };
|
|
781
|
+
}
|
|
782
|
+
if (signature.length === 5 && feltEquals(signature[0], 1n) && feltEquals(signature[1], 0n)) {
|
|
783
|
+
return { r: String(signature[3]), s: String(signature[4]) };
|
|
774
784
|
}
|
|
775
|
-
|
|
785
|
+
throw new Error(
|
|
786
|
+
`Unsupported ${signature.length}-felt signature: x402 needs one Starknet key, signed as [r, s] (OpenZeppelin, Braavos) or [1, 0, pubkey, r, s] (Argent / Ready).`
|
|
787
|
+
);
|
|
776
788
|
}
|
|
777
789
|
if (signature && typeof signature === "object" && "r" in signature && "s" in signature) {
|
|
778
790
|
const sig = signature;
|