Skip to content

Commit

Permalink
fix: json-ld fix for crypto changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Sep 25, 2024
1 parent 7480ec1 commit 14a064f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
22 changes: 22 additions & 0 deletions patches/@digitalcredentials+jsonld-signatures+9.4.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/node_modules/@digitalcredentials/jsonld-signatures/lib/sha256digest-reactnative.js b/node_modules/@digitalcredentials/jsonld-signatures/lib/sha256digest-reactnative.js
index d4012ad..8443cf3 100644
--- a/node_modules/@digitalcredentials/jsonld-signatures/lib/sha256digest-reactnative.js
+++ b/node_modules/@digitalcredentials/jsonld-signatures/lib/sha256digest-reactnative.js
@@ -3,7 +3,7 @@
*/
'use strict';

-const crypto = require('isomorphic-webcrypto');
+// const crypto = require('isomorphic-webcrypto');
require('fast-text-encoding');

module.exports = {
@@ -17,7 +17,7 @@ module.exports = {
async sha256digest({string}) {
const bytes = new TextEncoder().encode(string);
return new Uint8Array(
- await crypto.subtle.digest({name: 'SHA-256'}, bytes)
+ await global.crypto.subtle.digest({name: 'SHA-256'}, bytes)
);
}
};
31 changes: 31 additions & 0 deletions patches/@digitalcredentials+rdf-canonize+1.0.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
diff --git a/node_modules/@digitalcredentials/rdf-canonize/lib/MessageDigest-reactnative.js b/node_modules/@digitalcredentials/rdf-canonize/lib/MessageDigest-reactnative.js
index 3d50b27..243abe5 100644
--- a/node_modules/@digitalcredentials/rdf-canonize/lib/MessageDigest-reactnative.js
+++ b/node_modules/@digitalcredentials/rdf-canonize/lib/MessageDigest-reactnative.js
@@ -3,7 +3,7 @@
*/
'use strict';

-const crypto = require('isomorphic-webcrypto');
+// const crypto = require('isomorphic-webcrypto');
require('fast-text-encoding');

module.exports = class MessageDigest {
@@ -15,7 +15,7 @@ module.exports = class MessageDigest {
constructor(algorithm) {
// check if crypto.subtle is available
// check is here rather than top-level to only fail if class is used
- if(!(crypto && crypto.subtle)) {
+ if(!(global.crypto && global.crypto.subtle)) {
throw new Error('crypto.subtle not found.');
}
if(algorithm === 'sha256') {
@@ -35,7 +35,7 @@ module.exports = class MessageDigest {
async digest() {
const data = new TextEncoder().encode(this._content);
const buffer = new Uint8Array(
- await crypto.subtle.digest(this.algorithm, data));
+ await global.crypto.subtle.digest(this.algorithm, data));
// return digest in hex
let hex = '';
for(let i = 0; i < buffer.length; ++i) {

0 comments on commit 14a064f

Please sign in to comment.