Skip to content

feat: Added new setOwner method to establish connection before initialization of the owner - #509

Draft
roman-nazaruk wants to merge 3 commits into
mainfrom
feat/added-setOwner-method
Draft

feat: Added new setOwner method to establish connection before initialization of the owner#509
roman-nazaruk wants to merge 3 commits into
mainfrom
feat/added-setOwner-method

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

I removed the need to set the owner during initialization and added a setOwner method to assign it later. Now, if no owner is set when a method that requires it is called, the signer returns a NOT_INITIALIZED error via the notifyError function.

Tests

I updated the tests so that when an owner is not set, the owner-dependent methods return a NOT_INITIALIZED error via notifyError.

@roman-nazaruk
roman-nazaruk requested a review from a team as a code owner March 14, 2025 16:58

@peterpeterparker peterpeterparker left a comment

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.

Thanks. Few comments. Some new, some similar to those are provided in previous PR #504.

Note that I did not reviewed the tests yet. Let's first focus on the logical part if this makes sense.

});

export type SignerOptions = z.infer<typeof SignerOptionsSchema>;
export type SignerInitOptions = Omit<SignerOptions, '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.

Same question as previously: #504 (comment)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Created a new separate PR.

}, 'The value provided is not a valid Identity.');

const IdentityNotAnonymousSchema = IdentitySchema.refine(
export const IdentityNotAnonymousSchema = IdentitySchema.refine(

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.

If you export schema that wasn't exposed before, please provides the modification in a separate PR with dedicated tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Created a new separate PR.

Comment thread src/signer.ts
initialized: boolean;
} {
try {
// Use Zod to assert that the owner is not nullish and not anonymous.

@peterpeterparker peterpeterparker Mar 14, 2025

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.

  • I think we can spare this comment.
  • No strong opinion but for code consistency, should we use safeParse here?

Comment thread src/signer.ts
const {success: isCallCanisterRequest, data: callData} =
IcrcCallCanisterRequestSchema.safeParse(data);

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.

Same as #504 (comment)

Comment thread src/signer.ts
*/
setOwner = ({owner}: {owner: IdentityNotAnonymous}): void => {
if (nonNullish(this.#owner)) {
return;

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.

IMO we should throw an exception and not silently irgnore it because this might be a misusage.

Comment thread src/signer.ts
};

/**
* Sets owner to signer, thats allows to communicate with a relying party.

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.

I would reuse the existing JS Docs that describes the owner in SignerOptionsSchema. To some extent we just move it from the option argument to an internal variable.

/**
   * The owner who interacts with the signer.
   *
   * When the signer is initialized, the owner should be signed in to the consumer dApp.
   * Upon signing out, it is up to the consumer to disconnect the signer.
   */

Comment thread src/signer.ts
return;
}

const {initialized} = this.handleOwnerInitialized(message);

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.

Same as #504 (comment)

@roman-nazaruk
roman-nazaruk marked this pull request as draft March 17, 2025 10:01
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