fix: sha256 hash calculation for oid, cont’d

This commit is contained in:
Anton Strogonoff 2021-12-02 18:55:57 +01:00
parent 7c79ad6857
commit 7fcc71fe40
4 changed files with 129 additions and 6 deletions

View file

@ -21,9 +21,11 @@
"email": "open.source@ribose.com" "email": "open.source@ribose.com"
}, },
"peerDependencies": { "peerDependencies": {
"isomorphic-git": "^1.7.8" "isomorphic-git": "^1.7.8",
"@aws-crypto/sha256-universal": "^2.0.0"
}, },
"devDependencies": { "devDependencies": {
"@aws-crypto/sha256-universal": "^2.0.0",
"@babel/cli": "^7.1.5", "@babel/cli": "^7.1.5",
"@babel/core": "^7.4.0", "@babel/core": "^7.4.0",
"@babel/preset-env": "^7.4.2", "@babel/preset-env": "^7.4.2",

View file

@ -1,7 +1,6 @@
// This is Node-only code due to use of crypto.
import crypto from 'crypto';
import path from 'path'; import path from 'path';
import { SPEC_URL } from './util'; import { Sha256 } from '@aws-crypto/sha256-universal';
import { SPEC_URL, toHex } from './util';
export interface PointerInfo { export interface PointerInfo {
@ -76,6 +75,8 @@ export function formatPointerInfo(info: PointerInfo): Buffer {
export async function buildPointerInfo(content: Buffer): Promise<PointerInfo> { export async function buildPointerInfo(content: Buffer): Promise<PointerInfo> {
const size = Buffer.byteLength(content); const size = Buffer.byteLength(content);
const hash = crypto.createHash('sha256').update(content).digest('hex'); const hash = new Sha256();
return { oid: hash, size }; hash.update(content);
const oid = toHex(await hash.digest());
return { oid, size };
} }

View file

@ -77,3 +77,14 @@ export async function bodyToBuffer(body: Uint8Array[]): Promise<Buffer> {
} }
return Buffer.from(result.buffer); return Buffer.from(result.buffer);
} }
// Borrowed from Isomorphic Git core, it is not importable.
export function toHex(buffer: ArrayBuffer): string {
let hex = ''
for (const byte of new Uint8Array(buffer)) {
if (byte < 16) hex += '0'
hex += byte.toString(16)
}
return hex
}

109
yarn.lock
View file

@ -2,6 +2,105 @@
# yarn lockfile v1 # yarn lockfile v1
"@aws-crypto/ie11-detection@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@aws-crypto/ie11-detection/-/ie11-detection-2.0.0.tgz#bb6c2facf8f03457e949dcf0921477397ffa4c6e"
integrity sha512-pkVXf/dq6PITJ0jzYZ69VhL8VFOFoPZLZqtU/12SGnzYuJOOGNfF41q9GxdI1yqC8R13Rq3jOLKDFpUJFT5eTA==
dependencies:
tslib "^1.11.1"
"@aws-crypto/sha256-browser@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@aws-crypto/sha256-browser/-/sha256-browser-2.0.0.tgz#741c9024df55ec59b51e5b1f5d806a4852699fb5"
integrity sha512-rYXOQ8BFOaqMEHJrLHul/25ckWH6GTJtdLSajhlqGMx0PmSueAuvboCuZCTqEKlxR8CQOwRarxYMZZSYlhRA1A==
dependencies:
"@aws-crypto/ie11-detection" "^2.0.0"
"@aws-crypto/sha256-js" "^2.0.0"
"@aws-crypto/supports-web-crypto" "^2.0.0"
"@aws-crypto/util" "^2.0.0"
"@aws-sdk/types" "^3.1.0"
"@aws-sdk/util-locate-window" "^3.0.0"
"@aws-sdk/util-utf8-browser" "^3.0.0"
tslib "^1.11.1"
"@aws-crypto/sha256-js@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@aws-crypto/sha256-js/-/sha256-js-2.0.0.tgz#f1f936039bdebd0b9e2dd834d65afdc2aac4efcb"
integrity sha512-VZY+mCY4Nmrs5WGfitmNqXzaE873fcIZDu54cbaDaaamsaTOP1DBImV9F4pICc3EHjQXujyE8jig+PFCaew9ig==
dependencies:
"@aws-crypto/util" "^2.0.0"
"@aws-sdk/types" "^3.1.0"
tslib "^1.11.1"
"@aws-crypto/sha256-universal@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@aws-crypto/sha256-universal/-/sha256-universal-2.0.0.tgz#c4ed6b2f84d00cadf4911f63df251c17f1b3921d"
integrity sha512-gwEj8B9vr0LWFuV7kSQH5L0L02PMDNuWDrChL84E0/o0+TRyiTfqe0j4irXRwy1fEKj72grzxVPyKhCJo2BeIg==
dependencies:
"@aws-crypto/sha256-browser" "^2.0.0"
"@aws-sdk/hash-node" "^3.0.0"
"@aws-sdk/types" "^3.1.0"
tslib "^1.11.1"
"@aws-crypto/supports-web-crypto@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@aws-crypto/supports-web-crypto/-/supports-web-crypto-2.0.0.tgz#fd6cde30b88f77d5a4f57b2c37c560d918014f9e"
integrity sha512-Ge7WQ3E0OC7FHYprsZV3h0QIcpdyJLvIeg+uTuHqRYm8D6qCFJoiC+edSzSyFiHtZf+NOQDJ1q46qxjtzIY2nA==
dependencies:
tslib "^1.11.1"
"@aws-crypto/util@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@aws-crypto/util/-/util-2.0.0.tgz#17ba6f83c7e447b70fc24b84c5f6714d1e329f4a"
integrity sha512-YDooyH83m2P5A3h6lNH7hm6mIP93sU/dtzRmXIgtO4BCB7SvtX8ysVKQAE8tVky2DQ3HHxPCjNTuUe7YoAMrNQ==
dependencies:
"@aws-sdk/types" "^3.1.0"
"@aws-sdk/util-utf8-browser" "^3.0.0"
tslib "^1.11.1"
"@aws-sdk/hash-node@^3.0.0":
version "3.40.0"
resolved "https://registry.yarnpkg.com/@aws-sdk/hash-node/-/hash-node-3.40.0.tgz#bf4d31a41652cbc3c937055087c80096cfab67ae"
integrity sha512-yOXXK85DdGDktdnQtXgMdaVKii4wtMjEhJ1mrvx2A9nMFNaPhxvERkVVIUKSWlJRa9ZujOw5jWOx8d2R51/Kjg==
dependencies:
"@aws-sdk/types" "3.40.0"
"@aws-sdk/util-buffer-from" "3.37.0"
tslib "^2.3.0"
"@aws-sdk/is-array-buffer@3.37.0":
version "3.37.0"
resolved "https://registry.yarnpkg.com/@aws-sdk/is-array-buffer/-/is-array-buffer-3.37.0.tgz#aa87619f8172b1a2a7ac8d573032025d98ae6c50"
integrity sha512-XLjA/a6AuGnCvcJZLsMTy2jxF2upgGhqCCkoIJgLlzzXHSihur13KcmPvW/zcaGnCRj0SvKWXiJHl4vDlW75VQ==
dependencies:
tslib "^2.3.0"
"@aws-sdk/types@3.40.0", "@aws-sdk/types@^3.1.0":
version "3.40.0"
resolved "https://registry.yarnpkg.com/@aws-sdk/types/-/types-3.40.0.tgz#a9d7926fcb9b699bc46be975033559d2293e60d1"
integrity sha512-KpILcfvRaL88TLvo3SY4OuCCg90SvcNLPyjDwUuBqiOyWODjrKShHtAPJzej4CLp92lofh+ul0UnBfV9Jb/5PA==
"@aws-sdk/util-buffer-from@3.37.0":
version "3.37.0"
resolved "https://registry.yarnpkg.com/@aws-sdk/util-buffer-from/-/util-buffer-from-3.37.0.tgz#298d4a925b9f0ca23f99617648cd9fb3896b573c"
integrity sha512-aa3SBwjLwImuJoE4+hxDIWQ9REz3UFb3p7KFPe9qopdXb/yB12RTcbrXVb4whUux4i4mO6KRij0ZNjFZrjrKPg==
dependencies:
"@aws-sdk/is-array-buffer" "3.37.0"
tslib "^2.3.0"
"@aws-sdk/util-locate-window@^3.0.0":
version "3.37.0"
resolved "https://registry.yarnpkg.com/@aws-sdk/util-locate-window/-/util-locate-window-3.37.0.tgz#e041f411e5e6a235e5bcffacc4b7fa90f25d8d01"
integrity sha512-NvDCfOhLLVHp27oGUUs8EVirhz91aX5gdxGS7J/sh5PF0cNN8rwaR1vSLR7BxPmJHMO7NH7i9EwiELfLfYcq6g==
dependencies:
tslib "^2.3.0"
"@aws-sdk/util-utf8-browser@^3.0.0":
version "3.37.0"
resolved "https://registry.yarnpkg.com/@aws-sdk/util-utf8-browser/-/util-utf8-browser-3.37.0.tgz#d896899f4c475ceeaf8b77c5d7cdc453e5fe6b83"
integrity sha512-tuiOxzfqet1kKGYzlgpMGfhr64AHJnYsFx2jZiH/O6Yq8XQg43ryjQlbJlim/K/XHGNzY0R+nabeJg34q3Ua1g==
dependencies:
tslib "^2.3.0"
"@babel/cli@^7.1.5": "@babel/cli@^7.1.5":
version "7.16.0" version "7.16.0"
resolved "https://registry.yarnpkg.com/@babel/cli/-/cli-7.16.0.tgz#a729b7a48eb80b49f48a339529fc4129fd7bcef3" resolved "https://registry.yarnpkg.com/@babel/cli/-/cli-7.16.0.tgz#a729b7a48eb80b49f48a339529fc4129fd7bcef3"
@ -1561,6 +1660,16 @@ to-regex-range@^5.0.1:
dependencies: dependencies:
is-number "^7.0.0" is-number "^7.0.0"
tslib@^1.11.1:
version "1.14.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
tslib@^2.3.0:
version "2.3.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.3.1.tgz#e8a335add5ceae51aa261d32a490158ef042ef01"
integrity sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==
typescript@^4.4.2: typescript@^4.4.2:
version "4.5.2" version "4.5.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.2.tgz#8ac1fba9f52256fdb06fb89e4122fa6a346c2998" resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.2.tgz#8ac1fba9f52256fdb06fb89e4122fa6a346c2998"