0.0.0-8f2ae6 • Published 5 years ago

@dsnp/sdk v0.0.0-8f2ae6

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
5 years ago

DSNP TypeScript SDK

Easy to use SDK for the DSNP

Quick Start

Install the package

First, install the SDK package with the following command:

npm install @dsnp/sdk

Configure the SDK

The configuration can be set at runtime with the following:

// Node
const { setConfig } = require("@dsnp/sdk");
const { Wallet, providers } = require("ethers");

setConfig({
  signer: new Wallet("key"),
  provider: new providers.JsonRpcProvider("https://...")
});
// Do something with the SDK
// TypeScript
import { Wallet, providers } from "ethers";
import { setConfig } from "@dsnp/sdk";

setConfig({
  signer: new Wallet("key"),
  provider: new providers.JsonRpcProvider("https://...")
});
// Do something with the SDK

Storing Activity Content and Batch Files

Storage solutions can be added so as long it matches the StoreInterface.

interface StoreInterface {
  putStream: (targetPath: string, doWriteToStream: WriteStreamCallback) => Promise<URL>;
}

Configuration is set like so:

config
  .setConfig({
    store: MyStoreModule, // for modules
    store: new MyStore(), // for classes
   });

See Config Documentation for details on additional options.

Example Stores

An example implementations of storage can be found under the examples folder

Usage

Once the SDK is installed and configured, the following code can be used to post a batch on the chain:

// Node
const publisher = require("@dsnp/sdk/core/contracts/publisher");

publisher.publish([{ fileHash, fileUrl, announcementType }]);
// TypeScript
import publisher from "@dsnp/sdk/core/contracts/publisher";

publisher.publish([{ fileHash, fileUrl, announcementType }]);

Documentation

See Documentation or generate documentation locally via npm run doc.

How to Install

Run npm install @dsnp/sdk

How to Build

Run npm run build

How to Compile Documentation

Documentation is deployed on merge to main to GitHub Pages: https://libertydsnp.github.io/sdk-ts/

  • Run npm run doc for HTML documentation
  • Run npm run doc:json for JSON documentation
  • Run npm run doc:markdown for markdown documentation (published with the npm package)

Environment Variables

NameDescription
RPC_URLurl of node to make calls to
TESTING_PRIVATE_KEYOnly used in testing - private key of account you are sending transactions from

Testing

How to Test

  1. Check out the contracts repo and follow the instructions to start a hardhat test node and deploy the contracts.
    • Match sure you match the version in ./package.json!
  2. In the SDK create a .env file with the following content.
    RPC_URL=http://localhost:8545
    TESTING_PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
  3. Replace the value of TESTING_PRIVATE_KEY with the value of LOCAL_NETWORK_ACCOUNT_PRIVATE_KEY in the .env from the contracts repo, or use what is in .github/workflows/main.yml. It may be same as above.
  4. Ensure that the contracts version you would like to use is the correct version. The version of the @dsnp/contracts package is specified in the package.json
  5. In the contracts repo run: npm run hardhat -- node
  6. In the contracts repo run: npm run deploy:localhost
  7. In the sdk repo run: npm run test

Test Writing Utilities

  • test/hardhatRPC
    • setupSnapshot: Call this to use evm snapshots before each test to make sure the blockchain state is clean
    • snapshotHardhat/revertHardhat: Make other snapshots, but remember to revert them for other tests
  • test/sdkTestConfig
    • setupConfig: An easy way to setup the default config for the sdk for testing.
      • Often can be as simple as beforeAll(setupConfig);
      • Returns an object with the provider and signer if those are needed.
  • test/matchers
    • Helpful common Jest Matchers like expect("0x0").toMatch(EthAddressRegex)
  • test/customMatchers
    • Custom Loaded Jest expect matchers like expect(tx).transactionRejectsWith("message")
  • test/generators
    • Test Data Generators and fixtures

Testnet

We are currently running 2 POA nodes for our Testnet Tesnet Authority nodes are:

  • node0.testnet.dsnp.org
  • node1.testnet.dsnp.org

Contracts are located at the following addresses:

Migrations contract: 0xe7a6467113c2B7f09Aad3b99C30811718A114013 Publisher contract: 0xdBA8e92706e48bbFDe1A8496710d4e85d3388E71 Identity contract: 0xB708186004dAC4019417fa8deF9E8F49a55103b1 Registry contract: 0xDcc457296d9790C52B6746cD45AFaaD18b7FfEfa IdentityCloneFactory factory: 0x31C3fDb70078FD1d64D51ecA713bCdb2f4212E74 Beacon contract: 0x233FfDa2cEd4579B07bbc5e95bDe7f540A2DFd5a Beacon Factory: 0x26b21a1E90b86c779D9a1d31cD09F5cd8C7c8f1d

Contract source code is located here

0.0.0-77f102

4 years ago

0.0.0-9c522e

4 years ago

0.0.0-48d905

4 years ago

0.0.0-7303ed

4 years ago

0.0.0-2d8bb6

4 years ago

0.0.0-e51513

4 years ago

0.0.0-e20826

5 years ago

0.0.0-a965f4

5 years ago

0.0.0-3e0897

5 years ago

0.0.0-8aab7b

5 years ago

0.0.0-7fc294

5 years ago

0.0.0-833aa7

5 years ago

0.0.0-1e3994

5 years ago

3.0.3

5 years ago

0.0.0-7c48e2

5 years ago

0.0.0-1a634c

5 years ago

0.0.0-c4ef10

5 years ago

0.0.0-a6f997

5 years ago

0.0.0-3c2a7a

5 years ago

3.0.2

5 years ago

0.0.0-c27385

5 years ago

0.0.0-a38373

5 years ago

0.0.0-04a188

5 years ago

3.0.1

5 years ago

0.0.0-54f461

5 years ago

0.0.0-ae9c6f

5 years ago

0.0.0-0601cc

5 years ago

3.0.0

5 years ago

0.0.0-c1d95b

5 years ago

0.0.0-5f60c9

5 years ago

0.0.0-01269d

5 years ago

0.0.0-563c71

5 years ago

0.0.0-2709c9

5 years ago

0.0.0-841bd2

5 years ago

0.0.0-4aaafe

5 years ago

0.0.0-8d0236

5 years ago

0.0.0-33f2b8

5 years ago

0.0.0-e5777d

5 years ago

0.0.0-898a31

5 years ago

0.0.0-056cf1

5 years ago

0.0.0-86fe00

5 years ago

0.0.0-86da5a

5 years ago

2.1.2

5 years ago

0.0.0-44a710

5 years ago

0.0.0-b84a15

5 years ago

0.0.0-f3c5c5

5 years ago

0.0.0-15b656

5 years ago

2.1.1

5 years ago

0.0.0-d21e15

5 years ago

0.0.0-80e746

5 years ago

0.0.0-b62952

5 years ago

0.0.0-440437

5 years ago

0.0.0-abd844

5 years ago

2.1.0

5 years ago

0.0.0-6f2dab

5 years ago

0.0.0-e0c7ac

5 years ago

0.0.0-179bde

5 years ago

0.0.0-d06294

5 years ago

0.0.0-1c4cdc

5 years ago

2.0.2

5 years ago

0.0.0-6082ae

5 years ago

0.0.0-47f4fd

5 years ago

0.0.0-c6a5a2

5 years ago

0.0.0-261910

5 years ago

0.0.0-15c3f7

5 years ago

0.0.0-8f2ae6

5 years ago

0.0.0-50a5fe

5 years ago

2.0.1

5 years ago

0.0.0-994458

5 years ago

0.0.0-1e6fd2

5 years ago

0.0.0-a514ec

5 years ago

0.0.0-f39e7f

5 years ago

0.0.0-da02ec

5 years ago

2.0.0

5 years ago

0.0.0-aa2c5b

5 years ago

0.0.0-062c22

5 years ago

0.0.0-ac2374

5 years ago

0.0.0-bb9793

5 years ago

0.0.0-d4e3a7

5 years ago

0.0.0-899c38

5 years ago

0.0.0-e6bade

5 years ago

0.0.0-aee97e

5 years ago

0.0.0-85a1d1

5 years ago

0.0.0-75624c

5 years ago

0.0.0-2c0cd6

5 years ago

0.0.0-f6950a

5 years ago

0.0.0-e29064

5 years ago

0.0.0-fd1aba

5 years ago

0.0.0-f2350e

5 years ago

0.0.0-4d9a01

5 years ago

0.0.0-672eb7

5 years ago

0.0.0-b224f5

5 years ago

0.0.0-998232

5 years ago

0.0.0-d9b78c

5 years ago

0.0.0-23cc64

5 years ago

0.0.0-86342e

5 years ago

0.0.0-3c807d

5 years ago

0.0.0-2ddbab

5 years ago

0.0.0-37dc26

5 years ago

0.0.0-9fbd4b

5 years ago

0.0.0-0fe5bf

5 years ago

0.0.0-562008

5 years ago

0.0.0-56835d

5 years ago

0.0.0-aba284

5 years ago

0.0.0-85874c

5 years ago

0.0.0-2aa1e6

5 years ago

0.0.0-02ba0d

5 years ago

0.0.0-deb0b1

5 years ago

0.0.0-293123

5 years ago

1.0.0

5 years ago

0.0.0-322b6f

5 years ago

0.0.0-e9f4d1

5 years ago

0.0.0-1f5df5

5 years ago

0.0.0-7d4f28

5 years ago

0.0.0-869490

5 years ago

0.0.0-86a3e8

5 years ago

0.0.0-825e8b

5 years ago

0.0.0-c988da

5 years ago

0.0.0-b0dedf

5 years ago

0.0.0-daf646

5 years ago

0.0.0-546ddf

5 years ago

0.0.0-819b90

5 years ago

0.0.0-10b12c

5 years ago

0.0.0-0c04e9

5 years ago

0.0.0-3d7ded

5 years ago

0.0.0-0a73c1

5 years ago

0.0.0-97604a

5 years ago

0.0.0-0fb5a0

5 years ago

0.0.0-fc96b8

5 years ago

0.0.0-720317

5 years ago

0.0.0-875b82

5 years ago

0.0.0-f8b540

5 years ago

0.0.0-33a000

5 years ago

0.0.0-f86662

5 years ago

0.0.0-8391c7

5 years ago

0.0.0-372c56

5 years ago

0.0.0-78def2

5 years ago

0.0.0-513646

5 years ago

0.0.0-960a18

5 years ago

0.0.0-06dac2

5 years ago

0.0.0-58c147

5 years ago

0.1.0

5 years ago

0.0.0-d4cd6c

5 years ago

0.0.0-6803e8

5 years ago

0.0.0-63cb8d

5 years ago

0.0.0-f0b90d

5 years ago

0.0.0-fd18c1

5 years ago

0.0.0-f1a398

5 years ago

0.0.0-9a053e

5 years ago

0.0.0-04ac41

5 years ago

0.0.0-efdb66

5 years ago

0.0.0-ff6ac7

5 years ago

0.0.0-cdb32d

5 years ago

0.0.0-7c33d7

5 years ago

0.0.0-e3daf4

5 years ago

0.0.0-d4a9d4

5 years ago

0.0.0-c43b4e

5 years ago

0.0.0-ee5111

5 years ago

0.0.0-447f11

5 years ago

0.0.0-f67fb3

5 years ago

0.0.0-f4427d

5 years ago

0.0.0-49665c

5 years ago

0.0.0-3aa71c

5 years ago