Skip to content

Commit 0c76ac7

Browse files
Update jsonld dep, separate out sha256digest code into browser and RN.
1 parent 8cecc1e commit 0c76ac7

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

lib/sha256digest-reactnative.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved.
3+
*/
4+
'use strict';
5+
6+
const crypto = require('isomorphic-webcrypto');
7+
require('fast-text-encoding');
8+
9+
module.exports = {
10+
/**
11+
* Hashes a string of data using SHA-256.
12+
*
13+
* @param {string} string - the string to hash.
14+
*
15+
* @return {Uint8Array} the hash digest.
16+
*/
17+
async sha256digest({string}) {
18+
const bytes = new TextEncoder().encode(string);
19+
return new Uint8Array(
20+
await crypto.subtle.digest('SHA-256', bytes)
21+
);
22+
}
23+
};

package.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
],
3131
"dependencies": {
3232
"@digitalbazaar/security-context": "^1.0.0",
33-
"jsonld": "digitalbazaar/jsonld.js#v5.2.1-rc1",
33+
"fast-text-encoding": "^1.0.3",
34+
"isomorphic-webcrypto": "^2.3.8",
35+
"jsonld": "digitalbazaar/jsonld.js#v5.2.1-rc2",
3436
"serialize-error": "^8.0.1"
3537
},
3638
"devDependencies": {
@@ -79,6 +81,13 @@
7981
},
8082
"browser": {
8183
"crypto": false,
82-
"./lib/sha256digest.js": "./lib/sha256digest-browser.js"
84+
"./lib/sha256digest.js": "./lib/sha256digest-browser.js",
85+
"fast-text-encoding": false,
86+
"isomorphic-webcrypto": false
87+
},
88+
"react-native": {
89+
"crypto": false,
90+
"./lib/sha256digest.js": "./lib/sha256digest-reactnative.js",
91+
"./lib/sha256digest-browser.js": false
8392
}
8493
}

0 commit comments

Comments
 (0)