Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade to sarknet.js v6.11.0 #296

Merged
merged 21 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/starknet-snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"async-mutex": "^0.3.2",
"ethereum-unit-converter": "^0.0.17",
"ethers": "^5.5.1",
"starknet": "6.7.0",
"starknet": "^6.11.0",
"starknet_v4.22.0": "npm:[email protected]"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/starknet-snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/ConsenSys/starknet-snap.git"
},
"source": {
"shasum": "QTghmF19ZVAMHyKpyNlzjdwLvzrP6RHVWLfZzZHjynU=",
"shasum": "uG3NeaD7Ky06SZo9Hnx1KWn5EjavmUJC5VBSY/sqctM=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
18 changes: 6 additions & 12 deletions packages/starknet-snap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import {
ETHER_MAINNET,
ETHER_SEPOLIA_TESTNET,
PRELOADED_TOKENS,
STARKNET_INTEGRATION_NETWORK,
STARKNET_MAINNET_NETWORK,
STARKNET_SEPOLIA_TESTNET_NETWORK,
STARKNET_TESTNET_NETWORK,
Expand All @@ -82,7 +81,6 @@ const saveMutex = new Mutex();
export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
try {
const requestParams = request?.params as unknown as ApiRequestParams;
const isDev = Boolean(requestParams?.isDev);
const debugLevel = requestParams?.debugLevel;

logger.init(debugLevel as unknown as string);
Expand Down Expand Up @@ -120,16 +118,12 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
}
// pre-inserted the default networks and tokens
await upsertNetwork(STARKNET_MAINNET_NETWORK, snap, saveMutex, state);
if (isDev) {
await upsertNetwork(STARKNET_INTEGRATION_NETWORK, snap, saveMutex, state);
} else {
await upsertNetwork(
STARKNET_SEPOLIA_TESTNET_NETWORK,
snap,
saveMutex,
state,
);
}
await upsertNetwork(
STARKNET_SEPOLIA_TESTNET_NETWORK,
snap,
saveMutex,
state,
);

// remove the testnet network (migration)
await removeNetwork(STARKNET_TESTNET_NETWORK, snap, saveMutex, state);
Expand Down
1 change: 0 additions & 1 deletion packages/starknet-snap/src/types/snapApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export type ApiRequestParams =

export type BaseRequestParams = {
chainId?: string;
isDev?: boolean;
debugLevel?: string;
};

Expand Down
10 changes: 0 additions & 10 deletions packages/starknet-snap/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,6 @@ export const STARKNET_SEPOLIA_TESTNET_NETWORK: Network = {
accountClassHash: '', // from argent-x repo
};

export const STARKNET_INTEGRATION_NETWORK: Network = {
name: 'Goerli Integration',
chainId: constants.StarknetChainId.SN_GOERLI,
baseUrl: 'https://external.integration.starknet.io',
nodeUrl: '',
voyagerUrl: '',
accountClassHash: '',
};

export const ETHER_MAINNET: Erc20Token = {
address: '0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7',
name: 'Ether',
Expand Down Expand Up @@ -182,7 +173,6 @@ export const PRELOADED_TOKENS = [
export const PRELOADED_NETWORKS = [
STARKNET_MAINNET_NETWORK,
STARKNET_SEPOLIA_TESTNET_NETWORK,
STARKNET_INTEGRATION_NETWORK,
];

export const PROXY_CONTRACT_HASH =
Expand Down
22 changes: 11 additions & 11 deletions packages/starknet-snap/src/utils/keyPair.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { BIP44AddressKeyDeriver } from '@metamask/key-tree';
import { getBIP44AddressKeyDeriver } from '@metamask/key-tree';
import { utils } from 'ethers';
import { number, ec } from 'starknet_v4.22.0';
import { num as numUtils, ec } from 'starknet';
khanti42 marked this conversation as resolved.
Show resolved Hide resolved

/**
*
Expand All @@ -25,17 +25,17 @@ export async function getAddressKeyDeriver(wallet) {
* @param keySeed
* @param keyValueLimit
*/
export function grindKey(keySeed: string, keyValueLimit = ec.ec.n): string {
export function grindKey(
keySeed: string,
keyValueLimit: bigint | undefined | null = ec.starkCurve.CURVE.n,
): string {
if (!keyValueLimit) {
return keySeed;
}
const sha256EcMaxDigest = number.toBN(
'1 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000',
16,
);
const maxAllowedVal = sha256EcMaxDigest.sub(
sha256EcMaxDigest.mod(keyValueLimit),
const sha256EcMaxDigest = BigInt(
'0x10000000000000000000000000000000000000000000000000000000000000000',
);
const maxAllowedVal = sha256EcMaxDigest - (sha256EcMaxDigest % keyValueLimit);

// Make sure the produced key is derived by the Stark EC order,
// and falls within the range [0, maxAllowedVal).
Expand All @@ -44,9 +44,9 @@ export function grindKey(keySeed: string, keyValueLimit = ec.ec.n): string {
do {
key = hashKeyWithIndex(keySeed, i);
i += 1;
} while (!key.lt(maxAllowedVal));
} while (key >= maxAllowedVal);
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
return `0x${key.umod(keyValueLimit).toString('hex')}`;
return `0x${(key % keyValueLimit).toString(16)}`;
}

/**
Expand All @@ -57,7 +57,7 @@ export function grindKey(keySeed: string, keyValueLimit = ec.ec.n): string {
function hashKeyWithIndex(key: string, index: number) {
const payload = utils.concat([utils.arrayify(key), utils.arrayify(index)]);
const hash = utils.sha256(payload);
return number.toBN(hash);
return numUtils.toBigInt(hash);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/starknet-snap/test/constants.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const Cairo1Account1: AccContract = {
'0x5bc00132b8f2fc0f673dc232594b26727e712b204a2716f9dc28a8c5f607b5e',
publicKey:
'0x019e59f349e1aa813ab4556c5836d0472e5e1ae82d1e5c3b3e8aabfeb290befd',
chainId: constants.StarknetChainId.SN_GOERLI,
chainId: constants.StarknetChainId.SN_SEPOLIA,
};

export const token0: Erc20Token = {
Expand Down
20 changes: 20 additions & 0 deletions packages/wallet-ui/craco.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
khanti42 marked this conversation as resolved.
Show resolved Hide resolved
webpack: {
configure: (webpackConfig) => {
// Find the rule that uses 'source-map-loader'
const sourceMapLoaderRule = webpackConfig.module.rules.find(
rule => rule.loader && rule.loader.includes('source-map-loader')
);

if (sourceMapLoaderRule) {
// Exclude the entire folder
sourceMapLoaderRule.exclude = [
...(Array.isArray(sourceMapLoaderRule.exclude) ? sourceMapLoaderRule.exclude : [sourceMapLoaderRule.exclude]),
/node_modules\/starknet-types-07\/dist/
];
}

return webpackConfig;
},
},
};
13 changes: 7 additions & 6 deletions packages/wallet-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
"license": "(Apache-2.0 OR MIT)",
"scripts": {
"allow-scripts": "yarn workspace root allow-scripts",
"build": "react-scripts build",
"build": "craco build",
khanti42 marked this conversation as resolved.
Show resolved Hide resolved
stanleyyconsensys marked this conversation as resolved.
Show resolved Hide resolved
"build-storybook": "build-storybook",
"build:clean": "yarn clean && yarn build",
"clean": "rimraf dist",
"eject": "react-scripts eject",
"eject": "craco eject",
"lint": "yarn lint:eslint && yarn lint:misc --check",
"lint:eslint": "eslint . --cache --ext js,ts,tsx",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
"lint:misc": "prettier '**/*.ts' '**/*.json' '**/*.tsx' '**/*.md' '!CHANGELOG.md' --ignore-path .gitignore",
"serve": "react-scripts serve",
"start": "react-scripts start",
"serve": "craco serve",
"start": "craco start",
"storybook": "start-storybook -p 6006",
"test": "react-scripts test --coverage --passWithNoTests"
"test": "craco test --coverage --passWithNoTests"
},
"browserslist": {
"production": [
Expand Down Expand Up @@ -65,12 +65,13 @@
"react-redux": "^8.0.1",
"redux-persist": "^6.0.0",
"semver": "^7.5.2",
"starknet": "^4.22.0",
"starknet": "^6.11.0",
"styled-components": "^5.3.5",
"toastr2": "^3.0.0-alpha.18",
"web-vitals": "^2.1.4"
},
"devDependencies": {
"@craco/craco": "^7.1.0",
"@metamask/eslint-config": "^12.2.0",
"@metamask/eslint-config-browser": "^12.1.0",
"@metamask/eslint-config-jest": "^12.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default {
const asset = {
address: '0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7',
amount: BigNumber.from('1000000000000000000'),
chainId: constants.StarknetChainId.TESTNET,
chainId: constants.StarknetChainId.SN_SEPOLIA,
decimals: 18,
name: 'Ether',
symbol: 'ETH',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default {
const asset: Erc20TokenBalance = {
address: '0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7',
amount: BigNumber.from('1000000000000000000'),
chainId: constants.StarknetChainId.TESTNET,
chainId: constants.StarknetChainId.SN_SEPOLIA,
decimals: 18,
name: 'Ether',
symbol: 'ETH',
Expand Down
2 changes: 1 addition & 1 deletion packages/wallet-ui/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { constants } from 'starknet';
export const SEPOLIA_CHAINID = '0x534e5f5345504f4c4941';

export const TOKENS: any = {
[constants.StarknetChainId.MAINNET]: {
[constants.StarknetChainId.SN_MAIN]: {
'0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7': {
coingeckoId: 'ethereum',
},
Expand Down
2 changes: 1 addition & 1 deletion packages/wallet-ui/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const openExplorerTab = (
) => {
let explorerUrl = STARKNET_SEPOLIA_TESTNET_EXPLORER;
switch (chainId) {
case constants.StarknetChainId.MAINNET:
case constants.StarknetChainId.SN_MAIN:
explorerUrl = STARKNET_MAINNET_EXPLORER;
break;
case SEPOLIA_CHAINID:
Expand Down
Loading
Loading