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

upgrade canvas to 0.11.0 #9494

Closed
11 changes: 2 additions & 9 deletions libs/model/src/middleware/authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import {
type Context,
type Handler,
} from '@hicommonwealth/core';
import {
Group,
GroupPermissionAction,
} from '@hicommonwealth/schemas';
import { Group, GroupPermissionAction } from '@hicommonwealth/schemas';
import { Role } from '@hicommonwealth/shared';
import { Op, QueryTypes } from 'sequelize';
import { ZodSchema, z } from 'zod';
Expand Down Expand Up @@ -304,11 +301,7 @@ export function isAuthorized({

if (action) {
// waterfall stops here after validating the action
await hasTopicInteractionPermissions(
ctx.actor,
auth,
action,
);
await hasTopicInteractionPermissions(ctx.actor, auth, action);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion libs/model/src/thread/CreateThread.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function CreateThread(): Command<
...schemas.CreateThread,
auth: [
isAuthorized({
action: schemas.PermissionEnum.CREATE_THREAD
action: schemas.PermissionEnum.CREATE_THREAD,
}),
verifyThreadSignature,
],
Expand Down
2 changes: 1 addition & 1 deletion libs/schemas/src/entities/group-permission.schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export enum PermissionEnum {
CREATE_COMMENT = 'CREATE_COMMENT',
CREATE_THREAD_REACTION = 'CREATE_THREAD_REACTION',
CREATE_COMMENT_REACTION = 'CREATE_COMMENT_REACTION',
UPDATE_POLL = 'UPDATE_POLL'
UPDATE_POLL = 'UPDATE_POLL',
}

export type GroupPermissionAction = keyof typeof PermissionEnum;
Expand Down
21 changes: 12 additions & 9 deletions libs/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,22 @@
"lint-diff": "NODE_OPTIONS=\"--max-old-space-size=4096\" eslint -c ../../.eslintrc-diff.cjs './src/**/*.{ts,tsx}'"
},
"dependencies": {
"@canvas-js/chain-cosmos": "^0.10.10",
"@canvas-js/chain-ethereum": "^0.10.10",
"@canvas-js/chain-solana": "^0.10.10",
"@canvas-js/chain-substrate": "^0.10.10",
"@canvas-js/core": "^0.10.10",
"@canvas-js/gossiplog": "^0.10.10",
"@canvas-js/interfaces": "^0.10.10",
"@canvas-js/signatures": "^0.10.10",
"@canvas-js/chain-cosmos": "^0.11.0",
"@canvas-js/chain-ethereum": "^0.11.0",
"@canvas-js/chain-solana": "^0.11.0",
"@canvas-js/chain-substrate": "^0.11.0",
"@canvas-js/core": "^0.11.0",
"@canvas-js/gossiplog": "^0.11.0",
"@canvas-js/interfaces": "^0.11.0",
"@canvas-js/signatures": "^0.11.0",
"@cosmjs/encoding": "0.32.3",
"@ethersproject/bignumber": "^5.7.0",
"@ipld/dag-json": "^10.2.0",
"@libp2p/peer-id-factory": "^4.2.4",
"@libp2p/crypto": "^5.0.4",
"@libp2p/peer-id": "^5.0.4",
"@polkadot/util": "12.6.2",
"ethers": "^6.13.2",
"libp2p": "^2.1.3",
"moment": "^2.23.0",
"safe-stable-stringify": "^2.4.2"
},
Expand Down
32 changes: 15 additions & 17 deletions libs/shared/src/canvas/runtime/node.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { Canvas } from '@canvas-js/core';
import {
createEd25519PeerId,
createFromProtobuf,
} from '@libp2p/peer-id-factory';
import { generateKeyPair, privateKeyFromProtobuf } from '@libp2p/crypto/keys';
import { Libp2p } from 'libp2p';
import { ConnectionConfig } from 'pg';

import { getSessionSigners } from '../signers';
import { contract, contractTopic } from './contract';

export const CANVAS_TOPIC = contractTopic;

export const startCanvasNode = async (config: { PEER_ID?: string }) => {
export const startCanvasNode = async (config: {
PEER_ID?: string;
}): Promise<{ app: Canvas; libp2p: Libp2p }> => {
const path =
process.env.FEDERATION_POSTGRES_DB_URL ??
(process.env.APP_ENV === 'local'
Expand All @@ -21,9 +20,9 @@ export const startCanvasNode = async (config: { PEER_ID?: string }) => {
const listen =
process.env.FEDERATION_LISTEN_ADDRESS ?? '/ip4/127.0.0.1/tcp/8090/ws';

const peerId = config.PEER_ID
? await createFromProtobuf(Buffer.from(config.PEER_ID, 'base64'))
: await createEd25519PeerId();
const privateKey = config.PEER_ID
? privateKeyFromProtobuf(Buffer.from(config.PEER_ID, 'base64'))
: await generateKeyPair('Ed25519');

let pgConnectionConfig: ConnectionConfig | undefined = undefined;

Expand All @@ -47,19 +46,18 @@ export const startCanvasNode = async (config: { PEER_ID?: string }) => {
}

const app = await Canvas.initialize({
peerId,
topic: contractTopic,
path: pgConnectionConfig!,
contract,
signers: getSessionSigners(),
bootstrapList: [],
});

const libp2p = await app.startLibp2p({
announce: [announce],
listen: [listen],
bootstrapList: [],
privateKey,
start: true,
});

if (config.PEER_ID) {
await app.libp2p.start();
}

return app;
return { app, libp2p };
};
6 changes: 4 additions & 2 deletions libs/shared/src/canvas/signers/signers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import {
DidIdentifier,
Session,
Signer,
Snapshot,
} from '@canvas-js/interfaces';
import { fromBech32, toBech32 } from '@cosmjs/encoding';
import { addressSwapper } from '@hicommonwealth/shared';
import * as json from '@ipld/dag-json';
import { KeypairType } from '@polkadot/util-crypto/types';
import { Wallet } from 'ethers';

export const getTestSigner = () => {
return new SIWESigner();
return new SIWESigner({ signer: Wallet.createRandom() });
};

export const getSessionSigners = () => {
Expand Down Expand Up @@ -168,7 +170,7 @@ export class SubstrateSignerCW extends SubstrateSigner {
options: { did?: string; address?: string } = {},
): Promise<{
payload: Session<SubstrateSessionData>;
signer: Signer<Action | Session<SubstrateSessionData>>;
signer: Signer<Action | Snapshot | Session<SubstrateSessionData>>;
} | null> {
let did;
if (options.address) {
Expand Down
19 changes: 10 additions & 9 deletions packages/commonwealth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@
"dependencies": {
"@atomone/govgen-types-long": "^0.3.9",
"@brillout/import": "^0.2.2",
"@canvas-js/chain-cosmos": "^0.10.10",
"@canvas-js/chain-ethereum": "^0.10.10",
"@canvas-js/chain-solana": "^0.10.10",
"@canvas-js/chain-substrate": "^0.10.10",
"@canvas-js/core": "^0.10.10",
"@canvas-js/gossiplog": "^0.10.10",
"@canvas-js/interfaces": "^0.10.10",
"@canvas-js/signatures": "^0.10.10",
"@canvas-js/chain-cosmos": "^0.11.0",
"@canvas-js/chain-ethereum": "^0.11.0",
"@canvas-js/chain-solana": "^0.11.0",
"@canvas-js/chain-substrate": "^0.11.0",
"@canvas-js/core": "^0.11.0",
"@canvas-js/gossiplog": "^0.11.0",
"@canvas-js/interfaces": "^0.11.0",
"@canvas-js/signatures": "^0.11.0",
"@cosmjs/amino": "^0.31.3",
"@cosmjs/cosmwasm-stargate": "^0.31.3",
"@cosmjs/crypto": "0.31.3",
Expand Down Expand Up @@ -120,7 +120,8 @@
"@knocklabs/react": "^0.2.15",
"@knocklabs/react-notification-feed": "^0.8.15",
"@lexical/rich-text": "^0.17.0",
"@libp2p/peer-id-factory": "^4.2.4",
"@libp2p/crypto": "^5.0.4",
"@libp2p/peer-id": "^5.0.4",
"@magic-ext/cosmos": "^12.1.3",
"@magic-ext/oauth": "^11.1.1",
"@magic-sdk/admin": "^2.4.0",
Expand Down
14 changes: 10 additions & 4 deletions packages/commonwealth/scripts/create-peer-id.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { logger } from '@hicommonwealth/core';
import { createEd25519PeerId, exportToProtobuf } from '@libp2p/peer-id-factory';
import { generateKeyPair, privateKeyToProtobuf } from '@libp2p/crypto/keys';
import { peerIdFromPrivateKey } from '@libp2p/peer-id';

const log = logger(import.meta);

const id = await createEd25519PeerId();
log.info(`# ${id}`);
log.info(`PEER_ID=${Buffer.from(exportToProtobuf(id)).toString('base64')}`);
const privateKey = await generateKeyPair('Ed25519');

const peerId = peerIdFromPrivateKey(privateKey);

log.info(`# ${peerId}`);
log.info(
`PEER_ID=${Buffer.from(privateKeyToProtobuf(privateKey)).toString('base64')}`,
);
4 changes: 2 additions & 2 deletions packages/commonwealth/server/federation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { parse } from '@ipld/dag-json';
import { config } from '../config';

const log = logger(import.meta);
export const canvas = await startCanvasNode(config);
export const { app: canvas, libp2p } = await startCanvasNode(config);

log.info(
'canvas: started libp2p with multiaddrs: ' +
canvas.libp2p
libp2p
.getMultiaddrs()
.map((m) => m.toString())
.join(', '),
Expand Down
6 changes: 5 additions & 1 deletion packages/commonwealth/test/util/modelUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
type Role,
} from '@hicommonwealth/shared';
import chai from 'chai';
import { Wallet } from 'ethers';
import type { Application } from 'express';
import { z } from 'zod';
import { TEST_BLOCK_INFO_STRING } from './keys';
Expand Down Expand Up @@ -259,7 +260,10 @@ export const modelSeeder = (app: Application, models: DB): ModelSeeder => ({
if (chain === 'ethereum' || chain === 'alex') {
wallet_id = 'metamask';
chain_id = chain === 'alex' ? '3' : '1'; // use ETH mainnet for testing except alex
sessionSigner = new SIWESigner({ chainId: parseInt(chain_id) });
sessionSigner = new SIWESigner({
chainId: parseInt(chain_id),
signer: Wallet.createRandom(),
});
} else if (chain === 'edgeware') {
wallet_id = 'polkadot';
sessionSigner = new SubstrateSignerCW();
Expand Down
Loading
Loading