# Become a Model Provider

{% hint style="info" %}
Please refer to [Go ](https://github.com/orange-protocol/orange-ap-sample)and [Java ](https://github.com/orange-protocol/orange-java-ap-example)code samples from respective links.&#x20;
{% endhint %}

## 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](https://onto.app/en/download/?mode=app).

> You can use one and the same DID to set up a DP and an MP.

### Orange Provider SDK

An SDK in [Go](https://github.com/orange-protocol/orange-provider-go-sdk) or [Java ](https://github.com/orange-protocol/orange-provider-java-sdk)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.&#x20;

## Design Models and Build Methods

{% hint style="info" %}
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.
{% endhint %}

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.&#x20;

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.&#x20;

### **Request**

Requests should be made with parameters of the following in JSON: &#x20;

```json
{
	"provider_did":"<dp did>",
	"data":<detail data>,
	"encrypted":"<encrypted hex string>"
}
```

<table><thead><tr><th width="150">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><code>provider_did</code></td><td>DID of DP</td></tr><tr><td><code>data</code></td><td>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.</td></tr><tr><td><code>encrypted</code></td><td>Hex string of <code>data</code> encrypted by DP using public key of MP's DID</td></tr></tbody></table>

### **Response**

The response should be a score in JSON representing the user's reputation:

```json
{
	"score":number
}
```

## 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](https://app.orangeprotocol.io/).

**Step 1:** Click on the **"Connect Wallet"** button on the top right to connect your wallet. You can find a detailed guide [here](https://docs.orangeprotocol.io/support/reputation-studio-guide).

**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](https://github.com/orange-protocol/orange-provider-go-sdk) and a wallet to decrypt a request using your DID.

#### Import SDK

```go
import(
	orangeSDK "github.com/orange-protocol/orange-provider-go-sdk"
	orangeOnt "github.com/orange-protocol/orange-provider-go-sdk/ont"
)
```

#### Initialize SDK

```go
didsdk, err := orangeOnt.NewOrangeProviderOntSdk("./wallet.dat", "123456", "TESTNET")
if err != nil {
    panic(err)
}
```

**Parameters for initialization:**

* path of the wallet file
* wallet password
* network info: `TESTNET` or `MAINNET`

#### **Example**

```go
requestJson := &BalanceReq{}
if err := c.ShouldBindJSON(requestJson); err != nil {
	c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
	return
}
		
encryptMsg, err := hex.DecodeString(requestJson.Encrypted)
if err != nil {
	fmt.Printf("DecodeString encryptMsg failed:%s\n", err.Error())
	c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
	return
}
// Decrypt the message with SDK
decryptedbts, err := didsdk.DecryptData(encryptMsg)
if err != nil {
	fmt.Printf("DecryptMsg failed:%s\n", err.Error())
	c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
	return
}
```

### 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:

```go
//1. Convert json to bytes
msgbytes, err := json.Marshal(dataWithSig.Data)
if err != nil {
fmt.Printf("Marshal msgbytes failed:%s\n", err.Error())

	c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
	return
}
//2. Deseriliaze signature
sigbytes, err := hex.DecodeString(dataWithSig.Sig)
if err != nil {
	fmt.Printf("DecodeString sigbytes failed:%s\n", err.Error())

	c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
	return
}
//3. Verify signature with SDK
f, err := didsdk.VerifySig(requestJson.ProviderDID, msgbytes, sigbytes)
if err != nil || !f {
	fmt.Printf("VerifySig  failed:%s\n", err.Error())
	c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Errorf("invalid signature")})
	return
}
```

## Generate Responses

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.orangeprotocol.io/developers/become-a-model-provider.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
