Skip to content

Commit

Permalink
feat: New Apis for Snap (#207)
Browse files Browse the repository at this point in the history
* New Apis for Snap

---------

Co-authored-by: stanleyyuen <[email protected]>
  • Loading branch information
mario-christopher and stanleyyconsensys authored Mar 4, 2024
1 parent 5861156 commit 675647d
Show file tree
Hide file tree
Showing 22 changed files with 2,733 additions and 523 deletions.
20 changes: 11 additions & 9 deletions packages/starknet-snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
"scripts": {
"setup": "yarn install --immutable && yarn allow-scripts",
"build:clean": "yarn clean && yarn build",
"build": "mm-snap build",
"serve": "mm-snap serve",
"build": "cross-env SNAP_ENV=prod mm-snap build",
"serve": "cross-env SNAP_ENV=prod mm-snap serve",
"clean": "rimraf js && rimraf dist",
"watch": "yarn build && concurrently --kill-others --names SNAP,SERVE -c bgMagenta.bold,bgGreen.bold \"yarn run watch:snap\" \"yarn run serve\"",
"watch:snap": "mm-snap watch",
"watch:snap": "cross-env SNAP_ENV=prod mm-snap watch",
"prettier": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"lint": "eslint . --max-warnings 0 -f json -o eslint-report.json",
"lint:fix": "eslint '**/*.{js,ts,tsx}' --fix",
Expand All @@ -26,11 +26,9 @@
"author": "",
"devDependencies": {
"@lavamoat/allow-scripts": "^2.0.3",
"@metamask/key-tree": "^7.0.0",
"@metamask/rpc-methods": "^0.32.2",
"@metamask/snaps-cli": "^0.32.2",
"@metamask/snaps-types": "^0.32.2",
"@metamask/snaps-ui": "^0.32.2",
"@metamask/key-tree": "9.0.0",
"@metamask/rpc-methods": "3.0.0",
"@metamask/snaps-cli": "5.0.0",
"@types/chai": "^4.3.1",
"@types/chai-as-promised": "^7.1.5",
"@types/sinon": "^10.0.11",
Expand All @@ -40,6 +38,8 @@
"chai": "^4.3.6",
"chai-as-promised": "^7.1.1",
"concurrently": "^7.1.0",
"cross-env": "^7.0.3",
"envify": "^4.1.0",
"eslint": "^8.13.0",
"mocha": "^9.2.2",
"nyc": "^15.1.0",
Expand All @@ -52,6 +52,7 @@
"typescript": "^4.6.3"
},
"dependencies": {
"@metamask/snaps-sdk": "3.0.1",
"async-mutex": "^0.3.2",
"ethereum-unit-converter": "^0.0.17",
"ethers": "^5.5.1",
Expand All @@ -66,7 +67,8 @@
"allowScripts": {
"@lavamoat/preinstall-always-fail": false,
"@metamask/rpc-methods>@metamask/permission-controller>@metamask/controller-utils>ethereumjs-util>ethereum-cryptography>keccak": true,
"@metamask/rpc-methods>@metamask/permission-controller>@metamask/controller-utils>ethereumjs-util>ethereum-cryptography>secp256k1": true
"@metamask/rpc-methods>@metamask/permission-controller>@metamask/controller-utils>ethereumjs-util>ethereum-cryptography>secp256k1": true,
"ts-node>@swc/core": false
}
},
"nyc": {
Expand Down
11 changes: 10 additions & 1 deletion packages/starknet-snap/snap.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import envify from "envify/custom";

module.exports = {
cliOptions: {
dist: 'dist',
outfileName: 'bundle.js',
src: './src/index.ts',
},
};
bundlerCustomizer: (bundler) => {
bundler.transform(
envify({
SNAP_ENV: process.env.SNAP_ENV,
}),
);
},
};
6 changes: 4 additions & 2 deletions 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": "d88FLOvd7RKjJlzRixIQMpxnYGdnSyMuNaGYJbcIy3Q=",
"shasum": "PJ6E3d1eILzFgZu2TWIZwzTWI8E/8nyJzcWfo737V7c=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand All @@ -29,7 +29,9 @@
"endowment:rpc": {
"snaps": false,
"dapps": true
}
},
"endowment:lifecycle-hooks": {},
"endowment:page-home": {}
},
"manifestVersion": "0.1"
}
2 changes: 1 addition & 1 deletion packages/starknet-snap/src/addErc20Token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from './utils/snapUtils';
import { DEFAULT_DECIMAL_PLACES } from './utils/constants';
import { DialogType } from '@metamask/rpc-methods';
import { heading, panel } from '@metamask/snaps-ui';
import { heading, panel } from '@metamask/snaps-sdk';
import { logger } from './utils/logger';

export async function addErc20Token(params: ApiParams) {
Expand Down
2 changes: 1 addition & 1 deletion packages/starknet-snap/src/addNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { validateAddNetworkParams, upsertNetwork, getNetworkTxt } from './utils/
import { logger } from './utils/logger';
import { Network } from './types/snapState';
import { DialogType } from '@metamask/rpc-methods';
import { panel, heading } from '@metamask/snaps-ui';
import { panel, heading } from '@metamask/snaps-sdk';

export async function addNetwork(params: ApiParams) {
try {
Expand Down
2 changes: 1 addition & 1 deletion packages/starknet-snap/src/createAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { ApiParams, CreateAccountRequestParams } from './types/snapApi';
import { EstimateFee, num } from 'starknet';
import { ethers } from 'ethers';
import { DialogType } from '@metamask/rpc-methods';
import { heading, panel, text } from '@metamask/snaps-ui';
import { heading, panel, text } from '@metamask/snaps-sdk';
import { logger } from './utils/logger';

export async function createAccount(params: ApiParams, silentMode = false) {
Expand Down
2 changes: 1 addition & 1 deletion packages/starknet-snap/src/declareContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ApiParams, DeclareContractRequestParams } from './types/snapApi';
import { getNetworkFromChainId, getDeclareSnapTxt } from './utils/snapUtils';
import { getKeysFromAddress, declareContract as declareContractUtil } from './utils/starknetUtils';
import { DialogType } from '@metamask/rpc-methods';
import { heading, panel } from '@metamask/snaps-ui';
import { heading, panel } from '@metamask/snaps-sdk';
import { logger } from './utils/logger';

export async function declareContract(params: ApiParams) {
Expand Down
2 changes: 1 addition & 1 deletion packages/starknet-snap/src/executeTxn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getNetworkFromChainId, getTxnSnapTxt } from './utils/snapUtils';
import { getKeysFromAddress, executeTxn as executeTxnUtil } from './utils/starknetUtils';
import { ApiParams, ExecuteTxnRequestParams } from './types/snapApi';
import { DialogType } from '@metamask/rpc-methods';
import { heading, panel } from '@metamask/snaps-ui';
import { heading, panel } from '@metamask/snaps-sdk';
import { logger } from './utils/logger';

export async function executeTxn(params: ApiParams) {
Expand Down
2 changes: 1 addition & 1 deletion packages/starknet-snap/src/extractPrivateKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ApiParams, ExtractPrivateKeyRequestParams } from './types/snapApi';
import { getNetworkFromChainId } from './utils/snapUtils';
import { getKeysFromAddress } from './utils/starknetUtils';
import { DialogType } from '@metamask/rpc-methods';
import { copyable, panel, text } from '@metamask/snaps-ui';
import { copyable, panel, text } from '@metamask/snaps-sdk';
import { logger } from './utils/logger';

export async function extractPrivateKey(params: ApiParams) {
Expand Down
Loading

0 comments on commit 675647d

Please sign in to comment.