-
-
Notifications
You must be signed in to change notification settings - Fork 130
feat: Add CAIP-294 targets to wallet_announce event data. Announce CAIP-348 target in initializeProvider
#413
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
Changes from all commits
03f922c
f8a4957
a58c65d
7997c71
734a694
66bf400
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,17 +19,25 @@ declare global { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Represents the protocol/transport supported by the wallet. | ||
| * @type CAIP294Target | ||
| * @property type - The type of the target. SHOULD reference a CAIP number in the `caip-x` format. | ||
| * @property value - The value specifying how to connect to the target as specified by the specification in the `type` property. | ||
| */ | ||
| export type CAIP294Target = { type: string; value?: unknown }; | ||
|
|
||
| /** | ||
| * Represents the assets needed to display and identify a wallet. | ||
| * @type CAIP294WalletData | ||
| * @property uuid - A locally unique identifier for the wallet. MUST be a v4 UUID. | ||
| * @property name - The name of the wallet. | ||
| * @property icon - The icon for the wallet. MUST be data URI. | ||
| * @property rdns - The reverse syntax domain name identifier for the wallet. | ||
| * @property extensionId - The canonical extension ID of the wallet provider for the active browser. | ||
| * @property targets - The target objects specifying the protocol/transport supported by the wallet. | ||
| */ | ||
| export type CAIP294WalletData = BaseProviderInfo & { | ||
| extensionId?: string | undefined; | ||
| targets?: CAIP294Target[]; | ||
| }; | ||
|
|
||
| /** | ||
|
|
@@ -120,6 +128,16 @@ function isValidAnnounceWalletEvent( | |
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Validates a {@link CAIP294Target} object. | ||
| * | ||
| * @param data - The {@link CAIP294Target} to validate. | ||
| * @returns Whether the {@link CAIP294Target} is valid. | ||
| */ | ||
| function isValidWalletTarget(data: unknown): data is CAIP294Target { | ||
| return isObject(data) && typeof data.type === 'string' && Boolean(data.type); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah.... it's what Erik had before i think, so i just kept the pattern |
||
| } | ||
|
|
||
| /** | ||
| * Validates an {@link CAIP294WalletData} object. | ||
| * | ||
|
|
@@ -137,8 +155,8 @@ function isValidWalletData(data: unknown): data is CAIP294WalletData { | |
| data.icon.startsWith('data:image') && | ||
| typeof data.rdns === 'string' && | ||
| FQDN_REGEX.test(data.rdns) && | ||
| (data.extensionId === undefined || | ||
| (typeof data.extensionId === 'string' && data.extensionId.length > 0)) | ||
| (data.targets === undefined || | ||
| (Array.isArray(data.targets) && data.targets.every(isValidWalletTarget))) | ||
| ); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -122,11 +122,20 @@ export async function announceCaip294WalletData( | |
| const providerState = await provider.request<{ extensionId?: string }>({ | ||
| method: 'metamask_getProviderState', | ||
| }); | ||
|
|
||
| const targets = []; | ||
|
|
||
| const extensionId = providerState?.extensionId; | ||
| if (extensionId) { | ||
| targets.push({ | ||
| type: 'caip-348', | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i've gone back and forth on whether this belongs in a constant, and I don't think it's necessary because we don't do this for other standards numbers. The value itself is already effectively a symbol and moving it to a constant doesn't really buy us additional value
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add a link to the CAIP PR? |
||
| value: extensionId, | ||
| }); | ||
| } | ||
|
|
||
| const walletData = { | ||
| ...providerInfo, | ||
| extensionId, | ||
| targets, | ||
| }; | ||
|
|
||
| announceWallet(walletData); | ||
|
|
||
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.
Also should we add some links to CAIP-294 here?
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 the PR? it hasn't been merged yet so the link isn't going to be great
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.
meh ok