Skip to content
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

Updates & revamps ParticleAdapter #840

Closed
wants to merge 9 commits into from

Conversation

TABASCOatw
Copy link
Contributor

ParticleAdapter is the adapter for an MPC-TSS Wallet-as-a-Service provider, Particle Network.

This adapter was quite out of date, and thus configuration (through config on a new instance of ParticleAdapter) didn't work and was incompatible with the current Particle dashboard. This has been fixed through:

  • Updating dependency @particle-network/solana-wallet
  • Slight rework of core adapter logic to solve outstanding issues

This has been tested and is functional, enabling the standard level of configuration possible with modern implementations of Particle (customizing UI, choosing wallet popup options, etc.)

In addition to this, functionality has been introduced to select preferredAuthType when adding ParticleAdapter to a list of wallets. preferredAuthType can either be a string or an object containing type and boolean setAsDisplay

preferredAuthType dictates if ParticleAdapter automatically routes to a specific mechanism of wallet authentication (social login). If preferredAuthType is set to an object with setAsDisplay as true, Particle will display in the wallet connection list corresponding to the selected social login provider, indicating the shortcut. Otherwise if setAsDisplay is set to false or if preferredAuthType is undefined/a string, authentication will be handled within a generic Particle option according to the status of preferredAuthType.

@TABASCOatw
Copy link
Contributor Author

Quick bump

@TABASCOatw
Copy link
Contributor Author

GM @jordansexton! Happy to make any changes here if needed; all updates here have been tested and are working as of this week.

@TABASCOatw
Copy link
Contributor Author

TABASCOatw commented Nov 29, 2023

GM! Going to followup again here quickly if possible; would be awesome to have a review in the next few days as we'll be making a big Solana push soon, in which this update to our adapter is a key component. Apologies for the repeated bumps, just a bit important~ let me know if there's anything we can do to help make reviewing a bit easier @jordaaash; thank you!

@mcintyre94
Copy link
Collaborator

Hey @TABASCOatw, sorry for the delay here!

I'm trying to build this locally to test but I'm getting some build errors. From your branch I ran pnpm reinstall, and then cd packages/wallets/particle and then pnpm build. I'm getting this output:

../../../node_modules/.pnpm/@particle-network+auth@1.2.2/node_modules/@particle-network/auth/lib/types/service/evmService.d.ts:1:84 - error TS2307: Cannot find module '@metamask/eth-sig-util' or its corresponding type declarations.

1 import type { MessageTypes, SignTypedDataVersion, TypedDataV1, TypedMessage } from '@metamask/eth-sig-util';
                                                                                     ~~~~~~~~~~~~~~~~~~~~~~~~

src/adapter.ts:72:20 - error TS2339: Property 'chainId' does not exist on type '{}'.

72       nestedConfig.chainId !== undefined ? nestedConfig.chainId : 101;
                      ~~~~~~~

src/adapter.ts:72:57 - error TS2339: Property 'chainId' does not exist on type '{}'.

72       nestedConfig.chainId !== undefined ? nestedConfig.chainId : 101;
                                                           ~~~~~~~

src/adapter.ts:74:20 - error TS2339: Property 'chainName' does not exist on type '{}'.

74       nestedConfig.chainName !== undefined ? nestedConfig.chainName : "solana";
                      ~~~~~~~~~

src/adapter.ts:74:59 - error TS2339: Property 'chainName' does not exist on type '{}'.

74       nestedConfig.chainName !== undefined ? nestedConfig.chainName : "solana";
                                                             ~~~~~~~~~

src/adapter.ts:78:7 - error TS2739: Type '{ chainId: any; chainName: any; }' is missing the following properties from type 'Config': projectId, clientKey, appId

78       config: {
         ~~~~~~

  src/adapter.ts:40:3
    40   config?: Config;
         ~~~~~~
    The expected type comes from property 'config' which is declared here on type 'ParticleAdapterConfig'

src/adapter.ts:91:22 - error TS2532: Object is possibly 'undefined'.

91                 `./${config.preferredAuthType.type}.ts`
                        ~~~~~~~~~~~~~~~~~~~~~~~~

src/adapter.ts:91:47 - error TS2339: Property 'type' does not exist on type 'string | PreferredAuthTypeObject'.
  Property 'type' does not exist on type 'string'.

91                 `./${config.preferredAuthType.type}.ts`
                                                 ~~~~

[11:24:19 AM] Project 'tsconfig.esm.json' is out of date because output file 'lib/esm/adapter.js' does not exist

[11:24:19 AM] Building project '/home/sol/src/wallet-adapter/packages/wallets/particle/tsconfig.esm.json'...

../../../node_modules/.pnpm/@particle-network+auth@1.2.2/node_modules/@particle-network/auth/lib/types/service/evmService.d.ts:1:84 - error TS2307: Cannot find module '@metamask/eth-sig-util' or its corresponding type declarations.

1 import type { MessageTypes, SignTypedDataVersion, TypedDataV1, TypedMessage } from '@metamask/eth-sig-util';
                                                                                     ~~~~~~~~~~~~~~~~~~~~~~~~

src/adapter.ts:72:20 - error TS2339: Property 'chainId' does not exist on type '{}'.

72       nestedConfig.chainId !== undefined ? nestedConfig.chainId : 101;
                      ~~~~~~~

src/adapter.ts:72:57 - error TS2339: Property 'chainId' does not exist on type '{}'.

72       nestedConfig.chainId !== undefined ? nestedConfig.chainId : 101;
                                                           ~~~~~~~

src/adapter.ts:74:20 - error TS2339: Property 'chainName' does not exist on type '{}'.

74       nestedConfig.chainName !== undefined ? nestedConfig.chainName : "solana";
                      ~~~~~~~~~

src/adapter.ts:74:59 - error TS2339: Property 'chainName' does not exist on type '{}'.

74       nestedConfig.chainName !== undefined ? nestedConfig.chainName : "solana";
                                                             ~~~~~~~~~

src/adapter.ts:78:7 - error TS2739: Type '{ chainId: any; chainName: any; }' is missing the following properties from type 'Config': projectId, clientKey, appId

78       config: {
         ~~~~~~

  src/adapter.ts:40:3
    40   config?: Config;
         ~~~~~~
    The expected type comes from property 'config' which is declared here on type 'ParticleAdapterConfig'

src/adapter.ts:91:22 - error TS2532: Object is possibly 'undefined'.

91                 `./${config.preferredAuthType.type}.ts`
                        ~~~~~~~~~~~~~~~~~~~~~~~~

src/adapter.ts:91:47 - error TS2339: Property 'type' does not exist on type 'string | PreferredAuthTypeObject'.
  Property 'type' does not exist on type 'string'.

91                 `./${config.preferredAuthType.type}.ts`
                                                 ~~~~


Found 16 errors.

For the first one, the version of @particle-network/auth I'm getting is 1.2.2, which I can see does have @metamask/eth-sig-util as a dev dependency, so I'm not sure what the issue is there. FWIW when I installed without using pnpm reinstall I got an earlier version of auth which didn't export what was required by @particle-network/solana-wallet. I think that's caused by the @particle-network/auth: * dependency in @particle-network/solana-wallet here: https://www.npmjs.com/package/@particle-network/solana-wallet?activeTab=code (sorry, not sure where on Github that is!)

The other errors look like Typescript errors in the adapter code which will need to be fixed before we can merge this.

Are you seeing the same pnpm build errors locally? If not I'll need to do some more digging locally. I'm not too sure why we don't have the build running on PRs in this repo, so sorry for the back and forth here!

Copy link

socket-security bot commented Nov 30, 2023

No top level dependency changes detected. Learn more about Socket for GitHub ↗︎

@TABASCOatw
Copy link
Contributor Author

Hey @mcintyre94! Thank you so much for your initial testing here.

I went ahead and fixed the issues you mentioned (the TS errors and lack of @metamask/eth-sig-util); pnpm build now successfully builds with the new changes implemented (locally atleast).

This includes the requirement of a few new dependencies, as listed by the other comment on this PR. A few small changes were made to adapter.ts solving the underlying type errors.

@mcintyre94
Copy link
Collaborator

mcintyre94 commented Dec 1, 2023

Thanks for those updates @TABASCOatw, it's now building for me locally.

I've tried adding it to the example app in the wallet-adapter repo, by just adding new ParticleAdapter() to the wallets array.

When I connect to Particle, I get an error: "WalletConfigError: Param error, see doc for more info"

Using a debugger the underlying error being thrown is {code: 8002, message: 'Param error, see doc for more info'} from https://github.com/solana-labs/wallet-adapter/blob/621a845fc17dab5254e4566ab97e39fb513dc5c1/packages/wallets/particle/src/adapter.ts#L167-L174

I'm guessing that there's maybe some required config to use this adapter? Could you provide an example config that I can use to test it please?

If that is the issue then it'd be worth updating your adapter's constructor to require the config, so that not providing it becomes a type error. https://github.com/solana-labs/wallet-adapter/blob/621a845fc17dab5254e4566ab97e39fb513dc5c1/packages/wallets/particle/src/adapter.ts#L74

Also please could you commit the pnpm-lock.yaml file? You should have some changes on your branch as a result of the package.json file you changed. The CI requires this to be updated whenever any dependencies change.

@TABASCOatw
Copy link
Contributor Author

Hey @mcintyre94, sure, no problem at all! Just made those changes.

As for the config, feel free to use this setup:

return new ParticleAdapter({
        config: {
          projectId: '3e63e8c0-1df6-4efb-a96e-96836accebdc',
          clientKey: 'cx5kWWPJ0AmG80U6ePLJ3U3EpEknGBYeVlWdF4xv',
          appId: 'c98e6688-ffea-4a66-8282-f3c7b52c012a',
        },
      });

@mcintyre94
Copy link
Collaborator

mcintyre94 commented Dec 4, 2023

Hey @TABASCOatw thanks for that config! Is that definitely configured as a Solana project?

When I try to connect, I now get the Particle UI, but I get an error "WalletConnectionError: Non-base58 character"

Looking into the SolanaWallet class of @particle-network/solana-wallet I'm seeing:

    this.auth.on("connect", (userInfo2) => {
      const wallet = userInfo2.wallets.find((w) => w.chain_name === "solana" && w.public_address.length > 0);
      if (wallet) {
        this._publicKey = new import_web3.PublicKey(wallet.public_address);
        this.events.emit("connect", this._publicKey);
      }
    });

And in localstorage I'm seeing a field with key pn_auth_user_info_c98e6688-ffea-4a66-8282-f3c7b52c012a which contains an object, one field of which is wallets with value:

[
  {
    "uuid": "6fe39d83-b3a6-4c31-af4c-a0895fb18337",
    "chain_name": "evm_chain",
    "public_address": "0xBdB1285F8d3aa4Bb04A88E93c1c8DC46C9b3f579"
  }
]

So I think something is generating an EVM address and then trying to pass it to the Solana web3.js PublicKey method, which rejects it

Separately there's a type error introduced by the most recent changes:

src/adapter.ts:80:11 - error TS2322: Type 'NestedConfig | undefined' is not assignable to type 'NestedConfig'.
  Type 'undefined' is not assignable to type 'NestedConfig'.

80     const nestedConfig: NestedConfig = config.config;

@mcintyre94
Copy link
Collaborator

Ah okay I see what's going on, that build error meant I was on an earlier version locally and the chainId and chainName default wasn't implemented.

Fixing that type error locally by using const nestedConfig: NestedConfig = config.config ?? {} and then building the adapter got it working.

Let me just take a look at the code and then we should be able to get this merged :)

@@ -1,175 +1,277 @@
import type { Config, ParticleNetwork, SolanaWallet } from '@particle-network/solana-wallet';
Copy link
Collaborator

Choose a reason for hiding this comment

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

General comment: please run pnpm lint:fix from the root. There are a bunch of prettier issues but that should fix them all.

Comment on lines +44 to +46
projectId?: string;
clientKey?: string;
appId?: string;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are these actually optional? If I comment any of them out I get that param error again


export interface ParticleAdapterConfig {
config?: Config;
config?: NestedConfig;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similarly, I don't think this is actually optional? If it isn't then that'll fix the type error too, as well as being much clearer for devs how to use this adapter

@mcintyre94
Copy link
Collaborator

Also, the send transaction UI says "Sign but not send":

Screenshot 2023-12-04 at 14 39 57

BTW this example app is at packages/starter/example. If you edit src/components/ContextProvider.tsx to add your wallet it's a useful test playground :) Just run pnpm dev in the example directory.

Comment on lines +105 to +114
this.icon = await import(
`./${preferredAuthType.type}.ts`
).then((module) => module.default);
console.log(this.icon);
} catch (error) {
console.error(`Could not import icon: ${error}`);
}
})();
this.name = (preferredAuthType.type.charAt(0).toUpperCase() +
preferredAuthType.type.slice(1)) as WalletName<any>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We're also concerned about this functionality. We can't really have "Github" for example showing in the wallet modal, we need users to be able to trust what is displayed here at least by the wallets that we publish from this repo

It needs to be clear in all cases that the user is connecting to Particle wallet
We also can't use other people's logos here

@jordaaash
Copy link
Collaborator

I'm back in the office now. I'm sorry for all the time that was spent on this PR and its review, but we cannot accept it.

The proposed adapter includes multiple dependencies, including icons, which it loads in the constructor. This is not allowed in any adapter that we publish. Adapters that we publish that asynchronously load an SDK may only load one SDK, may only do it on connection, and may only include one dependency to do so.

Adapters may not include multiple icons, change the name or icon used, or use names or icons of other services besides the wallet. A user can connect to your wallet's adapter with a canonical name and icon, and then after that you can display social login options or anything else your wallet may display.

For these reasons, we can't publish this adapter, or provide further review of it. For adapters that we cannot accept, we encourage self-publishing with your own NPM package where you can fully decide what to load, when to load it, and what the behavior will be.

Additionally, instead of publishing an adapter, we encourage you to publish a smaller library to register a Wallet interface using the Wallet Standard. This is more robust and flexible than using an adapter, and allows your wallet to be used by projects that only support Standard Wallets and no longer use Wallet Adapter or load individual adapters.

@jordaaash jordaaash closed this Dec 4, 2023
@TABASCOatw
Copy link
Contributor Author

@jordaaash Understood, thank you for the update! In this case, would it be possible to open a separate PR purely updating the package version and fixing adapter.ts to function with the new SDK structure? In it's current state, the adapter doesn't function due to outdated dependencies and structure. The problems you outlined will be removed.

@jordaaash
Copy link
Collaborator

Yes definitely, happy to accept a PR if the current SDK isn't working.

@TABASCOatw
Copy link
Contributor Author

Yes definitely, happy to accept a PR if the current SDK isn't working.

Perfect, thank you! Just opened #854

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.

3 participants