-
Notifications
You must be signed in to change notification settings - Fork 422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement signRaw #196
Merged
Merged
Implement signRaw #196
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2019 @polkadot/extension-ui authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the Apache-2.0 license. See the LICENSE file for details. | ||
|
||
import styled from 'styled-components'; | ||
import React from 'react'; | ||
|
||
interface Props { | ||
className?: string; | ||
bytes: string; | ||
url: string; | ||
} | ||
|
||
function Bytes ({ bytes, className, url }: Props): React.ReactElement<Props> { | ||
return ( | ||
<table className={className}> | ||
<tbody> | ||
<tr> | ||
<td className='label'>from</td> | ||
<td className='data'>{url}</td> | ||
</tr> | ||
<tr> | ||
<td className='label'>bytes</td> | ||
<td className='data'>{bytes}</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
); | ||
} | ||
|
||
export default styled(Bytes)` | ||
border: 0; | ||
display: block; | ||
font-size: 0.75rem; | ||
margin-top: 0.75rem; | ||
|
||
td.data { | ||
max-width: 0; | ||
overflow: hidden; | ||
text-align: left; | ||
text-overflow: ellipsis; | ||
vertical-align: middle; | ||
width: 100%; | ||
|
||
pre { | ||
font-family: inherit; | ||
font-size: 0.75rem; | ||
margin: 0; | ||
} | ||
} | ||
|
||
td.label { | ||
opacity: 0.5; | ||
padding: 0 0.5rem; | ||
text-align: right; | ||
vertical-align: middle; | ||
white-space: nowrap; | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2019 @polkadot/extension authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the Apache-2.0 license. See the LICENSE file for details. | ||
|
||
import { KeyringPair } from '@polkadot/keyring/types'; | ||
import { RequestSign } from './types'; | ||
import { SignerPayloadJSON, SignerPayloadRaw } from '@polkadot/types/types'; | ||
import { u8aToHex, hexToU8a } from '@polkadot/util'; | ||
import { TypeRegistry } from '@polkadot/types'; | ||
|
||
export default class RequestBytesSign implements RequestSign { | ||
inner: SignerPayloadJSON | SignerPayloadRaw; | ||
|
||
constructor (inner: SignerPayloadRaw) { | ||
this.inner = inner; | ||
} | ||
|
||
sign (_registry: TypeRegistry, pair: KeyringPair): { signature: string } { | ||
const inner = this.inner as SignerPayloadRaw; | ||
const signedBytes = pair.sign(hexToU8a(inner.data)); | ||
return { signature: u8aToHex(signedBytes) }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2019 @polkadot/extension authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the Apache-2.0 license. See the LICENSE file for details. | ||
|
||
import { createType, TypeRegistry } from '@polkadot/types'; | ||
import { KeyringPair } from '@polkadot/keyring/types'; | ||
import { RequestSign } from './types'; | ||
import { SignerPayloadJSON, SignerPayloadRaw } from '@polkadot/types/types'; | ||
|
||
export default class RequestExtrinsicSign implements RequestSign { | ||
inner: SignerPayloadJSON | SignerPayloadRaw; | ||
|
||
constructor (inner: SignerPayloadJSON) { | ||
this.inner = inner; | ||
} | ||
|
||
sign (registry: TypeRegistry, pair: KeyringPair): { signature: string } { | ||
const inner = this.inner as SignerPayloadJSON; | ||
const extrinsic = createType(registry, 'ExtrinsicPayload', this.inner, { version: inner.version }); | ||
return extrinsic.sign(pair); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the
SignerPayloadRawBase
contract,data
will always be hex, so it is up to the caller to pass valid data.Also,
type?: 'bytes' | 'payload';
doesn't make sense. One can simplyconst bytes = extrinsic.toU8a(true)
andsignRaw(bytes)
. Can we remove it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
payload
was added specifically for other extensions, such as the centrality one - where they don't care about de-serliazing the payload, but rather just want to sign it as a raw blob. From an implementation perspective, both can just be treated asbytes
here, it does not need to be treated separately for the case wheresignRaw
is called.The reason behind it - in case of transactions, the API will first try to use the normal payload sign, if that is not available will fallback to
signRaw
. Since the normal sign path is catered for, we should not receive a payload in normal circumstances.Either way, it it ever does receive a
type: payload
it actually cannot quite decode it, since it is in a signable form, not a decodable form, so it should be treated it as a "piece of data". (There is a small trick here which came in with v4 where the signature needs to have type information attached in the case of apayload
, but we don't need to cater for it here insignRaw
)TL;DR Ignore the type specifier on
signRaw
, we can just treat alldata
as bytes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very interesting, thank you for writing this in an explanatory way