Skip to content

Commit

Permalink
long shot
Browse files Browse the repository at this point in the history
  • Loading branch information
oscartbeaumont committed Feb 5, 2024
1 parent e436021 commit 123bb1e
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 3 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"pnpm": {
"patchedDependencies": {
"@solid-mediakit/[email protected]": "patches/@[email protected]",
"[email protected]": "patches/[email protected]"
"[email protected]": "patches/[email protected]",
"[email protected]": "patches/[email protected]"
}
}
}
100 changes: 100 additions & 0 deletions patches/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
diff --git a/cjs/crypto/NodeCryptoProvider.js b/cjs/crypto/NodeCryptoProvider.js
index 54993975b7babb09d69d1da892f5932d9bc9144c..c0d6d84b9075b17f3a0661755bfd13f5b3fdc23b 100644
--- a/cjs/crypto/NodeCryptoProvider.js
+++ b/cjs/crypto/NodeCryptoProvider.js
@@ -1,18 +1,40 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NodeCryptoProvider = void 0;
-const crypto = require("crypto");
+// const crypto = require("crypto");
const CryptoProvider_js_1 = require("./CryptoProvider.js");
+const enc = new TextEncoder("utf-8");
/**
* `CryptoProvider which uses the Node `crypto` package for its computations.
*/
class NodeCryptoProvider extends CryptoProvider_js_1.CryptoProvider {
/** @override */
- computeHMACSignature(payload, secret) {
- return crypto
- .createHmac('sha256', secret)
- .update(payload, 'utf8')
- .digest('hex');
+ async acomputeHMACSignature(payload, secret) {
+ // return crypto
+ // .createHmac('sha256', secret)
+ // .update(payload, 'utf8')
+ // .digest('hex');
+
+ return await window.crypto.subtle.importKey(
+ "raw", // raw format of the key - should be Uint8Array
+ enc.encode(secret),
+ { // algorithm details
+ name: "HMAC",
+ hash: {name: "SHA-256"}
+ },
+ false, // export = false
+ ["sign", "verify"] // what this key can do
+ ).then( key => {
+ window.crypto.subtle.sign(
+ "HMAC",
+ key,
+ enc.encode(payload)
+ ).then(signature => {
+ var b = new Uint8Array(signature);
+ var str = Array.prototype.map.call(b, x => x.toString(16).padStart(2, '0')).join("")
+ return str;
+ });
+ });
}
/** @override */
async computeHMACSignatureAsync(payload, secret) {
diff --git a/cjs/platform/NodePlatformFunctions.js b/cjs/platform/NodePlatformFunctions.js
index adcadc470dfc6d2f318fdece6720a518b09ff308..b90f6302bed2b31c516613947251c8375132a98d 100644
--- a/cjs/platform/NodePlatformFunctions.js
+++ b/cjs/platform/NodePlatformFunctions.js
@@ -1,7 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NodePlatformFunctions = void 0;
-const crypto = require("crypto");
+// const crypto = require("crypto");
const events_1 = require("events");
const NodeCryptoProvider_js_1 = require("../crypto/NodeCryptoProvider.js");
const NodeHttpClient_js_1 = require("../net/NodeHttpClient.js");
@@ -11,6 +11,17 @@ const utils_js_1 = require("../utils.js");
const child_process_1 = require("child_process");
class StreamProcessingError extends Error_js_1.StripeError {
}
+let crypto = null;
+try {
+ crypto = require('crypto');
+ }
+ catch (e) {
+ // @ts-ignore
+ if (e.code !== 'MODULE_NOT_FOUND') {
+ throw e;
+ }
+ }
+
/**
* Specializes WebPlatformFunctions using APIs available in Node.js.
*/
@@ -23,7 +34,7 @@ class NodePlatformFunctions extends PlatformFunctions_js_1.PlatformFunctions {
/** @override */
uuid4() {
// available in: v14.17.x+
- if (crypto.randomUUID) {
+ if (crypto?.randomUUID) {
return crypto.randomUUID();
}
return super.uuid4();
@@ -70,7 +81,7 @@ class NodePlatformFunctions extends PlatformFunctions_js_1.PlatformFunctions {
}
// use crypto.timingSafeEqual if available (since Node.js v6.6.0),
// otherwise use our own scmp-internal function.
- if (crypto.timingSafeEqual) {
+ if (crypto?.timingSafeEqual) {
const textEncoder = new TextEncoder();
const aEncoded = textEncoder.encode(a);
const bEncoded = textEncoder.encode(b);
8 changes: 6 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 123bb1e

Please sign in to comment.