Skip to content

Commit

Permalink
refactor: use CairoFelt252 in classHash
Browse files Browse the repository at this point in the history
  • Loading branch information
b0rza committed Jul 8, 2024
1 parent 6600e21 commit c833c96
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/utils/hash/classHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import {
RawArgs,
SierraContractEntryPointFields,
} from '../../types';
import { CairoFelt252 } from '../cairoDataTypes/felt252';
import { CallData } from '../calldata';
import { felt } from '../calldata/cairo';
import { starkCurve } from '../ec';
import { addHexPrefix, utf8ToArray } from '../encode';
import { parse, stringify } from '../json';
Expand Down Expand Up @@ -79,7 +79,9 @@ export function calculateContractAddressFromHash(
const compiledCalldata = CallData.compile(constructorCalldata);
const constructorCalldataHash = computeHashOnElements(compiledCalldata);

const CONTRACT_ADDRESS_PREFIX = felt('0x535441524b4e45545f434f4e54524143545f41444452455353'); // Equivalent to 'STARKNET_CONTRACT_ADDRESS'
const CONTRACT_ADDRESS_PREFIX = new CairoFelt252(
'0x535441524b4e45545f434f4e54524143545f41444452455353'
).value; // Equivalent to 'STARKNET_CONTRACT_ADDRESS'

const hash = computeHashOnElements([
CONTRACT_ADDRESS_PREFIX,
Expand Down Expand Up @@ -242,7 +244,7 @@ export function hashByteCodeSegments(casm: CompiledSierraCasm): bigint {
* Compute compiled class hash for contract (Cairo 1)
* @param {CompiledSierraCasm} casm Cairo 1 compiled contract content
* @returns {string} hex-string of class hash
* @example
* @example
* ```typescript
* const compiledCasm = json.parse(fs.readFileSync("./cairo260.casm.json").toString("ascii"));
* const result = hash.computeCompiledClassHash(compiledCasm);
Expand Down Expand Up @@ -296,7 +298,7 @@ function hashAbi(sierra: CompiledSierra) {
* Compute sierra contract class hash (Cairo 1)
* @param {CompiledSierra} sierra Cairo 1 Sierra contract content
* @returns {string} hex-string of class hash
* @example
* @example
* ```typescript
* const compiledSierra = json.parse(fs.readFileSync("./cairo260.sierra.json").toString("ascii"));
* const result = hash.computeSierraContractClassHash(compiledSierra);
Expand Down Expand Up @@ -340,7 +342,7 @@ export function computeSierraContractClassHash(sierra: CompiledSierra): string {
* Compute ClassHash (sierra or legacy) based on provided contract
* @param {CompiledContract | string} contract Cairo 1 contract content
* @returns {string} hex-string of class hash
* @example
* @example
* ```typescript
* const compiledSierra = json.parse(fs.readFileSync("./cairo260.sierra.json").toString("ascii"));
* const result = hash.computeContractClassHash(compiledSierra);
Expand Down

0 comments on commit c833c96

Please sign in to comment.