Skip to content

Commit

Permalink
chore: update left over StarkNet casing
Browse files Browse the repository at this point in the history
  • Loading branch information
penovicp committed Mar 15, 2024
1 parent d37e22d commit 79890bd
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 27 deletions.
6 changes: 3 additions & 3 deletions __tests__/utils/typedData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import exampleEnum from '../../__mocks__/typedData/example_enum.json';
import examplePresetTypes from '../../__mocks__/typedData/example_presetTypes.json';
import typedDataStructArrayExample from '../../__mocks__/typedData/mail_StructArray.json';
import typedDataSessionExample from '../../__mocks__/typedData/session_MerkleTree.json';
import { BigNumberish, StarkNetDomain, num } from '../../src';
import { BigNumberish, StarknetDomain, num } from '../../src';
import { PRIME } from '../../src/constants';
import { getSelectorFromName } from '../../src/utils/hash';
import { MerkleTree } from '../../src/utils/merkle';
Expand Down Expand Up @@ -170,7 +170,7 @@ describe('typedData', () => {
const hash = getStructHash(
typedDataExample.types,
'StarkNetDomain',
typedDataExample.domain as StarkNetDomain
typedDataExample.domain as StarknetDomain
);
expect(hash).toMatchInlineSnapshot(
`"0x54833b121883a3e3aebff48ec08a962f5742e5f7b973469c1f8f4f55d470b07"`
Expand All @@ -181,7 +181,7 @@ describe('typedData', () => {
const hash = getStructHash(
exampleBaseTypes.types,
'StarknetDomain',
exampleBaseTypes.domain as StarkNetDomain,
exampleBaseTypes.domain as StarknetDomain,
TypedDataRevision.Active
);
expect(hash).toMatchInlineSnapshot(
Expand Down
6 changes: 3 additions & 3 deletions src/types/api/rpcspec_0_6/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ type ReadMethods = {
errors: Errors.BLOCK_NOT_FOUND;
};

// Call a StarkNet function without creating a StarkNet transaction
// Call a Starknet function without creating a Starknet transaction
starknet_call: {
params: {
request: FUNCTION_CALL;
Expand All @@ -172,7 +172,7 @@ type ReadMethods = {
errors: Errors.CONTRACT_NOT_FOUND | Errors.CONTRACT_ERROR | Errors.BLOCK_NOT_FOUND;
};

// Estimate the fee for StarkNet transactions
// Estimate the fee for Starknet transactions
starknet_estimateFee: {
params: {
request: BROADCASTED_TXN[];
Expand Down Expand Up @@ -207,7 +207,7 @@ type ReadMethods = {
errors: Errors.NO_BLOCKS;
};

// Return the currently configured StarkNet chain id
// Return the currently configured Starknet chain id
starknet_chainId: {
params: [];
result: CHAIN_ID;
Expand Down
6 changes: 3 additions & 3 deletions src/types/api/rpcspec_0_7/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ type ReadMethods = {
errors: Errors.BLOCK_NOT_FOUND;
};

// Call a StarkNet function without creating a StarkNet transaction
// Call a Starknet function without creating a Starknet transaction
starknet_call: {
params: {
request: FUNCTION_CALL;
Expand All @@ -182,7 +182,7 @@ type ReadMethods = {
errors: Errors.CONTRACT_NOT_FOUND | Errors.CONTRACT_ERROR | Errors.BLOCK_NOT_FOUND;
};

// Estimate the fee for StarkNet transactions
// Estimate the fee for Starknet transactions
starknet_estimateFee: {
params: {
request: BROADCASTED_TXN[];
Expand Down Expand Up @@ -217,7 +217,7 @@ type ReadMethods = {
errors: Errors.NO_BLOCKS;
};

// Return the currently configured StarkNet chain id
// Return the currently configured Starknet chain id
starknet_chainId: {
params: [];
result: CHAIN_ID;
Expand Down
18 changes: 8 additions & 10 deletions src/types/typedData.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
// TODO: adjust starknet casing in v6

export enum TypedDataRevision {
Active = '1',
Legacy = '0',
}

export type StarkNetEnumType = {
export type StarknetEnumType = {
name: string;
type: 'enum';
contains: string;
};

export type StarkNetMerkleType = {
export type StarknetMerkleType = {
name: string;
type: 'merkletree';
contains: string;
Expand All @@ -23,18 +21,18 @@ export type StarkNetMerkleType = {
* Note that the `uint` and `int` aliases like in Solidity, and fixed point numbers are not supported by the EIP-712
* standard.
*/
export type StarkNetType =
export type StarknetType =
| {
name: string;
type: string;
}
| StarkNetEnumType
| StarkNetMerkleType;
| StarknetEnumType
| StarknetMerkleType;

/**
* The EIP712 domain struct. Any of these fields are optional, but it must contain at least one field.
*/
export interface StarkNetDomain extends Record<string, unknown> {
export interface StarknetDomain extends Record<string, unknown> {
name?: string;
version?: string;
chainId?: string | number;
Expand All @@ -45,8 +43,8 @@ export interface StarkNetDomain extends Record<string, unknown> {
* The complete typed data, with all the structs, domain data, primary type of the message, and the message itself.
*/
export interface TypedData {
types: Record<string, StarkNetType[]>;
types: Record<string, StarknetType[]>;
primaryType: string;
domain: StarkNetDomain;
domain: StarknetDomain;
message: Record<string, unknown>;
}
16 changes: 8 additions & 8 deletions src/utils/typedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { PRIME, RANGE_FELT, RANGE_I128, RANGE_U128 } from '../constants';
import {
BigNumberish,
TypedDataRevision as Revision,
StarkNetEnumType,
StarkNetMerkleType,
StarkNetType,
StarknetEnumType,
StarknetMerkleType,
StarknetType,
TypedData,
} from '../types';
import assert from './assert';
Expand Down Expand Up @@ -107,7 +107,7 @@ export function prepareSelector(selector: string): string {
return isHex(selector) ? selector : getSelectorFromName(selector);
}

export function isMerkleTreeType(type: StarkNetType): type is StarkNetMerkleType {
export function isMerkleTreeType(type: StarknetType): type is StarknetMerkleType {
return type.type === 'merkletree';
}

Expand Down Expand Up @@ -142,7 +142,7 @@ export function getDependencies(

return [
type,
...(types[type] as StarkNetEnumType[]).reduce<string[]>(
...(types[type] as StarknetEnumType[]).reduce<string[]>(
(previous, t) => [
...previous,
...getDependencies(types, t.type, previous, t.contains, revision).filter(
Expand Down Expand Up @@ -198,7 +198,7 @@ export function encodeType(
const dependencyElements = allTypes[dependency].map((t) => {
const targetType =
t.type === 'enum' && revision === Revision.Active
? (t as StarkNetEnumType).contains
? (t as StarknetEnumType).contains
: t.type;
// parentheses handling for enum variant types
const typeString = targetType.match(/^\(.*\)$/)
Expand Down Expand Up @@ -265,9 +265,9 @@ export function encodeValue(
if (revision === Revision.Active) {
const [variantKey, variantData] = Object.entries(data as TypedData['message'])[0];

const parentType = types[ctx.parent as string][0] as StarkNetEnumType;
const parentType = types[ctx.parent as string][0] as StarknetEnumType;
const enumType = types[parentType.contains];
const variantType = enumType.find((t) => t.name === variantKey) as StarkNetType;
const variantType = enumType.find((t) => t.name === variantKey) as StarknetType;
const variantIndex = enumType.indexOf(variantType);

const encodedSubtypes = variantType.type
Expand Down

0 comments on commit 79890bd

Please sign in to comment.