Skip to content

Repository files navigation

This library is not actively maintained

scatter-sharp

Scatter C# library to interact with ScatterDesktop / ScatterMobile

Clone repo

git clone https://github.com/GetScatter/scatter-sharp --recursive

Prerequisite to build

Visual Studio 2017+

Instalation

scatter-sharp is now available throught nuget https://www.nuget.org/packages/scatter-sharp

Install-Package scatter-sharp

Usage

Configuration

In order to use scatter you need to create a instance with AppName and a Network configuration, connect to scatter application, request a Identity and then fetch a new Eos instance.

Example:

varnetwork=newApi.Network(){blockchain=Scatter.Blockchains.EOSIO,host="api.eossweden.se",port=443,protocol="https",chainId="aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906"};varscatter=newScatter(newScatterConfigurator(){AppName="SCATTER-SHARP",Network=network,StorageProvider=storageProvider});awaitscatter.Connect();varidentity=awaitscatter.GetIdentity(newApi.IdentityRequiredFields(){accounts=newList<Api.Network>(){network},location=newList<Api.LocationFields>(),personal=newList<Api.PersonalFields>()});vareos=newEos(newEosSharp.Core.EosConfigurator(){ChainId=network.chainId,HttpEndpoint=network.GetHttpEndpoint(),SignProvider=newScatterSignatureProvider(scatter)});varaccount=scatter.Identity.accounts.First();varresult=awaiteos.CreateTransaction(newEosSharp.Core.Api.v1.Transaction(){actions=newList<EosSharp.Core.Api.v1.Action>(){newEosSharp.Core.Api.v1.Action(){account="eosio.token",authorization=newList<PermissionLevel>(){newPermissionLevel(){actor=account.name,permission=account.authority}},name="transfer",//Using a dictionary with key, object works on WEBGLdata=newDictionary<string,object>(){{"from",account.name},{"to","eosio"},{"quantity","0.0001 EOS"},{"memo","Unity3D hello crypto world!"}}}}});
...**Useall eos api methods as usual from eos-sharp** ...scatter.Dispose();

App Storage Provider

Scatter uses a appKey and Nonce to help pair your application with the users permissions. By default this information is stored on memory but you may want to save on disk to be reused later.

Create a new Scatter instance and configure a FileStorageProvider with the target filePath.

varfileStorage=newFileStorageProvider(filePath);using(varscatter=newScatter(newScatterConfigurator(){AppName="SCATTER-SHARP",Network=network,StorageProvider=fileStorage}){awaitscatter.Connect();
.... }

Generic / Fiddler proxy

Is useful to configure a proxy to investigate and debug all the information that goes through scatter-sharp <-> ScatterDesktop. Fiddler is a popular http/websocket proxy solution but you can configure any other.

Enabling proxy

Add a proxy object to scatter configurator that accepts Url and optionaly User and Password. Note that this is used in websocket-sharp and not the implementation for WebGL (not needed).

varscatter=newScatter(newScatterConfigurator(){AppName="SCATTER-SHARP",Network=network,StorageProvider=storageProvider,Proxy=newProxy(){Url="http://127.0.0.1:8888"}});
Fiddler unmask websocket traffic

On tab "FiddlerScript" add this code in the end of function "OnBeforeRequest"

static function OnBeforeRequest(oSession: Session) {
...
if (oSession.RequestHeaders.ExistsAndContains ("Sec-WebSocket-Extensions", "permessage-deflate")) {
oSession.RequestHeaders.Remove ( "Sec-WebSocket-Extensions");
}
}
Fiddler check websocket traffic

Double click "ws" icon to open websocket tab

alt text

In websocket tab you can view in real-time all the communication between scatter-sharp <-> ScatterDesktop

alt text

Enable proxy on Unity Editor

To enable the proxy in unity editor go to the file:

C:\Program Files\Unity\Editor\Data\Mono\etc\mono\2.0\machine.config

Add this to the <system.net> node:

<defaultProxy>
<proxy proxyaddress="http://localhost:8888"/>
</defaultProxy>

Scatter Api methods

  • Connect Connect to scatter
awaitscatter.Connect();
  • GetVersion Gets the Scatter version
stringversion=awaitscatter.GetVersion();
  • GetIdentity Prompts the users for an Identity if there is no permission, otherwise returns the permission without a prompt based on origin.
Identityidentity=awaitscatter.GetIdentity(newApi.IdentityRequiredFields(){accounts=newList<Api.Network>(){network},location=newList<Api.LocationFields>(),personal=newList<Api.PersonalFields>()});

Returns:

publicclassIdentity{publicstringhash;publicstringpublicKey;publicstringname;publicboolkyc;publicList<IdentityAccount>accounts;}
  • GetIdentityFromPermissions Checks if an Identity has permissions and return the identity based on origin.
Identityidentity=awaitscatter.GetIdentityFromPermissions();

Returns:

publicclassIdentity{publicstringhash;publicstringpublicKey;publicstringname;publicboolkyc;publicList<IdentityAccount>accounts;}
  • ForgetIdentity Removes the identity permission for an origin from the user's Scatter, effectively logging them out.
boolresult=awaitscatter.ForgetIdentity();
  • Authenticate Sign origin (appName) with the Identity's private key. Or custom data with custom publicKey
stringsignature=awaitscatter.Authenticate();
  • GetArbitrarySignature Request arbitrary data with the constraint of max 12 words
stringsignature=awaitscatter.GetArbitrarySignature(stringpublicKey,stringdata,stringwhatfor="",boolisHash=false);
  • GetPublicKey Allows apps to request that the user provide a user-selected Public Key to the app. ( ONBOARDING HELPER )
stringpubKey=awaitscatter.GetPublicKey(stringblockchain);
  • LinkAccount Allows the app to suggest that the user link new accounts on top of public keys ( ONBOARDING HELPER )
boolresult=awaitscatter.LinkAccount(stringpublicKey);
  • HasAccountFor Allows dapps to see if a user has an account for a specific blockchain. DOES NOT PROMPT and does not return an actual account, just a boolean.
boolresult=awaitscatter.HasAccountFor();
  • SuggestNetwork Prompts the user to add a new network to their Scatter.
boolresult=awaitscatter.SuggestNetwork();
  • AddToken Add token to wallet
boolresult=awaitscatter.AddToken(Tokentoken);
  • On Register listener for scatter event type
scatter.On(stringtype,Action<object>callback);
  • Off Remove listeners
scatter.Off(stringtype);scatter.Off(stringtype,intindex);scatter.Off(Action<object>callback);scatter.Off(stringtype,Action<object>callback);

About

Scatter C# library to interact with ScatterDesktop/ScatterMobile

Resources

Stars

27 stars

Watchers

6 watching

Forks

Releases

Packages

Used by

Contributors

Languages