0.0.114 • Published 8 days ago

@msafe/sui-app-store v0.0.114

Weekly downloads
-
License
MIT
Repository
github
Last release
8 days ago

MSafe Sui App Store

Background

Due to Sui blockchain version limitations, multisig account can't propose multiple transactions at the same time. It's needed to be create as transaction intention first and propose transaction 1 by 1 for vote & execution.

Overview

Overview

Demos

https://msafe-sui-web-v3.vercel.app/

We provide a demo dApp for MSafe app store integration. please refer below GitHub repository: https://github.com/Momentum-Safe/msafe-sui-app-arbitrary-transaction

How to contribute

  • Fork the repository
  • Create a new branch for your app development
  • Create pull request for review

How to develop

Setup

  • Create your app folder under src/apps/ folder

Create intentions

  • Create your dapp intentions under src/apps/<your app> folder

Here is an example for transaction intention, if your dapp have multiple transaction types, you need to define 1 by 1 for each type of transaction intention.

export interface CoinTransferIntentionData {
  recipient: string;
  coinType: string;
  amount: string;
}

export class CoinTransferIntention extends CoreBaseIntention<CoinTransferIntentionData> {
  txType: TransactionType.Assets;

  txSubType: 'SendCoin';

  constructor(public readonly data: CoinTransferIntentionData) {
    super(data);
  }

  async build(input: { suiClient: SuiClient; account: WalletAccount }): Promise<TransactionBlock> {
    const { suiClient, account } = input;
    return buildCoinTransferTxb(suiClient, this.data, account.address);
  }

  static fromData(data: CoinTransferIntentionData) {
    return new CoinTransferIntention(data);
  }
}

Each intention should have one data structure to store transaction information for future build. This structure can be defined according to your own business logic, it can be any type of data, (should be JSON serializable)

Transaction intention implement mainly one API build(): Promise<TransactionBlock> which will build Sui transaction block from your defined business data.

Create helper

  • Create helper ts at src/apps/<your app>/intention.ts

Here is an example of intention.ts file

export type CoreIntention = CoinTransferIntention | ObjectTransferIntention;

export type CoreIntentionData = CoinTransferIntentionData | ObjectTransferIntentionData;

export class CoreHelper implements MSafeAppHelper<CoreIntention, CoreIntentionData> {
  application: string;

  constructor() {
    this.application = 'msafe-core';
  }

  deserialize(): CoreIntention {
    throw new Error('MSafe core transaction intention should be build from API');
  }

  async build(input: {
    intentionData: CoreIntentionData;
    txType: TransactionType;
    txSubType: string;
    suiClient: SuiClient;
    account: WalletAccount;
  }): Promise<TransactionBlock> {
    const { suiClient, account } = input;
    let intention: CoreIntention;
    switch (input.txSubType) {
      case 'coin-transfer':
        intention = CoinTransferIntention.fromData(input.intentionData as CoinTransferIntentionData);
        break;
      case 'object-transfer':
        intention = ObjectTransferIntention.fromData(input.intentionData as ObjectTransferIntentionData);
        break;
      default:
        throw new Error('not implemented');
    }
    return intention.build({ suiClient, account });
  }
}

The helper is responsible for convert a transaction block to your own transaction intention business data. this is call by SuiWallet standard API sui:signTransactionBlock feature.

Write test for your business logic

  • Create your test at test/<your app>.test.ts

You can follow be example to write test

import { TransactionType } from '@msafe/sui3-utils';

import { CoinTransferIntention, CoinTransferIntentionData } from '@/apps/msafe-core/coin-transfer';
import { appHelpers } from '@/index';

import { Account, Client } from './config';

describe('MSafe Core Wallet', () => {
  it('Core transaction build', async () => {
    const appHelper = appHelpers.getAppHelper('msafe-core');

    expect(appHelper.application).toBe('msafe-core');

    const res = await appHelper.build({
      txType: TransactionType.Assets,
      txSubType: 'coin-transfer',
      suiClient: Client,
      account: Account,
      intentionData: {
        amount: '1000',
        coinType: '0x2::sui::SUI',
        recipient: '123',
      } as CoinTransferIntentionData,
    });
    expect(res.blockData.version).toBe(1);
    expect(res.blockData.sender).toBe('0x0df172b18d30935ad68b2f9d6180e5adcf8edfd7df874852817002e6eccada66');
  });

  it('Test intention serialization', () => {
    const intention = CoinTransferIntention.fromData({
      recipient: 'a',
      coinType: 'b',
      amount: '100',
    });

    expect(intention.serialize()).toBe('{"amount":"100","coinType":"b","recipient":"a"}');
  });
});

Register your app helper

  • Add your app helper to file src/index.ts
export const appHelpers = new MSafeApps([new CoreHelper(), <your app helper instance here>]);

Create pull request for submit

Once you finish development, you can create a PR to submit your changes.

Integrate MSafe wallet with your app

The last step is to integrate MSafe wallet with your application

  • Run command yarn add @msafe/sui-wallet to add MSafe wallet package to your project
  • Add below code to your application, basically it should be added to your main.tsx file
import { MSafeWallet } from '@msafe/sui-wallet';
import { registerWallet } from '@mysten/wallet-standard';

registerWallet(new MSafeWallet('<your app name>'));

Next Step

Once the development mentioned above is complete, MSafe team will assist in verifying the integration. Feedback will be provided to your team upon completion of the verification process.

0.0.114

8 days ago

0.0.113

8 days ago

0.0.112

9 days ago

0.0.111

11 days ago

0.0.110

20 days ago

0.0.109

21 days ago

0.0.108

22 days ago

0.0.107

25 days ago

0.0.106

27 days ago

0.0.105

27 days ago

0.0.104

27 days ago

0.0.103

27 days ago

0.0.102

27 days ago

0.0.101

27 days ago

0.0.100

27 days ago

0.0.98

28 days ago

0.0.99

28 days ago

0.0.95

29 days ago

0.0.96

29 days ago

0.0.97

29 days ago

0.0.94

29 days ago

0.0.90

29 days ago

0.0.91

29 days ago

0.0.92

29 days ago

0.0.93

29 days ago

0.0.87

1 month ago

0.0.88

1 month ago

0.0.89

30 days ago

0.0.84

1 month ago

0.0.85

1 month ago

0.0.86

1 month ago

0.0.83

1 month ago

0.0.81

1 month ago

0.0.82

1 month ago

0.0.80

1 month ago

0.0.73

1 month ago

0.0.74

1 month ago

0.0.75

1 month ago

0.0.76

1 month ago

0.0.77

1 month ago

0.0.78

1 month ago

0.0.79

1 month ago

0.0.71

1 month ago

0.0.72

1 month ago

0.0.70

1 month ago

0.0.64

1 month ago

0.0.65

1 month ago

0.0.66

1 month ago

0.0.67

1 month ago

0.0.68

1 month ago

0.0.69

1 month ago

0.0.62

1 month ago

0.0.63

1 month ago

0.0.60

1 month ago

0.0.61

1 month ago

0.0.59

1 month ago

0.0.55

1 month ago

0.0.56

1 month ago

0.0.57

1 month ago

0.0.58

1 month ago

0.0.46

1 month ago

0.0.47

1 month ago

0.0.51

1 month ago

0.0.52

1 month ago

0.0.53

1 month ago

0.0.54

1 month ago

0.0.50

1 month ago

0.0.48

1 month ago

0.0.49

1 month ago

0.0.41

1 month ago

0.0.42

1 month ago

0.0.43

1 month ago

0.0.44

1 month ago

0.0.45

1 month ago

0.0.40

1 month ago

0.0.39

1 month ago

0.0.38

1 month ago

0.0.37

2 months ago

0.0.36

2 months ago

0.0.34

2 months ago

0.0.35

2 months ago

0.0.31

2 months ago

0.0.32

2 months ago

0.0.33

2 months ago

0.0.30

2 months ago

0.0.28

2 months ago

0.0.29

2 months ago

0.0.20

2 months ago

0.0.21

2 months ago

0.0.22

2 months ago

0.0.23

2 months ago

0.0.24

2 months ago

0.0.25

2 months ago

0.0.18

2 months ago

0.0.19

2 months ago

0.0.26

2 months ago

0.0.27

2 months ago

0.0.16

2 months ago

0.0.17

2 months ago

0.0.14

2 months ago

0.0.15

2 months ago

0.0.12

2 months ago

0.0.13

2 months ago

0.0.11

2 months ago

0.0.10

3 months ago

0.0.9

3 months ago

0.0.8

3 months ago

0.0.7

3 months ago

0.0.6

3 months ago

0.0.5

3 months ago

0.0.4

3 months ago

0.0.3

3 months ago