ubirch-metamask-key-register
TypeScript icon, indicating that this package has built-in type declarations

0.1.3 • Public • Published

Ubirch Metamask Key Register

JS-module to create key registration message (msgpack) for your Metamask key.

Build from sources

Install wasm-pack.

Build: wasm-pack build --scope ubirch.

Pack npm package: wasm-pack pack.

Usage example

See examples folder for Details on how to run the following html example locally:

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Metamask Key registration </title>
    </head>
    <body>
        <p>Ubirch Metamask sign key registration message example. See log output!</span></p>

        <script async type=module>
            import init, { get_signed_key_registration_message } from './pkg/ubirch_metamask_key_register.js';

            const isMetaMaskInstalled = () => {
                const { ethereum } = window;
                return Boolean(ethereum && ethereum.isMetaMask);
            };

            async function connectToMetamaskAndGetWalletAdress() {
                const result = await window.ethereum.request({ method: "eth_requestAccounts" });
                return result;
            };

            async function getKeyRegistrationMessage(wallet_address) {
                await init();
                // set your device ID here
                const deviceId = "00010203-0405-0607-0809-0a0b0c0d0e0f";
                return get_signed_key_registration_message(wallet_address, deviceId);
            }

            if (isMetaMaskInstalled) {
                connectToMetamaskAndGetWalletAdress().then(function(value) {
                    console.log("Your wallet address: ", value[0]);
                    getKeyRegistrationMessage(value[0]).then(function(value) {
                        console.log("Key registration message: ", value);

                        // send key registration message to backend
                        const request = new XMLHttpRequest();
                        request.open("POST", "https://identity.dev.ubirch.com/api/keyService/v1/pubkey/mpack");
                        request.setRequestHeader("accept", "application/json");
                        request.setRequestHeader("Content-Type", "application/octet-stream");
                        request.send(Uint8Array.from(value.match(/.{1,2}/g).map((byte) => parseInt(byte, 16))));
                        request.onreadystatechange=(e) => {
                            console.log(request.responseText)
                        }
                    });
                });
            } else {
                console.log("Metamask is not installed.");
            }
        </script>
    </body>
</html>

Readme

Keywords

none

Package Sidebar

Install

npm i ubirch-metamask-key-register

Weekly Downloads

1

Version

0.1.3

License

none

Unpacked Size

90.6 kB

Total Files

5

Last publish

Collaborators

  • sven-hm-ub