diff --git a/CHANGELOG.md b/CHANGELOG.md index 48fda33922..1cde7cf1c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,32 @@ +# [7.0.0](https://github.com/aeternity/aepp-sdk-js/compare/6.0.1...7.0.0) (2020-01-31) + + +### Bug Fixes + +* **AEX-2:** Fix firefox compatibility issue ([#882](https://github.com/aeternity/aepp-sdk-js/issues/882)) ([2e16e10](https://github.com/aeternity/aepp-sdk-js/commit/2e16e10)) + + +### Features + +* **Chain:** add new method `waitFOrTxConfirm`. Add new option { confirm: 3 } to all of high lvl SDK API. Add tests. Adjust docs ([#874](https://github.com/aeternity/aepp-sdk-js/issues/874)) ([43528f9](https://github.com/aeternity/aepp-sdk-js/commit/43528f9)) +* **Compiler:** Add new compiler methods API ([#875](https://github.com/aeternity/aepp-sdk-js/issues/875)) ([a939395](https://github.com/aeternity/aepp-sdk-js/commit/a939395)) +* **network:** Throw error when can not get networkId ([#863](https://github.com/aeternity/aepp-sdk-js/issues/863)) ([41b7bd1](https://github.com/aeternity/aepp-sdk-js/commit/41b7bd1)) + + +### Docs + +* **Guide** [Add 7.0.0 migration guide](https://github.com/aeternity/aepp-sdk-js/blob/develop/docs/guides/migration/migration-7.0.0.md) +* **Guide:** Add [Oracle](https://github.com/aeternity/aepp-sdk-js/blob/develop/docs/guides/oracle-usage.md), [AENS](https://github.com/aeternity/aepp-sdk-js/blob/develop/docs/guides/aens-usage.md) and [Contract](https://github.com/aeternity/aepp-sdk-js/blob/develop/docs/guides/contract-aci-usage.md) guides + + +### BREAKING CHANGES + +Please check out [7.0.0 migration guide](https://github.com/aeternity/aepp-sdk-js/blob/develop/docs/guides/migration/migration-7.0.0.md) + +This release include all changes from [7.0.0-next.1](https://github.com/aeternity/aepp-sdk-js/releases/tag/7.0.0-next.1), [7.0.0-next.2](https://github.com/aeternity/aepp-sdk-js/releases/tag/7.0.0-next.2), [7.0.0-next.3](https://github.com/aeternity/aepp-sdk-js/releases/tag/7.0.0-next.3) + + + # [7.0.0-next.3](https://github.com/aeternity/aepp-sdk-js/compare/6.0.1...7.0.0-next.3) (2020-01-22) diff --git a/docs/README.md b/docs/README.md index 7891c139e9..dc34f4ba19 100644 --- a/docs/README.md +++ b/docs/README.md @@ -48,6 +48,7 @@ You can use this URL with any releasee on [npmjs](https://www.npmjs.com/package/ ### Contract Usage - [Contract ACI](guides/contract-aci-usage.md) - [AENS usage](guides/aens-usage.md) + - [AENS usage](guides/racle-usage.md) ## Examples diff --git a/docs/api/account.md b/docs/api/account.md index 29738947e9..f3c6bcd12b 100644 --- a/docs/api/account.md +++ b/docs/api/account.md @@ -10,7 +10,6 @@ import Account from '@aeternity/aepp-sdk/es/account' * [@aeternity/aepp-sdk/es/account](#module_@aeternity/aepp-sdk/es/account) * [Account([options])](#exp_module_@aeternity/aepp-sdk/es/account--Account) ⇒ `Object` ⏏ - * [.signTransaction(tx, opt)](#module_@aeternity/aepp-sdk/es/account--Account+signTransaction) ⇒ `String` * [.getNetworkId()](#module_@aeternity/aepp-sdk/es/account--Account+getNetworkId) ⇒ `String` * *[.sign(data)](#module_@aeternity/aepp-sdk/es/account--Account+sign) ⇒ `String`* * *[.address()](#module_@aeternity/aepp-sdk/es/account--Account+address) ⇒ `String`* @@ -36,21 +35,6 @@ signing key pair. | [options] | `Object` | {} | Initializer object | | options.networkId | `String` | | NETWORK_ID using for signing transaction's | - - -#### account.signTransaction(tx, opt) ⇒ `String` -Sign encoded transaction - -**Kind**: instance method of [`Account`](#exp_module_@aeternity/aepp-sdk/es/account--Account) -**Returns**: `String` - Signed transaction -**Category**: async -**rtype**: `(tx: String) => tx: Promise[String], throws: Error` - -| Param | Type | Description | -| --- | --- | --- | -| tx | `String` | Transaction to sign | -| opt | `Object` | Options | - #### account.getNetworkId() ⇒ `String` diff --git a/docs/api/utils/aepp-wallet-communication/rpc/aepp-rpc.md b/docs/api/utils/aepp-wallet-communication/rpc/aepp-rpc.md index 0e6d4438a1..965376e9ce 100644 --- a/docs/api/utils/aepp-wallet-communication/rpc/aepp-rpc.md +++ b/docs/api/utils/aepp-wallet-communication/rpc/aepp-rpc.md @@ -11,7 +11,7 @@ import ContentScriptBridge from '@aeternity/aepp-sdk/es/utils/aepp-wallet-commun * [@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/aepp-rpc](#module_@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/aepp-rpc) * [exports.AeppRpc(param, onAddressChange, onDisconnect, onNetworkChange, connection)](#exp_module_@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/aepp-rpc--exports.AeppRpc) ⇒ `Object` ⏏ * [.connectToWallet(connection)](#module_@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/aepp-rpc--exports.AeppRpc+connectToWallet) ⇒ `void` - * [.disconnectWallet(force)](#module_@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/aepp-rpc--exports.AeppRpc+disconnectWallet) ⇒ `void` + * [.disconnectWallet(sendDisconnect)](#module_@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/aepp-rpc--exports.AeppRpc+disconnectWallet) ⇒ `void` * [.askAddresses()](#module_@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/aepp-rpc--exports.AeppRpc+askAddresses) ⇒ `Promise` * [.subscribeAddress(type, value)](#module_@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/aepp-rpc--exports.AeppRpc+subscribeAddress) ⇒ `Promise` * [.signTransaction()](#module_@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/aepp-rpc--exports.AeppRpc+signTransaction) ⇒ `Promise.<String>` @@ -49,7 +49,7 @@ Connect to wallet -#### exports.AeppRpc.disconnectWallet(force) ⇒ `void` +#### exports.AeppRpc.disconnectWallet(sendDisconnect) ⇒ `void` Disconnect from wallet **Kind**: instance method of [`exports.AeppRpc`](#exp_module_@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/aepp-rpc--exports.AeppRpc) @@ -57,7 +57,7 @@ Disconnect from wallet | Param | Type | Default | Description | | --- | --- | --- | --- | -| force | `Boolean` | false | Force sending close connection message | +| sendDisconnect | `Boolean` | false | Force sending close connection message | diff --git a/docs/examples/node/aecrypto.md b/docs/examples/node/aecrypto.md index 43fdf2fe15..59fd809d83 100644 --- a/docs/examples/node/aecrypto.md +++ b/docs/examples/node/aecrypto.md @@ -105,6 +105,40 @@ const promptSchema = { + +## Key Extraction (from Node nodes) + + + + +```js +function extractReadableKeys (dir, options) { + const pwd = options.input + prompt.start() + prompt.get(promptSchema, (_, { password }) => { + const key = fs.readFileSync(path.join(pwd, dir, 'sign_key')) + const pubKey = fs.readFileSync(path.join(pwd, dir, 'sign_key.pub')) + + const decrypted = Crypto.decryptPrivateKey(password, key) + + const privateHex = Buffer.from(decrypted).toString('hex') + const decryptedPub = Crypto.decryptPubKey(password, pubKey) + + console.log(`Private key (hex): ${privateHex}`) + console.log(`Public key (base check): ak_${Crypto.encodeBase58Check(decryptedPub)}`) + console.log(`Public key (hex): ${decryptedPub.toString('hex')}`) + }) +} + + +``` + + + + + + + ## Key Pair Generation @@ -113,9 +147,19 @@ const promptSchema = { ```js function generateKeyPair (name, { output }) { const { publicKey, secretKey } = Crypto.generateKeyPair() - return { publicKey, secretKey } - + + const data = [ + [path.join(output, name), secretKey], + [path.join(output, `${name}.pub`), publicKey] + ] + + data.forEach(([path, data]) => { + fs.writeFileSync(path, data) + console.log(`Wrote ${path}`) + }) } + + ``` @@ -126,27 +170,94 @@ function generateKeyPair (name, { output }) { ## Transaction Signing -This function shows how to sign an æternity +This function shows how to use a compliant private key to sign an æternity transaction and turn it into an RLP-encoded tuple ready for mining ```js -function signTx (tx, secretKey) { +function signTx (tx, privKey) { if (!tx.match(/^tx_.+/)) { throw Error('Not a valid transaction') } - secretKey = Buffer.from(keyPair.secretKey, 'hex') - const rlpBinaryTx = Crypto.decodeBase64Check(Crypto.assertedType(tx, 'tx')) - // Prepend `NETWORK_ID` to begin of data binary - const txWithNetworkId = Buffer.concat([Buffer.from(program.networkId), rlpBinaryTx]) + + const binaryKey = (() => { + if (program.file) { + return fs.readFileSync(program.file) + } else if (privKey) { + return Buffer.from(privKey, 'hex') + } else { + throw Error('Must provide either [privkey] or [file]') + } + })() + + const decryptedKey = program.password ? Crypto.decryptKey(program.password, binaryKey) : binaryKey + + +``` + + + + + + + +Split the base58Check part of the transaction + + + + +```js + const base58CheckTx = tx.split('_')[1] + +``` + + + + + + + +... and sign the binary create_contract transaction + + - const signatures = [Crypto.sign(txWithNetworkId, secretKey)] - const { tx } = buildTx({ encodedTx: rlpBinaryTx, signatures }, TX_TYPE.signed) - console.log('Signed transaction: ' + tx) + +```js + const binaryTx = Crypto.decodeBase58Check(base58CheckTx) + + const signature = Crypto.sign(binaryTx, decryptedKey) + + +``` + + + + + + + +the signed tx deserializer expects a 4-tuple: + + + + + +```js + const unpackedSignedTx = [ + Buffer.from([11]), + Buffer.from([1]), + [Buffer.from(signature)], + binaryTx + ] + + console.log(Crypto.encodeTx(unpackedSignedTx)) } -```` + + +``` + @@ -165,6 +276,8 @@ function unpackTx (tx) { const deserializedTx = TxBuilder.unpackTx(tx) console.log(JSON.stringify(deserializedTx, undefined, 2)) } + + ``` @@ -183,10 +296,22 @@ The `commander` library provides maximum command line parsing convenience. ```js program.version('0.1.0') +program + .command('decrypt ') + .description('Decrypts public and private key to readable formats for testing purposes') + .option('-i, --input [directory]', 'Directory where to look for keys', '.') + .action(extractReadableKeys) + +program + .command('genkey ') + .description('Generate keypair') + .option('-o, --output [directory]', 'Output directory for the keys', '.') + .action(generateKeyPair) program - .command('sign ') - .option('--networkId [networkId]', 'Network Id') + .command('sign [privkey]') + .option('-p, --password [password]', 'password of the private key') + .option('-f, --file [file]', 'private key file') .action(signTx) program diff --git a/package.json b/package.json index 55d195db8a..fd1eed333b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@aeternity/aepp-sdk", - "version": "7.0.0-next.3", + "version": "7.0.0", "description": "SDK for the æternity blockchain", "main": "dist/aepp-sdk.js", "browser": "dist/aepp-sdk.browser.js",