Skip to content

Commit

Permalink
Merge branch 'main' into class_context
Browse files Browse the repository at this point in the history
  • Loading branch information
lastmjs authored Sep 1, 2024
2 parents be3c4be + 71de06a commit 29de7fa
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 17 deletions.
16 changes: 10 additions & 6 deletions canisters/ledger/address/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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]));
Expand Down
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 17 additions & 3 deletions tests/end_to_end/candid_rpc/class_syntax/imports/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"azle": "0.23.0",
"js-sha256": "0.9.0"
"jssha": "^3.3.1"
},
"devDependencies": {
"@dfinity/agent": "^0.19.2",
Expand Down
4 changes: 2 additions & 2 deletions tests/end_to_end/candid_rpc/class_syntax/imports/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IDL, query } from 'azle';
import { sha224 } from 'js-sha256';
import jsSHA from 'jssha';

import { one, three, two } from './library';

Expand All @@ -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)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"azle": "0.23.0",
"js-sha256": "0.9.0"
"jssha": "^3.3.1"
},
"devDependencies": {
"@dfinity/agent": "^0.19.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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)
Expand Down

0 comments on commit 29de7fa

Please sign in to comment.