Skip to content

Commit

Permalink
validate metadata for communities with owner token (#541)
Browse files Browse the repository at this point in the history
* u

* u

* u

* a

* a

* u

* a

* u

* a

* f

* u

* c
  • Loading branch information
felicio authored Mar 26, 2024
1 parent 4e3f3bb commit 195e3f9
Show file tree
Hide file tree
Showing 8 changed files with 236 additions and 68 deletions.
5 changes: 5 additions & 0 deletions .changeset/flat-rabbits-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@status-im/js': minor
---

validate metadata for communities with owner token
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"smartStep": true,
"sourceMaps": true,
"env": {
"DEBUG": "*,-vite*,-connect:*",
// "DEBUG": "*,-vite*,-connect:*",
"DEBUG_HIDE_DATE": "0",
"DEBUG_COLORS": "1",
"VITE_NODE": "true"
Expand Down
6 changes: 3 additions & 3 deletions packages/status-js/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface ClientOptions {
* Public key of a community to join.
*/
publicKey: string
environment?: 'test' // 'production' | 'test'
environment?: 'development' | 'preview' | 'production'
/**
* Custom storage for data persistance
* @default window.localStorage
Expand Down Expand Up @@ -132,7 +132,7 @@ class Client {
}

static async start(options: ClientOptions): Promise<Client> {
const { environment = 'test' } = options
// const { environment = 'development' } = options

let waku: LightNode | undefined
let client: Client | undefined
Expand Down Expand Up @@ -161,7 +161,7 @@ class Client {
* >@see https://forum.vac.dev/t/waku-v2-scalability-studies/142/2
*/
bootstrap({
list: peers[environment],
list: peers['production'],
timeout: 0,
// note: Infinity prevents connection
// tagTTL: Infinity,
Expand Down
42 changes: 42 additions & 0 deletions packages/status-js/src/consts/contracts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* source: @see https://github.com/status-im/communities-contracts#deployments
* source: @see https://github.com/status-im/community-dapp/tree/master/packages/contracts#deployments
*/

// const development = {
// 5: {
// CommunityOwnerTokenRegistry: '0x59510D0b235c75d7bCAEb66A420e9bb0edC976AE',
// },
// 11155111: {
// CommunityOwnerTokenRegistry: '0x98E0A38A9c198F9F49a4F6b49475aE0c92aBbB66',
// },
// 420: {
// CommunityOwnerTokenRegistry: '0x99F0Eeb7E9F1Da6CA9DDf77dD7810B665FD85750',
// },
// // 11155420: {
// // CommunityOwnerTokenRegistry: '0xfFa8A255D905c909379859eA45B959D090DDC2d4',
// // },
// // 421613: {
// // CommunityOwnerTokenRegistry: '0x9C84f9f9970B22E67f1B2BE46ABb1C09741FF7d7',
// // },
// 421614: {
// CommunityOwnerTokenRegistry: '0x9C84f9f9970B22E67f1B2BE46ABb1C09741FF7d7',
// },
// }

const production = {
1: {
CommunityOwnerTokenRegistry: '0x898331B756EE1f29302DeF227a4471e960c50612',
},
10: {
CommunityOwnerTokenRegistry: '0x0AF2c7d60E89a941D586216059814D1Cb4Bd4CAb',
},
42161: {
CommunityOwnerTokenRegistry: '0x76352764590378011CAE677b50110Ae02eDE2b62',
},
}
export const contracts = {
development: production,
preview: production,
production,
}
24 changes: 15 additions & 9 deletions packages/status-js/src/consts/peers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@
* source: @see https://fleets.status.im
*/

const production = [
'/dns4/boot-01.do-ams3.shards.test.status.im/tcp/443/wss/p2p/16Uiu2HAmAR24Mbb6VuzoyUiGx42UenDkshENVDj4qnmmbabLvo31',
'/dns4/boot-01.gc-us-central1-a.shards.test.status.im/tcp/443/wss/p2p/16Uiu2HAm8mUZ18tBWPXDQsaF7PbCKYA35z7WB2xNZH2EVq1qS8LJ',
'/dns4/boot-01.ac-cn-hongkong-c.shards.test.status.im/tcp/443/wss/p2p/16Uiu2HAmGwcE8v7gmJNEWFtZtojYpPMTHy2jBLL6xRk33qgDxFWX',
'/dns4/store-01.do-ams3.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmAUdrQ3uwzuE4Gy4D56hX6uLKEeerJAnhKEHZ3DxF1EfT',
'/dns4/store-02.do-ams3.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAm9aDJPkhGxc2SFcEACTFdZ91Q5TJjp76qZEhq9iF59x7R',
'/dns4/store-01.gc-us-central1-a.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmMELCo218hncCtTvC2Dwbej3rbyHQcR8erXNnKGei7WPZ',
'/dns4/store-02.gc-us-central1-a.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmJnVR7ZzFaYvciPVafUXuYGLHPzSUigqAmeNw9nJUVGeM',
'/dns4/store-01.ac-cn-hongkong-c.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAm2M7xs7cLPc3jamawkEqbr7cUJX11uvY7LxQ6WFUdUKUT',
'/dns4/store-02.ac-cn-hongkong-c.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAm9CQhsuwPR54q27kNj9iaQVfyRzTGKrhFmr94oD8ujU6P',
]

// note!: users may experience additional latency due to cross-regional connection
// todo: use "dynamic" discovery protocol instead
// todo?: use a regional map together with an environment variable for the peer selection (e.g. `VERCEL_REGION`, but probably limited to Serverless Functions)
export const peers = {
// production: [],
test: [
'/dns4/store-01.do-ams3.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmAUdrQ3uwzuE4Gy4D56hX6uLKEeerJAnhKEHZ3DxF1EfT',
'/dns4/store-02.do-ams3.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAm9aDJPkhGxc2SFcEACTFdZ91Q5TJjp76qZEhq9iF59x7R',
'/dns4/store-01.gc-us-central1-a.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmMELCo218hncCtTvC2Dwbej3rbyHQcR8erXNnKGei7WPZ',
'/dns4/store-02.gc-us-central1-a.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmJnVR7ZzFaYvciPVafUXuYGLHPzSUigqAmeNw9nJUVGeM',
'/dns4/store-01.ac-cn-hongkong-c.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAm2M7xs7cLPc3jamawkEqbr7cUJX11uvY7LxQ6WFUdUKUT',
'/dns4/store-02.ac-cn-hongkong-c.shards.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAm9CQhsuwPR54q27kNj9iaQVfyRzTGKrhFmr94oD8ujU6P',
],
development: production,
preview: production,
production,
}
27 changes: 27 additions & 0 deletions packages/status-js/src/consts/providers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// const development = {
// infura: {
// 5: 'https://goerli.infura.io/v3/',
// 11155111: 'https://sepolia.infura.io/v3/',
// 420: 'https://optimism-sepolia.infura.io/v3',
// // 11155420: 'https://optimism-goerli.infura.io/v3'
// // 421613: 'https://arbitrum-goerli.infura.io/v3/',
// 421614: 'https://arbitrum-sepolia.infura.io/v3/',
// },
// }

const production = {
infura: {
1: 'https://mainnet.infura.io/v3/',
10: 'https://optimism-mainnet.infura.io/v3/',
42161: 'https://arbitrum-mainnet.infura.io/v3/',
},
}

export const providers: Record<
'development' | 'preview' | 'production',
Record<string, Record<number, string>>
> = {
development: production,
preview: production,
production,
}
41 changes: 37 additions & 4 deletions packages/status-js/src/ethereum-client/ethereum-client.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import { Point } from 'ethereum-cryptography/secp256k1'
import { ethers } from 'ethers'

import { publicKeyToETHAddress } from '../utils/public-key-to-eth-address'

export class EthereumClient {
private provider: ethers.JsonRpcApiProvider
#provider: ethers.JsonRpcApiProvider

constructor(url: string) {
this.provider = new ethers.JsonRpcProvider(url)
this.#provider = new ethers.JsonRpcProvider(url)
}

stop() {
this.#provider.destroy()
}

async resolvePublicKey(
ensName: string,
options: { compress: boolean }
): Promise<string | undefined> {
try {
const resolver = await this.provider.getResolver(ensName)
const resolver = await this.#provider.getResolver(ensName)

if (!resolver) {
return
Expand All @@ -24,7 +30,7 @@ export class EthereumClient {
'function pubkey(bytes32 node) view returns (bytes32 x, bytes32 y)',
]

const resolverContract = new ethers.Contract(address, abi, this.provider)
const resolverContract = new ethers.Contract(address, abi, this.#provider)

const node = ethers.namehash(ensName)
const [x, y] = await resolverContract.pubkey(node)
Expand All @@ -42,4 +48,31 @@ export class EthereumClient {
return
}
}

async resolveOwner(
registryContractAddress: string,
communityPublicKey: string
): Promise<string | undefined> {
try {
const registryContract = new ethers.Contract(
registryContractAddress,
['function getEntry(address _communityAddress) view returns (address)'],
this.#provider
)
const ownerContractAddress = await registryContract.getEntry(
publicKeyToETHAddress(communityPublicKey)
)

const ownerContract = new ethers.Contract(
ownerContractAddress,
['function signerPublicKey() view returns (bytes)'],
this.#provider
)
const owner = await ownerContract.signerPublicKey()

return owner
} catch {
return
}
}
}
Loading

0 comments on commit 195e3f9

Please sign in to comment.