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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { notify } from 'async-call-rpc/full'
import { MaskMessages } from '../../../shared'
import { nativeAPI, hasNativeAPI } from '../../../shared/native-rpc'
export default function NotificationsToMobile(signal: AbortSignal) {
if (!hasNativeAPI) return

// we don't need response
const forwardToMobile = notify(nativeAPI!.api.notify_visible_detected_profile_changed)
MaskMessages.events.Native_visibleSNS_currentDetectedProfileUpdated.on(forwardToMobile, { signal })
}
2 changes: 2 additions & 0 deletions packages/mask/background/tasks/setup.hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import * as InjectContentScript from './Cancellable/InjectContentScripts'
import * as InjectContentScriptMV3 from './Cancellable/InjectContentScripts-mv3'
import * as IsolatedDashboardBridge from './Cancellable/IsolatedDashboardBridge'
import * as CleanupProfileDatabase from './Cancellable/CleanProfileAndAvatar'
import * as NotificationsToMobile from './Cancellable/NotificationsToMobile'

type CancelableJob = { default: (signal: AbortSignal) => void }
const CancelableJobs: CancelableJob[] = [
NewInstalled,
process.env.manifest === '2' ? InjectContentScript : InjectContentScriptMV3,
IsolatedDashboardBridge,
CleanupProfileDatabase,
NotificationsToMobile,
]

const abort = new AbortController()
Expand Down
14 changes: 12 additions & 2 deletions packages/mask/src/social-network/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,18 @@ export async function activateSocialNetworkUIInner(ui_deferred: SocialNetworkUI.

function $unknownIdentityResolution() {
const provider = ui.collecting.identityProvider
provider?.start(signal)
if (provider?.hasDeprecatedPlaceholderName) {
if (!provider) return
provider.start(signal)
provider.recognized.addListener((newValue, oldValue) => {
if (document.visibilityState === 'hidden') return
if (newValue.identifier.equals(oldValue.identifier)) return
if (newValue.identifier.isUnknown) return

MaskMessages.events.Native_visibleSNS_currentDetectedProfileUpdated.sendToBackgroundPage(
newValue.identifier.toText(),
)
})
if (provider.hasDeprecatedPlaceholderName) {
provider.recognized.addListener((id) => {
if (signal.aborted) return
if (id.identifier.isUnknown) return
Expand Down
4 changes: 0 additions & 4 deletions packages/mask/src/utils/native-rpc/Web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,6 @@ export const MaskNetworkAPI: MaskNetworkAPIs = {
updatedAt: x.updatedAt.getTime(),
}))
},
async SNSAdaptor_getCurrentDetectedProfile() {
const { activatedSocialNetworkUI } = await import('../../social-network')
return activatedSocialNetworkUI.collecting.identityProvider?.recognized.value.identifier.toText()
},
get_all_indexedDB_records: async () => {
const personas = await Services.Identity.queryPersonaRecordsFromIndexedDB()
const profiles = await Services.Identity.queryProfileRecordFromIndexedDB()
Expand Down
2 changes: 2 additions & 0 deletions packages/public-api/src/mobile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
RelationRecord,
PostRecord,
} from './types'
import type { ProfileIdentifier_string } from './web'

/**
* APIs that both Android and iOS implements and have the same API signature
Expand Down Expand Up @@ -112,6 +113,7 @@ export interface SharedNativeAPIs {
pageOption?: PageOption
}): Promise<PostRecord[]>
update_post(params: { post: Partial<PostRecord>; options: { mode: 0 | 1 } }): Promise<PostRecord[]>
notify_visible_detected_profile_changed(newID: ProfileIdentifier_string): Promise<void>
}
/**
* APIs that only implemented by iOS Mask Network
Expand Down
25 changes: 25 additions & 0 deletions packages/public-api/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,31 @@ export interface LinkedProfileDetails {
}

// These type MUST be sync with packages/shared-base/src/crypto/JWKType
export interface JsonWebKey {
alg?: string
crv?: string
d?: string
dp?: string
dq?: string
e?: string
ext?: boolean
k?: string
key_ops?: string[]
kty?: string
n?: string
oth?: RsaOtherPrimesInfo[]
p?: string
q?: string
qi?: string
use?: string
x?: string
y?: string
}
export interface RsaOtherPrimesInfo {
d?: string
r?: string
t?: string
}
export interface EC_Public_JsonWebKey extends JsonWebKey, Nominal<'EC public'> {}
export interface EC_Private_JsonWebKey extends JsonWebKey, Nominal<'EC private'> {}
export interface AESJsonWebKey extends JsonWebKey, Nominal<'AES'> {}
Expand Down
5 changes: 2 additions & 3 deletions packages/public-api/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import type { PersonaRecord, ProfileRecord, RelationFavor, RelationRecord } from
* Methods starts with "SNSAdaptor_" can only be called in SNS Adaptor.
* Other methods can only be called in the background page.
*/
type ProfileIdentifier_string = string
type PersonaIdentifier_string = string
export type ProfileIdentifier_string = string
export type PersonaIdentifier_string = string
export interface MaskNetworkAPIs {
app_suspended(): Promise<void>
app_resume(): Promise<void>
Expand Down Expand Up @@ -79,7 +79,6 @@ export interface MaskNetworkAPIs {
wallet_updateEthereumAccount(params: { account: string }): Promise<void>
wallet_updateEthereumChainId(params: { chainId: number }): Promise<void>
wallet_getLegacyWalletInfo(): Promise<WalletInfo[]>
SNSAdaptor_getCurrentDetectedProfile(): Promise<ProfileIdentifier_string | undefined>
get_all_indexedDB_records(): Promise<{
personas: PersonaRecord[]
profiles: ProfileRecord[]
Expand Down
4 changes: 3 additions & 1 deletion packages/public-api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"compilerOptions": {
"rootDir": "./src/",
"outDir": "./dist/",
"tsBuildInfoFile": "./dist/.tsbuildinfo"
"tsBuildInfoFile": "./dist/.tsbuildinfo",
// NOT including web or node.
"types": []
},
"include": ["./src"],
// This package MUST NOT use any other package.
Expand Down
1 change: 1 addition & 0 deletions packages/shared-base/src/Messages/Mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface MaskSNSEvents {
NFTAvatarUpdated: NFTAvatarEvent
NFTAvatarTimelineUpdated: NFTAvatarEvent
nftAvatarSettingDialogUpdated: NFTAvatarSettingDialogEvent
Native_visibleSNS_currentDetectedProfileUpdated: string
}

export interface MaskEvents extends MaskSettingsEvents, MaskMobileOnlyEvents, MaskSNSEvents {
Expand Down