Lightstreams
WebsiteGithub
  • Lightstreams Docs
  • Why Lightstreams
    • Data Sovereignty
  • Overview
    • Privacy and Confidentiality
  • PRODUCTS
    • Smart Vault
      • Disclosures and Disclaimer
      • Demo
      • Getting Started
        • Install
        • Run a Smart Vault Node
        • Share a Private File
      • Smart Vault SDK
        • Smart Vault API
        • Smart Vault JS SDK
        • Smart Vault CLI
  • More
    • Github
Powered by GitBook
On this page
  • Source
  • Requirements
  • How to use
  • Modules
  • 1. Wallets (ethers-js)
  • 2. Web3 provider
  • 3. ENS
  • 4. Smart vault

Was this helpful?

  1. PRODUCTS
  2. Smart Vault
  3. Smart Vault SDK

Smart Vault JS SDK

Javascript Software Development Kit

PreviousSmart Vault SDKNextSmart Vault CLI

Last updated 5 years ago

Was this helpful?

The Lightstreams Javascript SDK provides is a library the provides modules for account management and interacting with a Lightstreams node.

Source

The Github repository.

Requirements

  • Node >= 10

  • Lightstreams node.

How to use

Install node module

Install lightstreams-js-sdk as part of your project dependencies:

npm install git+https://git@github.com:lightstreams-network/lightstreams-js-sdk#master --save

Modules

1. Wallets (ethers-js)

Learn more about

How to create a random new wallet

import { EthersWallet as EW } from 'lightstreams-js-sdk';

const encryptedJson = await EW.Keystore.createRandomWallet(seedPhrase, password);

How to create a wallet from seed phrase

import { EthersWallet as EW } from 'lightstreams-js-sdk';

const encryptedJson = await EW.Keystore.createWallet(seedPhrase, password);

How to generate a random seed phrase

import { EthersWallet as EW } from 'lightstreams-js-sdk';

const randomSeedPhrase = EW.Keystore.generateRandomSeedPhrase();

1.1 Account

How to create a new account

import { EthersWallet as EW } from 'lightstreams-js-sdk';
const encryptedJson = await EW.Keystore.createRandomWallet(seedPhrase, password);
const account = EW.Account.createAccount(encryptedJson)

Public account object API

  • lock():void: Lock wallet account

  • unlock(password):void: Unlock wallet account

  • isLocked():boolean: Return false is the account is unlock

  • sign(txParams):string: Return a signed transaction. Wallet must be unlocked

  • export():object: Returns encrypted privatekey in json format

  • seedPhrase():array: Return account seed phrase. Wallet must be unlocked

2. Web3 provider

In this repository you can find a customize web3 provider which uses a local keystorage to sign transactions. In addition other ethereum public API methods such as eth_lockAccount, eth_unlockAccount and eth_newAccount are being overwritten to use the key local storage.

How to initialize a LS web3 provider

import { Web3 } from 'lightstreams-js-sdk';

Web3.newEngine(window.process.env.WEB3_PROVIDER).then(web3 => {
  window.web3 = this.state.web3;
});

Using this web3 provider you could create a new account and unlock it as you would regularly do web3 engine api methods, such as:

web3.eth.personal.newAccount("password");
web3.eth.personal.unlockAccount("0x0Address", "password", 1000);

How to import a wallet

import { EthersWallet as EW } from 'lightstreams-js-sdk';

const encryptedJson = await EW.Keystore.createRandomWallet(password);
web3.currentProvider.importAccount(encryptedJson);

3. ENS

How to register new tld

import { ENS } from 'lightstreams-js-sdk';

const account = "0x0Address"; // Owner account
const tld = "lsn"
const { ensAddress, resolverAddress } = await ENS.SDK.deployNewRegistry(web3, { from: account });
await ENS.SDK.registerNode(web3, { ensAddress, from: account, node: tld});
const domain = 'fanbase.lsn';
const ens = ENS.SDK.initializeManager(web3.currentProvider, ensAddress);
console.log(`Registering ${domain}...`);
await ens.setSubnodeOwner(domain, account, { from: account });
console.log(`Setting resolver ...`);
await ens.setResolver(domain, resolverAddress, { from: account });
console.log(`Setting address ...`);
await ens.resolver(domain).setAddr(account, { from: account });
let address = await ens.resolver(domain).addr();
console.log(`${domain} is pointing to ${address}`);

4. Smart vault

4.1 Gateway proxy

Sample usage

const { Gateway as useGateway }  = require('lightstreams-js-sdk')
const gateway = useGateway('https://gateway.sirius.lightstreams.io')

Once LightstreamsSDK is initialized you interact with it as follow:

// Get user balance
const account = "0xa981f8ca77d069d79b609ca0069b052db79e7e30"
const { balance } = await gateway.wallet.balance(account)

Available Methods

  • /acl/revoke -> gateway.acl.revoke(acl, owner, password, to)

Learn more about it in .

How to use ENS official sdk Read docs

Gateway SDK interface is made to match, one to one, every available .

-> gateway.user.signUp(password)

-> gateway.user.signIn(account, password)

-> gateway.wallet.balance(account)

-> gateway.wallet.transfer(from, password, to, amountWei)

-> gateway.storage.add(owner, password, file)

-> gateway.storage.fetch(meta, token, stream)

-> gateway.acl.grant(acl, owner, password, to, permission)

-> gateway.acl.grantPublic(acl, owner, password)

-> gateway.acl.revokePublic(acl, owner, password)

-> gateway.shop.create(from, password)

-> gateway.shop.sell(shop, from, password, acl, priceWei)

-> gateway.shop.buy(shop, from, password, acl)

-> gateway.erc20.balance(erc20_address, account)

-> gateway.erc20.transfer(erc20_address, from, password, to, amount)

-> gateway.erc20.purchase(erc20_address, account, password, amount_wei)

Lightstreams Javascript SDK
How to install
ethers-js
official docs
here
smart vault endpoints
/user/signup
/user/signin
/wallet/balance
/wallet/transfer
/storage/add
/storage/fetch
/acl/grant
/acl/grant-public
/acl/revoke-public
/shop/create
/shop/shell
/shop/buy
/erc20/balance
/erc20/transfer
/erc20/purchase