* * @throws InvalidArgumentException When required values are missing. */ public function sign( string $siteId, string $apiKey, string $method, string $path, string $body, int $timestamp, string $nonce ): array { $siteId = trim( $siteId ); $apiKey = trim( $apiKey ); $method = strtoupper( trim( $method ) ); $path = trim( $path ); $nonce = trim( $nonce ); if ( $siteId === '' || $apiKey === '' || $method === '' || $path === '' || $nonce === '' ) { throw new InvalidArgumentException( 'Cloud request signing requires site id, API key, method, path, and nonce.' ); } if ( $timestamp <= 0 ) { throw new InvalidArgumentException( 'Cloud request timestamp must be positive.' ); } $canonical = implode( "\n", array( $method, $path, (string) $timestamp, $nonce, hash( 'sha256', $body ), ) ); $signature = hash_hmac( 'sha256', $canonical, $apiKey ); return array( 'X-AFFILUN-Site-Id' => $siteId, 'X-AFFILUN-Timestamp' => (string) $timestamp, 'X-AFFILUN-Nonce' => $nonce, 'X-AFFILUN-Signature' => $signature, ); } }