From 0929ef97df78232a3b57e555034a78c97d71a596 Mon Sep 17 00:00:00 2001 From: Eugene Luzgin Date: Tue, 16 Jun 2020 21:24:24 -0600 Subject: [PATCH 1/3] Fix all code sample formatting --- README.md | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index edcee64..edcd3e5 100644 --- a/README.md +++ b/README.md @@ -33,25 +33,29 @@ Make sure to install typescript by running, this command in terminal: # Using the SDK # Import if installing manually +``` const { Fio, Ecc } = require('fiojs'); - +``` # Import if using NPM package manager +``` const { Fio, Ecc } = require('@fioprotocol/fiojs'); - +``` # Errors Installing? if you don’t have tsc, install it, by navigating to terminal: +``` npm install -g typescript - +``` // Include textDecoder and textEncoder when using in Node, React Native, IE11 or Edge Browsers. +``` const { TextEncoder, TextDecoder } = require('util'); // node only; native TextEncoder/Decoder const { TextEncoder, TextDecoder } = require('text-encoding'); // React Native, IE11, and Edge Browsers only - +``` # How to Test The mock tests run under `npm run test` # prepareTransaction Client-side serialization and signing. It is recommended that the FIO TypeScript SDK is used for FIO API calls. But, instead, if you plan to use external RPC code. This is example RPC code, for use outside of the `Fio` JS Library instance: - +``` info = await rpc.get_info(); blockInfo = await rpc.get_block(info.last_irreversible_block_num); currentDate = new Date(); @@ -102,16 +106,16 @@ if (json.processed && json.processed.except) { } expect(Object.keys(json)).toContain('transaction_id'); - +``` # accountHash Hashes public key to an on-chain Fio account name. - +``` const accountHash = Fio.accountHash('FIO7bxrQUTbQ4mqcoefhWPz1aFieN4fA9RQAiozRz7FrUChHZ7Rb8'); expect(accountHash).toEqual('5kmx4qbqlpld'); - +``` # createSharedCipher The shared cipher class contains a secret used to encrypt and decrypt messages. For example, Alice sends a new_funds_request to Bob. In the `new_funds_request` there is a `content` field. The `content` field is encrypted by Alice and decrypted by Bob. - +``` newFundsContent = { payee_public_address: 'purse@alice', amount: '1.75', @@ -134,7 +138,7 @@ cipherAliceHex = cipherAlice.encrypt('new_funds_content', newFundsContent); cipherBob = Fio.createSharedCipher({privateKey: privateKeyBob, publicKey: publicKeyAlice, textEncoder: new TextEncoder(), textDecoder: new TextDecoder()}); newFundsContentBob = cipherBob.decrypt('new_funds_content', cipherAliceHex); expect(newFundsContentBob).toEqual(newFundsContent); - +``` See `src/encryption-fio.abi.json` for other message types like `new_funds_content`. # Message Encryption From ca3015b2f9731f727634464e5747264fb9900869 Mon Sep 17 00:00:00 2001 From: Son Nguyen Date: Tue, 6 Oct 2020 20:27:58 +0700 Subject: [PATCH 2/3] Fix readme example prepareTransaction not working --- README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index edcd3e5..32ee8cd 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ For information on the FIO Chain, API, and SDKs visit the [FIO Protocol Develope # Technology The FIOJS Library is built using tsc, to generate the JavaScript files. FIOJS is a utility/helper sdk used by the TypeScript SDK. This utility library provides encryption, packing and signing capabilities. Use the TypeScript SDK for FIO API support and private/public key creation. -# Version +# Version Visit the [FIO Protocol Developer Hub](https://developers.fioprotocol.io) to get information on FIO SDK versions. Only use an SDK that has a major version number that matches the current FIO Protocol blockchain major version number (e.g. 1.x.x). # Installing FIOJS Library, using npm: @@ -17,8 +17,8 @@ Visit the [FIO Protocol Developer Hub](https://developers.fioprotocol.io) to get # Building The FIOJS Library, manually #### Building FIOJS, manually -Navigate to the "fiojs" folder, run npm to install its dependencies, then run tsc to compile. - +Navigate to the "fiojs" folder, run npm to install its dependencies, then run tsc to compile. + cd fiojs npm install tsc @@ -27,7 +27,7 @@ Navigate to the "fiojs" folder, run npm to install its dependencies, then run ts ### Errors with compiling the SDKs #### Unable to find tsc Make sure to install typescript by running, this command in terminal: - + sudo npm install -g typescript # Using the SDK @@ -80,10 +80,11 @@ transaction = { permission: 'active', }], data: { - payeePublicKey: 'FIO5VE6Dgy9FUmd1mFotXwF88HkQN1KysCWLPqpVnDMjRvGRi1YrM', + payee_public_key: 'FIO5VE6Dgy9FUmd1mFotXwF88HkQN1KysCWLPqpVnDMjRvGRi1YrM', amount: '1000000000', - maxFee: 200000000, - technologyProviderId: '' + max_fee: 1000000000, + tpid: '', + actor: actorAccountHash }, }] }; From 3a48ceb3a1d47b3fc92c66a4de5a998f9b04192f Mon Sep 17 00:00:00 2001 From: Eric Butz <47221604+ericbutz@users.noreply.github.com> Date: Tue, 6 Oct 2020 11:30:55 -0600 Subject: [PATCH 3/3] Update JS example code in readme --- README.md | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 32ee8cd..90adf24 100644 --- a/README.md +++ b/README.md @@ -56,19 +56,19 @@ The mock tests run under `npm run test` # prepareTransaction Client-side serialization and signing. It is recommended that the FIO TypeScript SDK is used for FIO API calls. But, instead, if you plan to use external RPC code. This is example RPC code, for use outside of the `Fio` JS Library instance: ``` -info = await rpc.get_info(); -blockInfo = await rpc.get_block(info.last_irreversible_block_num); -currentDate = new Date(); -timePlusTen = currentDate.getTime() + 10000; -timeInISOString = (new Date(timePlusTen)).toISOString(); -expiration = timeInISOString.substr(0, timeInISOString.length - 1); +const info = await rpc.get_info(); +const blockInfo = await rpc.get_block(info.last_irreversible_block_num); +const currentDate = new Date(); +const timePlusTen = currentDate.getTime() + 10000; +const timeInISOString = (new Date(timePlusTen)).toISOString(); +const expiration = timeInISOString.substr(0, timeInISOString.length - 1); // hash the public key of the payer/sender const actorAccountHash = Fio.accountHash('FIO7bxrQUTbQ4mqcoefhWPz1aFieN4fA9RQAiozRz7FrUChHZ7Rb8'); expect(accountHash).toEqual('5kmx4qbqlpld'); // sending 1 FIO token using the trnsfiopubkey ACTION (1 FIO token = 1,000,000,000 SUFs) -transaction = { +const transaction = { expiration, ref_block_num: blockInfo.block_num & 0xffff, ref_block_prefix: blockInfo.ref_block_prefix, @@ -89,19 +89,18 @@ transaction = { }] }; -abiMap = new Map() -tokenRawAbi = await rpc.get_raw_abi('fio.token') +const abiMap = new Map() +const tokenRawAbi = await rpc.get_raw_abi('fio.token') abiMap.set('fio.token', tokenRawAbi) -tx = await Fio.prepareTransaction({transaction, chainId, privateKeys, abiMap, -textDecoder: new TextDecoder(), textEncoder: new TextEncoder()}); +const tx = await Fio.prepareTransaction({transaction, chainId, privateKeys, abiMap, textDecoder: new TextDecoder(), textEncoder: new TextEncoder()}); -pushResult = await fetch(httpEndpoint + '/v1/chain/push_transaction', { +const pushResult = await fetch(httpEndpoint + '/v1/chain/push_transaction', { body: JSON.stringify(tx), method: 'POST', }); -json = await pushResult.json() +const json = await pushResult.json() if (json.processed && json.processed.except) { throw new RpcError(json); }