-
Notifications
You must be signed in to change notification settings - Fork 11
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
feat(extension-chrome): ownership service #76
Conversation
41fcc72
to
cc84f60
Compare
added test cases mentioned above, and now the branch coverage is higher |
packages/extension-chrome/__tests__/services/ownership/ownership.ts
Outdated
Show resolved
Hide resolved
} | ||
} | ||
|
||
export class BackendProvider { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should remove it because config is loaded from ConfigService
nodeUri: string; | ||
indexer: Indexer; | ||
rpc: RPC; | ||
indexerRPC: IndexerRPC; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these properties are unnecessary, which make it hard to test and limits support for the other backend like the CKB Light Client in the future
indexerCursor?: string; | ||
}; | ||
}) => Promise<Paginate<Cell>>; | ||
getLiveCellFetcher: () => (outPoint: OutPoint) => Promise<Cell>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getLiveCell(outPoint: OutPoint): Promise<Cell>
is enough
rpc: RPC; | ||
indexerRPC: IndexerRPC; | ||
|
||
hasHistory: (payload: { lock: Script }) => Promise<boolean>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be hasHistories(payload: { lock: Script }): Promise<boolean[]>
fetch histories without batching probably cause performance issue
}, | ||
}; | ||
} | ||
export async function getOnchainLockProvider( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be getOnChainLockProvider
}); | ||
} | ||
|
||
async getlockInfoByLock({ lock }: { lock: Script }): Promise<LockInfo | undefined> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be getLockInfoByLock
const lockInfo = await config.locksManager.getlockInfoByLock({ lock: payload.lock }); | ||
asserts.asserts(lockInfo, 'Lock not found when call signData with', payload); | ||
const password = (await config.notificationService.requestSignData({ data: payload.data })).password; | ||
const signature = await config.keystoreService.signMessage({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to avoid security risk, the signData must with some magick bytes, we can mark a TODO here
const keystoreService = createServicesFactory().get('keystoreService'); | ||
const storage = createServicesFactory().get('storage'); | ||
if (!keystoreService || !storage) return; | ||
console.log('wallet already initialized, start probe task...'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can use the logger instead of console.log
const keystoreService = createServicesFactory().get('keystoreService'); | ||
const storage = createServicesFactory().get('storage'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactor the keystoreSertvice
and storage
to params instead of createServiceFactory
everywhere
|
||
export interface WalletMethods extends CallMap { | ||
wallet_enable: Call<void, void>; | ||
wallet_isEnabled: Call<void, boolean>; | ||
wallet_getNetworkName: Call<void, string>; | ||
|
||
wallet_fullOwnership_getUnusedLocks: Call<void, Script[]>; | ||
wallet_fullOwnership_getOffChainLocks: Call<GetOffChainLocksPayload, Promise<Script[]>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Promise
is unnecessary in Call
@@ -24,15 +30,121 @@ addMethod('wallet_enable', async (_, { getRequesterAppInfo, resolveService }) => | |||
} | |||
|
|||
await configService.addWhitelistItem({ host: host, favicon: `${protocol}//${host}/favicon.ico` }); | |||
const servicesFactory = createServicesFactory(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use resolveService
instead of createServicesFactory() everywhere
}); | ||
|
||
addMethod('wallet_fullOwnership_getOffChainLocks', async (payload) => { | ||
console.log('===================================='); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
======
is unnecessary, if you just want to make a different logger, please createLogger('special_module_name') to instead
const keystoreService = await servicesFactory.get('keystoreService'); | ||
const notificationService = await servicesFactory.get('notificationService'); | ||
const storage = await servicesFactory.get('storage'); | ||
console.log('storage', await storage.getItem('full' as never)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avoid using never
as a parameter, it is not recommendded
This PR has many issues, and we should plan to reimplement this PR Complex AsynchronousOwnership need to handle many async, this PR uses Not Enough AbstractionThe interface DerivedLocks {
lockInfos: LockInfo[];
}
const isFullOwnership = (info) => info.parantPath === FULL_OWNERSHIP_PARENT_PATH;
const isRuleBasedOwnership = (info) => info.parentPath === RULE_BASED_OWNERSHIP_PARENT_PATH;
const isOnChain = (info) => info.change === 'external';
const ifOffChain = (info) => info.change === 'internal';
// an async db driver
const infos = await lockInfos.filter(compose(isFullOwnership, isOffChain));
... Therefor, we will not merge this PR, but we will use this branch for writing e2e cases |
Signed-off-by: homura <homura.dev@gmail.com>
Signed-off-by: homura <homura.dev@gmail.com>
Signed-off-by: homura <homura.dev@gmail.com>
Signed-off-by: homura <homura.dev@gmail.com>
Signed-off-by: homura <homura.dev@gmail.com>
Signed-off-by: homura <homura.dev@gmail.com>
Signed-off-by: homura <homura.dev@gmail.com>
9812f54
to
ce4f107
Compare
usage: