From dec6672eca01c4d280408608d41001f8e1f1cd36 Mon Sep 17 00:00:00 2001 From: AnHyoChul Date: Wed, 6 Dec 2023 14:37:11 +0900 Subject: [PATCH 1/4] add parachain --- doc/index.md | 124 ++++++++- index.html | 249 +++++++++++------- info/supported_union_info.json | 16 ++ src/index.js | 73 ++++- src/native/request-method.js | 1 + src/type/dcent-web-type.js | 12 + .../20_coin.algorand.sign.spec.js | 14 +- 7 files changed, 382 insertions(+), 107 deletions(-) diff --git a/doc/index.md b/doc/index.md index 6410ba4..e9feb4f 100644 --- a/doc/index.md +++ b/doc/index.md @@ -503,6 +503,40 @@ The address string format is depend on the coin type. For some coin type(ex. TEZOS), include pubkey as a property of the response parameter. +For ss58 addresses used by the Substrate ecosystems such as Astar, a parameter called optionParam is added. +The value of optionParam is the prefix for each network defined in [ss58-registry](https://github.com/paritytech/ss58-registry). + +```js +var coinType = DcentWebConnector.coinType.PARA +var keyPath = "m/44'/810'/0'/0/0" // key path of the Astar's account +var optionParam = 5 // The address prefix + +var result +try{ + // Get the address corresponding to keyPath & prefix + result = await DcentWebConnector.getAddress(coinType, keyPath, optionParam) +}catch(e){ + result = e +} +``` + +Returned response object has: + +```json +{ + "header": { + "version": "1.0", + "response_from": "para", + "status": "success" + }, + "body": { + "command": "get_address", + "parameter": { + "address": "YzsEz5dG8TDqG49pGaejLrFoD4oeNTEX7yWt4qcCV4TA9LB" + } + } +} +``` ### Get XPUB @@ -1683,7 +1717,7 @@ For broadcast the sign transaction, you must reconstruct transaction include `Tx - This fuction for : - - POLCKADOT(DOT) + - POLKADOT(DOT) - Parameters : - unsignedTx: unsigned hexadecimal tx [Polkadot Docs](https://wiki.polkadot.network/docs/build-transaction-construction) @@ -1953,4 +1987,92 @@ For broadcast the sign transaction, you must reconstruct transaction include `Tx } ``` +**getParachainSignedTransaction()** + +- This fuction for : + + - Parachain - Astar(ASTR) + - Parachain Asset- Astar Asset(XC20) +- Parameters : + + - unsignedTx: unsigned hexadecimal tx [Polkadot Docs](https://wiki.polkadot.network/docs/build-transaction-construction) + - path: key path, wallet sign with that private key with a given key path (BIP32 ex) "m/44'/810'/0'/0/0"). + - fee: fee, It is fee that wallet displays on the screen. + - symbol: symbol, It is a symbol that the wallet displays on the screen. + - decimals: Parachain's decimals. + - RPCUrl: Network RPC endpoints. + - fee symbol: fee's symbol, It is a symbol that the wallet displays on the screen. + - fee decimals: fee's decimals. +- Requirements: + + - `D'CENT Bridge` version 1.5.3 or higher is required. + - D'CENT Biometric Wallet version 2.30.0 or higher is required. +- Useage: + + ```js + import { ApiPromise, HttpProvider } from '@polkadot/api' + + const httpProvider = new HttpProvider('https://evm.astar.network'); + const api = await ApiPromise({ provider: httpProvider }); + // Wait until we are ready and connected + await api.isReady; + + const blockNumber = await api.rpc.chain.getHeader(); + const blockHash = await api.rpc.chain.getBlockHash(blockNumber.number.toHex()); + // create SignerPayload + const signerPayload = api.createType('SignerPayload', { + genesisHash: api.genesisHash, + runtimeVersion: api.runtimeVersion, + version: api.extrinsicVersion, + blockHash: blockHash, + blockNumber: blockNumber.number, + era: api.createType('ExtrinsicEra', { + current: blockNumber.number, + period: 50 + }), + nonce, + address: to, + method: api.tx.balances.transfer(to, amount).method, // For tokens, method: api.tx.assets.transfer(contract, to, amount).method, + }); + + const sigHash = signerPayload.toRaw().data; + + const transactionJson = { + coinType: DcentWebConnector.coinType.PARA, + sigHash: sigHash, + path: `m/44'/810'/0'/0/0`, + decimals, // 18 + fee, + symbol: 'ASTR', + RPCUrl: 'https://evm.astar.network', + feeSymbol: 'ASTR', + feeDecimals, // 18 + }; + + var result; + try { + result = await DcentWebConnector.getParachainSignedTransaction(transactionJson); + } catch (e) { + console.log(e); + result = e; + } + ``` +- Returned response object: + + ```json + { + "header": { + "version": "1.0", + "response_from": "para", + "status": "success" + }, + "body": { + "command": "transaction", + "parameter": { + "signed_tx": "0x263b3ed036c74d15d875c7246abe73404c82763f3300316eb782cafdf5bd93f4f47f0fe34d823f9d07f8db7b2cb81051e58a1e58993c70888916c0ef6c3c910f" + } + } + } + ``` + Please Refer to the `index.html` to learn more about how to use the SDK APIs. There is an Web project using our Web SDK. diff --git a/index.html b/index.html index 0e66e38..5021a80 100644 --- a/index.html +++ b/index.html @@ -111,6 +111,8 @@
Response
+ +

@@ -168,6 +170,9 @@
Response

+ +
@@ -237,6 +242,7 @@
Response
$('#get_address_polkadot').click(get_address_polkadot_clicked); $('#get_address_cosmos').click(get_address_cosmos_clicked); $('#get_address_coreum').click(get_address_coreum_clicked); + $('#get_address_parachain').click(get_address_parachain_clicked); $('#getBitcoinSignedTransaction').click(getBitcoinSignedTransaction_clicked); @@ -277,6 +283,8 @@
Response
$('#getPolkadotSignedTransaction').click(getPolkadotSignedTransaction_clicked); $('#getCosmosSignedTransaction').click(getCosmosSignedTransaction_clicked); $('#getCoreumSignedTransaction').click(getCoreumSignedTransaction_clicked); + $('#getParachainSignedTransaction').click(getParachainSignedTransaction_clicked); + $('#getParachainXc20SignedTransaction').click(getParachainXc20SignedTransaction_clicked); }); async function info_clicked() { @@ -482,31 +490,39 @@
Response
} async function get_address_polkadot_clicked() { - set_command_name("Processing..."); - - var result = await getAddress(dcent.coinType.POLKADOT, "m/44'/354'/0'/0/0") - - set_command_name("get_address polkadot") - resp_editor.load(result) - } - - async function get_address_cosmos_clicked() { - set_command_name("Processing..."); - - var result = await getAddress(dcent.coinType.COSMOS, "m/44'/118'/0'/0/0") - - set_command_name("get_address cosmos") - resp_editor.load(result) - } - - async function get_address_coreum_clicked() { - set_command_name("Processing..."); - var result = await getAddress(dcent.coinType.COREUM, "m/44'/990'/0'/0/0") - - set_command_name("get_address coreum") - resp_editor.load(result) - } - + set_command_name("Processing..."); + + var result = await getAddress(dcent.coinType.POLKADOT, "m/44'/354'/0'/0/0") + + set_command_name("get_address polkadot") + resp_editor.load(result) + } + + async function get_address_cosmos_clicked() { + set_command_name("Processing..."); + + var result = await getAddress(dcent.coinType.COSMOS, "m/44'/118'/0'/0/0") + + set_command_name("get_address cosmos") + resp_editor.load(result) + } + + async function get_address_coreum_clicked() { + set_command_name("Processing..."); + var result = await getAddress(dcent.coinType.COREUM, "m/44'/990'/0'/0/0") + + set_command_name("get_address coreum") + resp_editor.load(result) + } + + async function get_address_parachain_clicked() { + set_command_name("Processing..."); + var result = await getAddress(dcent.coinType.PARA, "m/44'/810'/0'/0/0", 5) + + set_command_name("get_address parachain") + resp_editor.load(result) + } + async function getBitcoinSignedTransaction_clicked() { @@ -1068,54 +1084,92 @@
Response
set_command_name("getHavahHsp20SignedTransaction_deploy") resp_editor.load(result) } + async function getPolkadotSignedTransaction_clicked() { - set_command_name("Processing..."); - var transactionJson = { - coinType: dcent.coinType.POLKADOT, - sigHash: '040000163a5ee36b1243ce5241c0a45010dd1717869e9918c040bf5d305be4a5af9e7a0b00407a10f35a003400a223000007000000e143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423ee143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e', - path: `m/44'/354'/0'/0/0`, - decimals: 12, - fee: '0.00021', - symbol: 'DOT', - } - var result = await getPolkadotSignedTransaction(transactionJson); - - set_command_name("getPolkadotSignedTransaction") - resp_editor.load(result) - } - - async function getCosmosSignedTransaction_clicked() { - set_command_name("Processing..."); - var transactionJson = { - coinType: dcent.coinType.COSMOS, - sigHash: '0a94010a8f010a1c2f636f736d6f732e62616e6b2e763162657461312e4d736753656e64126f0a2d636f736d6f73317235763573726461377866746833686e327332367478767263726e746c646a756d74386d686c122d636f736d6f733138766864637a6a7574343467707379383034637266686e64356e713030336e7a306e663230761a0f0a057561746f6d1206313030303030120012670a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a21ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff12040a020801180a12130a0d0a057561746f6d12043530303010c09a0c1a0b636f736d6f736875622d34208f3a', - path: `m/44'/118'/0'/0/0`, - decimals: 6, - fee: '0.023', - symbol: 'ATOM', - } - var result = await getCosmosSignedTransaction(transactionJson); - - set_command_name("getCosmosSignedTransaction") - resp_editor.load(result) - } - - async function getCoreumSignedTransaction_clicked() { - set_command_name("Processing..."); - var transactionJson = { - coinType: dcent.coinType.COREUM, - sigHash: '0a90010a8b010a1c2f636f736d6f732e62616e6b2e763162657461312e4d736753656e64126b0a2b636f7265317432656d347a6b77346161716d7139373939656e756b66366538343577656671776e63667a78122b636f726531666c343876736e6d73647a637638357135643271347a35616a646861387975337834333537761a0f0a057561746f6d1206313030303030120012670a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a21ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff12040a020801180012130a0d0a057561746f6d12043530303010c09a0c1a0b636f736d6f736875622d342000', - path: `m/44'/990'/0'/0/0`, - decimals: 6, - fee: '0.12', - symbol: 'CORE', - } - var result = await getCosmosSignedTransaction(transactionJson); - - set_command_name("getCoreumSignedTransaction") - resp_editor.load(result) - } + set_command_name("Processing..."); + var transactionJson = { + coinType: dcent.coinType.POLKADOT, + sigHash: '040000163a5ee36b1243ce5241c0a45010dd1717869e9918c040bf5d305be4a5af9e7a0b00407a10f35a003400a223000007000000e143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423ee143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e', + path: `m/44'/354'/0'/0/0`, + decimals: 12, + fee: '0.00021', + symbol: 'DOT', + } + var result = await getPolkadotSignedTransaction(transactionJson); + + set_command_name("getPolkadotSignedTransaction") + resp_editor.load(result) + } + async function getCosmosSignedTransaction_clicked() { + set_command_name("Processing..."); + var transactionJson = { + coinType: dcent.coinType.COSMOS, + sigHash: '0a94010a8f010a1c2f636f736d6f732e62616e6b2e763162657461312e4d736753656e64126f0a2d636f736d6f73317235763573726461377866746833686e327332367478767263726e746c646a756d74386d686c122d636f736d6f733138766864637a6a7574343467707379383034637266686e64356e713030336e7a306e663230761a0f0a057561746f6d1206313030303030120012670a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a21ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff12040a020801180a12130a0d0a057561746f6d12043530303010c09a0c1a0b636f736d6f736875622d34208f3a', + path: `m/44'/118'/0'/0/0`, + decimals: 6, + fee: '0.023', + symbol: 'ATOM', + } + var result = await getCosmosSignedTransaction(transactionJson); + + set_command_name("getCosmosSignedTransaction") + resp_editor.load(result) + } + + async function getCoreumSignedTransaction_clicked() { + set_command_name("Processing..."); + var transactionJson = { + coinType: dcent.coinType.COREUM, + sigHash: '0a90010a8b010a1c2f636f736d6f732e62616e6b2e763162657461312e4d736753656e64126b0a2b636f7265317432656d347a6b77346161716d7139373939656e756b66366538343577656671776e63667a78122b636f726531666c343876736e6d73647a637638357135643271347a35616a646861387975337834333537761a0f0a057561746f6d1206313030303030120012670a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a21ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff12040a020801180012130a0d0a057561746f6d12043530303010c09a0c1a0b636f736d6f736875622d342000', + path: `m/44'/990'/0'/0/0`, + decimals: 6, + fee: '0.12', + symbol: 'CORE', + } + var result = await getCosmosSignedTransaction(transactionJson); + + set_command_name("getCoreumSignedTransaction") + resp_editor.load(result) + } + + async function getParachainSignedTransaction_clicked() { + set_command_name("Processing..."); + var transactionJson = { + coinType: dcent.coinType.PARA, + sigHash: '1f03003ec746fb0d6d9d66245d6dc6c02d23b1b290821d8674865f96c03ef86d9d690d025a62020917000042000000020000009eb76c5184c4ab8679d2d5d819fdf90b9c001403e9e17da2e14b6d8aec4029c6b3436f97b6760bddf33e816da9c746b0cf17a80307f7a8485732044c8c20284d', + path: `m/44'/810'/0'/0/0`, + decimals: 18, + fee: '0.038966870338267128', + symbol: 'ASTR', + RPCUrl: 'https://astar-rpc.dwellir.com', + feeSymbol: 'ASTR', + feeDecimals: 18, + } + var result = await getParachainSignedTransaction(transactionJson); + + set_command_name("getParachainSignedTransaction") + resp_editor.load(result) + } + + async function getParachainXc20SignedTransaction_clicked() { + set_command_name("Processing..."); + var transactionJson = { + coinType: dcent.coinType.PARA_XC20, + sigHash: '240817030000000000000001003ec746fb0d6d9d66245d6dc6c02d23b1b290821d8674865f96c03ef86d9d690d1733c42f5578e4495b038923000048000000020000009eb76c5184c4ab8679d2d5d819fdf90b9c001403e9e17da2e14b6d8aec4029c697111d520df41d8ff1801aa6532c0c3b80ff986adf37476846b0e7e09993b7af', + path: `m/44'/810'/0'/0/0`, + decimals: 18, + fee: '0.049131930863795561', + symbol: 'GLMR', + RPCUrl: 'https://astar-rpc.dwellir.com', + feeSymbol: 'ASTR', + feeDecimals: 18, + } + var result = await getParachainSignedTransaction(transactionJson); + + set_command_name("getParachainXc20SignedTransaction") + resp_editor.load(result) + } /////// DCENT WEB-SDK call @@ -1199,10 +1253,10 @@
Response
return result } - async function getAddress(coinType, key) { + async function getAddress(coinType, key, optionParam) { var result try { - result = await dcent.getAddress(coinType, key) + result = await dcent.getAddress(coinType, key, optionParam) } catch (e) { result = e } @@ -1392,26 +1446,35 @@
Response
return result } - async function getPolkadotSignedTransaction(transaction) { - var result - try { - result = await dcent.getPolkadotSignedTransaction(transaction) - } catch (e) { - result = e - } - return result - } - - async function getCosmosSignedTransaction(transaction) { - var result - try { - result = await dcent.getCosmosSignedTransaction(transaction) - } catch (e) { - result = e - } - return result - } - + async function getPolkadotSignedTransaction(transaction) { + var result + try { + result = await dcent.getPolkadotSignedTransaction(transaction) + } catch (e) { + result = e + } + return result + } + + async function getCosmosSignedTransaction(transaction) { + var result + try { + result = await dcent.getCosmosSignedTransaction(transaction) + } catch (e) { + result = e + } + return result + } + + async function getParachainSignedTransaction(transaction) { + var result + try { + result = await dcent.getParachainSignedTransaction(transaction) + } catch (e) { + result = e + } + return result + } diff --git a/info/supported_union_info.json b/info/supported_union_info.json index c4bbbc7..96430e6 100644 --- a/info/supported_union_info.json +++ b/info/supported_union_info.json @@ -86,5 +86,21 @@ { "name": "algo-app-test", "supportVersion": "2.29.1" + }, + { + "name": "para", + "supportVersion": "2.30.0" + }, + { + "name": "para-testnet", + "supportVersion": "2.30.0" + }, + { + "name": "para-xc20", + "supportVersion": "2.30.0" + }, + { + "name": "para-xc20-tesetnet", + "supportVersion": "2.30.0" } ] \ No newline at end of file diff --git a/src/index.js b/src/index.js index ecd5ae7..e0c83bf 100644 --- a/src/index.js +++ b/src/index.js @@ -516,7 +516,8 @@ const _contractNotStartWith0x = (coinGroup) => { coinGroup === dcentCoinGroup.XRC20.toLowerCase() || coinGroup === dcentCoinGroup.XRC20_APOTHEM.toLowerCase() || coinGroup === dcentCoinGroup.HTS_TESTNET.toLowerCase() || coinGroup === dcentCoinGroup.HEDERA_HTS.toLowerCase() || coinGroup === dcentCoinGroup.ALGORAND_ASSET.toLowerCase() || coinGroup === dcentCoinGroup.ALGORAND_ASSET_TESTNET.toLowerCase() || - coinGroup === dcentCoinGroup.ALGORAND_APP.toLowerCase() || coinGroup === dcentCoinGroup.ALGORAND_APP_TESTNET.toLowerCase() + coinGroup === dcentCoinGroup.ALGORAND_APP.toLowerCase() || coinGroup === dcentCoinGroup.ALGORAND_APP_TESTNET.toLowerCase() || + coinGroup === dcentCoinGroup.PARA_XC20.toLowerCase() || coinGroup === dcentCoinGroup.PARA_XC20_TESTNET.toLowerCase() ) { return true } @@ -596,6 +597,10 @@ function isAvaliableCoinType (coinType) { case dcentCoinType.ALGORAND_ASSET_TESTNET.toLowerCase(): case dcentCoinType.ALGORAND_APP.toLowerCase(): case dcentCoinType.ALGORAND_APP_TESTNET.toLowerCase(): + case dcentCoinType.PARA.toLowerCase(): + case dcentCoinType.PARA_TESTNET.toLowerCase(): + case dcentCoinType.PARA_XC20.toLowerCase(): + case dcentCoinType.PARA_XC20_TESTNET.toLowerCase(): return true default: return false @@ -625,6 +630,8 @@ function isTokenType (coinGroup) { case dcentCoinType.ALGORAND_ASSET_TESTNET.toLowerCase(): case dcentCoinType.ALGORAND_APP.toLowerCase(): case dcentCoinType.ALGORAND_APP_TESTNET.toLowerCase(): + case dcentCoinGroup.PARA_XC20.toLowerCase(): + case dcentCoinGroup.PARA_XC20_TESTNET.toLowerCase(): return true default: return false @@ -642,7 +649,7 @@ function isBitcoinTxCoinType (coinType) { return false } } - + function isCzoneCoinType (coinType) { switch (coinType.toLowerCase()) { case dcentCoinType.COREUM.toLowerCase(): @@ -652,6 +659,21 @@ function isCzoneCoinType (coinType) { } } +function isParachainCoinType (coinType) { + if (!coinType) { + return false + } + switch (coinType.toLowerCase()) { + case dcentCoinType.PARA.toLowerCase(): + case dcentCoinType.PARA_TESTNET.toLowerCase(): + case dcentCoinType.PARA_XC20.toLowerCase(): + case dcentCoinType.PARA_XC20_TESTNET.toLowerCase(): + return true + default: + return false + } +} + function getCzonePrifix (coinType) { switch (coinType.toLowerCase()) { case dcentCoinType.COREUM.toLowerCase(): @@ -752,7 +774,7 @@ dcent.selectAddress = async function (addresses) { * @param {string} path string value of key path to get address * @returns {Object} address. */ -dcent.getAddress = async function (coinType, path) { +dcent.getAddress = async function (coinType, path, optionParam = null) { if (!isAvaliableCoinType(coinType)) { throw dcent.dcentException('coin_type_error', 'not supported coin type') @@ -765,8 +787,15 @@ dcent.getAddress = async function (coinType, path) { if (isCzoneCoinType(coinType)) { params.optionParam = getCzonePrifix(coinType) -} - + } + + if (isParachainCoinType(coinType)) { + if (!Number(optionParam)) { + throw dcent.dcentException('param_error', 'Invaild Parameter') + } + params.optionParam = Number(optionParam) + } + const res = await dcent.call({ method: 'getAddress', params @@ -1425,7 +1454,7 @@ dcent.getPolkadotSignedTransaction = async function ({ params }) } - + dcent.getCosmosSignedTransaction = async function ({ coinType, sigHash, @@ -1491,6 +1520,38 @@ dcent.getAlgorandSignedTransaction = async function ({ }) } +dcent.getParachainSignedTransaction = async function ({ + coinType, + sigHash, + fee, + decimals, + nonce, + path, + symbol, + RPCUrl, + feeSymbol, + feeDecimals, + optionParam, +}) { + const params = { + coinType, + sig_hash: sigHash, + fee: UnitConverter(fee, feeDecimals).bignum.toString(16).padStart(16, '0'), + decimals, + path, + symbol, + RPCUrl, + feeSymbol, + feeDecimals, + } + if (nonce) params.nonce = nonce + if (optionParam) params.optionParam = optionParam + return await dcent.call({ + method: 'getUnionSignedTransaction', + params + }) +} + dcent.state = dcentState dcent.coinType = dcentCoinType dcent.coinGroup = dcentCoinGroup diff --git a/src/native/request-method.js b/src/native/request-method.js index d902e3a..9c43288 100644 --- a/src/native/request-method.js +++ b/src/native/request-method.js @@ -28,6 +28,7 @@ module.exports = { GET_POLKADOT_SIGN_TX: 'getPolkadotSignedTransaction', GET_COSMOS_SIGN_TX: 'getCosmosSignedTransaction', GET_ALGORAND_SIGN_TX: 'getAlgorandSignedTransaction', + GET_PARA_SIGN_TX: 'getParachainSignedTransaction', } /* //////////////////////////////////////////////////////////////////////// */ diff --git a/src/type/dcent-web-type.js b/src/type/dcent-web-type.js index c5908e4..9f7aefd 100644 --- a/src/type/dcent-web-type.js +++ b/src/type/dcent-web-type.js @@ -55,6 +55,10 @@ const coinType = { ALGORAND_ASSET_TESTNET: 'algo-asset-test', ALGORAND_APP: 'algo-app', ALGORAND_APP_TESTNET: 'algo-app-test', + PARA: 'para', + PARA_TESTNET: 'para-testnet', + PARA_XC20: 'para-xc20', + PARA_XC20_TESTNET: 'para-xc20-testnet', } const coinGroup = { @@ -112,6 +116,10 @@ const coinGroup = { ALGORAND_ASSET_TESTNET: 'ALGO-ASSET-TEST', ALGORAND_APP: 'ALGO-APP', ALGORAND_APP_TESTNET: 'ALGO-APP-TEST', + PARA: 'PARA', + PARA_TESTNET: 'PARAT', + PARA_XC20: 'XC20', + PARA_XC20_TESTNET: 'XC20T', } const coinName = { @@ -169,6 +177,10 @@ const coinName = { ALGORAND_ASSET_TESTNET: 'ALGO-ASSET-TEST', ALGORAND_APP: 'ALGO-APP', ALGORAND_APP_TESTNET: 'ALGO-APP-TEST', + PARA: 'PARA', + PARA_TESTNET: 'PARAT', + PARA_XC20: 'XC20', + PARA_XC20_TESTNET: 'XC20T', } const bitcoinTxType = { diff --git a/tests/unit/1_bridge_test/20_coin.algorand.sign.spec.js b/tests/unit/1_bridge_test/20_coin.algorand.sign.spec.js index 9c2f8ae..a1f789f 100644 --- a/tests/unit/1_bridge_test/20_coin.algorand.sign.spec.js +++ b/tests/unit/1_bridge_test/20_coin.algorand.sign.spec.js @@ -71,7 +71,7 @@ describe('[dcent-web-connector] Bridge - init', () => { } var response = await page.evaluate((transactionJson) => { // eslint-disable-next-line no-undef - return getHavahSignedTransaction(transactionJson) + return getAlgoSignedTransaction(transactionJson) }, transactionJson) var responseAddress = await page.evaluate(() => { @@ -105,7 +105,7 @@ describe('[dcent-web-connector] Bridge - init', () => { } var response = await page.evaluate((transactionJson) => { // eslint-disable-next-line no-undef - return getHavahSignedTransaction(transactionJson) + return getAlgoSignedTransaction(transactionJson) }, transactionJson) var responseAddress = await page.evaluate(() => { @@ -139,7 +139,7 @@ describe('[dcent-web-connector] Bridge - init', () => { } var response = await page.evaluate((transactionJson) => { // eslint-disable-next-line no-undef - return getHavahSignedTransaction(transactionJson) + return getAlgoSignedTransaction(transactionJson) }, transactionJson) var responseAddress = await page.evaluate(() => { @@ -173,7 +173,7 @@ describe('[dcent-web-connector] Bridge - init', () => { } var response = await page.evaluate((transactionJson) => { // eslint-disable-next-line no-undef - return getHavahSignedTransaction(transactionJson) + return getAlgoSignedTransaction(transactionJson) }, transactionJson) var responseAddress = await page.evaluate(() => { @@ -207,7 +207,7 @@ describe('[dcent-web-connector] Bridge - init', () => { } var response = await page.evaluate((transactionJson) => { // eslint-disable-next-line no-undef - return getHavahSignedTransaction(transactionJson) + return getAlgoSignedTransaction(transactionJson) }, transactionJson) var responseAddress = await page.evaluate(() => { @@ -241,7 +241,7 @@ describe('[dcent-web-connector] Bridge - init', () => { } var response = await page.evaluate((transactionJson) => { // eslint-disable-next-line no-undef - return getHavahSignedTransaction(transactionJson) + return getAlgoSignedTransaction(transactionJson) }, transactionJson) var responseAddress = await page.evaluate(() => { @@ -275,7 +275,7 @@ describe('[dcent-web-connector] Bridge - init', () => { } var response = await page.evaluate((transactionJson) => { // eslint-disable-next-line no-undef - return getHavahSignedTransaction(transactionJson) + return getAlgoSignedTransaction(transactionJson) }, transactionJson) var responseAddress = await page.evaluate(() => { From 71e843c6e1712b392a6bd5064efded25a03ec863 Mon Sep 17 00:00:00 2001 From: AnHyoChul Date: Thu, 7 Dec 2023 18:21:39 +0900 Subject: [PATCH 2/4] =?UTF-8?q?-=20readme=20=EC=88=98=EC=A0=95=20-=20polka?= =?UTF-8?q?dot=20api=20=ED=98=95=EC=8B=9D=EC=97=90=20=EB=A7=9E=EA=B2=8C=20?= =?UTF-8?q?signed=5Ftx=20=EA=B0=92=EC=9D=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/index.md | 10 +++++----- src/index.js | 12 ++++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/doc/index.md b/doc/index.md index e9feb4f..18da8f8 100644 --- a/doc/index.md +++ b/doc/index.md @@ -503,18 +503,18 @@ The address string format is depend on the coin type. For some coin type(ex. TEZOS), include pubkey as a property of the response parameter. -For ss58 addresses used by the Substrate ecosystems such as Astar, a parameter called optionParam is added. -The value of optionParam is the prefix for each network defined in [ss58-registry](https://github.com/paritytech/ss58-registry). +For ss58 addresses used by the Substrate ecosystems such as Astar, prefix is added. +The value of prefix is the prefix for each network defined in [ss58-registry](https://github.com/paritytech/ss58-registry). ```js var coinType = DcentWebConnector.coinType.PARA var keyPath = "m/44'/810'/0'/0/0" // key path of the Astar's account -var optionParam = 5 // The address prefix +var prefix = 5 // The address prefix of Astar var result try{ // Get the address corresponding to keyPath & prefix - result = await DcentWebConnector.getAddress(coinType, keyPath, optionParam) + result = await DcentWebConnector.getAddress(coinType, keyPath, prefix) }catch(e){ result = e } @@ -2069,7 +2069,7 @@ For broadcast the sign transaction, you must reconstruct transaction include `Tx "body": { "command": "transaction", "parameter": { - "signed_tx": "0x263b3ed036c74d15d875c7246abe73404c82763f3300316eb782cafdf5bd93f4f47f0fe34d823f9d07f8db7b2cb81051e58a1e58993c70888916c0ef6c3c910f" + "signed_tx": "0x00263b3ed036c74d15d875c7246abe73404c82763f3300316eb782cafdf5bd93f4f47f0fe34d823f9d07f8db7b2cb81051e58a1e58993c70888916c0ef6c3c910f" } } } diff --git a/src/index.js b/src/index.js index e0c83bf..c73f90a 100644 --- a/src/index.js +++ b/src/index.js @@ -774,7 +774,7 @@ dcent.selectAddress = async function (addresses) { * @param {string} path string value of key path to get address * @returns {Object} address. */ -dcent.getAddress = async function (coinType, path, optionParam = null) { +dcent.getAddress = async function (coinType, path, prefix = null) { if (!isAvaliableCoinType(coinType)) { throw dcent.dcentException('coin_type_error', 'not supported coin type') @@ -790,10 +790,10 @@ dcent.getAddress = async function (coinType, path, optionParam = null) { } if (isParachainCoinType(coinType)) { - if (!Number(optionParam)) { + if (!Number(prefix)) { throw dcent.dcentException('param_error', 'Invaild Parameter') } - params.optionParam = Number(optionParam) + params.optionParam = Number(prefix) } const res = await dcent.call({ @@ -1546,10 +1546,14 @@ dcent.getParachainSignedTransaction = async function ({ } if (nonce) params.nonce = nonce if (optionParam) params.optionParam = optionParam - return await dcent.call({ + + const res = await dcent.call({ method: 'getUnionSignedTransaction', params }) + + res.body.parameter.signed_tx = '0x00' + (res.body.parameter.signed_tx.startsWith('0x') ? res.body.parameter.signed_tx.substr(2) : res.body.parameter.signed_tx) + return res } dcent.state = dcentState From 0d8c308970917ebe1be71f176114e4c8f1153738 Mon Sep 17 00:00:00 2001 From: AnHyoChul Date: Thu, 7 Dec 2023 19:05:01 +0900 Subject: [PATCH 3/4] =?UTF-8?q?readme=EC=97=90=EC=84=9C=20=EA=B0=80?= =?UTF-8?q?=EC=9D=B4=EB=93=9C=ED=95=9C=20=EA=B2=83=EA=B3=BC=20=EB=8F=99?= =?UTF-8?q?=EC=9D=BC=ED=95=9C=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=ED=8F=AC?= =?UTF-8?q?=EB=A7=B7=EC=9C=BC=EB=A1=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=A7=84=ED=96=89=ED=95=98=EA=B8=B0=20=EC=9C=84=ED=95=B4=20hex?= =?UTF-8?q?=20string=EC=97=90=200x=EB=A5=BC=20=EB=B6=99=EC=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 5021a80..e26a036 100644 --- a/index.html +++ b/index.html @@ -1137,7 +1137,7 @@
Response
set_command_name("Processing..."); var transactionJson = { coinType: dcent.coinType.PARA, - sigHash: '1f03003ec746fb0d6d9d66245d6dc6c02d23b1b290821d8674865f96c03ef86d9d690d025a62020917000042000000020000009eb76c5184c4ab8679d2d5d819fdf90b9c001403e9e17da2e14b6d8aec4029c6b3436f97b6760bddf33e816da9c746b0cf17a80307f7a8485732044c8c20284d', + sigHash: '0x1f03003ec746fb0d6d9d66245d6dc6c02d23b1b290821d8674865f96c03ef86d9d690d025a62020917000042000000020000009eb76c5184c4ab8679d2d5d819fdf90b9c001403e9e17da2e14b6d8aec4029c6b3436f97b6760bddf33e816da9c746b0cf17a80307f7a8485732044c8c20284d', path: `m/44'/810'/0'/0/0`, decimals: 18, fee: '0.038966870338267128', @@ -1156,7 +1156,7 @@
Response
set_command_name("Processing..."); var transactionJson = { coinType: dcent.coinType.PARA_XC20, - sigHash: '240817030000000000000001003ec746fb0d6d9d66245d6dc6c02d23b1b290821d8674865f96c03ef86d9d690d1733c42f5578e4495b038923000048000000020000009eb76c5184c4ab8679d2d5d819fdf90b9c001403e9e17da2e14b6d8aec4029c697111d520df41d8ff1801aa6532c0c3b80ff986adf37476846b0e7e09993b7af', + sigHash: '0x240817030000000000000001003ec746fb0d6d9d66245d6dc6c02d23b1b290821d8674865f96c03ef86d9d690d1733c42f5578e4495b038923000048000000020000009eb76c5184c4ab8679d2d5d819fdf90b9c001403e9e17da2e14b6d8aec4029c697111d520df41d8ff1801aa6532c0c3b80ff986adf37476846b0e7e09993b7af', path: `m/44'/810'/0'/0/0`, decimals: 18, fee: '0.049131930863795561', From 5dee02f49bb5c63f2312e9e845be82573530dd71 Mon Sep 17 00:00:00 2001 From: AnHyoChul Date: Wed, 13 Dec 2023 12:26:29 +0900 Subject: [PATCH 4/4] =?UTF-8?q?Astar=20EVM=20getAddress=20=EB=B0=8F=20getS?= =?UTF-8?q?ignedTransaction=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/index.md | 12 ++++-- index.html | 68 ++++++++++++++++++++++++++++++---- info/supported_union_info.json | 8 ++-- src/index.js | 4 +- 4 files changed, 76 insertions(+), 16 deletions(-) diff --git a/doc/index.md b/doc/index.md index 18da8f8..2c8d1a3 100644 --- a/doc/index.md +++ b/doc/index.md @@ -22,9 +22,10 @@ | v0.12.1 | 2023. 05. 03 | add support coin group for syncAccount | | v0.13.0 | 2023. 05. 16 | add Tezos & Vechain & Near & Havah transaction function | | v0.13.1 | 2023. 05. 17 | Fixed fee display issue | -| v0.14.0 | 2023. 05. 25 | add Polkadot & Comsmos & Coreum & Near Token | -| v0.14.1 | 2023. 05. 25 | Fix Polkadot decimals | +| v0.14.0 | 2023. 05. 25 | add Polkadot & Comsmos & Coreum & Near Token | +| v0.14.1 | 2023. 05. 25 | Fix Polkadot decimals | | v0.14.2 | 2023. 11. 20 | add Algorand transaction function | +| v0.14.3 | 2023. 12. 13 | add Parachain(Astar) transaction function | ## 1. INTRODUCTION @@ -520,6 +521,8 @@ try{ } ``` +Please note that `Astar EVM` features an EVM (Ethereum Virtual Machine) compatible runtime environment, so it is the same as getting the address of ETHEREUM account. + Returned response object has: ```json @@ -831,7 +834,6 @@ The D'CENT Web SDK provides functions for signing transaction of coins. - nonce - gasPrice - gasLimit - - value - key path for signing - chain ID - contract information : @@ -2006,7 +2008,7 @@ For broadcast the sign transaction, you must reconstruct transaction include `Tx - Requirements: - `D'CENT Bridge` version 1.5.3 or higher is required. - - D'CENT Biometric Wallet version 2.30.0 or higher is required. + - D'CENT Biometric Wallet version 2.30.1 or higher is required. - Useage: ```js @@ -2075,4 +2077,6 @@ For broadcast the sign transaction, you must reconstruct transaction include `Tx } ``` + Please note that for `Astar EVM` transactions, you can use the getEthereumSignedTransaction() and getTokenSignedTransaction() methods with the chain ID set to 592. + Please Refer to the `index.html` to learn more about how to use the SDK APIs. There is an Web project using our Web SDK. diff --git a/index.html b/index.html index e26a036..3740d2c 100644 --- a/index.html +++ b/index.html @@ -111,9 +111,12 @@
Response
+
+ - + +


+ +
@@ -243,6 +249,7 @@
Response
$('#get_address_cosmos').click(get_address_cosmos_clicked); $('#get_address_coreum').click(get_address_coreum_clicked); $('#get_address_parachain').click(get_address_parachain_clicked); + $('#get_address_astarevm').click(get_address_astarevm_clicked); $('#getBitcoinSignedTransaction').click(getBitcoinSignedTransaction_clicked); @@ -285,6 +292,8 @@
Response
$('#getCoreumSignedTransaction').click(getCoreumSignedTransaction_clicked); $('#getParachainSignedTransaction').click(getParachainSignedTransaction_clicked); $('#getParachainXc20SignedTransaction').click(getParachainXc20SignedTransaction_clicked); + $('#getEthereumSignedTransactionForAstarEVM').click(getEthereumSignedTransactionForAstarEVM_clicked); + $('#getTokenSignedTransactionForAstarEVM').click(getTokenSignedTransactionForAstarEVM_clicked); }); async function info_clicked() { @@ -523,6 +532,13 @@
Response
resp_editor.load(result) } + async function get_address_astarevm_clicked() { + set_command_name("Processing..."); + var result = await getAddress(dcent.coinType.ETHEREUM, "m/44'/60'/0'/0/0") + + set_command_name("get_address for Astar EVM") + resp_editor.load(result) + } async function getBitcoinSignedTransaction_clicked() { @@ -1134,7 +1150,8 @@
Response
} async function getParachainSignedTransaction_clicked() { - set_command_name("Processing..."); + set_command_name("Processing...") + var transactionJson = { coinType: dcent.coinType.PARA, sigHash: '0x1f03003ec746fb0d6d9d66245d6dc6c02d23b1b290821d8674865f96c03ef86d9d690d025a62020917000042000000020000009eb76c5184c4ab8679d2d5d819fdf90b9c001403e9e17da2e14b6d8aec4029c6b3436f97b6760bddf33e816da9c746b0cf17a80307f7a8485732044c8c20284d', @@ -1146,14 +1163,15 @@
Response
feeSymbol: 'ASTR', feeDecimals: 18, } - var result = await getParachainSignedTransaction(transactionJson); - + var result = await getParachainSignedTransaction(transactionJson) + set_command_name("getParachainSignedTransaction") resp_editor.load(result) } async function getParachainXc20SignedTransaction_clicked() { - set_command_name("Processing..."); + set_command_name("Processing...") + var transactionJson = { coinType: dcent.coinType.PARA_XC20, sigHash: '0x240817030000000000000001003ec746fb0d6d9d66245d6dc6c02d23b1b290821d8674865f96c03ef86d9d690d1733c42f5578e4495b038923000048000000020000009eb76c5184c4ab8679d2d5d819fdf90b9c001403e9e17da2e14b6d8aec4029c697111d520df41d8ff1801aa6532c0c3b80ff986adf37476846b0e7e09993b7af', @@ -1165,12 +1183,48 @@
Response
feeSymbol: 'ASTR', feeDecimals: 18, } - var result = await getParachainSignedTransaction(transactionJson); - + var result = await getParachainSignedTransaction(transactionJson) + set_command_name("getParachainXc20SignedTransaction") resp_editor.load(result) } + async function getEthereumSignedTransactionForAstarEVM_clicked() { + set_command_name("Processing...") + + var result = await getEthereumSignedTransaction( + dcent.coinType.ETHEREUM, + '8', + '2400000000', + '210000', + '0x354609C4c9a15d4265cF6D94010568D5Cf4d0c1B', + '100000000000000000', + '0x', + "m/44'/60'/0'/0/0", + 592, + ) + + set_command_name("getEthereumSignedTransaction for Astar EVM") + resp_editor.load(result) + } + + async function getTokenSignedTransactionForAstarEVM_clicked() { + set_command_name("Processing...") + + var contract = { + name: 'Wrapped Astar', + address: '0xAeaaf0e2c81Af264101B9129C00F4440cCF0F720', + to: '0x354609C4c9a15d4265cF6D94010568D5Cf4d0c1B', + decimals: 18, + value: '100000000000000000', + symbol: 'WASTR', + } + var result = await getTokenSignedTransaction( dcent.coinType.ERC20, '21', '2400000000', '1000000', "m/44'/60'/0'/0/0", 592, contract ) + + set_command_name("getTokenSignedTransaction for Astar EVM") + resp_editor.load(result) + } + /////// DCENT WEB-SDK call async function info() { diff --git a/info/supported_union_info.json b/info/supported_union_info.json index 96430e6..fc2da58 100644 --- a/info/supported_union_info.json +++ b/info/supported_union_info.json @@ -89,18 +89,18 @@ }, { "name": "para", - "supportVersion": "2.30.0" + "supportVersion": "2.30.1" }, { "name": "para-testnet", - "supportVersion": "2.30.0" + "supportVersion": "2.30.1" }, { "name": "para-xc20", - "supportVersion": "2.30.0" + "supportVersion": "2.30.1" }, { "name": "para-xc20-tesetnet", - "supportVersion": "2.30.0" + "supportVersion": "2.30.1" } ] \ No newline at end of file diff --git a/src/index.js b/src/index.js index c73f90a..5283ce9 100644 --- a/src/index.js +++ b/src/index.js @@ -1552,7 +1552,9 @@ dcent.getParachainSignedTransaction = async function ({ params }) - res.body.parameter.signed_tx = '0x00' + (res.body.parameter.signed_tx.startsWith('0x') ? res.body.parameter.signed_tx.substr(2) : res.body.parameter.signed_tx) + if (res.header.status === 'success') { + res.body.parameter.signed_tx = '0x00' + (res.body.parameter.signed_tx.startsWith('0x') ? res.body.parameter.signed_tx.substr(2) : res.body.parameter.signed_tx) + } return res }