@saftswap/sdk
TypeScript icon, indicating that this package has built-in type declarations

0.5.1 • Public • Published

Saft Swap SDK

Following buckets are available:

  • ipfs (contains methods for adding data to ipfs or retrieving)
  • metamask (contains method for getting enc key and decryption using metamask)
  • saft (saft info object, add to ipfs and query)
  • shamir (setup and decrypt)
  • utils (useful utils)

IPFS

import { ipfs, utils } from '@saftswap/sdk';
import { ethers } from 'ethers';

const cid = await ipfs.addFile('Hello');

// gives bytes32 value that should be stored in sc
const bytes32 = utils.cidToDigest(cid);
const cid = utils.digestToCID(bytes32); // back to CID format

const rawData = await ipfs.getFile(cid); // gives Uint8Array
ethers.utils.toUtf8String(rawData); // parse data as UTF8

Metamask

import { metamask, utils } from '@saftswap/sdk';

// triggers metamask popup
await window.ethereum.enable();
const encKey = await metamask.getEncryptionPublicKey(window.ethereum); // passing a EIP-1193 provider works

// or
const provider = new ethers.providers.Web3Provider(window.ethereum);
const encKey = await metamask.getEncryptionPublicKey(provider); // passing a ethers provider works

const cipherText = utils.encryptData(encKey, 'Hello');

// triggers metamask popup
const data = await metamask.decryptCipherText(window.ethereum);

Shamir

import { shamir } from '@saftswap/sdk';

const { encryptedShares, fileEncryptionKey } = await shamir.setup(
  publicKeysFromMetamask
);
const cipherText = utils.encryptData(fileEncryptionKey, file);

// later
const decryptedFile = await shamir.decrypCipherText(shares.slice(0, 2), cipher);

Saft

import { saft, SaftInfo } from '@saftswap/sdk';

const info: SaftInfo = {
  name: 'hello',
  description: 'world',
  image: 'https://i.imgur.com/8oLKVUV.jpeg',
  properties: {
    prospectus: 'https://i.imgur.com/8oLKVUV.jpeg',
    purchasePrice: parseUnits('1000', 6),
    vestingType: 'hello',
    deliverySchedule: 'hello',
    nextDataOfDelivery: 'hello',
  },
};

const cid = await saft.addInfoToIPFS(info);
const resp = await saft.getInfoFromIPFS(cid);

Contracts

const { saftManager, accountManager } = await getContracts(arbtest);

Readme

Keywords

none

Package Sidebar

Install

npm i @saftswap/sdk

Weekly Downloads

52

Version

0.5.1

License

MIT

Unpacked Size

5.57 MB

Total Files

512

Last publish

Collaborators

  • 0xdosa
  • 134dd3v