GithubHelp home page GithubHelp logo

goplussecurity / riskdetect-snap Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 5.92 MB

Home Page: https://snaps.metamask.io/snap/npm/goplus/riskdetect-snap/

License: Apache License 2.0

JavaScript 12.59% TypeScript 87.41%

riskdetect-snap's Introduction

@goplus/riskdetect-snap

A MetaMask Snap that can detect risks of user assets, supported by GoPlusSecurity.

This repository demonstrates how to develop a snap with TypeScript. For detailed instructions, see the MetaMask documentation.

MetaMask Snaps is a system that allows anyone to safely expand the capabilities of MetaMask. A snap is a program that we run in an isolated environment that can customize the wallet experience.

Snaps is pre-release software

To interact with (your) Snaps, you will need to install MetaMask Flask, a canary distribution for developers that provides access to upcoming features.

Usage mode

Example

type GetSnapsResponse = Record<string, Snap>;

type Snap = {
    permissionName: string;
    id: string;
    version: string;
    initialPermissions: Record<string, unknown>;
};


/**
 * Get the installed snaps in MetaMask.
 *
 * @returns The snaps installed in MetaMask.
 */
export const getSnaps = async (): Promise<GetSnapsResponse> => {
    return (await window.ethereum.request({
        method: 'wallet_getSnaps',
    })) as unknown as GetSnapsResponse;
};

/**
 * Connect a snap to MetaMask.
 *
 * @param snapId - The ID of the snap.
 * @param params - The params to pass with the snap to connect.
 */
export const connectSnap = async (
    snapId: string = defaultSnapOrigin,
    params: Record<'version' | string, unknown> = {},
) => {
    await window.ethereum.request({
        method: 'wallet_requestSnaps',
        params: {
            [snapId]: params,
        },
    });
};


/**
 * Invoke the "token_detection" method from the snap.
 */
export const getTokenDetetion = async () => {
    await window.ethereum.request({
        method: 'wallet_invokeSnap',
        params: {
            snapId: 'npm:@goplus/riskdetect-snap',
            request: {
                method: 'token_detection',
                params: {},
            },
        },
    });
};

Notes

  • Babel is used for transpiling TypeScript to JavaScript, so when building with the CLI, transpilationMode must be set to localOnly (default) or localAndDeps.

riskdetect-snap's People

Contributors

jiehan330 avatar mr-lucky avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.