0.5.1 • Published 2 years ago
@saftswap/sdk v0.5.1
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);
0.5.1
2 years ago
0.4.1
2 years ago
0.5.0
2 years ago
0.4.0
2 years ago
0.3.2
2 years ago
0.3.1
2 years ago
0.3.0
2 years ago
0.2.20
2 years ago
0.2.19
2 years ago
0.2.18
2 years ago
0.2.17
2 years ago
0.2.16
2 years ago
0.2.15
2 years ago
0.2.14
2 years ago
0.2.13
2 years ago
0.2.12
2 years ago
0.2.11
2 years ago
0.2.10
2 years ago
0.2.9
2 years ago
0.2.8
2 years ago
0.2.7
2 years ago
0.2.6
2 years ago
0.2.5
2 years ago
0.2.4
2 years ago
0.2.3
2 years ago
0.2.2
2 years ago
0.2.1
2 years ago
0.2.0
2 years ago
0.1.0
2 years ago