Skip to content
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
2 changes: 1 addition & 1 deletion packages/injected-script/sdk/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class InjectedProvider {
/**
* Send RPC request to the sdk object.
*/
request(data: unknown): Promise<unknown> {
request<T extends unknown>(data: unknown): Promise<T> {
return createPromise((id) => sendEvent('web3BridgeExecute', [this.pathname, 'request'].join('.'), id, data))
}

Expand Down
6 changes: 3 additions & 3 deletions packages/injected-script/sdk/Coin98.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export class Coin98Provider extends InjectedProvider {
super(pathnameMap[type])
}

override async request(data: RequestArguments): Promise<unknown> {
override async request<T extends unknown>(data: RequestArguments): Promise<T> {
// coin98 cannot handle it correctly (test with coin98 v6.0.3)
if (data.method === 'eth_chainId') {
return this.getProperty('chainId')
return this.getProperty('chainId') as T
}
return super.request(data)
return super.request<T>(data)
}
}
107 changes: 53 additions & 54 deletions packages/plugins/Debugger/src/SNSAdaptor/components/TabContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useAccount, useBalance, useBlockNumber, useWeb3Connection, useWeb3State
import { makeStyles } from '@masknet/theme'
import type { NetworkPluginID, SocialAddress, SocialIdentity } from '@masknet/web3-shared-base'
import { useTokenConstants } from '@masknet/web3-shared-evm'
import { Button, List, ListItem, ListItemText, Table, TableCell, TableRow, Typography } from '@mui/material'
import { Button, List, ListItem, ListItemText, Table, TableBody, TableCell, TableRow, Typography } from '@mui/material'
import { useCallback } from 'react'

export interface TabContentProps {
Expand Down Expand Up @@ -56,11 +56,7 @@ export function TabContent({ identity, socialAddressList }: TabContentProps) {
{socialAddressList?.map((x) => (
<ListItem key={`${x.type}_${x.address}`}>
<ListItemText
primary={
<Typography color="textPrimary">
{x.type}: {x.label}
</Typography>
}
primary={<Typography color="textPrimary">{x.type}</Typography>}
secondary={x.address}
/>
</ListItem>
Expand All @@ -86,60 +82,63 @@ export function TabContent({ identity, socialAddressList }: TabContentProps) {

const onPersonaSign = useCallback(async () => {
const signed = await connection.signMessage('hello world', 'personalSign')
console.log(signed)
window.alert(`Signed: ${signed}`)
}, [connection])

return (
<section className={classes.container}>
<Table size="small">
<TableRow>
<TableCell>
<Typography variant="body2">Balance of {Others?.formatAddress(account, 4)}</Typography>
</TableCell>
<TableCell>
<Typography variant="body2">{balance}</Typography>
</TableCell>
</TableRow>
<TableRow>
<TableCell>
<Typography variant="body2">Block Number</Typography>
</TableCell>
<TableCell>
<Typography variant="body2">{blockNumber}</Typography>
</TableCell>
</TableRow>
<TableRow>
<TableCell>
<Typography variant="body2">Native Token Transfer</Typography>
</TableCell>
<TableCell>
<Button size="small" onClick={onTransferCallback}>
Transfer
</Button>
</TableCell>
</TableRow>
<TableRow>
<TableCell>
<Typography variant="body2">Sign Message</Typography>
</TableCell>
<TableCell>
<Button size="small" onClick={onPersonaSign}>
Sign Message
</Button>
</TableCell>
</TableRow>
<TableRow>
<TableCell>
<Typography variant="body2">Identity</Typography>
</TableCell>
<TableCell>{renderIdentity()}</TableCell>
</TableRow>
<TableRow>
<TableCell>
<Typography variant="body2">Social Address List</Typography>
</TableCell>
<TableCell>{renderAddressNames()}</TableCell>
</TableRow>
<TableBody>
<TableRow>
<TableCell>
<Typography variant="body2">Balance of {Others?.formatAddress(account, 4)}</Typography>
</TableCell>
<TableCell>
<Typography variant="body2">{balance}</Typography>
</TableCell>
</TableRow>
<TableRow>
<TableCell>
<Typography variant="body2">Block Number</Typography>
</TableCell>
<TableCell>
<Typography variant="body2">{blockNumber}</Typography>
</TableCell>
</TableRow>
<TableRow>
<TableCell>
<Typography variant="body2">Native Token Transfer</Typography>
</TableCell>
<TableCell>
<Button size="small" onClick={onTransferCallback}>
Transfer
</Button>
</TableCell>
</TableRow>
<TableRow>
<TableCell>
<Typography variant="body2">Sign Message</Typography>
</TableCell>
<TableCell>
<Button size="small" onClick={onPersonaSign}>
Sign Message
</Button>
</TableCell>
</TableRow>
<TableRow>
<TableCell>
<Typography variant="body2">Identity</Typography>
</TableCell>
<TableCell>{renderIdentity()}</TableCell>
</TableRow>
<TableRow>
<TableCell>
<Typography variant="body2">Social Address List</Typography>
</TableCell>
<TableCell>{renderAddressNames()}</TableCell>
</TableRow>
</TableBody>
</Table>
</section>
)
Expand Down
19 changes: 15 additions & 4 deletions packages/plugins/Flow/src/state/Connection/connection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { first } from 'lodash-unified'
import { unreachable } from '@dimensiondev/kit'
import type { BlockObject, CompositeSignature, MutateOptions, QueryOptions } from '@blocto/fcl'
import type { BlockObject, MutateOptions, QueryOptions } from '@blocto/fcl'
import { ChainId, ProviderType, SchemaType, TransactionStatusCode } from '@masknet/web3-shared-flow'
import {
Account,
Expand All @@ -13,6 +13,7 @@ import {
import { Providers } from './provider'
import type { FlowWeb3Connection as BaseConnection, FlowConnectionOptions } from './types'
import { Web3StateSettings } from '../../settings'
import { toHex } from '@masknet/shared-base'

class Connection implements BaseConnection {
constructor(private chainId: ChainId, private account: string, private providerType: ProviderType) {}
Expand Down Expand Up @@ -180,16 +181,26 @@ class Connection implements BaseConnection {
}
async signMessage(dataToSign: string, signType?: string, options?: FlowConnectionOptions) {
const web3 = await this.getWeb3(options)
return web3.currentUser.signUserMessage(dataToSign)
const data = new TextEncoder().encode(dataToSign)
const signed = first(await web3.currentUser.signUserMessage(toHex(data)))
if (!signed) throw new Error('Failed to sign message.')
return signed.signature
}
async verifyMessage(
dataToVerify: string,
signature: CompositeSignature[],
signature: string,
signType?: string,
options?: FlowConnectionOptions,
): Promise<boolean> {
const web3 = await this.getWeb3(options)
return web3.verifyUserSignatures(dataToVerify, signature)
if (!options?.account) throw new Error('No account found.')
return web3.verifyUserSignatures(dataToVerify, [
{
addr: options?.account,
keyId: 1,
signature,
},
])
}
async callTransaction(query: QueryOptions, options?: FlowConnectionOptions) {
const web3 = await this.getWeb3(options)
Expand Down
18 changes: 11 additions & 7 deletions packages/plugins/Solana/src/state/Connection/providers/Phantom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,37 @@ export class PhantomProvider extends BaseInjectedProvider implements SolanaProvi
super(ProviderType.Phantom, injectedPhantomProvider)
}

override signMessage(dataToSign: string) {
return this.bridge.request({
override async signMessage(dataToSign: string) {
const { signature } = await this.bridge.request<{
publicKey: string
signature: string
}>({
method: PhantomMethodType.SIGN_MESSAGE,
params: {
message: new TextEncoder().encode(dataToSign),
display: 'hex',
},
}) as Promise<string>
})
return signature
}

override signTransaction(transaction: Transaction) {
return this.bridge.request({
return this.bridge.request<Transaction>({
method: PhantomMethodType.SIGN_TRANSACTION,
params: {
message: bs58.encode(transaction.serializeMessage()),
},
}) as Promise<Transaction>
})
}

override async signTransactions(transactions: Transaction[]) {
return this.bridge.request({
return this.bridge.request<Transaction[]>({
method: 'signAllTransactions',
params: {
message: transactions.map((transaction) => {
return bs58.encode(transaction.serializeMessage())
}),
},
}) as Promise<Transaction[]>
})
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PublicKey, Transaction } from '@solana/web3.js'
import { injectedSolflareProvider } from '@masknet/injected-script'
import { Coin98MethodType, ProviderType } from '@masknet/web3-shared-solana'
import { PhantomMethodType, ProviderType } from '@masknet/web3-shared-solana'
import type { SolanaProvider } from '../types'
import { BaseInjectedProvider } from './BaseInjected'

Expand All @@ -11,15 +11,15 @@ export class SolflareProvider extends BaseInjectedProvider implements SolanaProv

override async signMessage(dataToSign: string): Promise<string> {
const { signature } = (await this.bridge.request({
method: Coin98MethodType.SOL_SIGN,
method: PhantomMethodType.SIGN_MESSAGE,
params: [new TextEncoder().encode(dataToSign)],
})) as { signature: string }
return signature
}

override async signTransaction(transaction: Transaction): Promise<Transaction> {
const { signature, publicKey } = (await this.bridge.request({
method: Coin98MethodType.SOL_SIGN,
method: PhantomMethodType.SIGN_TRANSACTION,
params: [transaction],
})) as { signature: Buffer; publicKey: PublicKey }
transaction.addSignature(publicKey, signature)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import base58 from 'bs58'
import type { Transaction } from '@solana/web3.js'
import Wallet from '@project-serum/sol-wallet-adapter'
import { ChainId, ProviderType } from '@masknet/web3-shared-solana'
Expand All @@ -23,7 +24,7 @@ export class SolletProvider extends BaseProvider implements SolanaProvider {
override async signMessage(dataToSign: string) {
const data = new TextEncoder().encode(dataToSign)
const { signature } = await this.solanaProvider.sign(data, 'uft8')
return signature.toString('utf8')
return base58.encode(signature)
}

override signTransaction(transaction: Transaction) {
Expand Down
4 changes: 2 additions & 2 deletions packages/web3-shared/flow/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference path="./env.d.ts" />

import type { CompositeSignature, MutateOptions, BlockObject, TransactionObject } from '@blocto/fcl'
import type { MutateOptions, BlockObject, TransactionObject } from '@blocto/fcl'

export enum ChainId {
Mainnet = 1,
Expand Down Expand Up @@ -42,7 +42,7 @@ export enum TransactionStatusCode {

export type Web3 = typeof import('@blocto/fcl')
export type Web3Provider = {}
export type Signature = CompositeSignature[]
export type Signature = string
export type GasOption = never
export type Block = BlockObject
export type Transaction = MutateOptions
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-shared/solana/constants/descriptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export const PROVIDER_DESCRIPTORS: Array<ProviderDescriptor<ChainId, ProviderTyp
icon: new URL('../assets/coin98.png', import.meta.url),
homeLink: 'https://coin98.com/',
shortenLink: 'solflare.com',
downloadLink: 'https://solflare.com/download',
downloadLink: 'https://coin98.com/wallet',
enableRequirements: {
supportedChainIds: getEnumAsArray(ChainId).map((x) => x.value),
supportedEnhanceableSites: getEnumAsArray(EnhanceableSite).map((x) => x.value),
Expand Down