Orange
Search…
Become a Model Provider
Setting up an MP service
Please refer to Go and Java code samples from respective links.

Prerequisites

ONT ID

Each Model Provider must have a unique decentralized identifier (DID) to decrypt the data included in request messages. At present, it must be an ONT ID. You can get one by creating a wallet using ONTO app.
You can use one and the same DID to set up a DP and an MP.

Orange Provider SDK

An SDK in Go or Java is needed for signature and data encryption. Below instructions are illustrated in Go.

Wallet

You need to include a wallet file in the local directory of your project for decryption and signature.

Design Models and Build Methods

Usually one model works with one dedicated dataset, so you need to design the model based on your dataset. Or, you can also choose to design and publish your model on the Orange platform and offer a bounty to attract a DP.
Models define the way data is used to determine the reputation for a user. You can create and customize models to define the operations that are performed on the data and the weightage that is assigned to data.
One MP can provide multiple models to Orange users. Every model must have an associated method. A method is an abstract definition or reference to a model that is useful when querying and fetching data.
Each method needs to have a name and a parameter (dataset) associated with it.
  • The name is used to refer to a particular method
  • The parameter schema defines the useful data that needs to be passed as input to calculate reputation scores using the model pertaining to the particular method

Create Interfaces for Model Access

MPs need to set up an externally accessible interface with specific endpoints that can be used to fetch models. These endpoints will be called when model requests are made to the Orange system. The endpoint design depends on the design of the associated dataset, so only RESTful API is supported.

Request

Requests should be made with parameters of the following in JSON:
1
{
2
"provider_did":"<dp did>",
3
"data":<detail data>,
4
"encrypted":"<encrypted hex string>"
5
}
Copied!
Parameter
Description
provider_did
DID of DP
data
Data acquired from DP for calculation using the model. Usually it's empty in the production environment due to security concerns, only used in a debug environment.
encrypted
Hex string of data encrypted by DP using public key of MP's DID

Response

The response should be a score in JSON representing the user's reputation:
1
{
2
"score":number
3
}
Copied!

Publish Interface

When your interface is ready to be accessed on the mainnet, you can publish it on the Orange platform for developers to discover and use it. You can do it in the Reputation Studio.
Step 1: Click on the "Connect Wallet" button on the top right to connect your wallet. You can find a detailed guide here.
Step 2: Click on the Menu button and select "Management". Choose "My Models".
Step 3: Click on the "Create Profile" button and fill out the form to create your profile as an MP.
Step 4: Click on the "Create Model" and fill out the information following the steps indicated on the page. Then you can either click "Save" to save the draft, or click "Publish" to submit your model for review and publication.

Handle API Requests

Decrypt Request Messages

Since the data in the request is encrypted, you need first to decrypt the data. You need the Orange Go SDK and a wallet to decrypt a request using your DID.

Import SDK

1
import(
2
orangeSDK "github.com/orange-protocol/orange-provider-go-sdk"
3
orangeOnt "github.com/orange-protocol/orange-provider-go-sdk/ont"
4
)
Copied!

Initialize SDK

1
didsdk, err := orangeOnt.NewOrangeProviderOntSdk("./wallet.dat", "123456", "TESTNET")
2
if err != nil {
3
panic(err)
4
}
Copied!
Parameters for initialization:
  • path of the wallet file
  • wallet password
  • network info: TESTNET or MAINNET

Example

1
requestJson := &BalanceReq{}
2
if err := c.ShouldBindJSON(requestJson); err != nil {
3
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
4
return
5
}
6
7
encryptMsg, err := hex.DecodeString(requestJson.Encrypted)
8
if err != nil {
9
fmt.Printf("DecodeString encryptMsg failed:%s\n", err.Error())
10
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
11
return
12
}
13
// Decrypt the message with SDK
14
decryptedbts, err := didsdk.DecryptData(encryptMsg)
15
if err != nil {
16
fmt.Printf("DecryptMsg failed:%s\n", err.Error())
17
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
18
return
19
}
Copied!

Verify DP Signature

After decryption, you'll get the data and the DP's signature to the data. To verify the authenticity of data, you need to verify DP's signature:
1
//1. Convert json to bytes
2
msgbytes, err := json.Marshal(dataWithSig.Data)
3
if err != nil {
4
fmt.Printf("Marshal msgbytes failed:%s\n", err.Error())
5
6
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
7
return
8
}
9
//2. Deseriliaze signature
10
sigbytes, err := hex.DecodeString(dataWithSig.Sig)
11
if err != nil {
12
fmt.Printf("DecodeString sigbytes failed:%s\n", err.Error())
13
14
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
15
return
16
}
17
//3. Verify signature with SDK
18
f, err := didsdk.VerifySig(requestJson.ProviderDID, msgbytes, sigbytes)
19
if err != nil || !f {
20
fmt.Printf("VerifySig failed:%s\n", err.Error())
21
c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("invalid signature")})
22
return
23
}
Copied!

Generate Responses

Now you can use the data to calculate a reputation score and send it back to the Orange system.