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

Added parameter for app display name for dynamic rendering in the wallet during web5 connect flow #945

Merged
merged 8 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lemon-bees-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@web5/agent": patch
---

Added parameter for app display name for dynamic rendering in the wallet during web5 connect flow
5 changes: 5 additions & 0 deletions .changeset/smooth-weeks-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@web5/api": patch
---

Added parameter for app display name for dynamic rendering in the wallet during web5 connect flow
10 changes: 8 additions & 2 deletions packages/agent/src/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { DwnInterfaceName, DwnMethodName } from '@tbd54566975/dwn-sdk-js';
* a did from a provider.
*/
async function initClient({
displayName,
connectServerUrl,
walletUri,
permissionRequests,
Expand Down Expand Up @@ -44,10 +45,12 @@ async function initClient({
const request = await Oidc.createAuthRequest({
client_id : clientDid.uri,
scope : 'openid did:jwk',
redirect_uri : callbackEndpoint,
// custom properties:
// code_challenge : codeChallengeBase64Url,
// code_challenge_method : 'S256',
permissionRequests : permissionRequests,
redirect_uri : callbackEndpoint,
displayName,
});

// Sign the Request Object using the Client DID's signing key.
Expand Down Expand Up @@ -133,7 +136,10 @@ async function initClient({
* a did from a provider.
*/
export type WalletConnectOptions = {
/** The URL of the intermediary server which relays messages between the client and provider */
/** The user friendly name of the client/app to be displayed when prompting end-user with permission requests. */
displayName: string;

/** The URL of the intermediary server which relays messages between the client and provider. */
connectServerUrl: string;

/**
Expand Down
16 changes: 10 additions & 6 deletions packages/agent/src/oidc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ export type SIOPv2AuthRequest = {
* The contents of this are inserted into a JWT inside of the {@link PushedAuthRequest}.
*/
export type Web5ConnectAuthRequest = {
/** The user friendly name of the client/app to be displayed when prompting end-user with permission requests. */
displayName: string;

/** PermissionGrants that are to be sent to the provider */
permissionRequests: ConnectPermissionRequest[];
} & SIOPv2AuthRequest;
Expand Down Expand Up @@ -242,7 +245,7 @@ async function generateCodeChallenge() {
async function createAuthRequest(
options: RequireOnly<
Web5ConnectAuthRequest,
'client_id' | 'scope' | 'redirect_uri' | 'permissionRequests'
'client_id' | 'scope' | 'redirect_uri' | 'permissionRequests' | 'displayName'
>
) {
// Generate a random state value to associate the authorization request with the response.
Expand Down Expand Up @@ -666,9 +669,12 @@ async function createPermissionGrants(
return grant.message;
});

const messages = await Promise.all(messagePromises);

return messages;
try {
const messages = await Promise.all(messagePromises);
return messages;
} catch (error) {
throw error;
}
}

/**
Expand All @@ -693,7 +699,6 @@ async function prepareProtocol(
`Could not fetch protocol: ${queryMessage.reply.status.detail}`
);
} else if (queryMessage.reply.entries === undefined || queryMessage.reply.entries.length === 0) {

// send the protocol definition to the remote DWN first, if it passes we can process it locally
const { reply: sendReply, message: configureMessage } = await agent.sendDwnRequest({
author : selectedDid,
Expand All @@ -716,7 +721,6 @@ async function prepareProtocol(
});

} else {

// the protocol already exists, let's make sure it exists on the remote DWN as the requesting app will need it
const configureMessage = queryMessage.reply.entries![0];
const { reply: sendReply } = await agent.sendDwnRequest({
Expand Down
8 changes: 8 additions & 0 deletions packages/agent/tests/connect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ describe('web5 connect', function () {
});

const options = {
displayName : 'Sample App',
client_id : clientEphemeralPortableDid.uri,
scope : 'openid did:jwk',
// code_challenge : Convert.uint8Array(codeChallenge).toBase64Url(),
Expand Down Expand Up @@ -457,6 +458,7 @@ describe('web5 connect', function () {
fetchStub.callThrough();

const results = await WalletConnect.initClient({
displayName : 'Sample App',
walletUri : 'http://localhost:3000/',
connectServerUrl : 'http://localhost:3000/connect',
permissionRequests : [
Expand Down Expand Up @@ -505,6 +507,7 @@ describe('web5 connect', function () {
});

const options = {
displayName : 'Sample App',
client_id : clientEphemeralPortableDid.uri,
scope : 'openid did:jwk',
// code_challenge : Convert.uint8Array(codeChallenge).toBase64Url(),
Expand Down Expand Up @@ -560,6 +563,7 @@ describe('web5 connect', function () {
});

const options = {
displayName : 'Sample App',
client_id : clientEphemeralPortableDid.uri,
scope : 'openid did:jwk',
// code_challenge : Convert.uint8Array(codeChallenge).toBase64Url(),
Expand Down Expand Up @@ -632,6 +636,7 @@ describe('web5 connect', function () {
});

const options = {
displayName : 'Sample App',
client_id : clientEphemeralPortableDid.uri,
scope : 'openid did:jwk',
// code_challenge : Convert.uint8Array(codeChallenge).toBase64Url(),
Expand Down Expand Up @@ -679,6 +684,7 @@ describe('web5 connect', function () {
});

const options = {
displayName : 'Sample App',
client_id : clientEphemeralPortableDid.uri,
scope : 'openid did:jwk',
// code_challenge : Convert.uint8Array(codeChallenge).toBase64Url(),
Expand Down Expand Up @@ -730,6 +736,7 @@ describe('web5 connect', function () {
});

const options = {
displayName : 'Sample App',
client_id : clientEphemeralPortableDid.uri,
scope : 'openid did:jwk',
// code_challenge : Convert.uint8Array(codeChallenge).toBase64Url(),
Expand Down Expand Up @@ -781,6 +788,7 @@ describe('web5 connect', function () {
mismatchedScopes[0].protocol = 'http://profile-protocol.xyz/other';

const options = {
displayName : 'Sample App',
client_id : clientEphemeralPortableDid.uri,
scope : 'openid did:jwk',
// code_challenge : Convert.uint8Array(codeChallenge).toBase64Url(),
Expand Down
8 changes: 7 additions & 1 deletion packages/api/src/web5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,22 @@ export type ConnectPermissionRequest = {
* The protocol definition for the protocol being requested.
*/
protocolDefinition: DwnProtocolDefinition;

/**
* The permissions being requested for the protocol. If none are provided, the default is to request all permissions.
*/
permissions?: Permission[];
}

/**
* Options for connecting to a Web5 agent. This includes the ability to connect to an external wallet
* Options for connecting to a Web5 agent. This includes the ability to connect to an external wallet.
*
* NOTE: the returned `ConnectPermissionRequest` type is different to the `ConnectPermissionRequest` type in the `@web5/agent` package.
*/
export type ConnectOptions = Omit<WalletConnectOptions, 'permissionRequests'> & {
/** The user friendly name of the client/app to be displayed when prompting end-user with permission requests. */
displayName: string;

/**
* The permissions that are being requested for the connected DID.
* This is used to create the {@link ConnectPermissionRequest} for the wallet connect flow.
Expand Down
6 changes: 6 additions & 0 deletions packages/api/tests/web5.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ describe('web5 api', () => {
// connect to the app, the options don't matter because we're stubbing the initClient method
const { web5, did, delegateDid } = await Web5.connect({
walletConnectOptions: {
displayName : 'Sample App',
connectServerUrl : 'https://connect.example.com',
walletUri : 'https://wallet.example.com',
validatePin : async () => { return '1234'; },
Expand Down Expand Up @@ -675,6 +676,7 @@ describe('web5 api', () => {
// connect to the app, the options don't matter because we're stubbing the initClient method
await Web5.connect({
walletConnectOptions: {
displayName : 'Sample App',
connectServerUrl : 'https://connect.example.com',
walletUri : 'https://wallet.example.com',
validatePin : async () => { return '1234'; },
Expand Down Expand Up @@ -735,6 +737,7 @@ describe('web5 api', () => {
await Web5.connect({
sync : 'off',
walletConnectOptions : {
displayName : 'Sample App',
connectServerUrl : 'https://connect.example.com',
walletUri : 'https://wallet.example.com',
validatePin : async () => { return '1234'; },
Expand Down Expand Up @@ -779,6 +782,7 @@ describe('web5 api', () => {
await Web5.connect({
sync : '1m',
walletConnectOptions : {
displayName : 'Sample App',
connectServerUrl : 'https://connect.example.com',
walletUri : 'https://wallet.example.com',
validatePin : async () => { return '1234'; },
Expand Down Expand Up @@ -822,6 +826,7 @@ describe('web5 api', () => {

await Web5.connect({
walletConnectOptions: {
displayName : 'Sample App',
connectServerUrl : 'https://connect.example.com',
walletUri : 'https://wallet.example.com',
validatePin : async () => { return '1234'; },
Expand Down Expand Up @@ -893,6 +898,7 @@ describe('web5 api', () => {

await Web5.connect({
walletConnectOptions: {
displayName : 'Sample App',
connectServerUrl : 'https://connect.example.com',
walletUri : 'https://wallet.example.com',
validatePin : async () => { return '1234'; },
Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@
"rimraf": "5.0.7",
"typescript": "5.5.3"
}
}
}
Loading