Giter Site home page Giter Site logo

perun-network / perun-icp-backend Goto Github PK

View Code? Open in Web Editor NEW
4.0 5.0 0.0 3.05 MB

Peer-to-peer payment channels on the Dfinity Internet Computer

Home Page: https://perun.network/

License: Apache License 2.0

Go 97.47% Shell 2.53%
dfinity icp internet-computer layer2 payment-channel perun

perun-icp-backend's Introduction

Perun

Perun ICP backend

This repository contains the Dfinity Internet Computer backend for the go-perun channel library. It provides the necessary components to run our secure peer-to-peer Perun Payment Channels on the Dfinity blockchain. The payment channel implementation connects our Perun state machine with the Perun canister, which implements the Perun Payment Channel logic on the Internet Computer. This project is financed through the DFINITY grants program.

In the following sections, we will describe how to run Payment Channels on a local instance of the Dfinity Internet Computer.

Project architecture

  • channel/: Main payment channel component implementation, including the Funder and Adjudicator interfaces
  • ./connector/: Interface for calling and querying Perun canister functions
    • ./icperun/: Perun canister functions
  • ./wallet/ & ./wire/: Wallet interface enabling the usage of ed25519 keypairs in payment channels
  • ./client: Building blocks for generation of Perun clients
  • ./userdata: User-specific data for setting up and running the backend
  • ./main.go: Main file for running the payment channel demo
  1. Install dfx, the DFINITY command-line execution environment:
sh -ci "$(curl -fsSL https://smartcontracts.org/install.sh)"
  1. Clone this repository
git clone https://github.com/perun-network/perun-icp-backend
cd perun-icp-backend
  1. Generate dfx accounts

To generate new seed phrases from scratch, we use keysmith:

keysmith generate
keysmith private-key

This generates an identity.pem file containing the private key to govern an identity on the Internet Computer. We import it into dfx using the dfx identity import function of dfx:

dfx identity import IDENTITYNAME identity.pem

This will store the pem file in ~/.config/dfx/identity/IDENTITYNAME/identity.pem.

NOTE: For quick testing purposes, we have already included .pem files for the minter, usera and userb identities in the ./userdata/identities directory. For running the demo and tests, you can import them into dfx using the following commands:

dfx identity import minter identity.pem
dfx identity import usera identity.pem
dfx identity import userb identity.pem

Verify that the identities have been imported, using dfx identity list and also checking ~/.config/dfx/identity/IDENTITYNAME/identity.pem.

After installation, to use the backend, you first need to instantiate a local Internet Computer and deploy the ledger Perun canister. The script deploycans.sh does this for you:

cd perun-icp-backend
./deploycans.sh

This will start a local Internet Computer blockchain and deploy both canisters necessary for Perun: the Ledger canister for processing transactions, and the Perun canister governing the Payment Channel logic. It will also mint ICP into the accounts you have imported into dfx.

Note that by default, the deploycans.sh script uses the provided minter, usera and userb identities:

createLedgerArg() {
    local ICP_PERUN_MINT_ACC="433bd8e9dd65bdfb34259667578e749136f3e0ea1566e10af1e0dd324cbd9144"
    local ICP_PERUN_USERA_ACC="97520b79b03e38d3f6b38ce5026a813ccc9d1a3e830edb6df5970e6ca6ad84be"
    local ICP_PERUN_USERB_ACC="40fd2dc85bc7d264b31f1fa24081d7733d303b49b7df84e3d372338f460aa678"

    echo "(record {minting_account = \"$ICP_PERUN_MINT_ACC\"; initial_values = vec { record { \"$ICP_PERUN_USERA_ACC\"; record { e8s=10_000_000} }; record { \"$ICP_PERUN_USERB_ACC\"; record { e8s=10_000_000 } }}; send_whitelist = vec {}})"
}

This uses the minter account to mint 10_000_000 ICP into the accounts usera and userb. The ICP_PERUN_MINT_ACC ICP_PERUN_USERA_ACC and ICP_PERUN_USERB_ACC are the account identifiers of the minter, usera and userb identities respectively. You can verify these account identifies by running dfx ledger account-id for each of the identities. If you want to use other identities, you can simply change the ICP_PERUN_MINT_ACC, ICP_PERUN_USERA_ACC and ICP_PERUN_USERB_ACC variables in the deploycans.sh script so that the ICP is minted into the accounts you want to use.

After successful initialization of the local blockchain, you can now run the demo and the tests. To stop the local blockchain, run the stopdfx.sh script,

./stopdfx.sh

To test the main components of the Perun Internet Computer backend, perform the installation, and initialize the local blockchain. Afterwards, run the tests with the following command:

cd perun-icp-backend
go test -v ./...

A Payment Channel demo for a local Internet Computer blockchain is located here. It uses this repository and the deploys the canister from the Perun IC canister repository.

Copyright

Copyright 2023 PolyCrypt GmbH. Use of the source code is governed by the Apache 2.0 license that can be found in the LICENSE file.

perun-icp-backend's People

Contributors

iljabvh avatar rmbrt avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.