EOS

兼容Scatter

MYKEY兼容Scatter协议,您可以直接开发兼容Scatter协议的dapp,再通过mykey内置浏览器访问。也可以参考以下链接,了解更多Scatter协议的内容:

登录

先使用scatter.connect方法,再使用login方法即可获得用户的账号信息。
1
import ScatterJS from "@scatterjs/core";
2
3
ScatterJS.connect("My DAPP", { network }).then(connected => {
4
if (!connected) return alert("no scatter");
5
6
const eos = ScatterJS.eos(network, Api, { rpc });
7
this.setState({ eos });
8
9
ScatterJS.login().then(id => {
10
if (!id) return alert("no identity");
11
const account = ScatterJS.account("eos");
12
this.setState({ account }, this.getVote);
13
});
14
});
Copied!

验证MYKEY的签名

MYKEY的账号体系与其他的EOS账号有所差异,验证MYKEY签名时,需要使用Reserved公钥
Reserved Key的公钥,可以通过智能合约mykeymanager的表keydata查询到。查询时,指定范围为MYKEY账号,index为3。
1
/**
2
* 获取ReservedKey
3
* 详情参考 https://docs.mykey.org/v/English/dive-into-mykey/mykey-on-eos#mykey-account-structure
4
* @param {String} name MYKEY账号
5
* @return {String} ReservedKey/the 3rd Operation Key
6
*/
7
async getReservedKey(name) {
8
const mgrcontract = await this.getMykeyMgr(name)
9
const mykey_signkey_index = 3
10
const keydata = await this.eosJsonRpc.get_table_rows({json:true, code:mgrcontract, scope:name, table:'keydata', lower_bound: mykey_signkey_index, limit:1})
11
if(!keydata) return '';
12
return keydata.rows[0].key.pubkey;
13
}
14
15
/**
16
* 验证已签名的数据
17
* Parameters
18
* signature (string | Buffer) buffer or hex string
19
* data (string | Buffer)
20
* pubkey (pubkey | PublicKey)
21
* encoding (optional, default 'utf8')
22
* hashData boolean sha256 hash data before verify (optional, default true)
23
*/
24
ecc.verify(signature, data, pubkey) === true
25
Copied!
Last modified 1yr ago