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
8 changes: 8 additions & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ jobs:
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/setup-node@v2
- run: npx prettier@2.5.0 --list-different .
anti-trojan-source:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/setup-node@v2
- run: npx anti-trojan-source --files='packages/**/src/**/*.{ts,tsx,js}'
locale-kit:
runs-on: ubuntu-20.04
steps:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"devDependencies": {
"@commitlint/cli": "^16.0.0",
"@commitlint/config-conventional": "^16.0.0",
"@dimensiondev/eslint-plugin": "^0.0.1-20220110102506-9f382ee",
"@dimensiondev/eslint-plugin": "^0.0.1-20220117062517-fd3cb01",
"@dimensiondev/patch-package": "^6.5.0",
"@jest/globals": "^27.4.4",
"@magic-works/i18n-codegen": "^0.0.6",
Expand Down
12 changes: 9 additions & 3 deletions packages/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
"yoda": "error",
"radix": "error",
"eqeqeq": ["error", "always"],
"import/no-deprecated": "error",
"import/no-duplicates": "error",
"no-cond-assign": "error",
"no-constant-condition": "error",
"no-extra-boolean-cast": "error",
"no-script-url": "error",
"no-throw-literal": "error",
"no-unmodified-loop-condition": "error",
"no-unneeded-ternary": "error",
"no-useless-concat": "error",
"no-loss-of-precision": "error",
"prefer-regex-literals": "error",
"react/jsx-boolean-value": "error",
"react/jsx-curly-brace-presence": ["warn", { "props": "never", "children": "never" }],
Expand All @@ -43,6 +44,8 @@
"react/self-closing-comp": ["warn", { "component": true, "html": true }],
"react-hooks/exhaustive-deps": "off",
"react-hooks/rules-of-hooks": "error",
"import/no-deprecated": "error",
"import/no-duplicates": "error",
"unicorn/better-regex": "error",
"unicorn/catch-error-name": ["error", { "ignore": ["^err$"] }],
"unicorn/no-instanceof-array": "error",
Expand All @@ -54,13 +57,16 @@
"unicorn/prefer-number-properties": "error",
"unicorn/throw-new-error": "error",
"unused-imports/no-unused-imports-ts": "error",
"@dimensiondev/no-bigint": "error",
"@dimensiondev/no-jsx-template-literal": "error",
"@dimensiondev/no-locale-case": "error",
"@dimensiondev/no-number-constructor": "off",
"@dimensiondev/no-simple-string-interpolation": "off",
"@dimensiondev/no-simple-template-literal": "error",
"@dimensiondev/no-unsafe-location": "error",
"@dimensiondev/no-unneeded-to-string": "error",
"@dimensiondev/prefer-early-return": "error",
"@dimensiondev/prefer-location-assign": "error",
"@dimensiondev/unicode-specific-set": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/no-base-to-string": "off",
"@typescript-eslint/no-for-in-array": "error",
Expand Down
2 changes: 1 addition & 1 deletion packages/dashboard/src/pages/Personas/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function Personas() {
</Paper>
<ContentContainer style={{ display: 'flex', flexDirection: 'column' }}>
<TabContext value={activeTab}>
<Tabs value={!!activeTab ? activeTab : false} onChange={(event, tab) => setActiveTab(tab)}>
<Tabs value={activeTab ? activeTab : false} onChange={(event, tab) => setActiveTab(tab)}>
{definedSocialNetworks.map(({ networkIdentifier }) => (
<Tab
key={networkIdentifier}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @dimensiondev/unicode-specific-set */
import { MenuItem } from '@mui/material'
import { useLanguage } from '../api'
import { Services } from '../../../API'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export const TransferERC20 = memo<TransferERC20Props>(({ token }) => {
InputProps={{
onClick: (event) => {
if (!anchorEl.current) anchorEl.current = event.currentTarget
if (!!ensContent) setPopoverOpen(true)
if (ensContent) setPopoverOpen(true)
setMinPopoverWidth(event.currentTarget.clientWidth)
},
spellCheck: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export const TransferERC721 = memo(() => {
InputProps={{
onClick: (event) => {
if (!anchorEl.current) anchorEl.current = event.currentTarget
if (!!ensContent) setPopoverOpen(true)
if (ensContent) setPopoverOpen(true)
setMinPopoverWidth(event.currentTarget.clientWidth)
},
spellCheck: false,
Expand Down
1 change: 1 addition & 0 deletions packages/dashboard/src/utils/checkLengthExceed.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint @dimensiondev/unicode-specific-set: ["error", { "only": "code" }] */
export const PERSONA_NAME_MAX_LENGTH = 24
export function isPersonaNameLengthValid(value: string) {
// Array.from(string).length is not equal to string.length.
Expand Down
6 changes: 3 additions & 3 deletions packages/encryption/src/payload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export async function parsePayload(payload: unknown): PayloadParserResult {
return parse37(payload.slice())
}
if (typeof payload === 'string') {
if (payload.startsWith('🎼4/4')) return parse38(payload)
if (payload.startsWith('🎼3/4')) return parse39(payload)
if (payload.startsWith('🎼2/4')) return parse40(payload)
if (payload.startsWith('\u{1F3BC}4/4')) return parse38(payload)
if (payload.startsWith('\u{1F3BC}3/4')) return parse39(payload)
if (payload.startsWith('\u{1F3BC}2/4')) return parse40(payload)
}
return new CheckedError(PayloadException.UnknownVersion, null).toErr()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint @dimensiondev/unicode-specific-set: ["error", { "only": "code" }] */
import { encodeText, encodeArrayBuffer } from '@dimensiondev/kit'
import { Ok, Option, Result } from 'ts-results'
import type { PayloadWellFormed, Signature } from '..'
Expand All @@ -24,7 +25,7 @@ export async function encode38(payload: PayloadWellFormed.Payload) {
const encrypted: string = encodeArrayBuffer(payload.encrypted.slice())
const signature: string = encodeSignature(payload.signature)

const fields: string[] = ['🎼4/4', AESKeyEncrypted.val, iv, encrypted, signature]
const fields: string[] = ['\u{1F3BC}4/4', AESKeyEncrypted.val, iv, encrypted, signature]

if (payload.authorPublicKey.some) {
const compressed = await compressSecp256k1Key(payload.authorPublicKey.val.key)
Expand Down
5 changes: 3 additions & 2 deletions packages/encryption/src/payload_internal/version-38.parser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint @dimensiondev/unicode-specific-set: ["error", { "only": "code" }] */
import {
AESKey,
AESAlgorithmEnum,
Expand Down Expand Up @@ -37,7 +38,7 @@ const importEC = CheckedError.withErr(importAsymmetryKeyFromJsonWebKeyOrSPKI, Cr

export async function parse38(payload: string): PayloadParserResult {
//#region Parse text
const header = '🎼4/4'
const header = '\u{1F3BC}4/4'
if (!payload.startsWith(header)) return new CheckedError(PayloadException.InvalidPayload, 'Unknown version').toErr()
let rest = payload.slice(header.length)
// cut the tail
Expand Down Expand Up @@ -107,7 +108,7 @@ function splitFields(raw: string) {
signature: (signature === '_' ? undefined : signature) as string | undefined,
authorPublicKey: authorPublicKey as string | undefined,
authorUserID,
isPublic: isPublic === '1' ? true : false,
isPublic: isPublic === '1',
}
}

Expand Down
5 changes: 3 additions & 2 deletions packages/encryption/src/payload_internal/version-39.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint @dimensiondev/unicode-specific-set: ["error", { "only": "code" }] */
import { parse40 } from './version-40'
import { PayloadException } from '../types'
import type { PayloadParserResult } from '.'
Expand All @@ -14,8 +15,8 @@ import { CheckedError } from '@masknet/shared-base'
// ? Version 40:🎼2/4|ownersAESKeyEncrypted|iv|encryptedText:||
// ? Version 39:🎼3/4|ownersAESKeyEncrypted|iv|encryptedText:||
export async function parse39(payload: string): PayloadParserResult {
const v_40 = '🎼2/4'
const v_39 = '🎼3/4'
const v_40 = '\u{1F3BC}2/4'
const v_39 = '\u{1F3BC}3/4'
if (!payload.startsWith(v_39)) return new CheckedError(PayloadException.UnknownVersion, null).toErr()

const result = await parse40(payload.replace(v_39, v_40))
Expand Down
3 changes: 2 additions & 1 deletion packages/encryption/src/payload_internal/version-40.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint @dimensiondev/unicode-specific-set: ["error", { "only": "code" }] */
import type { PayloadParseResult, Signature } from '../payload'
import { Ok } from 'ts-results'
import { PayloadException } from '../types'
Expand All @@ -13,7 +14,7 @@ const decodeUint8Array = decodeUint8ArrayF(PayloadException.InvalidPayload, Payl
// ? Version 40:🎼2/4|ownersAESKeyEncrypted|iv|encryptedText:||
export async function parse40(payload: string): PayloadParserResult {
//#region Parse string
const header = '🎼2/4|'
const header = '\u{1F3BC}2/4|'
if (!payload.startsWith(header)) return new CheckedError(PayloadException.DecodeFailed, 'Unknown version').toErr()
let rest = payload.slice(header.length)
// cut the tail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Some, None, Option } from 'ts-results'
*/
export function __TwitterEncoder(text: string) {
return `https://mask.io/?PostData_v1=${batchReplace(text, [
['🎼', '%20'],
['\u{1F3BC}', '%20'],
[':||', '%40'],
['+', '-'],
['=', '_'],
Expand All @@ -17,14 +17,14 @@ export function TwitterDecoder(raw: string): Option<string> {
if (!raw) return None
if (!raw.includes('%20') || !raw.includes('%40')) return None
const payloadLink = parseURL(raw)
.map((x) => x.replace(/$/, ''))
.map((x) => x.replace(/\u2026$/, ''))
.filter((x) => x.endsWith('%40'))[0]
try {
const { search, pathname } = new URL(payloadLink)
const payload = search ? search.slice(1) : pathname.slice(1)
if (!payload) return None
return Some(
`🎼${batchReplace(
`\u{1F3BC}${batchReplace(
payload
// https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1476
// eslint-disable-next-line unicorn/better-regex
Expand Down
2 changes: 1 addition & 1 deletion packages/encryption/tests/twitter-encode-decode.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from '@jest/globals'
import { TwitterDecoder } from '../src/social-network-encode-decode'
test('Can decode Twitter text payload', () => {
const payload = `This tweet is encrypted with #mask_io (@realMaskNetwork). 📪🔑
const payload = `This tweet is encrypted with #mask_io (@realMaskNetwork). \u{1F4EA}\u{1F511}

Install https://mask.io/?PostData_v1=%204/4.mFXgbxPDrAD6PYRHWJW5IVlHObuFYs/LUyd08kkUkKimTx4opjHXjrgorrsyTPidL0lkeqdXnW3EzEacdlPJChko-Q5Wy113UMHYy1aV1Wheqwy/vM3PLMVaoKW/HyIL/SjJtim75bWMSHmj+vzMYwV59jLJqlTjJqhz5ObdZhAsWwRJGYIzEkg+.SKlWOvMpyF9T1jL2pr95kA_=.ehROC4d3QudYHEABcBTpSuxLvxM=._.Aq/bVWAKvodJuURGk3enjE1gUiu2SELM8IIKIlNGqOWM.1.dHdpdHRlci5jb20vd2lsbHlvbnRvdXI=%40 to decrypt it.`
expect(TwitterDecoder(payload)).toMatchSnapshot('Twitter example')
Expand Down
4 changes: 2 additions & 2 deletions packages/encryption/tests/v38-encode-decode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ test('Encode v38 payload', async () => {

/* cspell:disable */
const oldInfraOutput =
'🎼4/4|avkwBKqMpCKznGclvChuuh2AEExV0J14xI/KANhwiKJfVyfm2ObWb432E3aAOa7ImRoCd7/JK1d' +
'\u{1F3BC}4/4|avkwBKqMpCKznGclvChuuh2AEExV0J14xI/KANhwiKJfVyfm2ObWb432E3aAOa7ImRoCd7/JK1d' +
'DQWk4rt9NqajTEaajARMc9hJ9GmR8lorBNRNHlgj/h1KJYk5th7Nsr04PWO0nJUKiDH2CJwieSxW2YqxC' +
'I1ceYKUYcZOsVJEZOrJ/IB8WUmU0|BjPbfiSAXCvc/2nqKv2nzQ==|Og1u5pLG9GiWsZbxQwHAGtL6Jqo' +
'=|_|Aq/bVWAKvodJuURGk3enjE1gUiu2SELM8IIKIlNGqOWM|1|ZmFjZWJvb2suY29tLzEwMDAyNzU2MjI' +
'0OTU3NA==:||'
const oldInfraOutputShort =
'🎼4/4|avkwBKqMpCKznGclvChuuh2AEExV0J14xI/KANhwiKJfVyfm2ObWb432E3aAOa7ImRoCd7/JK1d' +
'\u{1F3BC}4/4|avkwBKqMpCKznGclvChuuh2AEExV0J14xI/KANhwiKJfVyfm2ObWb432E3aAOa7ImRoCd7/JK1d' +
'DQWk4rt9NqajTEaajARMc9hJ9GmR8lorBNRNHlgj/h1KJYk5th7Nsr04PWO0nJUKiDH2CJwieSxW2YqxC' +
'I1ceYKUYcZOsVJEZOrJ/IB8WUmU0|BjPbfiSAXCvc/2nqKv2nzQ==|Og1u5pLG9GiWsZbxQwHAGtL6Jqo=|_:||'
/* cspell:enable */
Expand Down
2 changes: 1 addition & 1 deletion packages/encryption/tests/v39-v40-decode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PayloadException } from '../src/types'

/* cspell:disable */
const oldInfraOutput =
'🎼2/4|avkwBKqMpCKznGclvChuuh2AEExV0J14xI/KANhwiKJfVyfm2ObWb432E3aAOa7ImRoCd7/JK1d' +
'\u{1F3BC}2/4|avkwBKqMpCKznGclvChuuh2AEExV0J14xI/KANhwiKJfVyfm2ObWb432E3aAOa7ImRoCd7/JK1d' +
'DQWk4rt9NqajTEaajARMc9hJ9GmR8lorBNRNHlgj/h1KJYk5th7Nsr04PWO0nJUKiDH2CJwieSxW2YqxC' +
'I1ceYKUYcZOsVJEZOrJ/IB8WUmU0|BjPbfiSAXCvc/2nqKv2nzQ==|Og1u5pLG9GiWsZbxQwHAGtL6Jqo=:||'
/* cspell:enable */
Expand Down
7 changes: 4 additions & 3 deletions packages/mask/src/crypto/crypto-alpha-38.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint @dimensiondev/unicode-specific-set: ["error", { "only": "code" }] */
import { TypedMessage, makeTypedMessageText, isTypedMessageText, type AESJsonWebKey } from '@masknet/shared-base'
export * from './crypto-alpha-39'

Expand All @@ -21,15 +22,15 @@ export function typedMessageStringify(x: TypedMessage) {
const obj: Record<string, any> = {}
for (const [a, b] of x.meta) obj[a] = b

return JSON.stringify(obj) + '🧩' + x.content
return JSON.stringify(obj) + '\u{1F9E9}' + x.content
}
export function typedMessageParse(x: string) {
const [maybeMetadata, ...end] = x.split('🧩')
const [maybeMetadata, ...end] = x.split('\u{1F9E9}')
try {
const json: unknown = JSON.parse(maybeMetadata)
if (typeof json !== 'object' || json === null || Object.keys(json).length === 0)
throw new Error('Not a metadata')
return makeTypedMessageText(end.join('🧩'), new Map(Object.entries(json)))
return makeTypedMessageText(end.join('\u{1F9E9}'), new Map(Object.entries(json)))
} catch {}
return makeTypedMessageText(x)
}
5 changes: 3 additions & 2 deletions packages/mask/src/crypto/crypto-alpha-40.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint @dimensiondev/unicode-specific-set: ["error", { "only": "code" }] */
/**
* @deprecated This version of payload is not in use.
* Please goto Crypto alpha v38
Expand Down Expand Up @@ -267,7 +268,7 @@ export async function encryptWithAES(info: {

//#region Comment
function extractCommentPayload(text: string) {
const [_, toEnd] = text.split('🎶2/4|')
const [_, toEnd] = text.split('\u{1F3B6}2/4|')
const [content, _2] = (toEnd || '').split(':||')
if (content.length) return content
return
Expand All @@ -294,7 +295,7 @@ export async function encryptComment(
aesKey: key,
iv: decodeArrayBuffer(postIV as string),
})
return `🎶2/4|${encodeArrayBuffer(x.content)}:||`
return `\u{1F3B6}2/4|${encodeArrayBuffer(x.content)}:||`
}
export async function decryptComment(
postIV: string | ArrayBuffer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ async function* decryptFromImageUrlWithProgress_raw(
pass: author.toText(),
downloadImage: steganographyDownloadImage,
})
if (!post.startsWith('🎼') && !/https:\/\/.+\..+\/(\?PostData_v\d=)?%20(.+)%40/.test(post))
if (!post.startsWith('\u{1F3BC}') && !/https:\/\/.+\..+\/(\?PostData_v\d=)?%20(.+)%40/.test(post))
return makeError(i18n.t('service_decode_image_payload_failed'), true)
const worker = await Result.wrapAsync(() => getNetworkWorker(author))
if (worker.err) return makeError(worker.val as Error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default function (signal: AbortSignal) {
signal.addEventListener(
'abort',
MaskMessages.events.maskSDKHotModuleReload.on(async () => {
const code = (await fetchUserScript(maskSDK_URL)) + `\n;console.log("[@masknet/sdk] SDK reloaded.")`
const code = (await fetchUserScript(maskSDK_URL)) + '\n;console.log("[@masknet/sdk] SDK reloaded.")'
for (const tab of await browser.tabs.query({})) {
browser.tabs.executeScript(tab.id!, { code }).then(noop)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const PopupFrame = memo<PopupFrameProps>((props) => {
)}
</Box>
<Box className={classes.right}>
{!!excludePersonaPath ? null : (
{excludePersonaPath ? null : (
<NavLink to={PopupRoutes.Personas} className={classes.nav} activeClassName={classes.active}>
{t('personas')}
</NavLink>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,11 @@ export const GasSetting1559 = memo(() => {
if (value?.computedPayload._tx.maxFeePerGas && value?.computedPayload._tx.maxPriorityFeePerGas) {
setValue(
'maxPriorityFeePerGas',
fromWei(
new BigNumber(value.computedPayload._tx.maxPriorityFeePerGas).toString(),
'gwei',
).toString(),
fromWei(new BigNumber(value.computedPayload._tx.maxPriorityFeePerGas).toString(), 'gwei'),
)
setValue(
'maxFeePerGas',
fromWei(new BigNumber(value.computedPayload._tx.maxFeePerGas).toFixed(), 'gwei').toString(),
fromWei(new BigNumber(value.computedPayload._tx.maxFeePerGas).toFixed(), 'gwei'),
)
} else {
setOption(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export const Prior1559Transfer = memo<Prior1559TransferProps>(({ selectedAsset,
const { value: minGasLimit, error } = useGasLimit(
selectedAsset?.token.type,
selectedAsset?.token.address,
rightShift(!!amount ? amount : 0, selectedAsset?.token.decimals).toFixed(),
rightShift(amount ? amount : 0, selectedAsset?.token.decimals).toFixed(),
EthereumAddress.isValid(address) ? address : '',
)
//#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ export const Transfer1559 = memo<Transfer1559Props>(({ selectedAsset, openAssetM
const gasFee = formatGweiToWei(maxFeePerGas ?? 0).multipliedBy(MIN_GAS_LIMIT)
let amount_ = new BigNumber(tokenBalance ?? 0)
amount_ = selectedAsset?.token.type === EthereumTokenType.Native ? amount_.minus(gasFee) : amount_
return formatBalance(amount_.toFixed(), selectedAsset?.token.decimals).toString()
return formatBalance(amount_.toFixed(), selectedAsset?.token.decimals)
}, [selectedAsset, maxFeePerGas, minGasLimit, tokenBalance])

//#region set default gasLimit
Expand Down Expand Up @@ -567,7 +567,7 @@ export const Transfer1559TransferUI = memo<Transfer1559UIProps>(
),
onClick: (event) => {
if (!anchorEl.current) anchorEl.current = event.currentTarget
if (!!popoverContent) setPopoverOpen(true)
if (popoverContent) setPopoverOpen(true)
},
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const ActivityListItem = memo<ActivityListItemProps>(
) : (
<Typography className={classes.secondaryDesc}>
{transaction.at ? `${formatDateTime(transaction.at, 'MMM dd')}. ` : null}
{!!toAddress
{toAddress
? t('popups_wallet_activity_to_address', {
address: Utils?.formatDomainName?.(domain) || formatEthereumAddress(toAddress, 4),
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function NFTAvatarButton(props: NFTAvatarButtonProps) {
return (
<div className={classes.root} onClick={onClick}>
<Typography variant="body1" className={classes.text}>
🔥{t('nft_avatar')} <GearSettingsIcon className={classes.icon} />
&#x1F525;{t('nft_avatar')} <GearSettingsIcon className={classes.icon} />
</Typography>
</div>
)
Expand Down
Loading