summaryrefslogtreecommitdiff
path: root/deps/npm/lib/utils/package-integrity.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/lib/utils/package-integrity.js')
-rw-r--r--deps/npm/lib/utils/package-integrity.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/deps/npm/lib/utils/package-integrity.js b/deps/npm/lib/utils/package-integrity.js
new file mode 100644
index 0000000000..f9560d660e
--- /dev/null
+++ b/deps/npm/lib/utils/package-integrity.js
@@ -0,0 +1,21 @@
+'use strict'
+
+// Utilities for generating and verifying the packageIntegrity field for
+// package-lock
+//
+// Spec: https://github.com/npm/npm/pull/16441
+
+const ssri = require('ssri')
+const SSRI_OPTS = {
+ algorithms: ['sha512']
+}
+
+module.exports.check = check
+function check (pkg, integrity) {
+ return ssri.checkData(JSON.stringify(pkg), integrity, SSRI_OPTS)
+}
+
+module.exports.hash = hash
+function hash (pkg) {
+ return ssri.fromData(JSON.stringify(pkg), SSRI_OPTS).toString()
+}