二维码协议

简介

本文档描述了TokenPocket钱包支持的二维码协议,注意,TokenPocket钱包存在多个二维码扫描入口,个别入口扫码功能略有差异,下文会详细说明。

TokenPocket Android 1.6.7已经支持了新版本的二维码协议,1.6.7以及以上版本观察钱包冷钱包交互都使用新的扫码协议,详情请查看 EVM TRON EOSIO Solana BTC

TokenPocket支持二维码协议格式如下

  • 收款码

  • EOS创建账号

  • BTC观察钱包导入

  • 观察钱包冷钱包

  • DApp登录

  • DApp唤起钱包转账

  • DApp唤起钱包签名交易

  • DApp唤起钱包签名字符串

  • WalletConnect

  • 收藏DApp

  • 扫码打开DApp

收款码

EVM系列网络支持两种格式收款码协议

0xbc4ca0eda7647a8ab7c1161c2e118a18a936f13d
ethereum:0x4122131cd452e9729546b79f9f4e00c12e1d1c22

EOS支持两种格式收款码协议

账号

xiao1111aaaa

ScanProtocol

{
	"address": "xiaoyuantest", //收款地址
	"amount": "0", //数量
	"symbol": "EOS", //代币符号
	"contract": "eosio.token",//合约地址
	"precision": 4, //精度
	"protocol": "ScanProtocol", //协议名称
	"blockchain": "EOS", //网络
	"action": "transfer" //操作
}

BTC, TRON, Cosmos, SOL,IOST,Polkadot,均以钱包地址或者账号(IOST)作为内容生成收款码

EOS创建账号

该协议用于EOS账号创建

{
	"account": "pubyeoaad33k", //待创建账号
	//待创建账号的owner
	"owner": "EOS7eZbMjyMxtp35sg6xHcqtEHzEYb7ahzdHRAGcYgcJW8k8V8PnS", 
	//待创建账号的active
	"active": "EOS7eZbMjyMxtp35sg6xHcqtEHzEYb7ahzdHRAGcYgcJW8k8V8PnS",
	"blockchain": "EOS", //网络
	"action": "createAccount" //操作标识
}

BTC观察钱包导入协议

该二维码协议用于导入BTC观察钱包,注意,该二维码协议只有在导入BTC观察钱包界面扫码才能生效

{
	"action": "watchWallet",
	"data": [{
		"blockchain": "BTC",
		"extend_key": [{
			"key": "xpub6C7EYVsBR5Py964wD6Z71W5imraHCesnM9ofzAeKHXnow7yEzVJVgyZJub7VMDwuNYdwJLCgMrkzLhbdB6kbkLqXzzNg",
			"path": "m\/44'\/0'\/0'" //general
		}, {
			"key": "ypub6X2988R6rReDapW3dLojxVhw8MxiDU76xi16jhjHECfAaGTxdBp1tb4gJwNvvrU7Ye4uX5KjtAQPPtaZEf4j6pLWU",
			"path": "m\/49'\/0'\/0'" //segwit
		}, {
			"key": "zpub6rJrhc86dyTzQsBQNXujoTvAbGfFUr3TwQUdjy6SZgPkQmmFtRJRab92vhyMZufh7LSA5CcCiNaXRXr9TPAhPe32Z",
			"path": "m\/84'\/0'\/0'"  //nativeSegwit
		}]
	}]
}

观察钱包冷钱包

TokenPocket钱包目前支持观察钱包冷钱包的网络包含所有EVM系列网络,EOS,TRX,BTC,SQL

注意:观察钱包生成的二维码可以在冷钱包首页扫码入口扫描,冷钱包签名后生成的二维码必须在观察钱包转账页面弹出对话框扫码入口扫描才能生效

如下图:

EVM

观察钱包生成待冷钱包签名的二维码协议格式

{
	"signType": "ethSignTx", //签名类型
	"blockchain": "ETH", //网络
	"action": "coldWalletSign", //操作标识
	"sign": {
		"from": "0x8894E0a0c962CB723c1976a4421c95949bE2D4E3",
		"gas": "0x5208",
		"chainId": 1,
		"to": "0xdA5535939971B55c0Ecf4dAc961a8854D0aFad42",
		"value": "0x38d7ea4c68000",
		"type": "0x2",
		//注意,以下关于gas的字段,使用1559和不使用1559略有差异,以实际生成为准
		"maxFeePerGas": "0x11853fe080",
		"maxPriorityFeePerGas": "0x4a817c80",
		"nonce": "0x0"
	}
}

冷钱包签名后生成的二维码协议格式

0xf8ac82062e85013f2ed0c0828cf894eca41281c24451168a37211f0bc2b8645af4509280b844a9059cbb0000000000b79bbc09226198e8d15a05219fdd2a20cba0932621528743459250c016a00fd584c4e7bcfa0667e9f70a2

EOS

观察钱包生成待冷钱包签名的二维码协议格式

{
	"type": 21, //老版本App根据这个来识别是不是冷钱包签名数据
	"isHash": 0, //普通转账是0,其他字符串签名,如果是hash字符串则传1,否则为0
	"blockchain": "EOS",
	"action": "coldWalletSign",
	"sign": "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906950fa362c88e74ec1a4b00000000013015a4b966ea3055000000572d3ccdcd0190b1cad3684f8deb00000000a8ed32322190b1cad3684f8deb602483a5c79a9f98e803000000000000045450540000000000000000000000000000000000000000000000000000000000000000000000000000" //待冷钱包签名的数据
}

冷钱包签名后生成的二维码协议格式

SIG_K1_KjDBR53j7r4kMfF4KAYXrETK7mgKcG9q1t6MKShxvY2SufCiVc4pq1Ny9hKPsK5WKzXvjX

TRX

观察钱包生成待冷钱包签名的二维码协议格式

{
	"signType": "tronSignTx",
	"useTronHeader": true,
	"blockchain": "TRX",
	"action": "coldWalletSign",
	"sign": "b80514c0a5a9c498a60c8f76cdf45787e9522b16cc1" //待签名数据
}

冷钱包签名后生成的二维码协议格式

357e608c6e2a96da63d878be2a63fda3b0c778c69116e5000d56f05a4e2b3b3a86d85622a0810d64a2ece2ef44bd8bbb0bb7bcc4b21dc36c2cb7700

SOL

观察钱包生成待冷钱包签名的二维码协议格式

{
	"signType": "solanaSignTxMessages",
	"blockchain": "SOL",
	"action": "coldWalletSign",
	"sign": {
		"messages": ["87PYrB1jCEXWCkMKRvnub8UekEvf4LMp32PXBuNPMzdYqGU825U5iSw9UjKn81EeaxBtEZkS38auGm11m3LS1RsNrMd94VEax3ZpmQFyqxDGepsk871fFcKdXHAi3dR"]
	}
}

冷钱包签名后生成的二维码协议格式

["2quWLViqnUoDu3vih55mhzV4FJK5dPL6unEZm6Sm82JKiq2fLQj8xEqr3xbp5gmYTHyDdcCz"]

BTC

观察钱包生成的待冷钱包签名的二维码协议格式

{
	"blockchain": "BTC",
	"action": "coldWalletSign",
	"sign": "XU\/JbsIwEP2XufQSwI4dx86xKouAA5XoIhUO401BlJIShwZQ\/r2uqq6jmdEs743eXGDzUjWhhuLpAqHdWCjAS+k8WkOJ9TznmCllNTEStWSCEhpzhop5LY2lXGvHspxxLXguZGq0gwQqDGW8tFsNuLpaDchXRI\/bIz43DgraJ8NelkQF1rVQkATCqYpzqM1hU4US6zKCP5tFo2fuNPnAASrKkWRWCk8VyangUgmPXvpU5ZqaVKNnnnBJLZM5dOsE9k34\/hKtPbg61sBGvG7R5WYadsHN7Nw+4sL4ufHn5ZG9if34n1jZJX\/442mbGXtLp7y+pmy0vbnb3U+25+PDeFudlu51\/8OXfcbIL0uHPdGtu3c="
	
	//注意这里sign是经过zlib压缩后(压缩等级为5)并且base64 encode 处理的数据,原文结构为:
    {
	"inputs": [{
		"txid": "f88efadc93fb8cd14bbe35734b647682cbe",
		"path": "m\/49'\/0'\/0'\/0\/0",
		"value": 2.0E-5,
		"index": 0,
		"type": "scripthash",
		"scriptPubKeyHex": "a914a05d86f19071c2baf3f0481d387"
	}],
	"outputs": [{
		"address": "3F4sxae7cJtaPcfLcfzTv3w6oG",
		"value": 1.0E-8
	}, {
		"address": "3GJx5cdQWGkpyTeqo",
		"value": 1.330000000000002E-6
	}]
    }
}

冷钱包签名后生成的二维码协议格式

ZZDdbQAgCIRXQn4ExgGB/UcobdomTe9BY8S78wOEHx042fiuseYlFm3KPPwqjSb8ihGce4winyV4iXOw1hyoN2E99mul5+7K0Gp6TPmYHEf3ivfmge7RBEike+/ufAtwW/zR0fDDjvmQyAdP0b3bZjQpkd8oFErYFe+bn0lA/98HSG3KcdhibL4OY4OueR5mDA2wrbUpIO83WQBxm1Rkw4voiqipcQp9RVpe7E3Qz4pjfFieQQknkkxlerxG53UBQSnd2MaQuUqSBNq8JBhV2W4PPZhLOKehRoo21o7u5rPDZ5tgJFBb2Bf7i9nj0ctjcegneNkxEr0tCPe8x4EWwdelESPih8cH

这里签名后的数据,需要先base64 decode, 再用zlib解压缩得到真实的签名完成数据。

WalletConnect

TP钱包支持扫描WalletConnect二维码链接钱包,WalletConnect详情可参考:

DApp 登录,转账,签名交易,签名字符串

DApp扫码唤起钱包相关操作协议和DeepLink一致,详情可参考:

二维码内容和Deeplink协议中param参数内容格式保持一致,用TP钱包扫描二维码后,会自动唤起相关操作。这里注意,如果扫码后想要获取操作结果,必须提供callbackUrl用于接收操作结果。

收藏DApp

{
	"title": "Etherscan",
	"url": "https://etherscan.io/",
	"icon_url": "https://etherscan.io/images/logo-ether.png?v=0.0.2",
	"protocol": "TIP-001",
	"protocol_version": "1.0",
	"chain_list": [{
		"network": "ethereum",
		"chain_id": "1"
	}],
	"desc": "Etherscan is a Block Explorer and Analytics Platform for Ethereum, a decentralized smart contracts platform",
	"full_screen": 0,
	"hori_vert": 0,
	"title_color": "0xffffff",
	"navi_color": "0x2890fe"
}

TIP字段详情可参考:

扫码打开DApp

TP钱包扫描该协议二维码,可以用DApp浏览器打开对应链接

{
	"url": "https://dapp.mytokenpocket.vip/referendum/index.html#/", //要打开的url
	"chain": "EOS", //dapp属于哪个网络
	"source": "xxx" //来源,开发者自己定义
}

Last updated