The Skynet ecosystem has gone though a lot of drama much like many other web3 ecosystems have. At this time what I will refer to as Skynet v1 is dead long term. The tech can be used as a reference for future innovation, but it will no longer work in its current state by the end of 2023.
Based on this, the engineering paths being taken for this library and the related filesystem and nextcloud will be revisted in the future based on the new directions the Sia community takes. Do what you wish with this code, it is MIT after all, but I would not waste further time on using it for anything real.
I encourage you to drop into discord at https://lumeweb.com if you want to see where web3 is heading!
Kudos!
This SDK is a community-created, unofficial SDK in PHP for the Skynet Decentralized Internet Network. It is taken as primarily a port from https://github.com/SkynetLabs/skynet-js.
Better documentation will come in the future. However, despite being a mirror, there are some details to know to use the library. The API will also likely improve and change in the future. This initial version is a reflection of the JS library.
- Skynet
- This is the bottom layer of the system where most operations happen at
- Registry
- This is the basic key -> value store system. This is the database system that is used with your keypair to manage records
- Db
- This is the system that is used to set basic registry entries linked to your keypair, which are not encrypted
- MySky
- This is where all file management actions revolving around your account (seed) happen, including encrypted files. This also enables creating file paths that are stored as hashes in the Db and can also be encrypted via libsodium.
Most functions from skynet-js have been ported over. The ones of most interest will be in src/functions/mysky.php
. Not all functions are grouped together the same way.
- generateSeedPhrase
- validatePhrase
Please note there are two versions of genKeyPairFromSeed
in different namespaces since the mysky
library uses a different version only for signing registry entries and getting your PUBLIC ID
. \Skynet\functions\mysky\genKeyPairFromSeed
uses an extra derivation hashing step for security.
It was decided given the evolution of PHP; these functions don't need to emulate PHP classes. So they are standalone functions that are inner dependant unless there is a reason to refactor.
You will most often want to make use of the MySky
class. Example:
DO NOT USE THIS SEED. It is valid for demonstration purposes, but as it is published here, it can never be trusted since ANYONE can make use or abuse it. Portal can be configured but will default to siasky.net
This example will upload a file and, by being logged in, will be pinned to your account:
$drive = new \Skynet\MySky('roster donuts tycoon dunes muffin vector nasty jingle goblet amidst often wife digit earth eight');
$drive->setPortalLogin('john.doe@gmail.com', 'password');
$drive->setPortal('https://yourprivateportal.com');
$skyfile = $drive->getSkynet()->uploadFile(\Skynet\Types\File::fromResource('/mnt/data/file_to_upload.txt'));
echo $skyfile->getSkylink();
You can send raw data as well as long as it doesn't match a file:
$skyfile = $drive->getSkynet()->uploadFile(\Skynet\Types\File::fromResource('Hello World'));
This will pin a skylink to your account. A skylink must be pinned by atleast one portal to stay online. The skylink is a content ID including metadata:
$skynet = new \Skynet\Skynet();
$drive->setPortalLogin('john.doe@gmail.com', 'password');
$skyfile = $drive->pinSkylink('XABvi7JtJbQSMAcDwnUnmp2FKDPjg8_tTTFP4BwMSxVdEg')
echo $skyfile->getSkylink();
$drive = new \Skynet\MySky('roster donuts tycoon dunes muffin vector nasty jingle goblet amidst often wife digit earth eight');
$drive->setPortalLogin('john.doe@gmail.com', 'password');
$drive->getDb()->setDataLink($drive->getKey()->getPrivatekey(), 'hello_world', 'XABvi7JtJbQSMAcDwnUnmp2FKDPjg8_tTTFP4BwMSxVdEg');
$entry = $drive->getDb()->getRegistry()->getEntry( $drive->getKey()->getPublicKey(), 'hello_world');
JSON data can be either a stdClass object or an array. the returned datalink is the skylink. It can be referenced again from the file path.
$drive = new \Skynet\MySky('roster donuts tycoon dunes muffin vector nasty jingle goblet amidst often wife digit earth eight');
$drive->setPortalLogin('john.doe@gmail.com', 'password');
$skylink = $drive->setJSON('/data/my_json_file.json', ['message' => 'hello world'] );
echo $skylink->getDataLink();
Any contributions are welcome. I will rapidly be iterating on this software since running as a server-side language can be very different from the browser. Semver will be followed as practical. Consider this software tested because it has nearly all unit tests from the JS version, but still experimental as it has not gotten any real-world use yet, but that will change.