Core Library

Usage

The Core class is a TypeScript class that provides an interface for signing messages and transactions on the Ethereum blockchain. This library is used by all other Arianee SDK libraries to sign messages.

💡

This library uses the ethers library ethers library, which is a popular library for interacting with Ethereum.

You can instanciante Core with:

  • Mnemonic
import { Core } from '@arianee/core';
Core.fromMnemonic(mnemonic);
  • Passphrase
import { Core } from '@arianee/core';
Core.fromPassPhrase(passphrase);
  • PrivateKey
import { Core } from '@arianee/core';
Core.fromPrivateKey(privateKey);
  • Random: Generates random wallet.
    • For test purposes
    • Read-only wallet
import { Core } from '@arianee/core';
Core.fromRandom();

The returned instance will have the following methods:

  • signMessage(message:string): a function that behaves like the signMessage from ethers.
  • signTransaction(transaction:TransactionLike): a function that behaves like the signTransaction from ethers.

⚠️

Not compliant with MetaMask external wallet provider.

  • sendTransactions(transaction): a function that sends a transaction to MetaMask.
  • getAddress():string: a function that returns the address of the wallet.

Use Case - Implement Core to create an instance between Arianee and MetaMask

const accounts = await window.ethereum.request({
  method: 'eth_requestAccounts',
});

const address: string = accounts[0];

this.core = new Core({
  getAddress: () => {
    return address;
  },
  signMessage: async (message) => {
    const signature = await window.ethereum.request({
      method: 'personal_sign',
      params: [address, message],
    });
    return { message, signature };
  },
  sendTransaction: async (transaction) => {
    return window.ethereum.request({
      method: 'eth_sendTransaction',
      params: [transaction],
    });
  },
});

this.wallet = new Wallet({
  chainType: 'testnet',
  auth: { core: this.core },
});