> For the complete documentation index, see [llms.txt](https://armonia.gitbook.io/developer/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://armonia.gitbook.io/developer/dappaplink-scatter-xie-yi.md).

# DApp(APLink) - Scatter协议

[参考案例](https://github.com/armoniax/amax-dapp-demo/tree/main)

[参考详情](https://github.com/GetScatter/ScatterWebExtension/tree/6.1.0)

#### Scatter拥有的方法 <a href="#h3-scatter" id="h3-scatter"></a>

***

* getIdentity - 用于获取身份（登录）
* forgetIdentity - 用于忘记身份（登出）
* authenticate - 用于证明身份的所有权。
* SuggestNetwork - 这是一个帮助方法，用于请求添加网站正在使用的 EOS 网络。
* amax - 用于获取amaxjs使用 Scatter 作为signProvider.
* requireVersion - 用于要求 scatter 的最低特定版本。

#### 获取Scatter <a href="#huo-qu-scatter" id="huo-qu-scatter"></a>

***

有了scatter对像，才能操作scatter。

如果非页面初始化就要使用scatter，比如按钮点击事件调用等，就可以直接获取`window.scatter`全使用。

注意：scatter挂载需要在scatter插件初始化完成后，完成后才会`document.dispatchEvent(new CustomEvent("scatterLoaded"));`。

document.addEventListener("scatterLoaded", scatterExtension => { // Scatter will now be available from the window scope. // At this stage the connection to Scatter from the application is // already encrypted. const scatter = window\.scatter;

```
// It is good practice to take this off the window once you have 
// a reference to it.
window.scatter = null;

// If you want to require a specific version of Scatter
scatter.requireVersion(3.0);

//...

})
```

#### 获取身份（登录） <a href="#h3" id="h3"></a>

***

会现弹框，让你选择一个身份。如果已经登录，则不必在调用`getIdentity`，如果再次调用，则会报错。除非调用`forgetIdentity`登出，才能再次登录。

```
// You can require certain fields
scatter.getIdentity().then(identity => {
    //...
}).catch(error => {
    //...
});
```

<br>

<figure><img src="/files/ae3bDog9Ofg6xQVZPgsg" alt=""><figcaption></figcaption></figure>

当然也可以直接从`scatter.identity`获取身份，但这必须在身份选择后才能获取到。

`identity`信息如下：

```
{
    "hash": "8ed9aaf4d0ec98b510fcde1616d63c198ac5b40fa5588e1a1748f13b80f5bc32",
    "publicKey": "AM6cAE3pnY7peSdzv1DPdj15dHeoiu9hmwm41JzCe9sHmYZnrdCp",
    "name": "RandomRobin6658351",
    "kyc": false,
    "accounts": [
        {
            "name": "mk",
            "authority": "active",
            "blockchain": "amax"
        }
    ]
}
```

一般只使用`accounts`中信息，其它信息暂时无用（预留它用）。

<br>

#### 忘记身份（登出） <a href="#wang-ji-shen-fen-deng-chu" id="wang-ji-shen-fen-deng-chu"></a>

***

一但调用`forgetIdentity`操作，`scatter.identity`中身份将被移除。

```
scatter.forgetIdentity().then(() => {
    //...
});
```

<br>

#### 向用户推荐网络 <a href="#xiang-yong-hu-tui-jian-wang-luo" id="xiang-yong-hu-tui-jian-wang-luo"></a>

***

如果您不使用通用网络，您可以建议用户将网络添加到他们的 Scatter。\
相当于用户添加了一个网络。

```
scatter.suggestNetwork(network);
```

<br>

#### 任意签名 <a href="#ren-yi-qian-ming" id="ren-yi-qian-ming"></a>

***

您可以请求 Scatter 对您希望的任何类型的数据进行任意签名。\
如果您需要对sha256哈希进行签名，请务必设置isHash为true，因为它使用不同的签名方法。否则总是让它为假。

```
scatter.getArbitrarySignature(
    publicKey, 
    data, 
    whatfor = "Login Authentication", 
    isHash = false
)
```

<br>

#### 实例化一个AMAX对象 <a href="#shi-li-hua-yi-ge-amax-dui-xiang" id="shi-li-hua-yi-ge-amax-dui-xiang"></a>

***

返回一个AMAX的代理对象，用这个对象可以进行链上的所有操作。

```
import Amax from "@amax/amaxjs";
const client = scatter.amax(
    network,
    Amax,
    {
        ...options,
        authorization: [`${account.name}@${account.authority}`],
    },
    network.protocol,
);
```
