Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved example into owner package. #20

Merged
merged 9 commits into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
name: Continuous Integration
on: [push]

# Trigger the workflow on push or pull request
on:
push:
branches:
- master
pull_request:
branches:
- '*'

jobs:
test:
name: Test
Expand Down
10 changes: 6 additions & 4 deletions README.MD
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# libgrin

![](https://github.com/blockcypher/libgrin/workflows/Continuous%20Integration/badge.svg)
![CI](https://github.com/blockcypher/libgrin/workflows/Continuous%20Integration/badge.svg)
[![ISC License](http://img.shields.io/badge/license-apache2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg)](https://godoc.org/github.com/blockcypher/libgrin)

libgrin is a golang Grin library for building [Grin](https://github.com/mimblewimble/grin) applications.
Currently, it contains the basic consensus parameters, chain, slate structures and proof of work verification code. The `example` package contains examples of wrappers around the Grin node API and the wallet owner API using libgrin.
Currently, it contains the basic consensus parameters, chain, slate structures and proof of work verification code.

The `client` package contains wrappers around the Grin node API and the wallet owner API using libgrin.

## Requirements

[Go](http://golang.org) 1.11 or newer.
[Go](http://golang.org) 1.14 or newer.

## Installation

Expand Down Expand Up @@ -38,7 +40,7 @@ Any contribution is more than welcome. Currently libgrin has:

- Minimal API types.
- Minimal Core package which includes PoW verification.
- Example package containing wrappers around Node API and wallet owner API.
- Client package containing wrappers around Node API and wallet owner API.
- Minimal keychain types
- Minimal libwallet

Expand Down
2 changes: 1 addition & 1 deletion example/http.go → client/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package example
package client

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion example/node_api.go → client/node_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package example
package client

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion example/node_api_test.go → client/node_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package example
package client

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion example/owner_api.go → client/owner_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package example
package client

import (
"encoding/json"
Expand Down
2 changes: 1 addition & 1 deletion example/rpchttp.go → client/rpchttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package example
package client

import (
"bytes"
Expand Down
12 changes: 6 additions & 6 deletions example/rpchttp_test.go → client/rpchttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,31 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package example_test
package client_test

import (
"encoding/json"
"fmt"
"testing"

"github.com/blockcypher/libgrin/example"
"github.com/blockcypher/libgrin/client"
"github.com/stretchr/testify/assert"
)

func TestEnvelope(t *testing.T) {
requestBody, err := json.Marshal(example.Envelope{
requestBody, err := json.Marshal(client.Envelope{
Method: "test",
Params: nil,
})
assert.Nil(t, err)

var envl example.Envelope
var envl client.Envelope
err = json.Unmarshal(requestBody, &envl)
fmt.Println(envl)
assert.Nil(t, err)
assert.Equal(t, example.JSONRPCID("1"), envl.ID)
assert.Equal(t, client.JSONRPCID("1"), envl.ID)
assert.Equal(t, "test", envl.Method)
assert.Equal(t, example.JSONRPCV2Version("2.0"), envl.Version)
assert.Equal(t, client.JSONRPCV2Version("2.0"), envl.Version)
assert.Nil(t, envl.Params)
}

Expand Down
44 changes: 43 additions & 1 deletion example/secure_owner_api.go → client/secure_owner_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package example
package client

import (
"crypto/ecdsa"
Expand Down Expand Up @@ -140,6 +140,48 @@ func (owner *SecureOwnerAPI) InitSecureAPI(pubKey []byte) (string, error) {
return serverPubKey, nil
}

// Accounts Returns a list of accounts stored in the wallet
// (i.e. mappings between user-specified labels and BIP32 derivation paths
func (owner *SecureOwnerAPI) Accounts() (*[]libwallet.AccountPathMapping, error) {
params := struct {
Token string `json:"token"`
}{
Token: owner.token,
}
paramsBytes, err := json.Marshal(params)
if err != nil {
return nil, err
}

envl, err := owner.client.EncryptedRequest("accounts", paramsBytes, owner.sharedSecret)
if err != nil {
return nil, err
}

if envl == nil {
return nil, errors.New("OwnerAPI: Empty RPC Response from grin-wallet")
}
if envl.Error != nil {
log.WithFields(log.Fields{
"code": envl.Error.Code,
"message": envl.Error.Message,
}).Error("OwnerAPI: RPC Error during Accounts")
return nil, errors.New(string(envl.Error.Code) + "" + envl.Error.Message)
}
var result Result
if err = json.Unmarshal(envl.Result, &result); err != nil {
return nil, err
}
if result.Err != nil {
return nil, errors.New(string(result.Err))
}
var accounts []libwallet.AccountPathMapping
if err = json.Unmarshal(result.Ok, &accounts); err != nil {
return nil, err
}
return &accounts, nil
}

// OpenWallet `opens` a wallet, populating the internal keychain with the encrypted seed, and optionally
// returning a `keychain_mask` token to the caller to provide in all future calls.
// If using a mask, the seed will be stored in-memory XORed against the `keychain_mask`, and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package example_test
package client_test

import (
"testing"
)

//"github.com/blockcypher/libgrin/example"
//"github.com/blockcypher/libgrin/client"
//"github.com/blockcypher/libgrin/libwallet"
//"github.com/stretchr/testify/assert"

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 6 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
module github.com/blockcypher/libgrin

go 1.13
go 1.14

require (
github.com/btcsuite/btcd v0.20.1-beta
github.com/davecgh/go-spew v1.1.1
github.com/google/uuid v1.1.1
github.com/gorilla/mux v1.7.3
github.com/joho/godotenv v1.3.0
github.com/kelseyhightower/envconfig v1.4.0
github.com/mitchellh/mapstructure v1.1.2
github.com/sethgrid/pester v0.0.0-20190127155807-68a33a018ad0
github.com/sirupsen/logrus v1.4.2
github.com/stretchr/testify v1.4.0
github.com/stretchr/testify v1.6.1
github.com/tj/assert v0.0.3
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
gopkg.in/yaml.v2 v2.2.2 // indirect
)
13 changes: 13 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
github.com/blockcypher/libgrin v2.0.0+incompatible h1:ESNyziuY5NjwXmYW4H8pfvZCfQvm8EtEUCIWQBN6/8s=
github.com/blockcypher/libgrin v2.0.0+incompatible/go.mod h1:v+0kVsZz7bCDN4FZmDlKjVtU6SWvX/7EUJDadaavYz4=
github.com/btcsuite/btcd v0.20.1-beta h1:Ik4hyJqN8Jfyv3S4AGBOmyouMsYE3EdYODkMbQjwPGw=
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
Expand All @@ -20,7 +22,11 @@ github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
Expand All @@ -40,6 +46,10 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tj/assert v0.0.3 h1:Df/BlaZ20mq6kuai7f5z2TvPFiwC3xaWJSDQNiIS3Rk=
github.com/tj/assert v0.0.3/go.mod h1:Ne6X72Q+TB1AteidzQncjw9PabbMp4PBMZ1k+vd1Pvk=
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8=
Expand All @@ -60,3 +70,6 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWD
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c h1:grhR+C34yXImVGp7EzNk+DTIk+323eIUWOmEevy6bDo=
gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
8 changes: 8 additions & 0 deletions libwallet/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ import (
"github.com/google/uuid"
)

// AccountPathMapping maps name accounts to BIP32 paths
type AccountPathMapping struct {
// label used by user
Label string
// Corresponding parent BIP32 derivation path
Path string
}

// OutputData is the information about an output that's being tracked by the wallet. Must be
// enough to reconstruct the commitment associated with the output when the
// root private key is known.
Expand Down