New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

msafe-wallet

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

msafe-wallet

appstore sdk of msafe wallet

  • 1.1.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.3K
increased by9.16%
Maintainers
1
Weekly downloads
 
Created
Source

Msafe Wallet SDK

Msafe Wallet SDK is used to integrate any dapp into msafe multi-sign wallet.
The frontend of dapp will run in a sub-iframe of msafe, this SDK can be used for the interaction between dapp and msafe wallet.

Install

Installation of the npm package:

> npm install --save msafe-wallet

Usage(Dapp Side)

Init msafe wallet

You should initialize it once and use it later.

import { MsafeWallet } from "msafe-wallet";
const msafe = await MsafeWallet.new();

Connect to a msafe account

This method is used to connect to current account. It returns an account object containing the address and publicKey. ** In the current implementation, the account is always in connected state, and disconnect is not supported. **

import { MsafeWallet } from "msafe-wallet";
const msafe = await MsafeWallet.new();
const account = await msafe.connect(); // {addres:string, publicKey:string}
await msafe.isConnected(); // true

Get Network

This method is used to get current network. It returns a string.

import { MsafeWallet } from "msafe-wallet";
const msafe = await MsafeWallet.new();
const network:string = await msafe.network(); // 'Mainnet'

Get Account

This method is used to get current msafe account. It returns an account object containing the address and publicKey.

import { MsafeWallet } from "msafe-wallet";
const msafe = await MsafeWallet.new();
const account:Account = await msafe.account();
console.log("address:", account.address);
console.log("public key:", account.publicKey);

Get ChainId

This method is used to get current ChainId. It returns a number.

import { MsafeWallet } from "msafe-wallet";
const msafe = await MsafeWallet.new();
const account = await msafe.chainId();  // 1

Submit Transaction

This method is used to sign the transaction and then submit it to the blockchain.
It takes two parameters:

  • payload - mandatory parameter containing the transaction body.
  • option - optional parameter that overrides transaction parameters.
  • For arguments of type vector, you can pass in an array.
  • For vector<u8>, you can pass in Uint8Array.
  • You can also pass in a BCS serialized transaction as payload(Uint8Array), which ignores option.

** In current implementation, this function call never returns. This is because when a transaction is initiated, the dapp page will be closed and then the msafe page will be entered to collect signatures. We will optimize it in future releases.**

import { MsafeWallet } from "msafe-wallet";
const msafe = await MsafeWallet.new();
const payload = {
    function: "0x1::coin::transfer",
    type_arguments: ["0x1::aptos_coin::AptosCoin"],
    arguments: ["0x997b38d2127711011462bc42e788a537eae77806404769188f20d3dc46d72750", 50]
};
// each field of option is optional.
const option = {
   sender: account.address,
   sequence_number: "1",
   max_gas_amount: "4000",
   gas_unit_price: "100",
   // Unix timestamp, in seconds + 30 days
   expiration_timestamp_secs: (Math.floor(Date.now() / 1000) + 30*24*3600).toString(),
}
await msafe.signAndSubmit(payload, option);

Sign Transaction

Not supported for now.

Sign Message

Not supported for now.

Network Change Event

This function is used to register the callback function for the network change event.

import { MsafeWallet } from "msafe-wallet";
const msafe = await MsafeWallet.new();
msafe.onChangeAccount((network:string)=>{
    console.log("network change to:", network)
});

Account Change Event

This function is used to register the callback function for the account change event.

import { MsafeWallet } from "msafe-wallet";
const msafe = await MsafeWallet.new();
msafe.onChangeAccount((account:Account)=>{
    console.log("address:", account.address);
    console.log("public key:", account.publicKey);
});

Usage(Msafe Server Side)

This section is for implementation on the msafe server side and is intended for use only by the msafe developers themselves.

Accept dapp connection

import { Connector,MsafeServer } from "msafe-wallet";
// cleaner is a function that used to remove listener.
const cleaner = Connector.accepts(dappUrl, (connector:Connector) => {

})

Create Msafe Wallet Service

import { Connector,MsafeServer,WalletAPI } from "msafe-wallet";
const connector:Connector = await Connector.accept(dappUrl);
const server = new MsafeServer(connector, {
    async connect(): Promise<Account> {
        // ...
        return {address:'0x1', publicKey:'0x1234...'};
    },
    // ... signAndSubmit(),signTransaction()
    async signMessage(
        message: string | Uint8Array
    ): Promise<Uint8Array> {
        throw Error("unsupport");
    },
} as WalletAPI);

Emit Network Change Event

import { Connector,MsafeServer,WalletAPI } from "msafe-wallet";
const server = new MsafeServer(...);
await server.changeNetwork('Testnet');

Emit Account Change Event

import { Connector,MsafeServer,WalletAPI } from "msafe-wallet";
const server = new MsafeServer(...);
await server.changeAccount({address:'0x1234...', publicKey:'0xabce...'});

Development

# Install dependencies
> npm install

# Build
> npm run build

# Test
> npm run test

# Publish
> npm publish

Keywords

FAQs

Package last updated on 14 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc