Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #104 from klaytn/release/v1.2.0
Browse files Browse the repository at this point in the history
[Master] release/v1.2.0 QA Sign-off
  • Loading branch information
jimni1222 authored Oct 21, 2019
2 parents d225637 + 7b21d3f commit cc42ffe
Show file tree
Hide file tree
Showing 56 changed files with 13,269 additions and 1,764 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ $ npm install [email protected]

Getting Started
=================
If you want to run your own EN (Endpoint Node), see [EN Operation Guide](https://docs.klaytn.com/node/en) to set up. You can also use Klaytn Public EN like below:
If you want to run your own EN (Endpoint Node), see [EN Operation Guide](https://docs.klaytn.com/node/endpoint-node) to set up. You can also use Klaytn Public EN like below:
```
$ node
> const Caver = require('caver-js')
Expand All @@ -73,8 +73,8 @@ Klaytn/vX.X.X/linux-amd64/goX.X.X

## Using caver-js account/wallet
You can easily manage your account by using the account / wallet packages provided by caver-js.
[caver.klay.accounts](https://docs.klaytn.com/sdk/caverjs/caver.klay.accounts) package provides functions related to accounts, such as create, signTransaction, and privateKeyToAccount.
[caver.klay.accounts.wallet](https://docs.klaytn.com/sdk/caverjs/caver.klay.accounts#wallet) provides the **in-memory wallet** for easy account management in caver-js.
[caver.klay.accounts](https://docs.klaytn.com/bapp/sdk/caver-js/api-references/caver.klay.accounts) package provides functions related to accounts, such as create, signTransaction, and privateKeyToAccount.
[caver.klay.accounts.wallet](https://docs.klaytn.com/bapp/sdk/caver-js/api-references/caver.klay.accounts#wallet) provides the **in-memory wallet** for easy account management in caver-js.

**Note** Functions associated with wallet and account provided by caver-js have no effect on the actual Klaytn network.

Expand All @@ -101,7 +101,7 @@ You can add to the wallet instance of caver-js using the account object created
```

caver-js supports two types of private key formats.
One is a raw private key format of a 32-byte string type and the other is the [KlaytnWalletKey](https://docs.klaytn.com/klaytn/design/account#klaytn-wallet-key-format).
One is a raw private key format of a 32-byte string type and the other is the [KlaytnWalletKey](https://docs.klaytn.com/klaytn/design/accounts#klaytn-wallet-key-format).

You can also add your account using the KlaytnWalletKey format as shown below:
```
Expand All @@ -121,7 +121,7 @@ The private key that matches a specific account stored in the wallet instance ca
```

## Submitting a Transaction
You can use caver-js to submit various types of transactions to a node. Please refer to the [caver.klay.sendTransaction](https://docs.klaytn.com/sdk/caverjs/caver.klay/transaction#sendtransaction) to see how to send a transaction of each type.
You can use caver-js to submit various types of transactions to a node. Please refer to the [caver.klay.sendTransaction](https://docs.klaytn.com/bapp/sdk/caver-js/api-references/caver.klay/transaction#sendtransaction) to see how to send a transaction of each type.

You can submit the transaction as shown below, and the result can be confirmed by the returned receipt:
```
Expand Down Expand Up @@ -207,19 +207,19 @@ caver-js provides the caver.utils.toPeb function for unit conversion. Please ref
Documentation
=================

Documentation can be found at [Klaytn Docs-caver-js](https://docs.klaytn.com/sdk/caverjs).
Documentation can be found at [Klaytn Docs-caver-js](https://docs.klaytn.com/bapp/sdk/caver-js).

API Specification
=================

The API lists of caver-js are described in folloinwg links:

* [caver.klay](https://docs.klaytn.com/sdk/caverjs/caver.klay)
* [caver.klay.accounts](https://docs.klaytn.com/sdk/caverjs/caver.klay.accounts)
* [caver.klay.contract](https://docs.klaytn.com/sdk/caverjs/caver.klay.contract)
* [caver.klay.net](https://docs.klaytn.com/sdk/caverjs/caver.klay.net)
* [caver.klay.abi](https://docs.klaytn.com/sdk/caverjs/caver.klay.abi)
* [caver.utils](https://docs.klaytn.com/sdk/caverjs/caver.utils)
* [caver.klay](https://docs.klaytn.com/bapp/sdk/caver-js/api-references/caver.klay)
* [caver.klay.accounts](https://docs.klaytn.com/bapp/sdk/caver-js/api-references/caver.klay.accounts)
* [caver.klay.contract](https://docs.klaytn.com/bapp/sdk/caver-js/api-references/caver.klay.contract)
* [caver.klay.net](https://docs.klaytn.com/bapp/sdk/caver-js/api-references/caver.klay.net)
* [caver.klay.abi](https://docs.klaytn.com/bapp/sdk/caver-js/api-references/caver.klay.abi)
* [caver.utils](https://docs.klaytn.com/bapp/sdk/caver-js/api-references/caver.utils)


Web3.js Similarity
Expand Down Expand Up @@ -297,8 +297,8 @@ Sample Projects

The BApp (Blockchain Application) Development sample projects using caver-js are the following:

* [Count BApp](https://docs.klaytn.com/tutorials/countbapp)
* [Klaystagram](https://docs.klaytn.com/tutorials/klaystagram)
* [Count BApp](https://docs.klaytn.com/bapp/tutorials/count-bapp)
* [Klaystagram](https://docs.klaytn.com/bapp/tutorials/klaystagram)

Github Repository
=================
Expand Down
21 changes: 15 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"name": "caver-js",
"version": "1.1.2",
"version": "1.2.0",
"description": "caver-js is a JavaScript API library that allows developers to interact with a Klaytn node",
"main": "index.js",
"scripts": {
"test": "npm run build && mocha test/packages/caver.klay.utils.js && mocha test/packages/caver.klay.net.js && npm run serTest && npm run walletTest",
"test": "npm run build && mocha test/packages/caver.utils.js && mocha test/packages/caver.klay.net.js && npm run serTest && npm run walletTest",
"build-all": "gulp all",
"build": "gulp default",
"serTest": "mocha test/transactionType/serializationTest.js && mocha test/compressPublicKey.js && mocha test/encodeContractDeploy.js && mocha test/isCompressedPublicKey.js && mocha test/parseAccountKey.js",
"serTest": "mocha test/transactionType/serializationTest.js && mocha test/compressPublicKey.js && mocha test/encodeContractDeploy.js && mocha test/isCompressedPublicKey.js && mocha test/parseAccountKey.js && mocha test/decodeTransaction.js",
"walletTest": "mocha test/accountLib.js && mocha test/accounts.privateKeyToPublicKey.js && mocha test/accounts.recover.js && mocha test/packages/caver.klay.accounts.js && mocha test/getKlaytnWalletKey.js && mocha test/isValidPrivateKey.js && mocha test/privateKeyToAccount.js",
"txTest": "mocha test/estimateComputationCost.js && mocha test/getTransactionReceipt.js && mocha test/getTransaction.js && mocha test/setContractOptions.js && mocha test/encodeContractDeploy.js && mocha test/accounts.signTransaction.js && mocha test/transactionType/legacyTransaction.js && mocha test/transactionType/valueTransfer* && mocha test/transactionType/accountUpdate.js && mocha test/transactionType/contract* && mocha test/transactionType/cancelTransaction.js && mocha test/transactionType/feeDelegated*",
"etcTest": "mocha test/confirmationListener.js && mocha test/hashMessage.js && mocha test/iban.* && mocha test/randomHex.js && mocha test/sha3.js && mocha test/toChecksumAddress.js && mocha test/unitMap.js && mocha test/default* && mocha test/getNodeInfo.js && mocha test/eventEmitter.js && mocha test/packages/caver.klay.net.js && mocha test/getNetworkType.js && mocha test/invalidResponse.js && mocha test/isContractDeployment.js && mocha test/personal.js && mocha test/multiProviderTest.js && mocha test/subscription.js && mocha test/supportsSubscriptions.js && mocha test/contract.once.js",
"txTest": "mocha test/sendSignedTransaction.js && mocha test/estimateComputationCost.js && mocha test/getTransactionReceipt.js && mocha test/getTransaction.js && mocha test/setContractOptions.js && mocha test/encodeContractDeploy.js && mocha test/accounts.signTransaction.js && mocha test/sendTransactionCallback.js && mocha test/signWithMultiSig.js && mocha test/transactionType/legacyTransaction.js && mocha test/transactionType/valueTransfer* && mocha test/transactionType/accountUpdate.js && mocha test/transactionType/contract* && mocha test/transactionType/cancelTransaction.js && mocha test/transactionType/feeDelegated*",
"etcTest": "mocha test/packages/caver.utils.js && mocha test/confirmationListener.js && mocha test/hashMessage.js && mocha test/iban.* && mocha test/randomHex.js && mocha test/sha3.js && mocha test/toChecksumAddress.js && mocha test/unitMap.js && mocha test/default* && mocha test/getNodeInfo.js && mocha test/eventEmitter.js && mocha test/packages/caver.klay.net.js && mocha test/getNetworkType.js && mocha test/invalidResponse.js && mocha test/isContractDeployment.js && mocha test/personal.js && mocha test/multiProviderTest.js && mocha test/subscription.js && mocha test/supportsSubscriptions.js && mocha test/contract.once.js && mocha test/setProvider.js",
"accountKeyTest": "mocha test/scenarioTest/accountKeyPublic.js && mocha test/scenarioTest/accountKeyMultiSig.js && mocha test/scenarioTest/accountKeyRoleBased.js",
"intTxTest": "npm run intLEGACYTest && npm run intVTTest && npm run intVTMTest && npm run intACCUPTest && npm run intDEPLTest && npm run intEXETest && npm run intCANCELTest && npm run intFDTest && npm run intFDRTest",
"intLEGACYTest": "mocha --grep INT-LEGACY/ test/intTest.js",
"intVTTest": "mocha --grep INT-VT/ test/intTest.js",
Expand All @@ -33,6 +34,14 @@
"klaytn sdk",
"klaytn api"
],
"repository": {
"type": "git",
"url": "https://github.com/klaytn/caver-js.git"
},
"bugs": {
"url": "https://github.com/klaytn/caver-js/issues"
},
"homepage": "https://github.com/klaytn/caver-js",
"author": "Klaytn Team",
"license": "LGPL",
"dependencies": {
Expand All @@ -55,7 +64,7 @@
"oboe": "2.1.3",
"request": "2.87.0",
"requestretry": "^2.0.2",
"scrypt.js": "0.2.0",
"scryptsy": "2.1.0",
"underscore": "^1.9.1",
"utf8": "2.1.1",
"uuid": "2.0.1",
Expand Down
22 changes: 10 additions & 12 deletions packages/caver-core-helpers/src/formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ var _txInputFormatter = function (options){
if (options.to) {
options.humanReadable = options.humanReadable !== undefined? options.humanReadable : false
if (options.humanReadable) throw new Error('HumanReadableAddress is not supported yet.')
options.to = inputAddressFormatter(options.to)
if (!utils.isContractDeployment(options) || options.to !== '0x') {
options.to = inputAddressFormatter(options.to)
}
}

if (options.data && options.input) {
Expand Down Expand Up @@ -140,12 +142,9 @@ var inputTransactionFormatter = function (options) {

options = _txInputFormatter(options);

// If 'feePayer' or 'senderRawTransaction' exist in transaction, it means it doesn't need 'from' field.
if (options.feePayer || options.senderRawTransaction) {
if (options.senderRawTransaction === undefined) {
throw new Error('The "senderRawTransaction" field must be defined for signing with feePayer!');
}

// If senderRawTransaction' exist in transaction, it means object is fee payer transaction format like below
// { senderRawTransaction: '', feePayer: '' }
if (options.senderRawTransaction) {
if (options.feePayer === undefined) {
throw new Error('The "feePayer" field must be defined for signing with feePayer!');
}
Expand All @@ -164,8 +163,8 @@ var inputTransactionFormatter = function (options) {
options.from = inputAddressFormatter(options.from);
}

if (options.data && options.data.slice(0, 2) !== '0x') {
options.data = '0x' + options.data
if (options.data) {
options.data = utils.addHexPrefix(options.data)
}

const err = validateParams(options)
Expand Down Expand Up @@ -198,8 +197,8 @@ var inputPersonalTransactionFormatter = function (options) {
options.from = inputAddressFormatter(options.from);
}

if (options.data && options.data.slice(0, 2) !== '0x') {
options.data = '0x' + options.data
if (options.data) {
options.data = utils.addHexPrefix(options.data)
}

return options;
Expand Down Expand Up @@ -474,7 +473,6 @@ var outputPostFormatter = function(post){
};

var inputAddressFormatter = function (address) {

var iban = new utils.Iban(address);
if (iban.isValid() && iban.isDirect()) {
return iban.toAddress().toLowerCase();
Expand Down
58 changes: 51 additions & 7 deletions packages/caver-core-helpers/src/validateFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,50 @@
* @return {Error}
*/

const VALID_GAS_PRICE = require('./constants').VALID_GAS_PRICE
var utils = require('../../caver-utils')

function validateParams (tx) {
let error

// validate for fee payer transaction format
if (tx.senderRawTransaction) {
if (!tx.feePayer || tx.feePayer === '0x') {
error = new Error(`Invalid fee payer: ${tx.feePayer}`)
} else if (!utils.isAddress(tx.feePayer)) {
error = new Error(`Invalid address of fee payer: ${tx.feePayer}`)
}
return error
}

const isValidateType = validateTxType(tx.type)
if (!isValidateType) {
return new Error('The transaction type [' + tx.type + '] is not supported')
}

var error = validateTxObjectWithType(tx)
error = validateTxObjectWithType(tx)
if (error !== undefined) {
return error
}

if (!tx.from) {
error = new Error('"from" is missing')
} else if (!utils.isAddress(tx.from)) {
error = new Error(`Invalid address of from: ${tx.from}`)
} else if (tx.gas === undefined && tx.gasLimit === undefined) {
error = new Error('"gas" is missing')
} else if (tx.nonce < 0 || tx.gas < 0 || tx.gasPrice < 0 || tx.chainId < 0) {
error = new Error('gas, gasPrice, nonce or chainId is lower than 0')
// } else if (tx.gasPrice !== undefined && tx.gasPrice != VALID_GAS_PRICE) {
// error = new Error(`GasPrice should be a 25Gpeb(${VALID_GAS_PRICE})`);
}

// If feePayerSignatures is set in transaction object, feePayer also should be defined together.
if (tx.feePayerSignatures && !utils.isEmptySig(tx.feePayerSignatures)) {
if (!tx.feePayer || tx.feePayer === '0x') {
error = new Error(`"feePayer" is missing: feePayer must be defined with feePayerSignatures.`)
} else if (!utils.isAddress(tx.feePayer)) {
error = new Error(`Invalid address of fee payer: ${tx.feePayer}`)
}
}

return error
}

Expand Down Expand Up @@ -103,6 +124,8 @@ function validateParams (tx) {
switch (cf) {
case 0:
case 'EVM':
case '0x':
case '0x0':
return true
}
return false
Expand Down Expand Up @@ -159,6 +182,11 @@ function validateParams (tx) {
if (transaction.to === undefined && transaction.data === undefined) {
return new Error('contract creation without any data provided')
}

if (transaction.to && transaction.to !== '0x' && !utils.isAddress(transaction.to)) {
return new Error(`Invalid address of to: ${transaction.to}`)
}

if (transaction.codeFormat !== undefined) {
return new Error('"codeFormat" cannot be used with LEGACY transaction')
}
Expand All @@ -177,6 +205,9 @@ function validateParams (tx) {
if (transaction.feeRatio !== undefined) {
return new Error('"feeRatio" cannot be used with '+type+' transaction')
}
if (transaction.feePayerSignatures !== undefined) {
return new Error('"feePayerSignatures" cannot be used with '+type+' transaction')
}
}

function validateFeeDelegated(transaction) {
Expand All @@ -193,6 +224,9 @@ function validateParams (tx) {

function validateNotAccountTransaction(transaction) {
const type = transaction.type? transaction.type : 'LEGACY'
if (transaction.key !== undefined) {
return new Error('"key" cannot be used with '+type+' transaction')
}
if (transaction.legacyKey !== undefined) {
return new Error('"legacyKey" cannot be used with '+type+' transaction')
}
Expand All @@ -219,6 +253,8 @@ function validateParams (tx) {
function checkValueTransferEssential(transaction) {
if (transaction.to === undefined) {
return new Error('"to" is missing')
} else if (!utils.isAddress(transaction.to)) {
return new Error(`Invalid address of to: ${transaction.to}`)
}
if (transaction.value === undefined) {
return new Error('"value" is missing')
Expand Down Expand Up @@ -258,6 +294,8 @@ function validateParams (tx) {
function checkValueTransferMemoEssential(transaction) {
if (transaction.to === undefined) {
return new Error('"to" is missing')
} else if (!utils.isAddress(transaction.to)) {
return new Error(`Invalid address of to: ${transaction.to}`)
}
if (transaction.value === undefined) {
return new Error('"value" is missing')
Expand Down Expand Up @@ -302,12 +340,16 @@ function validateParams (tx) {
return new Error('"codeFormat" cannot be used with '+transaction.type+' transaction')
}

if (transaction.legacyKey === undefined && !transaction.publicKey && !transaction.multisig && !transaction.roleTransactionKey && !transaction.roleAccountUpdateKey && !transaction.roleFeePayerKey && transaction.failKey === undefined) {
if (!transaction.key && transaction.legacyKey === undefined && !transaction.publicKey && !transaction.multisig && !transaction.roleTransactionKey && !transaction.roleAccountUpdateKey && !transaction.roleFeePayerKey && transaction.failKey === undefined) {
return new Error('Missing key information with '+transaction.type+' transaction')
}

const duplicatedKeyInfo = 'The key parameter to be used for '+transaction.type+' is duplicated.'
if (transaction.legacyKey !== undefined) {
if (transaction.key) {
if (transaction.legacyKey !== undefined || transaction.publicKey || transaction.multisig || transaction.roleTransactionKey || transaction.roleAccountUpdateKey || transaction.roleFeePayerKey || transaction.failKey !== undefined) {
return new Error(duplicatedKeyInfo)
}
} else if (transaction.legacyKey !== undefined) {
if (transaction.publicKey || transaction.multisig || transaction.roleTransactionKey || transaction.roleAccountUpdateKey || transaction.roleFeePayerKey || transaction.failKey !== undefined) {
return new Error(duplicatedKeyInfo)
}
Expand Down Expand Up @@ -366,7 +408,7 @@ function validateParams (tx) {
if (transaction.data === undefined) {
return new Error('"data" is missing')
}
if (transaction.to !== undefined) {
if (transaction.to !== undefined && transaction.to !== '0x') {
return new Error('"to" cannot be used with '+transaction.type+' transaction')
}
if (transaction.codeFormat !== undefined && !validateCodeFormat(transaction.codeFormat)) {
Expand Down Expand Up @@ -401,6 +443,8 @@ function validateParams (tx) {
function checkExecutionEssential(transaction) {
if (transaction.to === undefined) {
return new Error('"to" is missing')
} else if (!utils.isAddress(transaction.to)) {
return new Error(`Invalid address of to: ${transaction.to}`)
}
if (transaction.data === undefined) {
return new Error('"data" is missing')
Expand Down
Loading

0 comments on commit cc42ffe

Please sign in to comment.