Skip to content

Commit

Permalink
WIP - Checksum error
Browse files Browse the repository at this point in the history
  • Loading branch information
codebycarson committed Dec 26, 2023
1 parent ab04325 commit d4e4bfa
Show file tree
Hide file tree
Showing 32 changed files with 448 additions and 142 deletions.
5 changes: 0 additions & 5 deletions .changeset/stupid-scissors-hide.md

This file was deleted.

18 changes: 18 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changelog

## 0.0.0-internal-20231226184402

### Minor Changes

- Simplified exports

## 0.0.0-internal-20231226181823

### Patch Changes

- Updated @noble versions

## 0.0.0-internal-20231226173424

### Patch Changes

- Moved helper libraries to /core

## 3.1.2

### Patch Changes
Expand Down
3 changes: 2 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sei-js/core",
"version": "3.1.2",
"version": "0.0.0-internal-20231226184402",
"private": false,
"description": "TypeScript library for front end integrations with Sei",
"keywords": [
Expand Down Expand Up @@ -49,6 +49,7 @@
"@cosmjs/utils": "^0.29.5",
"@ethersproject/keccak256": "^5.7.0",
"@keplr-wallet/types": "^0.11.41",
"@noble/secp256k1": "1.7.1",
"@sei-js/proto": "^3.1.0",
"bech32": "^2.0.0",
"buffer": "^6.0.3",
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './queryClient';
export * from './signingClient';
export * from './wallet';
export * from './utils';
export * from './mmSnap';
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,10 @@ import { SignDoc } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
import { AccountData, AminoSignResponse, StdSignDoc } from '@cosmjs/amino';
import { DirectSignResponse, OfflineDirectSigner } from '@cosmjs/proto-signing';
import Long from 'long';
import { MM_SNAP_ORIGIN } from './config';
import { SignAminoOptions } from './types';
import { makeADR36AminoSignDoc } from '@sei-js/core';
import { getWallet } from './snapWallet';

export const sendReqToSnap = async (method: string, params: any): Promise<any> => {
return window.ethereum.request({
method: 'wallet_invokeSnap',
params: {
snapId: MM_SNAP_ORIGIN,
request: {
method,
params
}
}
});
};
import { sendReqToSnap } from './utils';
import { makeADR36AminoSignDoc } from '../utils';

export const requestSignature = async (
chainId: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './config';
export * from './cosmjs';
export * from './snapWallet';
export * from './types';
export * from './utils';
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { SignDoc } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
import { BIP44Node } from '@metamask/key-tree';
import { AccountData, encodeSecp256k1Signature, StdSignDoc } from '@cosmjs/amino';
import { Buffer } from 'buffer';
import { compressedPubKeyToAddress, serializeAminoSignDoc, serializeDirectSignDoc, SeiWallet } from '@sei-js/core';
import { CosmJSOfflineSigner, sendReqToSnap } from './cosmjs';
import { CosmJSOfflineSigner } from './cosmjs';
import { MM_SNAP_ORIGIN } from './config';
import { getSnapEthereumProvider, sendReqToSnap } from './utils';
import { compressedPubKeyToAddress, serializeAminoSignDoc, serializeDirectSignDoc } from '../utils';
import { SeiWallet } from '../wallet';

export class SnapWallet {
constructor(private privateKey: Uint8Array, private compressedPubKey: Uint8Array, private address: string) {}
Expand Down Expand Up @@ -93,7 +95,7 @@ export const experimental_SEI_METAMASK_SNAP: SeiWallet = {
return offlineSigner.getAccounts();
},
connect: async (_: string) => {
const provider = window.ethereum;
const provider = await getSnapEthereumProvider();
const installedSnaps: any = await provider.request({ method: 'wallet_getSnaps' });
if (!installedSnaps || !installedSnaps[MM_SNAP_ORIGIN]) {
await provider.request({
Expand All @@ -118,7 +120,9 @@ export const experimental_SEI_METAMASK_SNAP: SeiWallet = {
return offlineSigner.signArbitrary(signer, message);
},
verifyArbitrary: async (_: string, signingAddress, data, signature) => {
return (await window.ethereum.request({
const provider = await getSnapEthereumProvider();

return (await provider.request({
method: 'wallet_invokeSnap',
params: {
snapId: MM_SNAP_ORIGIN,
Expand Down
18 changes: 18 additions & 0 deletions packages/core/src/lib/mmSnap/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { MetaMaskInpageProvider } from '@metamask/providers';

export type EthereumProvider = MetaMaskInpageProvider & {
providers: MetaMaskInpageProvider[];
detected: MetaMaskInpageProvider[];
setProvider: (provider: MetaMaskInpageProvider) => void;
};

declare global {
interface Window {
ethereum: EthereumProvider;
}
}

export type SignAminoOptions = {
isADR36?: boolean;
enableExtraEntropy?: boolean;
};
66 changes: 66 additions & 0 deletions packages/core/src/lib/mmSnap/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { EthereumProvider } from './types';
import { MM_SNAP_ORIGIN } from './config';

/**
* The fool proof version of getting the ethereum provider suggested by
* https://github.com/Montoya/snap-connect-test/blob/0dad2dd53ab2ecbf4b4369230d3aaaeca08c6dae/index.html#L41
*
* @returns the ethereum provider which supports snaps
*/
export const getSnapEthereumProvider = async (): Promise<EthereumProvider> => {
let mmFound = false;
if ('detected' in window.ethereum) {
for (const provider of window.ethereum.detected) {
try {
// Detect snaps support
await provider.request({
method: 'wallet_getSnaps'
});
// enforces MetaMask as provider
window.ethereum.setProvider(provider);

mmFound = true;
// @ts-ignore
return provider;
} catch {
// no-op
}
}
}

if (!mmFound && 'providers' in window.ethereum) {
for (const provider of window.ethereum.providers) {
try {
// Detect snaps support
await provider.request({
method: 'wallet_getSnaps'
});

// @ts-ignore
window.ethereum = provider;

mmFound = true;
// @ts-ignore
return provider;
} catch {
// no-op
}
}
}

return window.ethereum;
};

export const sendReqToSnap = async (method: string, params: any): Promise<any> => {
const provider = await getSnapEthereumProvider();
return provider.request({
method: 'wallet_invokeSnap',
params: {
snapId: MM_SNAP_ORIGIN,
request: {
method,
params
}
}
});
};
25 changes: 0 additions & 25 deletions packages/metamask-snap/.babelrc.js

This file was deleted.

75 changes: 75 additions & 0 deletions packages/metamask-snap/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# @sei-js/metamask-snap

## 0.0.0-internal-20231226184402

### Minor Changes

- Simplified exports

### Patch Changes

- Updated dependencies
- @sei-js/core@0.0.0-internal-20231226184402

## 0.0.0-internal-20231226181823

### Patch Changes

- Updated @noble versions
- Updated dependencies
- @sei-js/core@0.0.0-internal-20231226181823

## 0.0.0-internal-20231226173424

### Patch Changes

- Moved helper libraries to /core
- Updated dependencies
- @sei-js/core@0.0.0-internal-20231226173424

## 0.0.0-internal-20231226165919

### Patch Changes

- Include files in export
- Updated dependencies
- @sei-js/core@0.0.0-internal-20231226165919

## 0.0.0-internal-20231226154916

### Patch Changes

- Testing splitting out functions
- Updated dependencies
- @sei-js/core@0.0.0-internal-20231226154916

## 0.0.0-internal-20231218170904

### Patch Changes

- Use safe provider throughout

## 0.0.0-internal-20231218165750

### Patch Changes

- Use safe provider function to get ethereum provider that supports snaps

## 0.0.0-internal-20231218151625

### Patch Changes

- Adjusted library entry path

## 0.0.0-internal-20231218151104

### Patch Changes

- Changed package entry file

## 0.0.0-internal-20231213101440

### Patch Changes

- Release for testing
- ab04325: Initial pre-release of MM snap
7 changes: 0 additions & 7 deletions packages/metamask-snap/jest.config.lib.ts

This file was deleted.

29 changes: 5 additions & 24 deletions packages/metamask-snap/package.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,22 @@
{
"name": "@sei-js/metamask-snap",
"version": "0.1.0",
"version": "0.0.0-internal-20231226184402",
"description": "A MetaMask snap for the SEI blockchain",
"repository": {
"type": "git",
"url": "https://github.com/MetaMask/template-snap-monorepo.git"
},
"license": "MIT",
"exports": {
".": {
"import": "./lib/esm/index.js",
"require": "./lib/cjs/index.js",
"browser": {
"import": "./lib/esm/index.js",
"require": "./lib/cjs/index.js"
},
"types": "./lib/types/index.d.ts"
}
},
"main": "./lib/esm/index.js",
"module": "./lib/esm/index.js",
"browser": "./lib/esm/index.js",
"types": "./lib/types/index.d.ts",
"main": "src/index.ts",
"files": [
"snap/",
"lib/",
"dist/",
"images/",
"snap.manifest.json"
],
"scripts": {
"prebuild": "yarn clean",
"build": "yarn build:snap && yarn build:types && yarn build:cjs && yarn build:esm && yarn build:prettier",
"build": "yarn build:snap && yarn build:prettier",
"build:snap": "mm-snap build",
"build:types": "tsc --project tsconfig.declarations.json",
"build:cjs": "BABEL_ENV=cjs babel src/lib --out-dir dist/lib/cjs --extensions '.js,.jsx,.ts,.tsx' --source-maps --copy-files --no-copy-ignored",
"build:esm": "BABEL_ENV=esm babel src/lib --out-dir dist/lib/esm --extensions '.js,.jsx,.ts,.tsx' --source-maps --copy-files --no-copy-ignored",
"build:prettier": "prettier --write 'dist/**/*.js'",
"build:clean": "yarn clean && yarn build",
"clean": "rimraf dist",
Expand All @@ -44,13 +26,12 @@
"serve": "mm-snap serve",
"start": "mm-snap watch",
"test": "yarn test:lib && yarn test:snap",
"test:lib": "jest --config ./jest.config.lib.ts",
"test:snap": "jest --config ./jest.config.snap.js"
},
"dependencies": {
"@metamask/snaps-types": "^3.1.0",
"@metamask/snaps-ui": "^3.1.0",
"@sei-js/core": "^3.1.2",
"@sei-js/core": "0.0.0-internal-20231226184402",
"buffer": "^6.0.3"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/metamask-snap/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import type { SnapConfig } from '@metamask/snaps-cli';

const config: SnapConfig = {
bundler: 'webpack',
input: resolve(__dirname, 'src/snap/index.ts'),
input: resolve(__dirname, 'src/index.ts'),
output: {
path: resolve(__dirname, 'dist/snap'),
path: resolve(__dirname, 'dist'),
filename: 'bundle.js',
clean: true,
minimize: true
Expand Down
Loading

0 comments on commit d4e4bfa

Please sign in to comment.