Skip to content

Commit bbc26aa

Browse files
fix: Use starkbank/ecdsa 2.1.0 (#1111)
* Use starkbank/ecdsa 2 * Add gmp to CI * Require gmp here as well * Install gmp in docker --------- Co-authored-by: Shubham <tiwarishubham635@gmail.com>
1 parent e61bdc6 commit bbc26aa

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
lines changed

.github/workflows/test-and-deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ jobs:
5252
uses: shivammathur/setup-php@2.15.0
5353
with:
5454
php-version: '8.1'
55+
extensions: gmp
5556
id: php
5657

5758
- name: Build Release Artifacts

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ ARG version=latest
22
FROM php:$version
33

44
RUN apt-get update \
5-
&& apt-get install -y zip
5+
&& apt-get install -y zip \
6+
&& apt-get install -y libgmp-dev \
7+
&& docker-php-ext-install gmp
68

79
RUN curl -s https://getcomposer.org/installer | php \
810
&& mv composer.phar /usr/local/bin/composer

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
"require": {
1616
"php": ">=7.3",
1717
"sendgrid/php-http-client": "~4.1",
18-
"starkbank/ecdsa": "0.*",
18+
"starkbank/ecdsa": "^2.1.0",
1919
"ext-curl": "*",
2020
"ext-json": "*",
2121
"ext-mbstring": "*",
22-
"ext-openssl": "*"
22+
"ext-openssl": "*",
23+
"ext-gmp": "*"
2324
},
2425
"require-dev": {
2526
"phpunit/phpunit": "^9",

lib/eventwebhook/EventWebhook.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use EllipticCurve\Ecdsa;
66
use EllipticCurve\PublicKey;
77
use EllipticCurve\Signature;
8+
use EllipticCurve\Utils\Binary;
89

910
/**
1011
* This class allows you to use the Event Webhook feature. Read the docs for
@@ -22,7 +23,7 @@ class EventWebhook
2223
*/
2324
public function convertPublicKeyToECDSA($publicKey)
2425
{
25-
return PublicKey::fromString($publicKey);
26+
return PublicKey::fromDer(Binary::byteStringFromBase64($publicKey));
2627
}
2728

2829
/**

test/unit/EventWebhookTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class EventWebhookTest extends TestCase
1414
{
1515
private static $PUBLIC_KEY;
1616
private static $SIGNATURE;
17+
private static $BAD_SIGNATURE;
1718
private static $TIMESTAMP;
1819
private static $PAYLOAD;
1920

@@ -23,6 +24,8 @@ public static function setUpBeforeClass(): void
2324
IW4mdBgQ/7dAfSmpqIM8kF9mN1flpVKS3GRqe62gw+2fNNRaINXvVpiglSI8eNEc6wEA3F+g==';
2425
self::$SIGNATURE = 'MEUCIGHQVtGj+Y3LkG9fLcxf3qfI10QysgDWmMOVmxG0u6ZUAiE
2526
AyBiXDWzM+uOe5W0JuG+luQAbPIqHh89M15TluLtEZtM=';
27+
self::$BAD_SIGNATURE = 'BADSIGNATURE+Y3LkG9fLcxf3qfI10QysgDWmMOVmxG0u6ZUAiE
28+
AyBiXDWzM+uOe5W0JuG+luQAbPIqHh89M15TluLtEZtM=';
2629
self::$TIMESTAMP = '1600112502';
2730
self::$PAYLOAD = \json_encode(
2831
[
@@ -81,7 +84,7 @@ public function testBadSignature()
8184
$isValidSignature = $this->verify(
8285
self::$PUBLIC_KEY,
8386
self::$PAYLOAD,
84-
'signature',
87+
self::$BAD_SIGNATURE,
8588
self::$TIMESTAMP
8689
);
8790

0 commit comments

Comments
 (0)