@m2c/core
v0.11.0
Published
Shared protocol primitives (HMAC signing, error taxonomy, money) for the M2C SDKs.
Readme
@m2c/core
Shared protocol primitives for the M2C SDKs. You normally do not depend on this
directly - use @m2c/server (merchant backend) or
@m2c/vendor (payment vendor), which build on it.
It exists so the security-sensitive parts of the protocol have exactly one implementation:
sign(secret, body, { timestampSeconds? })- produce theX-M2C-Signature/X-M2C-Timestamppair (HMAC-SHA256 overtimestamp + "\n" + body).verify(secret, body, signature, timestamp, { maxSkewSeconds?, nowSeconds? })- constant-time verification with the full failure taxonomy.
M2CError/M2CSignatureError(with areason:missing|incomplete|malformed|timestamp_skew|mismatch|empty_secret).getHeader, the header-name constants, and the skew default.MIN_MONETARY_VALUE/MAX_MONETARY_VALUE+assertMonetaryAmountfor the major-units-at-the-wire boundary check.parseRetryAfter,isLoopbackHost, andassertSecureBaseUrlfor the shared HTTP transport policy used by the server and vendor SDKs.readBoundedResponseBodyfor timeout-aware response consumption with a 64-KiB memory bound.
Zero runtime dependencies (built on node:crypto). Requires Node 18+.
The malformed-vs-missing distinction is part of the protocol contract: a malformed-but-present signature is a tampering signal and must always be rejected. Every M2C SDK and the M2C server share this behavior, anchored by a known-answer test vector asserted in every suite.
