Skip to content

Commit 101f463

Browse files
authored
Added parameter for app display name for dynamic rendering in the wallet during web5 connect flow (#945)
1 parent b747a2d commit 101f463

File tree

8 files changed

+44
-8
lines changed

8 files changed

+44
-8
lines changed

.changeset/lemon-bees-yawn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@web5/agent": patch
3+
---
4+
5+
Added parameter for app display name for dynamic rendering in the wallet during web5 connect flow

.changeset/smooth-weeks-serve.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@web5/api": patch
3+
---
4+
5+
Added parameter for app display name for dynamic rendering in the wallet during web5 connect flow

packages/agent/src/connect.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { DwnInterfaceName, DwnMethodName } from '@tbd54566975/dwn-sdk-js';
1717
* a did from a provider.
1818
*/
1919
async function initClient({
20+
displayName,
2021
connectServerUrl,
2122
walletUri,
2223
permissionRequests,
@@ -44,10 +45,12 @@ async function initClient({
4445
const request = await Oidc.createAuthRequest({
4546
client_id : clientDid.uri,
4647
scope : 'openid did:jwk',
48+
redirect_uri : callbackEndpoint,
49+
// custom properties:
4750
// code_challenge : codeChallengeBase64Url,
4851
// code_challenge_method : 'S256',
4952
permissionRequests : permissionRequests,
50-
redirect_uri : callbackEndpoint,
53+
displayName,
5154
});
5255

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

139145
/**

packages/agent/src/oidc.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ export type SIOPv2AuthRequest = {
128128
* The contents of this are inserted into a JWT inside of the {@link PushedAuthRequest}.
129129
*/
130130
export type Web5ConnectAuthRequest = {
131+
/** The user friendly name of the client/app to be displayed when prompting end-user with permission requests. */
132+
displayName: string;
133+
131134
/** PermissionGrants that are to be sent to the provider */
132135
permissionRequests: ConnectPermissionRequest[];
133136
} & SIOPv2AuthRequest;
@@ -242,7 +245,7 @@ async function generateCodeChallenge() {
242245
async function createAuthRequest(
243246
options: RequireOnly<
244247
Web5ConnectAuthRequest,
245-
'client_id' | 'scope' | 'redirect_uri' | 'permissionRequests'
248+
'client_id' | 'scope' | 'redirect_uri' | 'permissionRequests' | 'displayName'
246249
>
247250
) {
248251
// Generate a random state value to associate the authorization request with the response.
@@ -667,7 +670,6 @@ async function createPermissionGrants(
667670
});
668671

669672
const messages = await Promise.all(messagePromises);
670-
671673
return messages;
672674
}
673675

@@ -693,7 +695,6 @@ async function prepareProtocol(
693695
`Could not fetch protocol: ${queryMessage.reply.status.detail}`
694696
);
695697
} else if (queryMessage.reply.entries === undefined || queryMessage.reply.entries.length === 0) {
696-
697698
// send the protocol definition to the remote DWN first, if it passes we can process it locally
698699
const { reply: sendReply, message: configureMessage } = await agent.sendDwnRequest({
699700
author : selectedDid,
@@ -716,7 +717,6 @@ async function prepareProtocol(
716717
});
717718

718719
} else {
719-
720720
// the protocol already exists, let's make sure it exists on the remote DWN as the requesting app will need it
721721
const configureMessage = queryMessage.reply.entries![0];
722722
const { reply: sendReply } = await agent.sendDwnRequest({

packages/agent/tests/connect.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ describe('web5 connect', function () {
224224
});
225225

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

459460
const results = await WalletConnect.initClient({
461+
displayName : 'Sample App',
460462
walletUri : 'http://localhost:3000/',
461463
connectServerUrl : 'http://localhost:3000/connect',
462464
permissionRequests : [
@@ -505,6 +507,7 @@ describe('web5 connect', function () {
505507
});
506508

507509
const options = {
510+
displayName : 'Sample App',
508511
client_id : clientEphemeralPortableDid.uri,
509512
scope : 'openid did:jwk',
510513
// code_challenge : Convert.uint8Array(codeChallenge).toBase64Url(),
@@ -560,6 +563,7 @@ describe('web5 connect', function () {
560563
});
561564

562565
const options = {
566+
displayName : 'Sample App',
563567
client_id : clientEphemeralPortableDid.uri,
564568
scope : 'openid did:jwk',
565569
// code_challenge : Convert.uint8Array(codeChallenge).toBase64Url(),
@@ -632,6 +636,7 @@ describe('web5 connect', function () {
632636
});
633637

634638
const options = {
639+
displayName : 'Sample App',
635640
client_id : clientEphemeralPortableDid.uri,
636641
scope : 'openid did:jwk',
637642
// code_challenge : Convert.uint8Array(codeChallenge).toBase64Url(),
@@ -679,6 +684,7 @@ describe('web5 connect', function () {
679684
});
680685

681686
const options = {
687+
displayName : 'Sample App',
682688
client_id : clientEphemeralPortableDid.uri,
683689
scope : 'openid did:jwk',
684690
// code_challenge : Convert.uint8Array(codeChallenge).toBase64Url(),
@@ -730,6 +736,7 @@ describe('web5 connect', function () {
730736
});
731737

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

783790
const options = {
791+
displayName : 'Sample App',
784792
client_id : clientEphemeralPortableDid.uri,
785793
scope : 'openid did:jwk',
786794
// code_challenge : Convert.uint8Array(codeChallenge).toBase64Url(),

packages/api/src/web5.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,22 @@ export type ConnectPermissionRequest = {
4444
* The protocol definition for the protocol being requested.
4545
*/
4646
protocolDefinition: DwnProtocolDefinition;
47+
4748
/**
4849
* The permissions being requested for the protocol. If none are provided, the default is to request all permissions.
4950
*/
5051
permissions?: Permission[];
5152
}
5253

5354
/**
54-
* Options for connecting to a Web5 agent. This includes the ability to connect to an external wallet
55+
* Options for connecting to a Web5 agent. This includes the ability to connect to an external wallet.
56+
*
57+
* NOTE: the returned `ConnectPermissionRequest` type is different to the `ConnectPermissionRequest` type in the `@web5/agent` package.
5558
*/
5659
export type ConnectOptions = Omit<WalletConnectOptions, 'permissionRequests'> & {
60+
/** The user friendly name of the client/app to be displayed when prompting end-user with permission requests. */
61+
displayName: string;
62+
5763
/**
5864
* The permissions that are being requested for the connected DID.
5965
* This is used to create the {@link ConnectPermissionRequest} for the wallet connect flow.

packages/api/tests/web5.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ describe('web5 api', () => {
455455
// connect to the app, the options don't matter because we're stubbing the initClient method
456456
const { web5, did, delegateDid } = await Web5.connect({
457457
walletConnectOptions: {
458+
displayName : 'Sample App',
458459
connectServerUrl : 'https://connect.example.com',
459460
walletUri : 'https://wallet.example.com',
460461
validatePin : async () => { return '1234'; },
@@ -675,6 +676,7 @@ describe('web5 api', () => {
675676
// connect to the app, the options don't matter because we're stubbing the initClient method
676677
await Web5.connect({
677678
walletConnectOptions: {
679+
displayName : 'Sample App',
678680
connectServerUrl : 'https://connect.example.com',
679681
walletUri : 'https://wallet.example.com',
680682
validatePin : async () => { return '1234'; },
@@ -735,6 +737,7 @@ describe('web5 api', () => {
735737
await Web5.connect({
736738
sync : 'off',
737739
walletConnectOptions : {
740+
displayName : 'Sample App',
738741
connectServerUrl : 'https://connect.example.com',
739742
walletUri : 'https://wallet.example.com',
740743
validatePin : async () => { return '1234'; },
@@ -779,6 +782,7 @@ describe('web5 api', () => {
779782
await Web5.connect({
780783
sync : '1m',
781784
walletConnectOptions : {
785+
displayName : 'Sample App',
782786
connectServerUrl : 'https://connect.example.com',
783787
walletUri : 'https://wallet.example.com',
784788
validatePin : async () => { return '1234'; },
@@ -822,6 +826,7 @@ describe('web5 api', () => {
822826

823827
await Web5.connect({
824828
walletConnectOptions: {
829+
displayName : 'Sample App',
825830
connectServerUrl : 'https://connect.example.com',
826831
walletUri : 'https://wallet.example.com',
827832
validatePin : async () => { return '1234'; },
@@ -893,6 +898,7 @@ describe('web5 api', () => {
893898

894899
await Web5.connect({
895900
walletConnectOptions: {
901+
displayName : 'Sample App',
896902
connectServerUrl : 'https://connect.example.com',
897903
walletUri : 'https://wallet.example.com',
898904
validatePin : async () => { return '1234'; },

packages/common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,4 @@
9999
"rimraf": "5.0.7",
100100
"typescript": "5.5.3"
101101
}
102-
}
102+
}

0 commit comments

Comments
 (0)