diff --git a/CHANGELOG.md b/CHANGELOG.md index 193373dcd9..356109ee7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,29 @@ +# [6.1.0](https://github.com/aeternity/aepp-sdk-js/compare/6.0.2...6.1.0) (2019-11-11) + + +### Bug Fixes + +* **AENS:** auction end block calculation ([#746](https://github.com/aeternity/aepp-sdk-js/issues/746)) ([4c1f5e4](https://github.com/aeternity/aepp-sdk-js/commit/4c1f5e4)) +* **AENS:** Fix `produceNameId` function(Make name lowercase). Enable … ([#750](https://github.com/aeternity/aepp-sdk-js/issues/750)) ([fd14225](https://github.com/aeternity/aepp-sdk-js/commit/fd14225)) +* **state channels:** wait for connection to be established before sending generic message ([#723](https://github.com/aeternity/aepp-sdk-js/issues/723)) ([c5f35d1](https://github.com/aeternity/aepp-sdk-js/commit/c5f35d1)) +* **TxHelpers:** Use BigNumber in auction end block calculation ([777c012](https://github.com/aeternity/aepp-sdk-js/commit/777c012)) + + +### Features + +* **ACI:** Add validation for contractAddress ([#764](https://github.com/aeternity/aepp-sdk-js/issues/764)) ([07cb0e7](https://github.com/aeternity/aepp-sdk-js/commit/07cb0e7)) +* **AENS:** Add nameFee validation to TxValidator ([#765](https://github.com/aeternity/aepp-sdk-js/issues/765)) ([5250e75](https://github.com/aeternity/aepp-sdk-js/commit/5250e75)) +* **AENS:** Increase default nameTtl ([#775](https://github.com/aeternity/aepp-sdk-js/issues/775)) ([c5f2582](https://github.com/aeternity/aepp-sdk-js/commit/c5f2582)) +* **Contract:** Add ability to pass arguments or callData for contract `deploy/call/callStatic` API ([#768](https://github.com/aeternity/aepp-sdk-js/issues/768)) ([12aaca3](https://github.com/aeternity/aepp-sdk-js/commit/12aaca3)) +* **Http:** Assign error object to http error ([#770](https://github.com/aeternity/aepp-sdk-js/issues/770)) ([87062ea](https://github.com/aeternity/aepp-sdk-js/commit/87062ea)) +* **state channels:** add round method ([#763](https://github.com/aeternity/aepp-sdk-js/issues/763)) ([c950937](https://github.com/aeternity/aepp-sdk-js/commit/c950937)) +* **state channels:** allow off chain updates to be cancelled with custom error code ([#753](https://github.com/aeternity/aepp-sdk-js/issues/753)) ([ae4426e](https://github.com/aeternity/aepp-sdk-js/commit/ae4426e)) +* **state channels:** allow to pass metadata to transfer update ([#755](https://github.com/aeternity/aepp-sdk-js/issues/755)) ([ddc6611](https://github.com/aeternity/aepp-sdk-js/commit/ddc6611)) +* **state channels:** make state channels compatible with node v5.0.0… ([#688](https://github.com/aeternity/aepp-sdk-js/issues/688)) ([deed7fc](https://github.com/aeternity/aepp-sdk-js/commit/deed7fc)), closes [#632](https://github.com/aeternity/aepp-sdk-js/issues/632) [#653](https://github.com/aeternity/aepp-sdk-js/issues/653) [#658](https://github.com/aeternity/aepp-sdk-js/issues/658) [#660](https://github.com/aeternity/aepp-sdk-js/issues/660) [#680](https://github.com/aeternity/aepp-sdk-js/issues/680) [#693](https://github.com/aeternity/aepp-sdk-js/issues/693) [#687](https://github.com/aeternity/aepp-sdk-js/issues/687) +* **state channels:** make state channels compatible with node v5.1.0… ([#776](https://github.com/aeternity/aepp-sdk-js/issues/776)) ([74952aa](https://github.com/aeternity/aepp-sdk-js/commit/74952aa)) + + + ## [6.0.2](https://github.com/aeternity/aepp-sdk-js/compare/6.0.1...6.0.2) (2019-10-31) @@ -17,9 +43,6 @@ - - - # [6.0.0](https://github.com/aeternity/aepp-sdk-js/compare/4.7.0...6.0.0) (2019-10-16) diff --git a/docs/api/ae/contract.md b/docs/api/ae/contract.md index 8292ecb9e7..ca3a3ef4bc 100644 --- a/docs/api/ae/contract.md +++ b/docs/api/ae/contract.md @@ -21,7 +21,7 @@ import { Contract } from '@aeternity/aepp-sdk' (Using bundle) * [handleCallError(result)](#exp_module_@aeternity/aepp-sdk/es/ae/contract--handleCallError) ⇒ `Promise.<void>` ⏏ * [contractEncodeCall(source, name, args, [options])](#exp_module_@aeternity/aepp-sdk/es/ae/contract--contractEncodeCall) ⇒ `Promise.<String>` ⏏ * [contractDecodeData(source, fn, callValue, callResult, [options])](#exp_module_@aeternity/aepp-sdk/es/ae/contract--contractDecodeData) ⇒ `Promise.<String>` ⏏ - * [contractCallStatic(source, address, name, args, [options], bytecode, options, filesystem)](#exp_module_@aeternity/aepp-sdk/es/ae/contract--contractCallStatic) ⇒ `Promise.<Object>` ⏏ + * [contractCallStatic(source, address, name, args, [options])](#exp_module_@aeternity/aepp-sdk/es/ae/contract--contractCallStatic) ⇒ `Promise.<Object>` ⏏ * [contractCall(source, address, name, args, [options])](#exp_module_@aeternity/aepp-sdk/es/ae/contract--contractCall) ⏏ * [contractDeploy(code, source, initState, [options])](#exp_module_@aeternity/aepp-sdk/es/ae/contract--contractDeploy) ⇒ `Promise.<Object>` ⏏ * [contractCompile(source, [options])](#exp_module_@aeternity/aepp-sdk/es/ae/contract--contractCompile) ⇒ `Promise.<Object>` ⏏ @@ -118,7 +118,7 @@ const decodedData = await client.contractDecodeData(SourceCode ,'functionName', ``` -### contractCallStatic(source, address, name, args, [options], bytecode, options, filesystem) ⇒ `Promise.<Object>` ⏏ +### contractCallStatic(source, address, name, args, [options]) ⇒ `Promise.<Object>` ⏏ Static contract call(using dry-run) **Kind**: Exported function @@ -130,12 +130,12 @@ Static contract call(using dry-run) | source | `String` | | Contract source code | | address | `String` | | Contract address | | name | `String` | | Name of function to call | -| args | `Array` | | Argument's for call function | +| args | `Array` \| `String` | | Argument's or callData for call/deploy transaction | | [options] | `Object` | {} | Options | | [options.top] | `String` | | Block hash on which you want to call contract | -| bytecode | | | | -| options | `String` | | [options.options] Transaction options (fee, ttl, gas, amount, deposit) | -| filesystem | `Object` | | [options.options.filesystem] Contract external namespaces map | +| [options.bytecode] | `String` | | Block hash on which you want to call contract | +| [options.options] | `Object` | | Transaction options (fee, ttl, gas, amount, deposit) | +| [options.options.filesystem] | `Object` | | Contract external namespaces map | **Example** ```js @@ -158,7 +158,7 @@ Call contract function | source | `String` | | Contract source code | | address | `String` | | Contract address | | name | `String` | | Name of function to call | -| args | `Array` | | Argument's for call function | +| args | `Array` \| `String` | | Argument's or callData for call function | | [options] | `Object` | {} | Transaction options (fee, ttl, gas, amount, deposit) | | [options.filesystem] | `Object` | {} | Contract external namespaces map* @return {Promise} Result object | @@ -184,7 +184,7 @@ Deploy contract to the node | --- | --- | --- | --- | | code | `String` | | Compiled contract | | source | `String` | | Contract source code | -| initState | `Array` | | Arguments of contract constructor(init) function | +| initState | `Array` \| `String` | | Arguments of contract constructor(init) function. Can be array of arguments or callData string | | [options] | `Object` | {} | Transaction options (fee, ttl, gas, amount, deposit) | | [options.filesystem] | `Object` | {} | Contract external namespaces map* @return {Promise} Result object | diff --git a/docs/api/ae/oracle.md b/docs/api/ae/oracle.md index c8e45a528f..973f8131aa 100644 --- a/docs/api/ae/oracle.md +++ b/docs/api/ae/oracle.md @@ -16,7 +16,8 @@ import Oracle from '@aeternity/aepp-sdk/es/ae/oracle' * [Oracle([options])](#exp_module_@aeternity/aepp-sdk/es/ae/oracle--Oracle) ⇒ `Object` ⏏ * _instance_ * _async_ - * [.pollForQueries(oracleId, onQuery, [options])](#exp_module_@aeternity/aepp-sdk/es/ae/oracle--pollForQueries) ⇒ `function` ⏏ + * [.getOracleObject(oracleId)](#exp_module_@aeternity/aepp-sdk/es/ae/oracle--getOracleObject) ⇒ `Promise.<Object>` ⏏ + * [.pollForQueries(oracleId, onQuery, [options])](#exp_module_@aeternity/aepp-sdk/es/ae/oracle--exports.pollForQueries) ⇒ `function` ⏏ * [.getQueryObject(oracleId, queryId)](#exp_module_@aeternity/aepp-sdk/es/ae/oracle--getQueryObject) ⇒ `Promise.<Object>` ⏏ * [.exports.pollForQueryResponse(oracleId, queryId, [options])](#exp_module_@aeternity/aepp-sdk/es/ae/oracle--exports.pollForQueryResponse) ⇒ `Promise.<Object>` ⏏ * [.registerOracle(queryFormat, responseFormat, [options])](#exp_module_@aeternity/aepp-sdk/es/ae/oracle--registerOracle) ⇒ `Promise.<Object>` ⏏ @@ -54,7 +55,7 @@ Poll for oracle queries | oracleId | `String` | Oracle public key | | onQuery | `function` | OnQuery callback | | [options] | `Object` | Options object | -| [options.interval] | `Object` | Poll interval(default: 5000) | +| [options.interval] | `Number` | Poll interval(default: 5000) | diff --git a/docs/api/channel/index.md b/docs/api/channel/index.md index 5f900cea64..85b3180f3a 100644 --- a/docs/api/channel/index.md +++ b/docs/api/channel/index.md @@ -11,11 +11,13 @@ import Channel from '@aeternity/aepp-sdk/es/channel/index' * [@aeternity/aepp-sdk/es/channel/index](#module_@aeternity/aepp-sdk/es/channel/index) * [Channel(options)](#exp_module_@aeternity/aepp-sdk/es/channel/index--Channel) ⇒ `Promise.<Object>` ⏏ * [~on(event, callback)](#module_@aeternity/aepp-sdk/es/channel/index--Channel..on) + * [~off(event, callback)](#module_@aeternity/aepp-sdk/es/channel/index--Channel..off) * [~disconnect()](#module_@aeternity/aepp-sdk/es/channel/index--Channel..disconnect) * [~status()](#module_@aeternity/aepp-sdk/es/channel/index--Channel..status) ⇒ `String` * [~state()](#module_@aeternity/aepp-sdk/es/channel/index--Channel..state) ⇒ `Promise.<Object>` + * [~round()](#module_@aeternity/aepp-sdk/es/channel/index--Channel..round) ⇒ `Number` * [~id()](#module_@aeternity/aepp-sdk/es/channel/index--Channel..id) ⇒ `String` - * [~update(from, to, amount, sign)](#module_@aeternity/aepp-sdk/es/channel/index--Channel..update) ⇒ `Promise.<Object>` + * [~update(from, to, amount, sign, metadata)](#module_@aeternity/aepp-sdk/es/channel/index--Channel..update) ⇒ `Promise.<Object>` * [~poi(addresses)](#module_@aeternity/aepp-sdk/es/channel/index--Channel..poi) ⇒ `Promise.<String>` * [~balances(accounts)](#module_@aeternity/aepp-sdk/es/channel/index--Channel..balances) ⇒ `Promise.<Object>` * [~leave()](#module_@aeternity/aepp-sdk/es/channel/index--Channel..leave) ⇒ `Promise.<Object>` @@ -105,6 +107,18 @@ Possible events: | event | `String` | Event name | | callback | `function` | Callback function | + + +#### Channel~off(event, callback) +Remove event listener function + +**Kind**: inner method of [`Channel`](#exp_module_@aeternity/aepp-sdk/es/channel/index--Channel) + +| Param | Type | Description | +| --- | --- | --- | +| event | `String` | Event name | +| callback | `function` | Callback function | + #### Channel~disconnect() @@ -122,6 +136,15 @@ Get current status #### Channel~state() ⇒ `Promise.<Object>` Get current state +**Kind**: inner method of [`Channel`](#exp_module_@aeternity/aepp-sdk/es/channel/index--Channel) + + +#### Channel~round() ⇒ `Number` +Get current round + +If round cannot be determined (for example when channel has not been opened) +it will return `null`. + **Kind**: inner method of [`Channel`](#exp_module_@aeternity/aepp-sdk/es/channel/index--Channel) @@ -131,7 +154,7 @@ Get channel id **Kind**: inner method of [`Channel`](#exp_module_@aeternity/aepp-sdk/es/channel/index--Channel) -#### Channel~update(from, to, amount, sign) ⇒ `Promise.<Object>` +#### Channel~update(from, to, amount, sign, metadata) ⇒ `Promise.<Object>` Trigger a transfer update The transfer update is moving tokens from one channel account to another. @@ -148,6 +171,7 @@ can take those roles. Any public key outside of the channel is considered invali | to | `String` | Receiver's public address | | amount | `Number` | Transaction amount | | sign | `function` | Function which verifies and signs offchain transaction | +| metadata | `Array.<String>` | | **Example** ```js diff --git a/docs/api/contract/aci.md b/docs/api/contract/aci.md index e4cd0564f5..8cda76e338 100644 --- a/docs/api/contract/aci.md +++ b/docs/api/contract/aci.md @@ -68,9 +68,10 @@ Generate contract ACI object with predefined js methods for contract usage - can | --- | --- | --- | --- | | source | `String` | | Contract source code | | [options] | `Object` | {} | Options object | -| [options.aci] | `Object` | | Contract ACI | -| [options.contractAddress] | `Object` | | Contract address | +| [options.aci] | `String` | | Contract ACI | +| [options.contractAddress] | `String` | | Contract address | | [options.filesystem] | `Object` | | Contact source external namespaces map | +| [options.forceCodeCheck] | `Boolean` | false | Flag to force validation of corresponding on chain bytecode | | [options.opt] | `Object` | | Contract options | **Example** diff --git a/docs/api/utils/crypto.md b/docs/api/utils/crypto.md index d85bc67a85..5a300b1e07 100644 --- a/docs/api/utils/crypto.md +++ b/docs/api/utils/crypto.md @@ -46,6 +46,8 @@ import * as Crypto from '@aeternity/aepp-sdk/es/utils/crypto' * [.isValidKeypair(privateKey, publicKey)](#module_@aeternity/aepp-sdk/es/utils/crypto.isValidKeypair) ⇒ `Boolean` * [.envKeypair(env)](#module_@aeternity/aepp-sdk/es/utils/crypto.envKeypair) ⇒ `Object` * [.deserialize(binary, opts)](#module_@aeternity/aepp-sdk/es/utils/crypto.deserialize) ⇒ `Object` + * [.encryptData(msg, publicKey)](#module_@aeternity/aepp-sdk/es/utils/crypto.encryptData) ⇒ `Object` + * [.decryptData(secretKey, encryptedData)](#module_@aeternity/aepp-sdk/es/utils/crypto.decryptData) ⇒ `Buffer` \| `null` * _inner_ * [~Transaction](#module_@aeternity/aepp-sdk/es/utils/crypto..Transaction) : `Array` @@ -213,7 +215,7 @@ Base58 encode given `input` | Param | Type | Description | | --- | --- | --- | -| input | `String` | Data to encode | +| input | `String` \| `Buffer` | Data to encode | @@ -534,6 +536,34 @@ Deserialize `binary` state channel transaction | binary | `String` | Data to deserialize | | opts | `Object` | Options | + + +### @aeternity/aepp-sdk/es/utils/crypto.encryptData(msg, publicKey) ⇒ `Object` +This function encrypts a message using base58check encoded and 'ak' prefixed +publicKey such that only the corresponding secretKey will +be able to decrypt + +**Kind**: static method of [`@aeternity/aepp-sdk/es/utils/crypto`](#module_@aeternity/aepp-sdk/es/utils/crypto) +**rtype**: `(msg: String, publicKey: String) => Object` + +| Param | Type | Description | +| --- | --- | --- | +| msg | `Buffer` | Data to encode | +| publicKey | `String` | Public key | + + + +### @aeternity/aepp-sdk/es/utils/crypto.decryptData(secretKey, encryptedData) ⇒ `Buffer` \| `null` +This function decrypt a message using secret key + +**Kind**: static method of [`@aeternity/aepp-sdk/es/utils/crypto`](#module_@aeternity/aepp-sdk/es/utils/crypto) +**rtype**: `(secretKey: String, encryptedData: Object) => Buffer|null` + +| Param | Type | Description | +| --- | --- | --- | +| secretKey | `String` | Secret key | +| encryptedData | `Object` | Encrypted data | + ### @aeternity/aepp-sdk/es/utils/crypto~Transaction : `Array` diff --git a/docs/examples/node/aecrypto.md b/docs/examples/node/aecrypto.md index 545f51d118..59fd809d83 100644 --- a/docs/examples/node/aecrypto.md +++ b/docs/examples/node/aecrypto.md @@ -178,22 +178,7 @@ transaction and turn it into an RLP-encoded tuple ready for mining ```js function signTx (tx, privKey) { - -``` - - - - - - - -eslint-disable-next-line no-useless-escape - - - - -```js - if (!tx.match(/^tx\_.+/)) { + if (!tx.match(/^tx_.+/)) { throw Error('Not a valid transaction') } diff --git a/es/ae/contract.js b/es/ae/contract.js index f8dc45b51d..0d66764d81 100644 --- a/es/ae/contract.js +++ b/es/ae/contract.js @@ -115,8 +115,8 @@ async function contractDecodeData (source, fn, callValue, callResult, options) { * @param {Object} [options={}] Options * @param {String} [options.top] Block hash on which you want to call contract * @param {String} [options.bytecode] Block hash on which you want to call contract - * @param {Object} options [options.options] Transaction options (fee, ttl, gas, amount, deposit) - * @param {Object} filesystem [options.options.filesystem] Contract external namespaces map + * @param {Object} [options.options] Transaction options (fee, ttl, gas, amount, deposit) + * @param {Object} [options.options.filesystem] Contract external namespaces map * @return {Promise} Result object * @example * const callResult = await client.contractCallStatic(source, address, fnName, args = [], { top, options = {} }) diff --git a/es/tx/builder/helpers.js b/es/tx/builder/helpers.js index ca4e99b5c6..5dfa971ea6 100644 --- a/es/tx/builder/helpers.js +++ b/es/tx/builder/helpers.js @@ -279,14 +279,23 @@ export function classify (s) { * Get the minimum name fee for a domain * @function * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers - * @param {string} domain the domain name to get the fee for - * @return String the minimum fee for the domain auction + * @param {String} domain the domain name to get the fee for + * @return {String} the minimum fee for the domain auction */ export function getMinimumNameFee (domain) { const nameLength = domain.replace('.chain', '').length return NAME_BID_RANGES[nameLength >= NAME_BID_MAX_LENGTH ? NAME_BID_MAX_LENGTH : nameLength] } +/** + * Compute bid fee for AENS auction + * @function + * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers + * @param {String} domain the domain name to get the fee for + * @param {Number|String} startFee Auction start fee + * @param {Number} [increment=0.5] Bid multiplier(In percentage, must be between 0 and 1) + * @return {String} Bid fee + */ export function computeBidFee (domain, startFee = NAME_FEE, increment = NAME_FEE_BID_INCREMENT) { if (!(Number(increment) === increment && increment % 1 !== 0)) throw new Error(`Increment must be float. Current increment ${increment}`) if (increment < NAME_FEE_BID_INCREMENT) throw new Error(`minimum increment percentage is ${NAME_FEE_BID_INCREMENT}`) @@ -295,13 +304,21 @@ export function computeBidFee (domain, startFee = NAME_FEE, increment = NAME_FEE ) } +/** + * Compute auction end height + * @function + * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers + * @param {String} domain the domain name to get the fee for + * @param {Number|String} claimHeight Auction starting height + * @return {String} Auction end height + */ export function computeAuctionEndBlock (domain, claimHeight) { return R.cond([ - [R.lt(5), R.always(NAME_BID_TIMEOUTS[4] + claimHeight)], - [R.lt(9), R.always(NAME_BID_TIMEOUTS[8] + claimHeight)], - [R.lte(NAME_BID_MAX_LENGTH), R.always(NAME_BID_TIMEOUTS[12] + claimHeight)], - [R.T, R.always(claimHeight)] - ])(domain.replace('.chain', '').length) + [R.lt(5), R.always(NAME_BID_TIMEOUTS[4].plus(claimHeight))], + [R.lt(9), R.always(NAME_BID_TIMEOUTS[8].plus(claimHeight))], + [R.lte(NAME_BID_MAX_LENGTH), R.always(NAME_BID_TIMEOUTS[12].plus(claimHeight))], + [R.T, R.always(BigNumber(claimHeight))] + ])(domain.replace('.chain', '').length).toString(10) } export default { diff --git a/es/tx/builder/schema.js b/es/tx/builder/schema.js index c730e6b902..af0f024b0d 100644 --- a/es/tx/builder/schema.js +++ b/es/tx/builder/schema.js @@ -70,10 +70,10 @@ export const NAME_BID_RANGES = { // # ref: https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L273 // # name bid timeouts export const NAME_BID_TIMEOUTS = { - 13: 0, - 12: NAME_BID_TIMEOUT_BLOCKS, // # 480 blocks - 8: 31 * NAME_BID_TIMEOUT_BLOCKS, // # 14880 blocks - 4: 62 * NAME_BID_TIMEOUT_BLOCKS // # 29760 blocks + 13: BigNumber(0), + 12: BigNumber(NAME_BID_TIMEOUT_BLOCKS), // # 480 blocks + 8: BigNumber(31).times(NAME_BID_TIMEOUT_BLOCKS), // # 14880 blocks + 4: BigNumber(62).times(NAME_BID_TIMEOUT_BLOCKS) // # 29760 blocks } // # Tag constant for ids (type uint8) diff --git a/es/utils/crypto.js b/es/utils/crypto.js index e99a39c1c0..732d60346c 100644 --- a/es/utils/crypto.js +++ b/es/utils/crypto.js @@ -196,7 +196,7 @@ export function decodeBase64Check (str) { /** * Base58 encode given `input` * @rtype (input: String) => String - * @param {String} input - Data to encode + * @param {String|Buffer} input - Data to encode * @return {String} Base58 encoded data */ export function encodeBase58Check (input) { diff --git a/package.json b/package.json index 83fa90b688..ff370174b3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@aeternity/aepp-sdk", - "version": "6.0.2", + "version": "6.1.0", "description": "SDK for the æternity blockchain", "main": "dist/aepp-sdk.js", "browser": "dist/aepp-sdk.browser.js",