Skip to content

Commit

Permalink
feat: 兼容NodeJS 16版本
Browse files Browse the repository at this point in the history
  • Loading branch information
otakustay committed Mar 3, 2023
1 parent 1d06eae commit 2ca3e66
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"main": "./cjs/index.js",
"types": "./cjs/index.d.ts",
"engines": {
"node": ">= 18"
"node": ">= 16"
},
"scripts": {
"lint": "eslint src",
Expand Down Expand Up @@ -51,7 +51,7 @@
"@ecomfe/eslint-config": "^7.4.0",
"@types/babel__core": "^7",
"@types/eslint": "^8",
"@types/node": "^18.7.14",
"@types/node": "16.0.0",
"@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.36.1",
"eslint": "^8.23.0",
Expand Down
15 changes: 3 additions & 12 deletions src/shared/authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,9 @@ const canonicalizeHeaders = (headers: Record<string, string>, headerNamesToSign
};

const hash = async (key: string, value: string) => {
const encoder = new TextEncoder();
const cryptoKey = await crypto.subtle.importKey(
'raw',
encoder.encode(key),
{name: 'HMAC', hash: 'SHA-256'},
false,
['sign']
);
const signature = await crypto.subtle.sign('HMAC', cryptoKey, encoder.encode(value));
// const buffer = await crypto.subtle.digest('SHA-256', encoder.encode(value));
const array = [...new Uint8Array(signature)];
return array.map(v => v.toString(16).padStart(2, '0')).join('');
const mac = crypto.createHmac('sha256', key);
mac.update(value);
return mac.digest('hex');
};

interface Options {
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ __metadata:
"@ecomfe/eslint-config": ^7.4.0
"@types/babel__core": ^7
"@types/eslint": ^8
"@types/node": ^18.7.14
"@types/node": 16.0.0
"@typescript-eslint/eslint-plugin": ^5.36.1
"@typescript-eslint/parser": ^5.36.1
eslint: ^8.23.0
Expand Down Expand Up @@ -770,20 +770,20 @@ __metadata:
languageName: node
linkType: hard

"@types/node@npm:16.0.0":
version: 16.0.0
resolution: "@types/node@npm:16.0.0::__archiveUrl=https%3A%2F%2Fregistry.npmjs.org%2F%40types%2Fnode%2F-%2Fnode-16.0.0.tgz"
checksum: 57e5731ba8d64d9a6434c69f1153186b7fc1b0f58ae54f3eb8c32cd122e87e9aca35947f62e92e1902027994dac97b5bff7cce4d9c56cb319f07f694fe55d012
languageName: node
linkType: hard

"@types/node@npm:^14.0.0":
version: 14.18.27
resolution: "@types/node@npm:14.18.27::__archiveUrl=https%3A%2F%2Fregistry.npmjs.org%2F%40types%2Fnode%2F-%2Fnode-14.18.27.tgz"
checksum: b5ed55caf950ae0a49dbf39a349ca4875b2af6c6ea5a90e733c151226f79ead6c23f61908491b0b96063c21ba2f1ab818a0c3edd59b8cc45c024a30d4e478ec6
languageName: node
linkType: hard

"@types/node@npm:^18.7.14":
version: 18.7.15
resolution: "@types/node@npm:18.7.15::__archiveUrl=https%3A%2F%2Fregistry.npmjs.org%2F%40types%2Fnode%2F-%2Fnode-18.7.15.tgz"
checksum: 1435fc7fe44744467a3ba8ace646455be228516530dbb3db64a03cca6abcfdc5ba2e48a3eafc71f25f836d2ca871132361c58a5e760237a53674cb09151147d9
languageName: node
linkType: hard

"@types/normalize-package-data@npm:^2.4.0":
version: 2.4.1
resolution: "@types/normalize-package-data@npm:2.4.1::__archiveUrl=https%3A%2F%2Fregistry.npmjs.org%2F%40types%2Fnormalize-package-data%2F-%2Fnormalize-package-data-2.4.1.tgz"
Expand Down

0 comments on commit 2ca3e66

Please sign in to comment.