Skip to content
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

Web3 fixes #1126

Merged
merged 6 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/provider_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jobs:

# create the provider image for AMD64
- name: Build the Provider Container
id: build_docker_provider
id: build_docker_provider_amd64
continue-on-error: true
uses: docker/build-push-action@v5
with:
Expand All @@ -129,7 +129,7 @@ jobs:

# create the provider image for ARM64
- name: Build the Provider Container
id: build_docker_provider
id: build_docker_provider_arm64
continue-on-error: true
uses: docker/build-push-action@v5
with:
Expand Down
2 changes: 2 additions & 0 deletions demos/client-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"@emotion/react": "^11.9.3",
"@emotion/styled": "^11.9.3",
"@mui/material": "^5.9.1",
"@polkadot/extension-dapp": "0.46.6",
"@polkadot/extension-inject": "0.46.6",
"@prosopo/common": "0.3.36",
"@prosopo/procaptcha": "0.3.36",
"@prosopo/procaptcha-react": "0.3.36",
Expand Down
22 changes: 15 additions & 7 deletions demos/client-example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import {
ProcaptchaConfigSchema,
ProcaptchaOutput,
} from '@prosopo/types'
import { ExtensionAccountSelect, Procaptcha } from '@prosopo/procaptcha-react'
import { ExtensionAccountSelect } from './components/ExtensionAccountSelect.js'
import { Procaptcha } from '@prosopo/procaptcha-react'
import { ProcaptchaFrictionless } from '@prosopo/procaptcha-frictionless'
import { useState } from 'react'

Expand Down Expand Up @@ -165,15 +166,22 @@ function App(props: AppProps) {
>
<Box>
<Typography component={'span'}>{message ? getMessage() : null}</Typography>
{!config.web2 ? (
<ExtensionAccountSelect dappName={config.dappName} value={account} onChange={setAccount} />
) : (
<></>
)}

<Box>
<h1>{label}</h1>
<form>
<FormGroup sx={{ '& .MuiTextField-root': { m: 1 } }}>
<FormGroup sx={{ '& .MuiTextField-root,#select-account': { m: 1 } }}>
{!config.web2 ? (
<FormControl>
<ExtensionAccountSelect
dappName={config.dappName}
value={account}
onChange={setAccount}
/>
</FormControl>
) : (
<></>
)}
<FormControl>
<TextField
id="email"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const ExtensionAccountSelect = ({
}
}}
value={accounts.length > 0 && account ? account.address : undefined}
style={{ width: '550px' }}
style={{ width: '550px', borderRadius: '4px', padding: '16.5px 14px' }}
>
{accounts.map(({ address, meta: { name } }) => (
<option value={address}>{name}</option>
Expand Down
1 change: 0 additions & 1 deletion packages/procaptcha-react/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.
export * from './CaptchaWidget.js'
export * from './CaptchaComponent.js'
export * from './ExtensionAccountSelect.js'
export { default as ProcaptchaWidget } from './ProcaptchaWidget.js'
export { default as Procaptcha } from './Procaptcha.js'
export * from './Procaptcha.js'
23 changes: 11 additions & 12 deletions packages/procaptcha/src/modules/ProsopoCaptchaApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,22 @@ export class ProsopoCaptchaApi implements ProsopoCaptchaApiInterface {

let signature: string | undefined = undefined

if (this.web2) {
if (!signer || !signer.signRaw) {
throw new ProsopoEnvError('GENERAL.CANT_FIND_KEYRINGPAIR', {
context: { error: 'Signer is not defined, cannot sign message to prove account ownership' },
})
}
// sign the request hash to prove account ownership
const signed = await signer.signRaw({
address: this.userAccount,
data: stringToHex(requestHash),
type: 'bytes',
if (!signer || !signer.signRaw) {
throw new ProsopoEnvError('GENERAL.CANT_FIND_KEYRINGPAIR', {
context: { error: 'Signer is not defined, cannot sign message to prove account ownership' },
})
signature = signed.signature
}

let result: CaptchaSolutionResponse

// sign the request hash to prove account ownership
const signed = await signer.signRaw({
address: this.userAccount,
data: stringToHex(requestHash),
type: 'bytes',
})
signature = signed.signature

try {
result = await this.providerApi.submitCaptchaSolution(
solutions,
Expand Down
4 changes: 2 additions & 2 deletions packages/provider/src/tasks/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,15 @@ export class Tasks {
dappAccount: string,
requestHash: string,
captchas: CaptchaSolution[],
signature: string // the signature to indicate ownership of account (web2 only)
signature: string // the signature to indicate ownership of account
): Promise<DappUserSolutionResult> {
if (!(await this.dappIsActive(dappAccount))) {
throw new ProsopoEnvError('CONTRACT.DAPP_NOT_ACTIVE', {
context: { failedFuncName: this.getPaymentInfo.name, dappAccount },
})
}

// check that the signature is valid (i.e. the web2 user has signed the message with their private key, proving they own their account)
// check that the signature is valid (i.e. the user has signed the request hash with their private key, proving they own their account)
const verification = signatureVerify(stringToHex(requestHash), signature, userAccount)
if (!verification.isValid) {
// the signature is not valid, so the user is not the owner of the account. May have given a false account address with good reputation in an attempt to impersonate
Expand Down
Loading