Skip to content

feat: added new method to set owner after establishing connection signer with wallet - #504

Draft
roman-nazaruk wants to merge 6 commits into
mainfrom
feat/icrc-29-without-owner
Draft

feat: added new method to set owner after establishing connection signer with wallet#504
roman-nazaruk wants to merge 6 commits into
mainfrom
feat/icrc-29-without-owner

Conversation

@roman-nazaruk

Copy link
Copy Markdown
Contributor

Motivation

We are updating the oisy-signer so that it now waits for a valid owner to be set before processing non‑read‑only messages, ensuring that it returns a clear NOT_INITIALIZED error when not logged in.

Changes

Added new method to init owner after the connection was established between Signer and wallet

Tests

Added new unit test to cover new logic.

});
};

export const notifyErrorNotInitializes = (notify: Notify): void => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide this in another PR.

});

export const SignerOptionsSchema = z.object({
export const SignerInitOptionsSchema = z.object({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you creating a duplicate of the options?

Why are host and sessionOptions provided in both SignerInitOptionsSchema and SignerOptionsSchema?

If this is necessary, can at least parts of it be provided in a separate PR with related tests?

Comment thread src/signer.ts
private handleOwnerInitialized({data: msgData, origin}: SignerMessageEvent): {
initialized: boolean;
} {
if (isNullish(this.#owner)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use Zod to assert not nullish and no anonymous as well? Just in case sh** happens.

Comment thread src/signer.ts
return {handled: false};
}

if (isNullish(this.#owner)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not sound correct, should an error be throw somewhere if the owner is null at this point?

Comment thread src/signer.ts

const currentPermission = sessionScopeState({
owner: owner.getPrincipal(),
owner: this.#owner?.getPrincipal(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional chaining is not necessary here no?

Comment thread src/signer.ts
window.addEventListener('message', this.onMessageListener);
}

setOwner = (owner: IdentityNotAnonymous) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Can you add the missing JS docs.

  • Should we use an object as parameter? {owner}: {owner: IdentityNotAnonymous}?

Comment thread src/signer.spec.ts
});
});

describe('Should init Signer without owner and notify error regarding owner not set', () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we perform the same test for every types of request not solely for status?

Comment thread src/signer.ts
setOwner = (owner: IdentityNotAnonymous) => {
IdentityNotAnonymousSchema.parse(owner);

this.#owner = owner;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldln't we add an assertion that disallow overwriting the owner once set?

Comment thread src/signer.ts
disconnect = (): void => {
window.removeEventListener('message', this.onMessageListener);
this.#walletOrigin = null;
this.#owner = null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a test that asserts the owner is set back to null after disconnect?

Comment thread src/signer.spec.ts
vi.restoreAllMocks();
});

it('should emit NOT_INITIALIZED error when a status message is received and no owner is set', async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this test actually incorrect? Status and supported standard should be emitted even if the signer is not initialized. Can you improve the code and add some tests in that direction?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants