Skip to content

Commit

Permalink
- Renamed file
Browse files Browse the repository at this point in the history
- Added notice on Sign Arbitrary requests
  • Loading branch information
codebycarson committed Jan 4, 2024
1 parent 844e830 commit 43e01bd
Show file tree
Hide file tree
Showing 54 changed files with 53 additions and 1,048 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export * from './queryClient';
export * from './signingClient';
export * from './wallet';
export * from './utils';
export * from './mmSnap';
export * from './metamask-snap';
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export class CosmJSOfflineSigner implements OfflineDirectSigner {
const signDoc = makeADR36AminoSignDoc(signer, data);
const result = await requestSignAmino(this.chainId, signer, signDoc, this.snapId, {
isADR36: true,
preferNoSetFee: true,
enableExtraEntropy: signOptions?.enableExtraEntropy
});
return result.signature;
Expand All @@ -101,17 +100,7 @@ export const requestSignAmino = async (
snapId: string,
options?: SignAminoOptions
): Promise<AminoSignResponse> => {
const { isADR36 = false, enableExtraEntropy = false, preferNoSetFee = true } = options || {};

if (!preferNoSetFee) {
// @ts-ignore
signDoc.fee.amount = [
{
amount: '0.1',
denom: 'usei'
}
];
}
const { isADR36 = false, enableExtraEntropy = false } = options || {};

if (!isADR36 && chainId !== signDoc.chain_id) {
throw new Error('Chain ID does not match signer chain ID');
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 0 additions & 18 deletions packages/metamask-snap/sei-metamask-test-site/.eslintrc.cjs

This file was deleted.

2 changes: 1 addition & 1 deletion packages/metamask-snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/template-snap-monorepo.git"
},
"source": {
"shasum": "8x/y6X8Re9ZD9X/Ug1hu9QCMGs53PrM/NAFULstl48U=",
"shasum": "lNzA3MPIVYkpwOrvg9HdFZMIWtoY9Dv73mQoafkIGq8=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/metamask-snap/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
return await wallet.signDirect(signerAddress, sd);
}
case 'signAmino': {
const { signerAddress, signDoc, chainId, enableExtraEntropy } = request.params as unknown as SignAminoRequest;
const { signerAddress, signDoc, chainId, enableExtraEntropy, isADR36 } = request.params as unknown as SignAminoRequest;

const sortedSignDoc: StdSignDoc = {
chain_id: chainId || 'pacific-1',
Expand All @@ -79,7 +79,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
method: 'snap_dialog',
params: {
type: 'confirmation',
content: getAminoPanel(sortedSignDoc)
content: getAminoPanel(sortedSignDoc, isADR36)
}
});

Expand Down
1 change: 1 addition & 0 deletions packages/metamask-snap/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface SignAminoRequest extends SnapRequest {
readonly signerAddress: string;
readonly chainId: string;
readonly enableExtraEntropy?: boolean;
readonly isADR36?: boolean;
}

export type RawLong = { low: number; high: number; unsigned: boolean };
Expand Down
17 changes: 12 additions & 5 deletions packages/metamask-snap/src/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { byteArrayToHex, longResponseToNumber, sanitizedUint8Array } from './uti
import { cosmos, ibc, seiprotocol, tendermint, cosmwasm, google } from '@sei-js/proto';
import { Any } from '@sei-js/proto/dist/types/codegen/google/protobuf/any';
import Long from 'long';
import { copyable, divider, heading, NodeType, panel, text } from '@metamask/snaps-ui';
import { copyable, divider, heading, panel, text } from '@metamask/snaps-ui';
import { StdSignDoc } from '@cosmjs/amino';
import { PanelOption } from './types';
import { SignDoc } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
Expand Down Expand Up @@ -134,9 +134,16 @@ export const getDirectPanel = (signDoc: SignDoc, accountNumber: Long): any => {
return panel(options);
};

export const getAminoPanel = (signDoc: StdSignDoc) => {
const options: PanelOption[] = [
heading('Sign Transaction (Amino)'),
export const getAminoPanel = (signDoc: StdSignDoc, isADR36: boolean = false) => {
const options: PanelOption[] = [];

if (isADR36) {
options.push(heading('Sign Arbitrary (ADR-036)'));
} else {
options.push(heading('Sign Transaction (Amino)'));
}

options.push(
divider(),
heading('Chain ID:'),
text(signDoc.chain_id),
Expand Down Expand Up @@ -165,7 +172,7 @@ export const getAminoPanel = (signDoc: StdSignDoc) => {
divider(),
heading('Fee:'),
text(JSON.stringify(signDoc.fee, null, 2))
];
);
if (signDoc.memo) {
options.push(divider(), heading('Memo'), copyable(signDoc.memo));
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ You will also see any lint errors in the console.

### Configuration
#### Snap Origin
- Change between the local snap server and using a published npm build by setting the `VITE_SNAP_ORIGIN` environment variable in `.env.local` to your snaps origin (`local:http://localhost:8080` for local, `npm:@sei-js/metamask-snap` for the latest published npm version)
- Change between the local snap server and using a published npm build by setting the `VITE_SNAP_ID` environment variable in `.env.local` to your snaps origin (`local:http://localhost:8080` for local, `npm:@sei-js/metamask-snap` for the latest published npm version)
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"name": "sei-metamask-test-site",
"name": "sei-metamask-test-ui",
"private": true,
"version": "1.0.0",
"type": "module",
"license": "(MIT-0 OR Apache-2.0)",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
Expand Down Expand Up @@ -40,15 +39,6 @@
"@typescript-eslint/eslint-plugin": "^6.17.0",
"@typescript-eslint/parser": "^6.17.0",
"@vitejs/plugin-react": "^4.2.1",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^27.6.1",
"eslint-plugin-jsdoc": "^48.0.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^5.1.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
"prettier": "^3.1.1",
"prettier-plugin-packagejson": "^2.4.8",
"rimraf": "^5.0.5",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const Header = ({ handleToggleClick }: { handleToggleClick(): void }) =>

const handleConnectClick = async () => {
try {
const origin = import.meta.env.VITE_SNAP_ORIGIN || `npm:@sei-js/metamask-snap`;
const origin = import.meta.env.VITE_SNAP_ID || `npm:@sei-js/metamask-snap`;
await connectSnap(origin);
const installedSnap = await getSnap(origin);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const MetaMaskProvider = ({ children }: { children: ReactNode }) => {

// Set installed snaps
useEffect(() => {
const origin = import.meta.env.VITE_SNAP_ORIGIN || `npm:@sei-js/metamask-snap`;
const origin = import.meta.env.VITE_SNAP_ID || `npm:@sei-js/metamask-snap`;
async function detectSnapInstalled() {
dispatch({
type: MetamaskActions.SetInstalled,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const Index = () => {
const [bankSendAminoResponse, setBankSendAminoResponse] = useState<DeliverTxResponse>(null);
const [signArbitraryResponse, setSignArbitraryResponse] = useState<object>(null);

const origin = import.meta.env.VITE_SNAP_ORIGIN || `npm:@sei-js/metamask-snap`;
const origin = import.meta.env.VITE_SNAP_ID || `npm:@sei-js/metamask-snap`;
const metamaskSnap = getMetaMaskSnap(origin);
// const metamaskSnap = COMPASS_WALLET;

Expand Down Expand Up @@ -284,7 +284,7 @@ const Index = () => {

const handleConnectClick = async () => {
try {
const origin = import.meta.env.VITE_SNAP_ORIGIN || `npm:@sei-js/metamask-snap`;
const origin = import.meta.env.VITE_SNAP_ID || `npm:@sei-js/metamask-snap`;
await connectSnap(origin);
const installedSnap = await getSnap(origin);

Expand Down Expand Up @@ -413,7 +413,7 @@ const Index = () => {
return (
<Container>
<Heading>MetaMask Snap ID</Heading>
<Span>{import.meta.env.VITE_SNAP_ORIGIN || `npm:@sei-js/metamask-snap`}</Span>
<Span>{import.meta.env.VITE_SNAP_ID || `npm:@sei-js/metamask-snap`}</Span>
<CardContainer>
{state.error && (
<ErrorMessage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const getMetaMaskSnap = (snapId: string): SeiWallet => {
},
signArbitrary: async (chainId, signer, message) => {
const offlineSigner = new CosmJSOfflineSigner(chainId, snapId);
return offlineSigner.signArbitrary(signer, message);
return offlineSigner.signArbitrary(signer, message, { enableExtraEntropy: true });
},
verifyArbitrary: async (_: string, signingAddress, data, signature) => {
return (await sendReqToSnap(
Expand Down
Loading

0 comments on commit 43e01bd

Please sign in to comment.