Skip to content

Commit 6d4de37

Browse files
authored
Create README.md
1 parent b085659 commit 6d4de37

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

README.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<img src="https://www.activeledger.io/wp-content/uploads/2018/09/Asset-23.png" alt="Activeledger" width="500"/>
2+
3+
# Activeledger - Golang SDK
4+
5+
The Activeledger Golang SDK has been built to provide an easy way to connect your Go application to an Activeledger Network
6+
7+
### Activeledger
8+
9+
[Visit Activeledger.io](https://activeledger.io/)
10+
11+
[Read Activeledgers documentation](https://github.com/activeledger/activeledger)
12+
13+
14+
## Usage
15+
16+
The SDK currently supports the following functionality
17+
18+
- Connection handling
19+
- Key generation
20+
- Key onboarding
21+
- Transaction building
22+
23+
### Connection
24+
25+
When sending a transaction, you must pass a connection that provides the information needed to establish a link to the network and specified node.
26+
27+
To do this a connection object must be created. This object must be passed the protocol, address, and port.
28+
29+
```go
30+
sdk.SetUrl(sdk.Connection{Scheme:"protocol",Url:"url",Port:"port"})
31+
```
32+
#### Example
33+
```go
34+
sdk.SetUrl(sdk.Connection{Scheme:"http",Url:"testnet-uk.activeledger.io",Port:"5260"})
35+
```
36+
37+
---
38+
39+
### Key
40+
41+
There are two key types that can be generated currently, more are planned and will be implemented into Activeledger first. These types are RSA and Elliptic Curve.
42+
43+
#### Generating a key
44+
45+
46+
##### Example
47+
48+
```go
49+
//RSA
50+
privatekey:=sdk.RsaKeyGen()
51+
publicKey:=privatekey.PublicKey
52+
//ECDSA
53+
privateKey,_ := sdk.EcdsaKeyGen() // public key can be extract using private key e.g. privateKey.PublicKey
54+
55+
56+
```
57+
58+
#### Exporting Key
59+
60+
61+
##### Example
62+
63+
```go
64+
publicKeyString:=sdk.RsaToPem(publicKey)
65+
privatekeyStr,publicKeyString:=sdk.EcdsaToPem(privateKey)
66+
```
67+
68+
69+
#### Onboarding a key
70+
71+
Once you have a key generated, to use it to sign transactions it must be onboarded to the ledger network
72+
73+
##### Example
74+
```go
75+
resp := onboardRSA(key, sdk.RSA/sdk.EC, <keyName>) //resp is on object with code and description. Description in this case is a StreamID or error(Can be distinguished using the code)
76+
```
77+
78+
79+
#### Creating a transaction
80+
```go
81+
tx := new(sdk.TxObject) //create a new TxObject
82+
tx.Namespace = <namespace>
83+
tx.Contract = <contract>
84+
tx.entry = <entry> //optional
85+
tx.Input=<input> // map[string]interface{}
86+
tx.Output=<output> // map[string]interface{}. optional
87+
tx.ReadOnly=<readOnly> // map[string]interface{}. Optional
88+
89+
90+
91+
var trxReq = new(sdk.TransactionReq)// a transaction request object
92+
trxReq.TxObject = *tx
93+
trxReq.SelfSign = true/false
94+
trxReq.StreamID = <StreamId>
95+
trxReq.KeyName = <keyName>
96+
trxReq.RsaKey = <key>
97+
trxReq.KeyType = sdk.Encrptype[sdk.RSA/sdk.EC]
98+
99+
100+
txObject:=sdk.TxObject{Namespace:"default",Contract:"onboard",Input:input,Output:output,ReadOnly:readOnly}
101+
102+
sdk.SetUrl(sdk.Connection{Scheme:"protocol",Url:"url",Port:"port"}) //Set connection url
103+
txResp := sdk.CreateTransaction(*trxReq) //Returns a transaction object
104+
sdk.SendTransaction(*txResp,sdk.GetUrl()) // Returns Response object with Code and Description. Description is either a stream ID or error(Can be distinguished using code)
105+
106+
or
107+
108+
sdk.CreateAndSendTransaction(*txResp)// Creates and Sends the transaction. Returns Response object with Code and Description. Description is either a stream ID or error(Can be distinguished using code)
109+
110+
111+
```
112+
113+
---
114+
115+
## License
116+
117+
---
118+
119+
This project is licensed under the [MIT](https://github.com/activeledger/SDK-Golang/blob/master/LICENSE) License
120+
121+

0 commit comments

Comments
 (0)