GithubHelp home page GithubHelp logo

trust-machines / multisafe Goto Github PK

View Code? Open in Web Editor NEW
26.0 7.0 15.0 1.04 MB

MultiSafe is a shared crypto wallet for managing Stacks (STX) and Bitcoin (BTC).

License: MIT License

Clarity 48.87% TypeScript 45.95% JavaScript 5.17%
stacks bitcoin stx btc blockchain

multisafe's Introduction

MultiSafe

MultiSafe is a shared crypto wallet for managing Stacks (STX) and Bitcoin (BTC).

Deploy a MultiSafe

https://app.multisafe.xyz/

Features

Current supported features:

  • Send, transfer and hold STX
  • SIP-009 Non-fungible token and SIP-010 Fungible token support
  • Supports up to 20 owners

Future updates (coming soon):

  • User-friendly app
  • Native Bitcoin (BTC) support

Security

CoinFabrik audit report

Least Authority audit report

Please report any security issues you find via our bug bounty program on Immunefi.

Clarity Usage

Requires Clarinet

Install Clarinet: https://github.com/hirosystems/clarinet

MultiSafe is written in Clarity and therefore requires you to install Clarinet locally on the command line. Type the following command to check that you have Clarinet installed:

$ clarinet --version

Please make sure you have Clarinet version 0.31.1 or higher installed.

Download MultiSafe

  1. Clone the repo:
$ git clone https://github.com/Trust-Machines/multisafe.git && cd multisafe
  1. Run the unit test to confirm all the tests passed and everything is working:
$ clarinet test
  1. Open the Clarinet console in order to interact with the contract
$ clarinet console

Setup the first MultiSafe owners

Go to /contracts/safe.clar. At the bottom of that contract you'll see a list with three sample owners. These are the default Clarinet wallets that you can use for testing locally in Clarinet.

(init (list 
    'ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5 
    'ST2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CFRK9AG 
    'ST2JHG361ZXG51QTKY2NQCVBPPRRE2KZB1HR05NNC
) u2)

If you'd like to deploy to mainnet/testnet update those wallet addresses with your own wallet addresses.

Get Safe Owners

(contract-call? 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.safe get-owners)

In the example above ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.safe is your safe's contract name.

get-owners will return [ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5, ST2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CFRK9AG, ST2JHG361ZXG51QTKY2NQCVBPPRRE2KZB1HR05NNC]

Get confirmation threshold

(contract-call? 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.safe get-threshold)

The Clarinet console demo will return u2

In this example “u2” tells us that we need a minimum of 2 confirmations in order to approve a transaction

Add new owners

  1. Change the transaction sender to “wallet_1”
::set_tx_sender ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5
  1. Add a new user to the wallet. In this example, we add “wallet_9” to MultiSafe.
(contract-call? 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.safe submit 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.add-owner 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.safe 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.ft-none 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.nft-none (some 'STNHKEPYEPJ8ET55ZZ0M5A34J0R3N5FM2CMMMAZ6) none none)

ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM = deployer 'STNHKEPYEPJ8ET55ZZ0M5A34J0R3N5FM2CMMMAZ6 = wallet_9

  1. If you “get-owners” you’ll see that there are still only 3 owners. In order to confirm the 4th owner you will need to switch to “wallet_2” or “wallet_3” (the other owner”) and approve the transaction.
(contract-call? 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.safe get-owners)

Returns: [ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5, ST2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CFRK9AG, ST2JHG361ZXG51QTKY2NQCVBPPRRE2KZB1HR05NNC]

  1. Change owner to wallet_2
::set_tx_sender ST2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CFRK9AG
  1. As wallet_2 owner, now you can approve the 4th new owner
(contract-call? 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.safe confirm u0 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.add-owner 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.safe 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.ft-none 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.nft-none)
  1. Call “get-owners” again and you will see the 4th owner has been added
(contract-call? 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.safe get-owners)

Returns: [ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5, ST2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CFRK9AG, ST2JHG361ZXG51QTKY2NQCVBPPRRE2KZB1HR05NNC, STNHKEPYEPJ8ET55ZZ0M5A34J0R3N5FM2CMMMAZ6]

Send STX to the MultiSafe

If you are the wallet_3 owner (ST2JHG361ZXG51QTKY2NQCVBPPRRE2KZB1HR05NNC) then the following command will allow you to send STX from your wallet to the MultiSafe

(stx-transfer? u5000 'ST2JHG361ZXG51QTKY2NQCVBPPRRE2KZB1HR05NNC 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.safe)

::get_assets_maps will show you that the STX has been transfered into the .safe contract

Send STX from MultiSafe to a new wallet

In this example, using Clarinet console, we will send STX from MultiSafe to "wallet_7"

  1. Send STX to wallet_7

Assuming you are an owner — in this example, you will send 1000 uSTX from the MultisSafe to wallet_7 (ST3PF13W7Z0RRM42A8VZRVFQ75SV1K26RXEP8YGKJ).

(contract-call? 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.safe submit 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.transfer-stx 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.safe 
'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.ft-none 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.nft-none (some 'ST3PF13W7Z0RRM42A8VZRVFQ75SV1K26RXEP8YGKJ) (some u1000) none)
  1. Change owner to wallet_2
::set_tx_sender ST2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CFRK9AG
  1. Wallet_2 can now confirm the transaction
(contract-call? 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.safe confirm u1 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.transfer-stx 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.safe 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.ft-none 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.nft-none)

MultiSafe now has -1000 uSTX, and wallet_7 +1000 uSTX

API Reference

Owner only functions

The following function can be run by only safe owners:

submit (executor <executor-trait>, safe <safe-trait>, param-ft <ft-trait>, param-nft <nft-trait>, param-p (optional principal), param-u (optional uint), param-b (optional (buff 20))) => (response uint)

confirm (tx-id uint, executor <executor-trait>, safe <safe-trait>, param-ft <ft-trait>, param-nft <nft-trait>) => (response bool)

revoke (tx-id uint) => (response bool)

Safe only functions

The following functions can be run by only safe contract itself and requires the minimum number of confirmations:

add-owner (owner principal) => (response bool)

remove-owner (owner principal) => (response bool)

set-threshold (value uint) => (response bool)

Views (Read only functions)

get-version() => string-ascii

get-owners() => list

get-threshold() => uint

get-nonce() => uint

get-info() => tuple

get-transaction (tx-id uint) => tuple

get-transactions (tx-ids (list 20 uint)) => list

multisafe's People

Contributors

castig avatar moodmosaic avatar talhasch avatar wbnns avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

multisafe's Issues

Changing `min-confirmations` affects all transactions

When we change min-confirmations from X to Y it affects both on going and future transactions.
I think that each transaction should have its own fixed min-confirmation threshold that is set up when transaction is created.

In UI there it is not possible to revoke a pending, unauthorized transaction

On the Transactions page, when loaded by for review an owner that was not the transaction originator, there is no REVOKE button. So hypothetically speaking, let's say one of the owner accounts was compromised and an unauthorized transaction was made by it. There is no revoke button for the other owners.

image

Add 'get-owners' or 'get-info' function to safe-trait

Adding 'get-owners' or 'get-info' function to safe-trait would allow on-chain verification of safe owner from other clarity contracts.

e.g.
In LEOS project, this will help verify if a user have created multi-safe contract, is in the list of owners of that contract or not.

License is missing from this repository and needs to be added

@talhasch

Hello, we just observed there is no License file in this repository -- we're interested in developing on top of MultiSafe and extending it via code contributions here but can't do so if there is no license defined since the opaqueness of not having one creates an undefined state of what is permissible use of this code.

Cc: @muneeb-ali

A list of improvements

  • Optional transaction parameters
    param-p and param-u are not necessary for every transaction. It's better to have them as optional to keep state data smaller.

  • A new buffer parameter
    An optional buffer parameter param-b to use for transfer memo.

  • sip-009 and sip-010 support:
    This is something we must have for built-in ft and nft transfers. We need two more executors and transaction parameters as param-ft (sip-009-trait) and param-nft (sip-010-trait). They won't be optional since trait references cannot be stored on smart contracts and they have to be validated in confirm function by taking principal. values with contract-of function. Therefore we'll need to use some default/none/null values for transactions other than token/nft transfers. I believe that is a reasonable trade-off to provide support for all tokens/nfts.

  • Include transaction id in get-transaction(s) function response to provide better ux.

  • Rename min-confirmation (and all related variables and constants) to threshold to avoid confusion.

  • Info function:
    A new function to allow read all basic safe information (version, owners, threshold, nonce) at once.

  • Test improvements:
    Our tests getting bigger and they should be improved to provide a cleaner code. Some re-uses can be optimized.

Open sourcing frontend code for app.multisafe.xyz

Does this initiative exist? Might be worth considering adding to this repo (or its own separate repo if that is preferred).

This will enable people to contribute to improving the UI, UX, etc. Speaking for myself, I noted some issues + opportunities and would be interested.

Example issue:

On the Transactions page, when loaded by for review an owner that was not the transaction originator, there is no REVOKE button. So hypothetically speaking, let's say one of the owner accounts was compromised and an unauthorized transaction was made by it. There is no revoke button for the other owners.

image

[BUG] One "transaction" can be executed multiple times.

If safe have multiple owners, then one transaction can be executed more than once.

# switch to one of the owners
::set_tx_sender ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5
# create new "transaction"
(contract-call? 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.safe submit 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.set-min-confirmation 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.safe .tx-sender u3)

# change to 2nd owner
::set_tx_sender ST2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CFRK9AG
# confirm transaction => 1st execution
(contract-call? 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.safe confirm u0 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.set-min-confirmation 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.safe)

# change to 3rd owner
::set_tx_sender ST2JHG361ZXG51QTKY2NQCVBPPRRE2KZB1HR05NNC
# confirm transaction => 2nd execution
(contract-call? 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.safe confirm u0 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.set-min-confirmation 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.safe)

Add here:

(let
(
(tx (unwrap! (map-get? transactions tx-id) ERR-TX-NOT-FOUND))
(confirmations (get confirmations tx))
)
(asserts! (is-none (index-of confirmations tx-sender)) ERR-TX-ALREADY-CONFIRMED-BY-OWNER)
(asserts! (is-eq (get executor tx) (contract-of executor)) ERR-TX-INVALID-EXECUTOR)

one extra assert:

(asserts! (not (get confirmed tx)) ERR-TX-CONFIRMED)

Buffer size use is limited

With only 20 bytes for FT/NFT param-b, there is limited information that can be kept
Addresses (at least) 40 characters
Transactions 66 characters
uuid 36 characters

saving it as binary, compressed or both may save a few bytes but doesn't change the fact, that to keep any meaningful information an external storage is required, What where the design goals for the size?

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.