Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloudflare Worker support #169

Open
lukasjaronis opened this issue May 21, 2024 · 4 comments
Open

Cloudflare Worker support #169

lukasjaronis opened this issue May 21, 2024 · 4 comments

Comments

@lukasjaronis
Copy link

Can we add support for CF workers? Would need to use node:crypto instead of crypto.

@dantio
Copy link
Collaborator

dantio commented May 24, 2024

Yep, definitely planed. However, it's more work than just replace the 'crypto' with 'node: crypto' ...

@lukasjaronis
Copy link
Author

Only thing that was getting in the way of using the ebayApi in a Cloudflare Worker was the digitalSignature, which I locally patched to account for environment and use the appropriate crypto API. XML parsing is not an issue since you can set compatibility flags in a worker to make it work.

@dantio
Copy link
Collaborator

dantio commented May 26, 2024

@lukasjaronis
Might you share all your changes? That would be great.

@cjlawson02
Copy link

Here's my diff:

diff --git a/node_modules/ebay-api/dist/api/digitalSignature.js b/node_modules/ebay-api/dist/api/digitalSignature.js
index 6f544dc..566e884 100644
--- a/node_modules/ebay-api/dist/api/digitalSignature.js
+++ b/node_modules/ebay-api/dist/api/digitalSignature.js
@@ -1,4 +1,4 @@
-import { createHash, sign } from 'crypto';
+import { createHash } from 'node:crypto';
 import { EBayError } from '../errors/index.js';
 const beginPrivateKey = '-----BEGIN PRIVATE KEY-----';
 const endPrivateKey = '-----END PRIVATE KEY-----';
@@ -60,7 +60,7 @@ export function generateSignature(headers, privateKey, signatureComponents, payl
     if (!privateKey.startsWith(beginPrivateKey)) {
         privateKey = beginPrivateKey + '\n' + privateKey + '\n' + endPrivateKey;
     }
-    const signatureBuffer = sign(undefined, Buffer.from(baseString), privateKey);
+    const signatureBuffer = crypto.subtle.sign(undefined, privateKey, Buffer.from(baseString));
     const signature = signatureBuffer.toString('base64');
     return `sig1=:${signature}:`;
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants