From f547b5c6f599ba9441447d1510f83799ffdc9260 Mon Sep 17 00:00:00 2001 From: Jordan Last Date: Sat, 31 Aug 2024 21:17:56 -0500 Subject: [PATCH] remove js-sha256 from non-experimental areas --- canisters/ledger/address/index.ts | 16 +++++++++------ package-lock.json | 9 +++++++++ package.json | 1 + .../class_syntax/imports/package-lock.json | 20 ++++++++++++++++--- .../class_syntax/imports/package.json | 2 +- .../class_syntax/imports/src/index.ts | 4 ++-- .../class_syntax/vanilla_js/package-lock.json | 13 ++++++++++-- .../class_syntax/vanilla_js/package.json | 2 +- .../class_syntax/vanilla_js/src/index.js | 4 ++-- 9 files changed, 54 insertions(+), 17 deletions(-) diff --git a/canisters/ledger/address/index.ts b/canisters/ledger/address/index.ts index 31e39989ad..e579506f69 100755 --- a/canisters/ledger/address/index.ts +++ b/canisters/ledger/address/index.ts @@ -1,5 +1,5 @@ import { getCrc32 } from '@dfinity/principal/lib/esm/utils/getCrc'; -import { sha224 } from 'js-sha256'; +import jsSHA from 'jssha'; import { blob, Principal } from '../../../src/lib/experimental'; import { Address } from '../index'; @@ -50,11 +50,15 @@ function addressFromPrincipal( const principalBytes = principal.toUint8Array(); const subaccountBytes = getSubAccountArray(subaccount); - const hash = new Uint8Array( - sha224 - .update([...prefixBytes, ...principalBytes, ...subaccountBytes]) - .digest() - ); + const hash = new jsSHA('SHA-224', 'UINT8ARRAY') + .update( + Uint8Array.from([ + ...prefixBytes, + ...principalBytes, + ...subaccountBytes + ]) + ) + .getHash('UINT8ARRAY'); const checksum = to32Bits(getCrc32(hash)); return toHexString(new Uint8Array([...checksum, ...hash])); diff --git a/package-lock.json b/package-lock.json index 56bb0ab610..4003acff35 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,6 +29,7 @@ "http-message-parser": "^0.0.34", "intl": "^1.2.5", "js-sha256": "0.9.0", + "jssha": "^3.3.1", "net": "^1.0.2", "pako": "^2.1.0", "reflect-metadata": "^0.2.2", @@ -6161,6 +6162,14 @@ "graceful-fs": "^4.1.6" } }, + "node_modules/jssha": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/jssha/-/jssha-3.3.1.tgz", + "integrity": "sha512-VCMZj12FCFMQYcFLPRm/0lOBbLi8uM2BhXPTqw3U4YAfs4AZfiApOoBLoN8cQE60Z50m1MYMTQVCfgF/KaCVhQ==", + "engines": { + "node": "*" + } + }, "node_modules/keyv": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", diff --git a/package.json b/package.json index c3936730a3..07c90d6a77 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "http-message-parser": "^0.0.34", "intl": "^1.2.5", "js-sha256": "0.9.0", + "jssha": "^3.3.1", "net": "^1.0.2", "pako": "^2.1.0", "reflect-metadata": "^0.2.2", diff --git a/tests/end_to_end/candid_rpc/class_syntax/imports/package-lock.json b/tests/end_to_end/candid_rpc/class_syntax/imports/package-lock.json index 9e8eb8275d..c1d5b0ce78 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/imports/package-lock.json +++ b/tests/end_to_end/candid_rpc/class_syntax/imports/package-lock.json @@ -6,7 +6,7 @@ "": { "dependencies": { "azle": "0.23.0", - "js-sha256": "0.9.0" + "jssha": "^3.3.1" }, "devDependencies": { "@dfinity/agent": "^0.19.2", @@ -32,9 +32,10 @@ } }, "../../functional_syntax/imports": { + "name": "imports_end_to_end_test_functional_syntax", "dev": true, "dependencies": { - "azle": "0.22.0", + "azle": "0.23.0", "js-sha256": "0.9.0" }, "devDependencies": { @@ -4619,6 +4620,14 @@ "graceful-fs": "^4.1.6" } }, + "node_modules/jssha": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/jssha/-/jssha-3.3.1.tgz", + "integrity": "sha512-VCMZj12FCFMQYcFLPRm/0lOBbLi8uM2BhXPTqw3U4YAfs4AZfiApOoBLoN8cQE60Z50m1MYMTQVCfgF/KaCVhQ==", + "engines": { + "node": "*" + } + }, "node_modules/kleur": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz", @@ -9172,7 +9181,7 @@ "version": "file:../../functional_syntax/imports", "requires": { "@dfinity/agent": "^0.19.2", - "azle": "0.22.0", + "azle": "0.23.0", "jest": "^29.7.0", "js-sha256": "0.9.0", "ts-jest": "^29.1.5", @@ -9837,6 +9846,11 @@ "universalify": "^2.0.0" } }, + "jssha": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/jssha/-/jssha-3.3.1.tgz", + "integrity": "sha512-VCMZj12FCFMQYcFLPRm/0lOBbLi8uM2BhXPTqw3U4YAfs4AZfiApOoBLoN8cQE60Z50m1MYMTQVCfgF/KaCVhQ==" + }, "kleur": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz", diff --git a/tests/end_to_end/candid_rpc/class_syntax/imports/package.json b/tests/end_to_end/candid_rpc/class_syntax/imports/package.json index 7bfeaa27a5..8ce91e71f1 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/imports/package.json +++ b/tests/end_to_end/candid_rpc/class_syntax/imports/package.json @@ -5,7 +5,7 @@ }, "dependencies": { "azle": "0.23.0", - "js-sha256": "0.9.0" + "jssha": "^3.3.1" }, "devDependencies": { "@dfinity/agent": "^0.19.2", diff --git a/tests/end_to_end/candid_rpc/class_syntax/imports/src/index.ts b/tests/end_to_end/candid_rpc/class_syntax/imports/src/index.ts index b60e5ea28c..cc47c5a179 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/imports/src/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/imports/src/index.ts @@ -1,5 +1,5 @@ import { IDL, query } from 'azle'; -import { sha224 } from 'js-sha256'; +import jsSHA from 'jssha'; import { one, three, two } from './library'; @@ -21,7 +21,7 @@ export default class { @query([IDL.Text], IDL.Text) sha224Hash(message: string): string { - return sha224.update(message).hex(); + return new jsSHA('SHA-224', 'TEXT').update(message).getHash('HEX'); } @query([], IDL.Int) diff --git a/tests/end_to_end/candid_rpc/class_syntax/vanilla_js/package-lock.json b/tests/end_to_end/candid_rpc/class_syntax/vanilla_js/package-lock.json index 47877d1db4..b12e39d1f1 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/vanilla_js/package-lock.json +++ b/tests/end_to_end/candid_rpc/class_syntax/vanilla_js/package-lock.json @@ -6,7 +6,7 @@ "": { "dependencies": { "azle": "0.23.0", - "js-sha256": "0.9.0" + "jssha": "^3.3.1" }, "devDependencies": { "@dfinity/agent": "^0.19.2", @@ -33,9 +33,10 @@ } }, "../../functional_syntax/vanilla_js": { + "name": "vanilla_js_end_to_end_test_functional_syntax", "dev": true, "dependencies": { - "azle": "0.22.0", + "azle": "0.23.0", "js-sha256": "0.9.0" }, "devDependencies": { @@ -4337,6 +4338,14 @@ "graceful-fs": "^4.1.6" } }, + "node_modules/jssha": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/jssha/-/jssha-3.3.1.tgz", + "integrity": "sha512-VCMZj12FCFMQYcFLPRm/0lOBbLi8uM2BhXPTqw3U4YAfs4AZfiApOoBLoN8cQE60Z50m1MYMTQVCfgF/KaCVhQ==", + "engines": { + "node": "*" + } + }, "node_modules/kleur": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz", diff --git a/tests/end_to_end/candid_rpc/class_syntax/vanilla_js/package.json b/tests/end_to_end/candid_rpc/class_syntax/vanilla_js/package.json index 1f47d99de8..2ea847a0fb 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/vanilla_js/package.json +++ b/tests/end_to_end/candid_rpc/class_syntax/vanilla_js/package.json @@ -5,7 +5,7 @@ }, "dependencies": { "azle": "0.23.0", - "js-sha256": "0.9.0" + "jssha": "^3.3.1" }, "devDependencies": { "@dfinity/agent": "^0.19.2", diff --git a/tests/end_to_end/candid_rpc/class_syntax/vanilla_js/src/index.js b/tests/end_to_end/candid_rpc/class_syntax/vanilla_js/src/index.js index a19cc13a6f..a0abbd6ff2 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/vanilla_js/src/index.js +++ b/tests/end_to_end/candid_rpc/class_syntax/vanilla_js/src/index.js @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/explicit-function-return-type */ import { IDL, query } from 'azle'; -import { sha224 } from 'js-sha256'; +import jsSHA from 'jssha'; import { relativeImport } from './library'; @@ -12,7 +12,7 @@ export default class { @query([IDL.Text], IDL.Text) packageImport(message) { - return sha224.update(message).hex(); + return new jsSHA('SHA-224', 'TEXT').update(message).getHash('HEX'); } @query([], IDL.Int)