From 349c35cf41d3c9dd75348d717ec713c51e995cc5 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Thu, 28 Jun 2018 17:19:18 +0200 Subject: [PATCH] Fix extrinsic submissions (#111) * Update parent when values have changed * Fix linting * Cast for correct signature * Cater for correct "Bytes" for submitExtrinsic --- package.json | 2 +- packages/app-accounts/src/Creator.tsx | 4 +- packages/app-explorer/package.json | 4 +- packages/app-extrinsics/package.json | 2 +- packages/ui-app/package.json | 4 +- packages/ui-app/src/Params/index.tsx | 10 ++ packages/ui-identicon/package.json | 2 +- packages/ui-keyring/package.json | 2 +- packages/ui-react-rx/package.json | 6 +- packages/ui-react-rx/src/util/numberFormat.ts | 2 +- packages/ui-react/package.json | 2 +- packages/ui-signer/package.json | 2 +- packages/ui-signer/src/sign.ts | 15 +- packages/ui-signer/src/submit.ts | 2 + yarn.lock | 169 +++++++++--------- 15 files changed, 128 insertions(+), 100 deletions(-) diff --git a/package.json b/package.json index c1fb6bd145..1007878a98 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ }, "devDependencies": { "@polkadot/dev-react": "^0.20.8", - "@polkadot/ts": "^0.1.3", + "@polkadot/ts": "^0.1.5", "autoprefixer": "^8.6.2", "gh-pages": "^1.1.0", "postcss-import": "^11.1.0", diff --git a/packages/app-accounts/src/Creator.tsx b/packages/app-accounts/src/Creator.tsx index 5219ca8099..edad000b68 100644 --- a/packages/app-accounts/src/Creator.tsx +++ b/packages/app-accounts/src/Creator.tsx @@ -40,7 +40,7 @@ type State = { function formatSeed (seed: string): Uint8Array { return isHex(seed) ? hexToU8a(seed) - : u8aFromString((seed as string).padEnd(32, ' ')); + : u8aFromString(seed.padEnd(32, ' ')); } function addressFromSeed (seed: string): string { @@ -176,7 +176,7 @@ class Creator extends React.PureComponent { const isNameValid = !!name; const isSeedValid = isHex(seed) ? seed.length === 66 - : (seed as string).length <= 32; + : seed.length <= 32; const isPassValid = password.length > 0 && password.length <= 32; if (isSeedValid && seed !== prevState.seed) { diff --git a/packages/app-explorer/package.json b/packages/app-explorer/package.json index 73314f0d25..88a97567b3 100644 --- a/packages/app-explorer/package.json +++ b/packages/app-explorer/package.json @@ -16,8 +16,8 @@ }, "dependencies": { "@babel/runtime": "^7.0.0-beta.51", - "@polkadot/primitives": "^0.26.6", + "@polkadot/primitives": "^0.26.9", "@polkadot/ui-app": "^0.18.6", - "@polkadot/util-crypto": "^0.26.6" + "@polkadot/util-crypto": "^0.26.9" } } diff --git a/packages/app-extrinsics/package.json b/packages/app-extrinsics/package.json index c758d283b4..7bbc7bd16d 100644 --- a/packages/app-extrinsics/package.json +++ b/packages/app-extrinsics/package.json @@ -16,7 +16,7 @@ }, "dependencies": { "@babel/runtime": "^7.0.0-beta.51", - "@polkadot/extrinsics": "^0.26.6", + "@polkadot/extrinsics": "^0.26.9", "@polkadot/ui-app": "^0.18.6", "@polkadot/ui-signer": "^0.18.6", "react-dropzone": "^4.2.9" diff --git a/packages/ui-app/package.json b/packages/ui-app/package.json index 5acd97a52f..04fb880c3b 100644 --- a/packages/ui-app/package.json +++ b/packages/ui-app/package.json @@ -16,8 +16,8 @@ }, "dependencies": { "@babel/runtime": "^7.0.0-beta.51", - "@polkadot/extrinsics": "^0.26.6", - "@polkadot/storage": "^0.26.6", + "@polkadot/extrinsics": "^0.26.9", + "@polkadot/storage": "^0.26.9", "@polkadot/ui-keyring": "^0.18.6", "@polkadot/ui-react": "^0.18.6", "@polkadot/ui-react-rx": "^0.18.6", diff --git a/packages/ui-app/src/Params/index.tsx b/packages/ui-app/src/Params/index.tsx index 9950ebfe8a..ca8d8c36dd 100644 --- a/packages/ui-app/src/Params/index.tsx +++ b/packages/ui-app/src/Params/index.tsx @@ -59,6 +59,16 @@ class Params> extends React.PureComponent, } as State; } + // NOTE This is needed in the case where the item changes, i.e. the values get initialised and we need to alert the parent that we have new values + componentDidUpdate (prevProps: Props, prevState: State) { + const { onChange } = this.props; + const { values } = this.state; + + if (prevState.values !== values) { + onChange(values); + } + } + render () { const { className, item: { params }, overrides, style } = this.props; const { handlers, values } = this.state; diff --git a/packages/ui-identicon/package.json b/packages/ui-identicon/package.json index 46c7375a39..40621ad179 100644 --- a/packages/ui-identicon/package.json +++ b/packages/ui-identicon/package.json @@ -22,7 +22,7 @@ "color": "^3.0.0" }, "devDependencies": { - "@polkadot/util-crypto": "^0.26.6", + "@polkadot/util-crypto": "^0.26.9", "xmlserializer": "^0.6.1" } } diff --git a/packages/ui-keyring/package.json b/packages/ui-keyring/package.json index 28ccdd66f7..77473da4f1 100644 --- a/packages/ui-keyring/package.json +++ b/packages/ui-keyring/package.json @@ -17,7 +17,7 @@ "dependencies": { "@babel/runtime": "^7.0.0-beta.51", "@polkadot/ui-react": "^0.18.6", - "@polkadot/util-keyring": "^0.26.6", + "@polkadot/util-keyring": "^0.26.9", "store": "^2.0.12" }, "peerDependencies": { diff --git a/packages/ui-react-rx/package.json b/packages/ui-react-rx/package.json index e72f06be76..5723986815 100644 --- a/packages/ui-react-rx/package.json +++ b/packages/ui-react-rx/package.json @@ -36,9 +36,9 @@ }, "dependencies": { "@babel/runtime": "^7.0.0-beta.51", - "@polkadot/api-rx": "^0.14.9", - "@polkadot/extrinsics": "^0.26.6", - "@polkadot/storage": "^0.26.6" + "@polkadot/api-rx": "^0.14.11", + "@polkadot/extrinsics": "^0.26.9", + "@polkadot/storage": "^0.26.9" }, "devDependencies": { "babel-loader": "^8.0.0-beta.2", diff --git a/packages/ui-react-rx/src/util/numberFormat.ts b/packages/ui-react-rx/src/util/numberFormat.ts index 31ada5383f..c6431e967e 100644 --- a/packages/ui-react-rx/src/util/numberFormat.ts +++ b/packages/ui-react-rx/src/util/numberFormat.ts @@ -11,5 +11,5 @@ export default function numberFormat (value?: BN | number): string { return '0'; } - return (value.toString().match(NUMBER_REGEX) || []).join(','); + return ((value as number).toString().match(NUMBER_REGEX) || []).join(','); } diff --git a/packages/ui-react/package.json b/packages/ui-react/package.json index a36b0389cf..88b4010ca9 100644 --- a/packages/ui-react/package.json +++ b/packages/ui-react/package.json @@ -19,7 +19,7 @@ "@polkadot/ui-identicon": "^0.18.6" }, "devDependencies": { - "@polkadot/util-keyring": "^0.26.6", + "@polkadot/util-keyring": "^0.26.9", "babel-loader": "^8.0.0-beta.2", "css-loader": "0.28.9", "empty": "^0.10.1", diff --git a/packages/ui-signer/package.json b/packages/ui-signer/package.json index 87c4e31a75..e014b96a99 100644 --- a/packages/ui-signer/package.json +++ b/packages/ui-signer/package.json @@ -16,7 +16,7 @@ }, "dependencies": { "@babel/runtime": "^7.0.0-beta.51", - "@polkadot/extrinsics": "^0.26.6", + "@polkadot/extrinsics": "^0.26.9", "@polkadot/ui-app": "^0.18.6", "@polkadot/ui-keyring": "^0.18.6" }, diff --git a/packages/ui-signer/src/sign.ts b/packages/ui-signer/src/sign.ts index 65d17df8d3..dcd7eca8f3 100644 --- a/packages/ui-signer/src/sign.ts +++ b/packages/ui-signer/src/sign.ts @@ -9,23 +9,32 @@ import { Signed } from './types'; import encodeCall from '@polkadot/extrinsics/codec/encode/call'; import prefixes from '@polkadot/extrinsics/codec/encode/prefixes'; import keyring from '@polkadot/ui-keyring/index'; +import bnToU8a from '@polkadot/util/bn/toU8a'; import u8aConcat from '@polkadot/util/u8a/concat'; import u8aToHex from '@polkadot/util/u8a/toHex'; export default function signMessage (publicKey: Uint8Array, nonce: BN | number, value: Uint8Array, apiSupport: EncodingVersions): Signed { const message = encodeCall(publicKey, nonce, value, apiSupport); const signature = keyring.getPair(publicKey).sign(message); + const data = u8aConcat( + apiSupport === 'poc-1' + ? new Uint8Array([]) + : prefixes.publicKey, + message, + signature + ); console.log(`signMessage : message :: ${u8aToHex(message)}`); console.log(`signMessage : signature :: ${u8aToHex(signature)}`); + console.log(`signMessage : data :: ${u8aToHex(data)}`); return { data: u8aConcat( + // TODO We append the length here, but it probably needs to be done in the actual formatter - however there are differences between different encodings, here the extrinsic requires a length, where some other 'Bytes' types do not apiSupport === 'poc-1' ? new Uint8Array([]) - : prefixes.publicKey, - message, - signature + : bnToU8a(data.length, 32, true), + data ), message, signature diff --git a/packages/ui-signer/src/submit.ts b/packages/ui-signer/src/submit.ts index 1e041b5204..8a37c15fc8 100644 --- a/packages/ui-signer/src/submit.ts +++ b/packages/ui-signer/src/submit.ts @@ -9,6 +9,8 @@ import { QueueTx$Result } from './types'; export default async function submitMessage (api: RxApiInterface, params: Array, { name, section }: SectionItem): Promise { try { + console.log(`submitMessage : ${section}.${name} :`, params); + const result = await api[section][name].apply(null, params).toPromise(); console.log(`${section}.${name}: result ::`, result); diff --git a/yarn.lock b/yarn.lock index 2092457034..a0afbbc113 100644 --- a/yarn.lock +++ b/yarn.lock @@ -871,50 +871,50 @@ version "1.0.2" resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-1.0.2.tgz#d056b68999769728a1cff8d643bc59eb6f0be436" -"@polkadot/api-format@^0.14.9": - version "0.14.9" - resolved "https://registry.yarnpkg.com/@polkadot/api-format/-/api-format-0.14.9.tgz#59bcf2e864d31904d059bb745c4dce6b4e4d10d6" +"@polkadot/api-format@^0.14.11": + version "0.14.11" + resolved "https://registry.yarnpkg.com/@polkadot/api-format/-/api-format-0.14.11.tgz#27669b3e952fdc18549e9d52a97071ebdd8f8bc9" dependencies: "@babel/runtime" "^7.0.0-beta.51" - "@polkadot/jsonrpc" "^0.26.6" - "@polkadot/primitives" "^0.26.6" - "@polkadot/util" "^0.26.6" - "@polkadot/util-keyring" "^0.26.6" + "@polkadot/jsonrpc" "^0.26.9" + "@polkadot/primitives" "^0.26.9" + "@polkadot/util" "^0.26.9" + "@polkadot/util-keyring" "^0.26.9" -"@polkadot/api-provider@^0.14.9": - version "0.14.9" - resolved "https://registry.yarnpkg.com/@polkadot/api-provider/-/api-provider-0.14.9.tgz#4cd88f51ad7c558b65bd001986fe8047524ed379" +"@polkadot/api-provider@^0.14.11": + version "0.14.11" + resolved "https://registry.yarnpkg.com/@polkadot/api-provider/-/api-provider-0.14.11.tgz#3e6adfb81798608abd7a2a9df70f74ce1cbb7c64" dependencies: "@babel/runtime" "^7.0.0-beta.51" - "@polkadot/storage" "^0.26.6" - "@polkadot/util" "^0.26.6" - "@polkadot/util-crypto" "^0.26.6" - "@polkadot/util-keyring" "^0.26.6" + "@polkadot/storage" "^0.26.9" + "@polkadot/util" "^0.26.9" + "@polkadot/util-crypto" "^0.26.9" + "@polkadot/util-keyring" "^0.26.9" "@types/nock" "^9.1.3" eventemitter3 "^2.0.3" isomorphic-fetch "^2.2.1" websocket "^1.0.25" -"@polkadot/api-rx@^0.14.9": - version "0.14.9" - resolved "https://registry.yarnpkg.com/@polkadot/api-rx/-/api-rx-0.14.9.tgz#e7cda950cb381f6a508c72cbc799afc98117801d" +"@polkadot/api-rx@^0.14.11": + version "0.14.11" + resolved "https://registry.yarnpkg.com/@polkadot/api-rx/-/api-rx-0.14.11.tgz#536c942382984f35b0ae951c17ed134471e538b1" dependencies: "@babel/runtime" "^7.0.0-beta.51" - "@polkadot/api" "^0.14.9" - "@polkadot/api-provider" "^0.14.9" + "@polkadot/api" "^0.14.11" + "@polkadot/api-provider" "^0.14.11" "@types/rx" "^4.1.1" rxjs "^5.5.10" -"@polkadot/api@^0.14.9": - version "0.14.9" - resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-0.14.9.tgz#c590217e8b3246d44db67b342733e96ef6f32bb1" +"@polkadot/api@^0.14.11": + version "0.14.11" + resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-0.14.11.tgz#7fab1cc484ab366312eba590e09b6b6b3bd2d0a2" dependencies: "@babel/runtime" "^7.0.0-beta.51" - "@polkadot/api-format" "^0.14.9" - "@polkadot/api-provider" "^0.14.9" - "@polkadot/jsonrpc" "^0.26.6" - "@polkadot/params" "^0.26.6" - "@polkadot/util" "^0.26.6" + "@polkadot/api-format" "^0.14.11" + "@polkadot/api-provider" "^0.14.11" + "@polkadot/jsonrpc" "^0.26.9" + "@polkadot/params" "^0.26.9" + "@polkadot/util" "^0.26.9" "@polkadot/dev-react@^0.20.8": version "0.20.8" @@ -982,96 +982,97 @@ tslint-config-semistandard "^7.0.0" typescript "^2.9.2" -"@polkadot/extrinsics@^0.26.6": - version "0.26.6" - resolved "https://registry.yarnpkg.com/@polkadot/extrinsics/-/extrinsics-0.26.6.tgz#20706a5ad2b153144048e97d2d493fe4d90ea0a3" +"@polkadot/extrinsics@^0.26.9": + version "0.26.9" + resolved "https://registry.yarnpkg.com/@polkadot/extrinsics/-/extrinsics-0.26.9.tgz#6a55b2629038f88cbc5126a69103ba3d785e1c02" dependencies: "@babel/runtime" "^7.0.0-beta.51" - "@polkadot/params" "^0.26.6" - "@polkadot/primitives" "^0.26.6" - "@polkadot/util" "^0.26.6" + "@polkadot/params" "^0.26.9" + "@polkadot/primitives" "^0.26.9" + "@polkadot/util" "^0.26.9" -"@polkadot/jsonrpc@^0.26.6": - version "0.26.6" - resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-0.26.6.tgz#e3eedf0175ab754deacdf0ea8a9eb49f901ac744" +"@polkadot/jsonrpc@^0.26.9": + version "0.26.9" + resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-0.26.9.tgz#f21f8665f57fbaedd2d60dbe08eb478ba9c3797e" dependencies: - "@polkadot/params" "^0.26.6" + "@polkadot/params" "^0.26.9" babel-runtime "^6.26.0" -"@polkadot/params@^0.26.6": - version "0.26.6" - resolved "https://registry.yarnpkg.com/@polkadot/params/-/params-0.26.6.tgz#7aed34e68bde18fa46a32da9099c2aa25072261e" +"@polkadot/params@^0.26.9": + version "0.26.9" + resolved "https://registry.yarnpkg.com/@polkadot/params/-/params-0.26.9.tgz#cfaa1b1fb649003d7fd0308b2578c4f13ac8ec90" dependencies: "@babel/runtime" "^7.0.0-beta.51" - "@polkadot/extrinsics" "^0.26.6" - "@polkadot/primitives" "^0.26.6" - "@polkadot/util" "^0.26.6" + "@polkadot/extrinsics" "^0.26.9" + "@polkadot/primitives" "^0.26.9" + "@polkadot/util" "^0.26.9" -"@polkadot/primitives@^0.26.6": - version "0.26.6" - resolved "https://registry.yarnpkg.com/@polkadot/primitives/-/primitives-0.26.6.tgz#c3ccc7f22846d8e048ab44e2985ff0004f0e5393" +"@polkadot/primitives@^0.26.9": + version "0.26.9" + resolved "https://registry.yarnpkg.com/@polkadot/primitives/-/primitives-0.26.9.tgz#1caef6a6b51ff944964a27200d56068fd985d14d" dependencies: "@babel/runtime" "^7.0.0-beta.51" - "@polkadot/trie-hash" "^0.26.6" - "@polkadot/util" "^0.26.6" + "@polkadot/trie-hash" "^0.26.9" + "@polkadot/util" "^0.26.9" -"@polkadot/storage@^0.26.6": - version "0.26.6" - resolved "https://registry.yarnpkg.com/@polkadot/storage/-/storage-0.26.6.tgz#7fc0e7ae54885af8ecf8f26afeeff3e2746ce8c4" +"@polkadot/storage@^0.26.9": + version "0.26.9" + resolved "https://registry.yarnpkg.com/@polkadot/storage/-/storage-0.26.9.tgz#5b7d60b74eb6a3bc73859f06547b3e7fe61cd6ba" dependencies: "@babel/runtime" "^7.0.0-beta.51" - "@polkadot/params" "^0.26.6" - "@polkadot/primitives" "^0.26.6" - "@polkadot/util" "^0.26.6" - "@polkadot/util-crypto" "^0.26.6" - "@polkadot/util-keyring" "^0.26.6" + "@polkadot/params" "^0.26.9" + "@polkadot/primitives" "^0.26.9" + "@polkadot/util" "^0.26.9" + "@polkadot/util-crypto" "^0.26.9" + "@polkadot/util-keyring" "^0.26.9" -"@polkadot/trie-hash@^0.26.6": - version "0.26.6" - resolved "https://registry.yarnpkg.com/@polkadot/trie-hash/-/trie-hash-0.26.6.tgz#5b128c44bd63234bbf871a48c40141022f1d5790" +"@polkadot/trie-hash@^0.26.9": + version "0.26.9" + resolved "https://registry.yarnpkg.com/@polkadot/trie-hash/-/trie-hash-0.26.9.tgz#9df4529b5bcf4694988f8168c6bb874c45040603" dependencies: "@babel/runtime" "^7.0.0-beta.51" - "@polkadot/util" "^0.26.6" - "@polkadot/util-crypto" "^0.26.6" - "@polkadot/util-rlp" "^0.26.6" + "@polkadot/util" "^0.26.9" + "@polkadot/util-crypto" "^0.26.9" + "@polkadot/util-rlp" "^0.26.9" -"@polkadot/ts@^0.1.3": - version "0.1.3" - resolved "https://registry.yarnpkg.com/@polkadot/ts/-/ts-0.1.3.tgz#e277fb89c43a64b244a6d1ae03fc4ede128b155d" +"@polkadot/ts@^0.1.5": + version "0.1.5" + resolved "https://registry.yarnpkg.com/@polkadot/ts/-/ts-0.1.5.tgz#bd944090a788d9379866059fb61b5708b4696cc7" -"@polkadot/util-crypto@^0.26.6": - version "0.26.6" - resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.26.6.tgz#c7a000066b1ed4ce5dab1ab558833907a9a5d399" +"@polkadot/util-crypto@^0.26.9": + version "0.26.9" + resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.26.9.tgz#86176ec7c0dcfa44056f64e42283f2e8f052f87a" dependencies: "@babel/runtime" "^7.0.0-beta.51" - "@polkadot/util" "^0.26.6" + "@polkadot/util" "^0.26.9" blakejs "^1.1.0" js-sha3 "^0.7.0" tweetnacl "^1.0.0" xxhashjs "^0.2.2" -"@polkadot/util-keyring@^0.26.6": - version "0.26.6" - resolved "https://registry.yarnpkg.com/@polkadot/util-keyring/-/util-keyring-0.26.6.tgz#a7aa5dd8162f469616d9839c872d7ca50d83fd5d" +"@polkadot/util-keyring@^0.26.9": + version "0.26.9" + resolved "https://registry.yarnpkg.com/@polkadot/util-keyring/-/util-keyring-0.26.9.tgz#fd358feeebf2a15613d3a1de6efb61ee39231c45" dependencies: "@babel/runtime" "^7.0.0-beta.51" - "@polkadot/util" "^0.26.6" - "@polkadot/util-crypto" "^0.26.6" + "@polkadot/util" "^0.26.9" + "@polkadot/util-crypto" "^0.26.9" "@types/bs58" "^3.0.30" bs58 "^4.0.1" -"@polkadot/util-rlp@^0.26.6": - version "0.26.6" - resolved "https://registry.yarnpkg.com/@polkadot/util-rlp/-/util-rlp-0.26.6.tgz#bc66fc975760e9d5999eb243c66298c2e940ac7f" +"@polkadot/util-rlp@^0.26.9": + version "0.26.9" + resolved "https://registry.yarnpkg.com/@polkadot/util-rlp/-/util-rlp-0.26.9.tgz#cee23ed6662903d8c59207c36bb7c3e7aed62d02" dependencies: "@babel/runtime" "^7.0.0-beta.51" - "@polkadot/util" "^0.26.6" + "@polkadot/util" "^0.26.9" -"@polkadot/util@^0.26.6": - version "0.26.6" - resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.26.6.tgz#0405175f4d9fb39e8e5f9d30b504ea566c1ba42e" +"@polkadot/util@^0.26.9": + version "0.26.9" + resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.26.9.tgz#9a90aa66b2425d7350faa1c1764069f74eadd97a" dependencies: "@babel/runtime" "^7.0.0-beta.51" + "@types/bn.js" "^4.11.1" "@types/deasync" "^0.1.0" "@types/ip-regex" "^2.0.0" "@types/xxhashjs" "^0.1.1" @@ -1104,6 +1105,12 @@ version "1.0.29" resolved "https://registry.yarnpkg.com/@types/base-x/-/base-x-1.0.29.tgz#8a2d73e4a5c3121757a5f8870cfa4509655186b6" +"@types/bn.js@^4.11.1": + version "4.11.1" + resolved "https://registry.yarnpkg.com/@types/bn.js/-/bn.js-4.11.1.tgz#6fd07b93490ecf0f3501a31ea9cfd330885b10fa" + dependencies: + "@types/node" "*" + "@types/bs58@^3.0.30": version "3.0.30" resolved "https://registry.yarnpkg.com/@types/bs58/-/bs58-3.0.30.tgz#916ba10992465e56f81afc735e7935fd749893e1"