-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e436021
commit 123bb1e
Showing
3 changed files
with
108 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.