Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apl 2090 create apollo web crypto doc #2

Open
wants to merge 4 commits into
base: stage
Choose a base branch
from

Conversation

0486
Copy link
Member

@0486 0486 commented Oct 12, 2021

No description provided.

@@ -0,0 +1 @@
<html><head><meta content="text/html; charset=UTF-8" http-equiv="content-type"><style type="text/css">@import url('https://themes.googleusercontent.com/fonts/css?kit=lhDjYqiy3mZ0x6ROQEUoUw');ol{margin:0;padding:0}table td,table th{padding:0}.c13{border-right-style:solid;padding:5pt 5pt 5pt 5pt;border-bottom-color:#000000;border-top-width:0pt;border-right-width:0pt;border-left-color:#000000;vertical-align:top;border-right-color:#000000;border-left-width:0pt;border-top-style:solid;background-color:#333333;border-left-style:solid;border-bottom-width:0pt;width:468pt;border-top-color:#000000;border-bottom-style:solid}.c7{color:#000000;font-weight:400;text-decoration:none;vertical-align:baseline;font-size:16pt;font-family:"Arial";font-style:normal}.c3{padding-top:18pt;padding-bottom:6pt;line-height:1.15;page-break-after:avoid;orphans:2;widows:2;text-align:left}.c8{padding-top:16pt;padding-bottom:4pt;line-height:1.15;page-break-after:avoid;orphans:2;widows:2;text-align:left}.c9{color:#000000;font-weight:400;text-decoration:none;vertical-align:baseline;font-size:11pt;font-family:"Arial";font-style:normal}.c0{color:#000000;font-weight:400;text-decoration:none;vertical-align:baseline;font-size:11pt;font-family:"Courier New";font-style:normal}.c23{color:#000000;font-weight:400;text-decoration:none;vertical-align:baseline;font-size:20pt;font-family:"Arial";font-style:normal}.c22{padding-top:20pt;padding-bottom:6pt;line-height:1.15;page-break-after:avoid;orphans:2;widows:2;text-align:left}.c20{color:#434343;font-weight:400;text-decoration:none;vertical-align:baseline;font-size:14pt;font-family:"Arial";font-style:normal}.c2{padding-top:0pt;padding-bottom:0pt;line-height:1.15;orphans:2;widows:2;text-align:left}.c19{background-color:#333333;font-family:"Consolas";color:#888888;font-weight:400}.c11{background-color:#333333;font-family:"Consolas";color:#ffffaa;font-weight:400}.c14{background-color:#333333;font-family:"Consolas";color:#a2fca2;font-weight:400}.c6{background-color:#333333;font-family:"Consolas";color:#fcc28c;font-weight:400}.c4{background-color:#333333;font-family:"Consolas";color:#ffffff;font-weight:400}.c12{padding-top:0pt;padding-bottom:0pt;line-height:1.15;text-align:left}.c10{border-spacing:0;border-collapse:collapse;margin-right:auto}.c17{background-color:#333333;font-family:"Consolas";color:#d36363;font-weight:400}.c18{text-decoration:none;vertical-align:baseline;font-size:11pt;font-style:normal}.c16{background-color:#ffffff;max-width:468pt;padding:72pt 72pt 72pt 72pt}.c15{font-weight:400;font-family:"Courier New"}.c1{height:0pt}.c5{height:11pt}.c21{height:0.6pt}.title{padding-top:0pt;color:#000000;font-size:26pt;padding-bottom:3pt;font-family:"Arial";line-height:1.15;page-break-after:avoid;orphans:2;widows:2;text-align:left}.subtitle{padding-top:0pt;color:#666666;font-size:15pt;padding-bottom:16pt;font-family:"Arial";line-height:1.15;page-break-after:avoid;orphans:2;widows:2;text-align:left}li{color:#000000;font-size:11pt;font-family:"Arial"}p{margin:0;color:#000000;font-size:11pt;font-family:"Arial"}h1{padding-top:20pt;color:#000000;font-size:20pt;padding-bottom:6pt;font-family:"Arial";line-height:1.15;page-break-after:avoid;orphans:2;widows:2;text-align:left}h2{padding-top:18pt;color:#000000;font-size:16pt;padding-bottom:6pt;font-family:"Arial";line-height:1.15;page-break-after:avoid;orphans:2;widows:2;text-align:left}h3{padding-top:16pt;color:#434343;font-size:14pt;padding-bottom:4pt;font-family:"Arial";line-height:1.15;page-break-after:avoid;orphans:2;widows:2;text-align:left}h4{padding-top:14pt;color:#666666;font-size:12pt;padding-bottom:4pt;font-family:"Arial";line-height:1.15;page-break-after:avoid;orphans:2;widows:2;text-align:left}h5{padding-top:12pt;color:#666666;font-size:11pt;padding-bottom:4pt;font-family:"Arial";line-height:1.15;page-break-after:avoid;orphans:2;widows:2;text-align:left}h6{padding-top:12pt;color:#666666;font-size:11pt;padding-bottom:4pt;font-family:"Arial";line-height:1.15;page-break-after:avoid;font-style:italic;orphans:2;widows:2;text-align:left}</style></head><body class="c16"><h1 class="c22" id="h.vp1iv35cz2m7"><span class="c23">Apollo Web Crypto typescript library</span></h1><h2 class="c3" id="h.y24qtcnfpfsy"><span class="c7">Introduction</span></h2><p class="c2"><span class="c9">Apollo web crypto library is used for offline transaction processing - create and sign transactions with no secretPhrase or secret key disclosing in communication with Apollo Blockchain node.</span></p><p class="c2 c5"><span class="c9"></span></p><h2 class="c3" id="h.g30nw3unjyhm"><span class="c7">Quick Start Guide</span></h2><h3 class="c8" id="h.eqp10lcsk8ku"><span class="c20">Installation</span></h3><p class="c2 c5"><span class="c9"></span></p><p class="c2"><span>First, You need to install the apl-web-crypto</span><span class="c15">&nbsp;</span><span class="c9">nodejs package.</span></p><p class="c2 c5"><span class="c0"></span></p><p class="c2"><span class="c0">npm install apl-web-crypto</span></p><p class="c2 c5"><span class="c0"></span></p><p class="c2"><span class="c9">Second, we need to configure the Apollo Node we have to use.</span></p><p class="c2"><span class="c9">Apollo web crypto uses dotenv module for configuration:</span></p><h3 class="c8" id="h.97uxxxwbsp64"><span>Project setup</span></h3><p class="c2"><span>Create a</span><span class="c15">&nbsp;.env </span><span class="c9">file at the root of the project add the following line into it.</span></p><p class="c2 c5"><span class="c0"></span></p><a id="t.d9dae14da08ed2b33ee7c11a5b34a9ff694e49a5"></a><a id="t.0"></a><table class="c10"><tbody><tr class="c1"><td class="c13" colspan="1" rowspan="1"><p class="c12"><span class="c4">APL_SERVER=https:</span><span class="c19">//wallet.test.apollowallet.org</span></p></td></tr></tbody></table><p class="c2 c5"><span class="c0"></span></p><p class="c2"><span class="c9">Then we will create an example JavaScript file, simpleTransactionSign.js</span></p><p class="c2"><span>Add following lines into simpleTransactionSign.js file</span><span class="c0">&nbsp;</span></p><p class="c2 c5"><span class="c0"></span></p><a id="t.ada6b36c7f517d6363759ee5bda8cf13dd2e225a"></a><a id="t.1"></a><table class="c10"><tbody><tr class="c1"><td class="c13" colspan="1" rowspan="1"><p class="c12"><span class="c6">import</span><span class="c4">&nbsp;{ Transaction } </span><span class="c6">from</span><span class="c4">&nbsp;</span><span class="c14">&quot;apl-web-crypto&quot;</span><span class="c4">;<br></span><span class="c11">require</span><span class="c4">(</span><span class="c14">&quot;dotenv&quot;</span><span class="c4">).config()</span></p></td></tr></tbody></table><p class="c2 c5"><span class="c0"></span></p><h3 class="c8" id="h.hd4r8eso1kyr"><span>Transaction creation</span></h3><p class="c2"><span class="c9">To create transactions in Apollo, we have to add to transaction data several fields. In this document, we will use sendMoney transaction. For sendMoney, we have to fill following fields: amountATM, deadline, recipient, feeATM. One of publicKey or secretPhrase. For offline signing, we do not want to disclose our secretPhrase, so we will fill publicKey. It has to be sender&rsquo;s publicKey</span></p><p class="c2 c5"><span class="c9"></span></p><a id="t.fa906cc147294db76354052cbc84c384e8d9b4cb"></a><a id="t.2"></a><table class="c10"><tbody><tr class="c1"><td class="c13" colspan="1" rowspan="1"><p class="c12"><span class="c19">// Apollo has 8 decimals</span><span class="c4"><br></span><span class="c6">const</span><span class="c4">&nbsp;ONE_APL = </span><span class="c17">100000000</span><span class="c4">;<br></span><span class="c6">const</span><span class="c4">&nbsp;data = {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;requestType: </span><span class="c14">&#39;sendMoney&#39;</span><span class="c4">,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;publicKey: </span><span class="c14">&quot;24a88cc13c9a3a9f06c636b58c5b607fcb7cff14d449325691fa448933e6b870&quot;</span><span class="c4">,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;amountATM: </span><span class="c17">2</span><span class="c4">&nbsp;* ONE_APL,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;feeATM: ONE_APL,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;deadline: </span><span class="c17">60</span><span class="c4">,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;recipient: </span><span class="c14">&quot;APL-RQTU-56W2-AAMY-7MTLB&quot;</span><span class="c4"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};</span></p></td></tr></tbody></table><p class="c2 c5"><span class="c0"></span></p><h3 class="c8" id="h.yf9jnrvaerr7"><span>Get not signed transaction bytes</span></h3><p class="c2"><span class="c9">At first, we can get Transaction Bytes from the server, and then we will perform offline signing. Note, that this way we can get Transaction Bytes for any transaction type.</span></p><p class="c2 c5"><span class="c9"></span></p><a id="t.db16cb23db65f0290c48246686c5bf70431f7b60"></a><a id="t.3"></a><table class="c10"><tbody><tr class="c1"><td class="c13" colspan="1" rowspan="1"><p class="c12"><span class="c19">// function notSign used to get transaction bytes without </span><span class="c4"><br></span><span class="c19">// signing</span><span class="c4"><br></span><span class="c6">async</span><span class="c4">&nbsp;</span><span class="c6">function</span><span class="c4">&nbsp;</span><span class="c11">getNotSignedData</span><span class="c4">(data)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="c6">const</span><span class="c4">&nbsp;result = </span><span class="c6">await</span><span class="c4">&nbsp;Transaction.sendNotSign(data);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="c6">return</span><span class="c4">&nbsp;result;<br>}<br><br></span><span class="c6">let</span><span class="c4">&nbsp;unsignedTransactionData = getNotSignedData(data)<br>.then(unsignedResponse =&gt; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="c19">/* process unsigned transaction here */</span><span class="c4"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="c11">console</span><span class="c4">.log(unsignedResponse);<br>}).catch();</span></p></td></tr></tbody></table><p class="c2 c5"><span class="c0"></span></p><p class="c2"><span class="c9">This way we will get unsigned transaction data from the server.</span></p><h3 class="c8" id="h.7dow9o7bfwia"><span>Sign transaction</span></h3><p class="c2 c5"><span class="c0"></span></p><p class="c2"><span class="c9">To sign transaction we have to add sign function:</span></p><p class="c2 c5"><span class="c0"></span></p><a id="t.b7799e3b3e1c4299abadc212a2845193fbf2953b"></a><a id="t.4"></a><table class="c10"><tbody><tr class="c1"><td class="c13" colspan="1" rowspan="1"><p class="c12"><span class="c6">async</span><span class="c4">&nbsp;</span><span class="c6">function</span><span class="c4">&nbsp;</span><span class="c11">sign</span><span class="c4">(secretPhrase, unsignedResponse)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="c6">const</span><span class="c4">&nbsp;sendData = &nbsp;{secretPhrase: secretPhrase };<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="c6">const</span><span class="c4">&nbsp;result = </span><span class="c6">await</span><span class="c4">&nbsp;Transaction.processOfflineSign(sendData, unsignedResponse);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="c6">return</span><span class="c4">&nbsp;result;<br>}</span></p></td></tr></tbody></table><p class="c2 c5"><span class="c0"></span></p><p class="c2"><span class="c9">Then, we can modify the code, to add transaction signing, and processing (broadcast):</span></p><p class="c2 c5"><span class="c9"></span></p><a id="t.04787b757644cf7213a025f74ca01c8aadc0b4c2"></a><a id="t.5"></a><table class="c10"><tbody><tr class="c1"><td class="c13" colspan="1" rowspan="1"><p class="c12"><span class="c4">getNotSignedData(data)<br>.then(unsignedResponse =&gt; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="c19">/* process unsigned transaction here */</span></p><p class="c12"><span class="c11">&nbsp; &nbsp; &nbsp; console</span><span class="c4">.log(unsignedResponse);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sign(</span><span class="c14">&quot;10&quot;</span><span class="c4">, unsignedResponse).then(signedBytes =&gt; {<br> &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;</span><span class="c19">/* process signed transaction here */</span></p><p class="c12"><span class="c11">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console</span><span class="c4">.log(signedBytes);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}).catch();<br> <br>}).catch();</span></p></td></tr><tr class="c21"><td class="c13" colspan="1" rowspan="1"><p class="c12 c5"><span class="c4 c18"></span></p></td></tr></tbody></table><p class="c2 c5"><span class="c9"></span></p><p class="c2 c5"><span class="c9"></span></p><p class="c2 c5"><span class="c0"></span></p><p class="c2 c5"><span class="c9"></span></p><p class="c2 c5"><span class="c0"></span></p><p class="c2 c5"><span class="c0"></span></p><p class="c2 c5"><span class="c9"></span></p><p class="c2 c5"><span class="c9"></span></p><p class="c2 c5"><span class="c9"></span></p><p class="c2 c5"><span class="c9"></span></p></body></html>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double dot in file name - .......tlibrary..html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants