# SP server guide (JAVA)

## SP API guide document

### Unlock KeyManager

Use the KeyManager class to get the secrete key.

```java
String keyManagerFile = "key.wallet";
String keyManagerPass = "keywalletPassword";

IWKeyManager keyManager = new IWKeyManager(keyManagerFile, keyManagerPass);
keyManager.unLock(keyManagerPass, new OnUnLockListener() {
    @Override
    public void onSuccess() {
        System.out.println("KeyManager Unlock onSuccess");
    }
    
    @Override
    public void onFail(int errCode) {
        System.out.println("KeyManager Unlock onFail:" + errCode);
    }
    
    @Override
    public void onCancel() {
         System.out.println("KeyManager Unlock onCancel");       
    }
});
```

## Read DID document

SP DID document can get it through the IWDID File class.

Use getData() function to transfer to the Jason string.

```java
String issuerDidFile = "sp.did";
IWDIDFile iwdidFile = new IWDIDFile(issuerDidFile);
String didDocJson = iwdidFile.getData();

System.out.println("didDocJson:" + didDocJson);  
```

## BlockChain node settings

The RPC address of the blockchain node can be set.

```java
String blockChainNodeUrl = "https://testnet.omnione.net:8889";
ServerInfo serverInfo = new ServerInfo(blockChainNodeUrl);
```

## Agent Server settings

The RPC address of the Agent Server INFO can be set.

```java
String agentUrl = "https://testnet.omnione.net";
ServerInfo agentServerInfo = new ServerInfo(agentUrl);
```

## Send Callback confirmation URL to mobile app

* `callBackUrl`: URL to VC 검증 restApi
* `queryParameter`: Key(txid), value(Unique key)
* PC web : create QR code image
* mobile web : send URL Scheme

```java
//qr code data source sample
{
  "spProfileUrl": "http://[IP address]:8080/omniissuer/sp/spProfile?txid=GAuw...pguh",
  "type": "VC",
  "vcLevel": "0"
}

//url scheme sample
omnione://authentication?spurl=http://[IP주소]:8080/omniissuer/shop/spProfileSt?txid=GAuw...pguh
```

## VC verification API

To request the validity verification regarding the mobile app, it should be requested by the JSON format of SpProfile type. SpProfile includes the submit URL(CallBackUrl) of the VC copy.

* [makeSpProfile](https://app.gitbook.com/@omnione-1/s/omnione/~/drafts/-M0Kxkh1b5yhV1W2x4pW/sdk-1/server-sdk/java/spprofileparam): creates the entered data and SpProfile JSON
* [spVerify](broken://pages/-LzplXp__h45FSXOlzx0#spverify)~~:~~  VC information copay verification API

### SP profile

* Profile
  * `callBackUrl` : URL for submitting the VC copy
  * `nonce` : Random value (txid)
  * `spName` : SP name<br>
* [SpProfileParam](broken://pages/-LzpfptQ6ykQEX0wGggd) class : SpProfile data
  * `serverInfo` : Blockchain node server URL
  * `keyManager` : Private key (secrete key) Wallet manager
  * `mainKeyId` : The stored key on the KeyManager for signing.
  * `serviceCode` : SP service code(The registered information on the [SP Console](broken://pages/-LmxUCKEJG_9G8NkwFex#add-service))
  * `profile` : Profile object
  * `spDid` : SP's DID ID<br>
* [SpApi.makeSpProfile](broken://pages/-LzplXp__h45FSXOlzx0#makespprofile)
  * makeSpProfile (SpProfileParam spProfileParam)<br>
* Return String
  * `spProfileJson` : SP profile JSON String

```java
String callBackUrl = "http://sp.com/verify";
String nonce = "random value";
String spDid = iwdidFile.getData().getId();

Profile profile = new Profile();
profile.setCallBackUrl(callBackUrl);
profile.setSpName("Pay");
profile.setNonce(nonce);

SpProfileParam spProfileParam = new SpProfileParam(
    serverInfo, 
    keyManager, 
    "key1", 
    serviceCode, 
    profile, 
    spDid);

String spProfileJson = SpApi.makeSpProfile(spProfileParam);
```

### VC Verification

The API for final registration for VC on BlockChain

* VC CallBack JSON Structure
  * `vcEncHex` - Encrypted VC copy information&#x20;
  * `vcId` - VC ID
  * `sessionId` - Same value as the SpProfile nonce value
  * `userDID` - The user's DID ID<br>
* VcVerifyParam Class - Registeration data
  * `serverInfo` -Blockchain node server URL URL
  * `agentServerInfo`- Agent server URL
  * `keyManager` - private key (Secreate key) Wallet manager
  * `mainKeyId` - Stored key on the KeyManager for signing&#x20;
  * `vcEncHex` - Encrypted VC copy information&#x20;
  * `vcId` - VC ID
  * `sessionId` - Same value as the SpProfile nonce value
  * `userDID` - The user's DID ID
  * `didDocuemntPath` - SP DID document file path<br>
* SpApi.spVerify Class - reset API
  * spVerify(vcVerifyParam)<br>
* VcResult class - result class
  * `status` - Status information
    * 0 = VC creation incomplete
    * 1 = VC creation completed
  * `vcComplete` - Completed VC object

```java
String vcEncHex = "";
String vcId = "";
String sessionId = "";
String userDid = "";

VcVerifyParam vcVerifyParam = new VcVerifyParam(
    serverInfo, 
    agentServerInfo, 
    keyManager, 
    "key1",
    vcEncHex, 
    vcId, 
    sessionId, 
    userDID, 
    didDocuemntPath);

VcResult vcResult = SpApi.spVerify(vcVerifyParam);
VerifiableClaim vcComplete = vcResult.getVcComplete();
String vcCompleteJson = vcComplete.toJson();
```


---

# 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://dev-en.omnione.net/server-system-construction/untitled-1/sp-server-guide-java.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.
