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

Activated accounts only #1355

Merged
merged 59 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
83cfb71
Basic site key restrictions and scoring checks
forgetso Sep 12, 2024
862e0ca
site key registration in pow integration tests
forgetso Sep 12, 2024
c594dd8
Merge branch 'staging' into activated-accounts-only
forgetso Sep 12, 2024
a4ea455
get integration tests working
forgetso Sep 12, 2024
b4db259
don't double negative
forgetso Sep 12, 2024
ee9be45
Move error
forgetso Sep 13, 2024
5626753
link to FAQ when an error shows
forgetso Sep 13, 2024
1c9ffa6
Make score optional
forgetso Sep 13, 2024
5367915
lint-fix
forgetso Sep 13, 2024
b69ed44
Lint-fix
forgetso Sep 14, 2024
ebad311
Run admin api in cypress tests
forgetso Sep 14, 2024
f448b7a
pass timestamps in auth middleware tests
forgetso Sep 14, 2024
c58e540
Release 2.1.0 (#1371)
prosoponator Sep 19, 2024
06830ad
Remove score related stuff
forgetso Sep 20, 2024
304c6ce
Apply code scanning fix for information exposure through a stack trace
forgetso Sep 20, 2024
c0bfe32
Sort out test config
forgetso Sep 20, 2024
79e5a65
Don't send stacks via API
forgetso Sep 20, 2024
cab9fa6
Merge branch 'staging' into activated-accounts-only
forgetso Sep 20, 2024
97673f5
lint-fix
forgetso Sep 20, 2024
98fb634
Remove argument level
forgetso Sep 20, 2024
32aaa26
Add command to start provider with admin api
forgetso Sep 20, 2024
96a3f4d
Change command to work with concurrently
forgetso Sep 20, 2024
e1e7283
Update correct workflow
forgetso Sep 20, 2024
aba8672
Merge branch 'staging' into activated-accounts-only
forgetso Sep 20, 2024
d112c2c
Move imports
forgetso Sep 20, 2024
fe3f1f2
📦🔒
forgetso Sep 20, 2024
9dce7c2
lint-fix
forgetso Sep 21, 2024
817aa27
Bundle docs URL
forgetso Sep 21, 2024
ad59289
Move translation strings
forgetso Sep 23, 2024
1d3d1f1
Add test to catch translation keys missing
forgetso Sep 23, 2024
5c4ace9
Merge branch 'staging' into activated-accounts-only
forgetso Sep 23, 2024
60e9c00
Big locale overhaul
forgetso Sep 23, 2024
ed026a3
Big locale overhaul
forgetso Sep 23, 2024
8b29639
📦🔒
forgetso Sep 23, 2024
38a6b44
📦🔒
forgetso Sep 23, 2024
f5b29bd
📦🔒
forgetso Sep 23, 2024
d609ee6
tsconfig refs
forgetso Sep 23, 2024
93c96d5
📦🔒
forgetso Sep 23, 2024
cf93f5b
remove polkadot/util from common
forgetso Sep 23, 2024
d08fd29
Use correct package name
forgetso Sep 23, 2024
4856fa6
Use correct package name
forgetso Sep 23, 2024
12af1b8
lint-fix
forgetso Sep 23, 2024
c8efb92
package dir getters
forgetso Sep 23, 2024
a48e47c
Lint-fix and fix import
forgetso Sep 23, 2024
d7c5886
Address PR comments
forgetso Sep 23, 2024
3c47f57
specify no tests for the locale-browser package
forgetso Sep 23, 2024
a3431f3
More imports placed below license
forgetso Sep 23, 2024
20cf36a
Fix merge
forgetso Sep 23, 2024
d40f0d6
Lint-fix
forgetso Sep 23, 2024
24ada94
Merge branch 'staging' into locale-overhaul
forgetso Sep 23, 2024
e991c8c
Merge branch 'locale-overhaul' into activated-accounts-only
forgetso Sep 23, 2024
2d707c2
Merge branch 'staging' into activated-accounts-only
forgetso Sep 23, 2024
3bae3c1
Merge branch 'staging' into activated-accounts-only
forgetso Sep 24, 2024
437c6e6
Merge branch 'staging' into activated-accounts-only
forgetso Sep 24, 2024
58f5255
remove rogue npmignore
forgetso Sep 24, 2024
b412853
Merge branch 'staging' into activated-accounts-only
forgetso Sep 24, 2024
3e16f1a
Merge branch 'staging' into activated-accounts-only
forgetso Sep 24, 2024
7204656
Merge branch 'staging' into activated-accounts-only
forgetso Sep 24, 2024
99f1efb
merge main
forgetso Sep 24, 2024
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
3 changes: 3 additions & 0 deletions .github/workflows/bump_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ on:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
GITHUB_TOKEN: ${{ secrets.PROSOPONATOR_PAT }}

env:
GITHUB_TOKEN: ${{ secrets.PROSOPONATOR_PAT }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ jobs:

- name: Run the cypress tests on client-example
run: |
npx concurrently "npm run start:server" "npm run start:provider" "npm run start:demo" "sleep 10s && npm -w @prosopo/cypress-shared run cypress:run:client-example" --success "first" --kill-others
npx concurrently "npm run start:server" "npm run start:provider:admin" "npm run start:demo" "sleep 10s && npm -w @prosopo/cypress-shared run cypress:run:client-example" --success "first" --kill-others

- name: Run the cypress tests on client-bundle-example
run: |
npx concurrently "npm run start:server" "npm run start:provider" "npm run start:bundle" "sleep 10s && npm -w @prosopo/cypress-shared run cypress:run:client-bundle-example" --success "first" --kill-others
npx concurrently "npm run start:server" "npm run start:provider:admin" "npm run start:bundle" "sleep 10s && npm -w @prosopo/cypress-shared run cypress:run:client-bundle-example" --success "first" --kill-others

- name: Run the cypress tests on client-bundle-example explicit rendering
run: |
npx concurrently "npm run start:server" "npm run start:provider" "npm run start:bundle" "sleep 10s && npm -w @prosopo/cypress-shared run cypress:run:client-bundle-example:explicit" --success "first" --kill-others
npx concurrently "npm run start:server" "npm run start:provider:admin" "npm run start:bundle" "sleep 10s && npm -w @prosopo/cypress-shared run cypress:run:client-bundle-example:explicit" --success "first" --kill-others

# after the test run completes store videos and any screenshots
- uses: actions/upload-artifact@v4
Expand Down
337 changes: 337 additions & 0 deletions .github/workflows/deploy.yml

Large diffs are not rendered by default.

56 changes: 56 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,62 @@ jobs:
cat missing_references.txt
fi

# check that each package.json contains a `build` and `build:cjs` script.
- name: Check for build and build:cjs scripts
run: |
for file in $(find ./packages -name package.json -not -path "**/node_modules/*" -not -path "./packages/detector/*"); do
if ! grep -q '"build":' $file; then
echo "Missing 'build' script in $file"
exit 1
fi
if ! grep -q '"build:cjs":' $file; then
echo "Missing 'build:cjs' script in $file"
exit 1
fi
done

# check that the number of references in each tsconfig.json is equal to the number of references in the tsconfig.cjs.json for each package
- name: Check for matching references in tsconfig.json and tsconfig.cjs.json
run: |
rm -f mismatched_references.txt
for file in $(find ./packages -name tsconfig.json -not -path "**/node_modules/*" -not -path "./packages/detector/*"); do
if [ $(jq '.references | length' $file) -ne $(jq '.references | length' $(dirname $file)/tsconfig.cjs.json) ]; then
echo "Mismatched number of references in $file and $(dirname $file)/tsconfig.cjs.json" >> mismatched_references.txt
fi
done
if [ -f mismatched_references.txt ]; then
cat mismatched_references.txt
exit 1
fi

# check that each @prosopo package referenced in package.json is in the tsconfig.json for each package
- name: Check for matching references in package.json and tsconfig.json
run: |
rm -f missing_references.txt
for file in $(find ./packages -name package.json -not -path "**/node_modules/*" -not -path "./packages/detector/*"); do
for package in $(jq -r '.dependencies | keys[]' $file); do
# if the package is not a @prosopo package, skip it
if ! echo $package | grep -q "^@prosopo"; then
continue
fi

# if the package is @prosopo/config, skip it
if [[ "$package" == "@prosopo/config" ]]; then
continue
fi

# split the package by '/' and get the last element
searchterm=$(echo $package | awk -F/ '{print $NF}')
if ! grep -oI "\"..\/$searchterm\"" $(dirname $file)/tsconfig.json; then
# store the results
echo "Missing reference to $searchterm in $(dirname $file)/tsconfig.json" >> missing_references.txt
fi
done
done
if [ -f missing_references.txt ]; then
cat missing_references.txt
fi

- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
Expand Down
3 changes: 3 additions & 0 deletions demos/client-example/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export default defineConfig(async ({ command, mode }) => {
"process.env.PROSOPO_LOG_LEVEL": JSON.stringify(
process.env.PROSOPO_LOG_LEVEL || "Info",
),
"process.env.PROSOPO_DOCS_URL": JSON.stringify(
process.env.PROSOPO_DOCS_URL,
),
},
build: {
outDir: path.resolve("./dist"),
Expand Down
7 changes: 7 additions & 0 deletions demos/cypress-shared/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@ import vitePreprocessor from "cypress-vite";
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { loadEnv } from "@prosopo/dotenv";
import { defineConfig } from "cypress";
import vitePreprocessor from "cypress-vite";
import { nodePolyfills } from "vite-plugin-node-polyfills";

loadEnv();

export default defineConfig({
video: true,
headers: { "Accept-Encoding": "gzip, deflate" },
env: {
...process.env,
default_page: "/",
},
e2e: {
Expand Down
22 changes: 21 additions & 1 deletion demos/cypress-shared/cypress/e2e/captcha.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,33 @@
// limitations under the License.
/// <reference types="cypress" />
import "@cypress/xpath";
import { u8aToHex } from "@polkadot/util";
import { ProsopoDatasetError } from "@prosopo/common";
import { getPairAsync } from "@prosopo/contract";
import { datasetWithSolutionHashes } from "@prosopo/datasets";
import type { Captcha } from "@prosopo/types";
import { AdminApiPaths, type Captcha } from "@prosopo/types";
import { at } from "@prosopo/util";
import { checkboxClass } from "../support/commands.js";

describe("Captchas", () => {
before(async () => {
const timestamp = new Date().getTime();
const pair = await getPairAsync(Cypress.env("PROSOPO_PROVIDER_MNEMONIC"));
const signature = u8aToHex(pair.sign(timestamp.toString()));
const adminSiteKeyURL = `http://localhost:9229${AdminApiPaths.SiteKeyRegister}`;
await fetch(adminSiteKeyURL, {
method: "POST",
headers: {
"Content-Type": "application/json",
signature: signature,
timestamp: timestamp.toString(),
},
body: JSON.stringify({
siteKey: Cypress.env("PROSOPO_SITE_KEY"),
}),
});
});

beforeEach(() => {
const solutions = datasetWithSolutionHashes.captchas.map((captcha) => ({
captchaContentId: captcha.captchaContentId,
Expand Down
22 changes: 21 additions & 1 deletion demos/cypress-shared/cypress/e2e/correct.captcha.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,32 @@
// limitations under the License.
/// <reference types="cypress" />
import "@cypress/xpath";
import { u8aToHex } from "@polkadot/util";
import { ProsopoDatasetError } from "@prosopo/common";
import { getPairAsync } from "@prosopo/contract";
import { datasetWithSolutionHashes } from "@prosopo/datasets";
import type { Captcha } from "@prosopo/types";
import { AdminApiPaths, type Captcha } from "@prosopo/types";
import { checkboxClass } from "../support/commands.js";

describe("Captchas", () => {
before(async () => {
const timestamp = new Date().getTime();
const pair = await getPairAsync(Cypress.env("PROSOPO_PROVIDER_MNEMONIC"));
const signature = u8aToHex(pair.sign(timestamp.toString()));
const adminSiteKeyURL = `http://localhost:9229${AdminApiPaths.SiteKeyRegister}`;
await fetch(adminSiteKeyURL, {
method: "POST",
headers: {
"Content-Type": "application/json",
signature: signature,
timestamp: timestamp.toString(),
},
body: JSON.stringify({
siteKey: Cypress.env("PROSOPO_SITE_KEY"),
}),
});
});

beforeEach(() => {
const solutions = datasetWithSolutionHashes.captchas.map((captcha) => ({
captchaContentId: captcha.captchaContentId,
Expand Down
22 changes: 21 additions & 1 deletion demos/cypress-shared/cypress/e2e/correct.captcha.signup.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,32 @@
// limitations under the License.
/// <reference types="cypress" />
import "@cypress/xpath";
import { u8aToHex } from "@polkadot/util";
import { ProsopoDatasetError } from "@prosopo/common";
import { getPairAsync } from "@prosopo/contract";
import { datasetWithSolutionHashes } from "@prosopo/datasets";
import type { Captcha } from "@prosopo/types";
import { AdminApiPaths, type Captcha } from "@prosopo/types";
import { checkboxClass } from "../support/commands.js";

describe("Captchas", () => {
before(async () => {
const timestamp = new Date().getTime();
const pair = await getPairAsync(Cypress.env("PROSOPO_PROVIDER_MNEMONIC"));
const signature = u8aToHex(pair.sign(timestamp.toString()));
const adminSiteKeyURL = `http://localhost:9229${AdminApiPaths.SiteKeyRegister}`;
await fetch(adminSiteKeyURL, {
method: "POST",
headers: {
"Content-Type": "application/json",
signature: signature,
timestamp: timestamp.toString(),
},
body: JSON.stringify({
siteKey: Cypress.env("PROSOPO_SITE_KEY"),
}),
});
});

beforeEach(() => {
const solutions = datasetWithSolutionHashes.captchas.map((captcha) => ({
captchaContentId: captcha.captchaContentId,
Expand Down
3 changes: 3 additions & 0 deletions dev/config/src/vite/vite.frontend.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ export default async function (
"process.env.PROSOPO_PACKAGE_VERSION": JSON.stringify(
process.env.PROSOPO_PACKAGE_VERSION,
),
"process.env.PROSOPO_DOCS_URL": JSON.stringify(
process.env.PROSOPO_DOCS_URL,
),
// only needed if bundling with a site key
"process.env.PROSOPO_SITE_KEY": JSON.stringify(
process.env.PROSOPO_SITE_KEY,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"setup": "npm -w @prosopo/scripts run setup",
"setup:all": "npm run setup",
"start:provider": "npm -w @prosopo/cli run start",
"start:provider:admin": "npm -w @prosopo/cli run start:admin",
"start:server": "npm -w @prosopo/client-example-server run start",
"start:demo": "npm -w @prosopo/client-example run start",
"start:bundle": "npm -w @prosopo/client-bundle-example run start",
Expand Down
6 changes: 5 additions & 1 deletion packages/api/src/api/ProviderApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
type PowCaptchaSolutionResponse,
type ProcaptchaToken,
type Provider,
type ProviderApiInterface,
type ProviderRegistered,
type RandomProvider,
type ServerPowCaptchaVerifyRequestBodyType,
Expand All @@ -36,7 +37,10 @@ import {
} from "@prosopo/types";
import HttpClientBase from "./HttpClientBase.js";

export default class ProviderApi extends HttpClientBase implements ProviderApi {
export default class ProviderApi
extends HttpClientBase
implements ProviderApiInterface
{
private account: string;

constructor(providerUrl: string, account: string) {
Expand Down
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"test": "NODE_ENV=${NODE_ENV:-test}; npx vitest run --config ./vite.test.config.ts",
"cli": "node ./dist/cli.js",
"start": "node ./dist/cli.js --api",
"start:admin": "node ./dist/cli.js --api --adminApi",
"start:dev": "node ./dist/cli.js --api --dev"
},
"dependencies": {
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/RateLimiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ export const getRateLimitConfig = () => {
windowMs: process.env.PROSOPO_SUBMIT_USER_EVENTS_WINDOW,
limit: process.env.PROSOPO_SUBMIT_USER_EVENTS_LIMIT,
},
[AdminApiPaths.BatchCommit]: {
windowMs: process.env.PROSOPO_BATCH_COMMIT_WINDOW,
limit: process.env.PROSOPO_BATCH_COMMIT_LIMIT,
},
[AdminApiPaths.UpdateDataset]: {
windowMs: process.env.PROSOPO_UPDATE_DATASET_WINDOW,
limit: process.env.PROSOPO_UPDATE_DATASET_LIMIT,
},
[AdminApiPaths.SiteKeyRegister]: {
windowMs: process.env.PROSOPO_SITE_KEY_REGISTER_WINDOW,
limit: process.env.PROSOPO_SITE_KEY_REGISTER_LIMIT,
},
[AdminApiPaths.ProviderDeregister]: {
windowMs: process.env.PROSOPO_PROVIDER_DEREGISTER_WINDOW,
limit: process.env.PROSOPO_PROVIDER_DEREGISTER_LIMIT,
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/argv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import {
commandProviderSetDataset,
commandSiteKeyRegister,
commandStoreCaptchasExternally,
commandVersion,
} from "./commands/index.js";
Expand Down Expand Up @@ -45,6 +46,7 @@ export function processArgs(
} as const)
.command(commandProviderSetDataset(pair, config, { logger }))
.command(commandStoreCaptchasExternally(pair, config, { logger }))
.command(commandSiteKeyRegister(pair, config, { logger }))
.command(commandVersion(pair, config, { logger }))
.parse();
}
1 change: 1 addition & 0 deletions packages/cli/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
export { default as commandProviderSetDataset } from "./providerSetDataset.js";
export { default as commandStoreCaptchasExternally } from "./storeCaptchasExternally.js";
export { default as commandVersion } from "./version.js";
export { default as commandSiteKeyRegister } from "./siteKeyRegister.js";
53 changes: 53 additions & 0 deletions packages/cli/src/commands/siteKeyRegister.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2021-2024 Prosopo (UK) Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import type { KeyringPair } from "@polkadot/keyring/types";
import { LogLevel, type Logger, getLogger } from "@prosopo/common";
import { ProviderEnvironment } from "@prosopo/env";
import { Tasks } from "@prosopo/provider";
import type { ProsopoConfigOutput } from "@prosopo/types";
import type { ArgumentsCamelCase, Argv } from "yargs";
import { validateSiteKey } from "./validators.js";

export default (
pair: KeyringPair,
config: ProsopoConfigOutput,
cmdArgs?: { logger?: Logger },
) => {
const logger =
cmdArgs?.logger || getLogger(LogLevel.enum.info, "cli.dapp_register");

return {
command: "site_key_register <sitekey>",
describe: "Register a Site Key",
builder: (yargs: Argv) =>
yargs.positional("sitekey", {
type: "string" as const,
demandOption: true,
desc: "The AccountId of the application to register the Site Key with",
} as const),
handler: async (argv: ArgumentsCamelCase) => {
try {
const env = new ProviderEnvironment(config, pair);
await env.isReady();
const siteKey = argv.sitekey;
const tasks = new Tasks(env);
await tasks.clientTaskManager.registerSiteKey(siteKey as string);
logger.info(`Site Key ${argv.sitekey} registered`);
} catch (err) {
logger.error(err);
}
},
middlewares: [validateSiteKey],
};
};
8 changes: 8 additions & 0 deletions packages/cli/src/commands/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ export const validateAddress = (
return { address };
};

export const validateSiteKey = (
argv: ArgumentsCamelCase,
): { sitekey: string } => {
const sitekey = encodeStringAddress(argv.sitekey as string);

return { sitekey };
};

export const validateValue = (argv: ArgumentsCamelCase) => {
if (typeof argv.value !== "number") {
throw new ProsopoEnvError("CLI.PARAMETER_ERROR", {
Expand Down
Loading
Loading