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

introduce wallet connect #713

Merged
merged 152 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
19725d6
add back examples
shamilovtim May 24, 2024
125f453
add back authServer.js
shamilovtim May 24, 2024
efbe7af
add back json-rpc changes
shamilovtim May 24, 2024
b7c2e4d
add back rpcserver
shamilovtim May 24, 2024
106b7e2
add back utils
shamilovtim May 24, 2024
fc6a8a3
add back agent exports
shamilovtim May 24, 2024
0fa79e4
add back ws-rpc-server
shamilovtim May 24, 2024
14c1841
add back auth-api
shamilovtim May 24, 2024
ad5f030
add back level.js
shamilovtim May 24, 2024
6fb8fec
add back crypto randompin
shamilovtim May 24, 2024
446ce35
add back test for randomPin
shamilovtim May 24, 2024
65a2c71
simplify request-uri
shamilovtim Jun 13, 2024
7be2827
make testharness setup a little more readable
shamilovtim Jun 18, 2024
d78257f
add pollWithTTL
shamilovtim Jun 19, 2024
f804ad3
add abort to pollWithTTL
shamilovtim Jun 19, 2024
8d3d6d6
add jsdoc to pollWithTTL
shamilovtim Jun 20, 2024
4d014bd
WIP
shamilovtim Jun 20, 2024
6c36646
fix a couple of docs
shamilovtim Jun 21, 2024
3f65789
param style nit
shamilovtim Jun 21, 2024
7d47e51
fix signing and migrate kms code to newer agent code
shamilovtim Jun 21, 2024
1669ddc
use the word "claims" rather than payload
shamilovtim Jun 24, 2024
fa3256f
format authServer and update code
shamilovtim Jun 29, 2024
915a345
push up latest WIP
shamilovtim Jun 29, 2024
98b5c64
remove dead code
shamilovtim Jun 29, 2024
5a1afc9
Merge branch 'main' into tshamilov/connect-v2
shamilovtim Jun 29, 2024
4bc11fc
bump types/node
shamilovtim Jun 29, 2024
40a2b14
cleanup
shamilovtim Jun 29, 2024
b46bbdc
fix eslint
shamilovtim Jun 29, 2024
c9817f9
format test file
shamilovtim Jun 30, 2024
a077bb9
format with eslint
shamilovtim Jun 30, 2024
058cf67
cleanup
shamilovtim Jul 1, 2024
329e10d
format eslint config
shamilovtim Jul 8, 2024
f38718a
Update authServer.js
shamilovtim Jul 8, 2024
843b17c
Update tsconfig.json
shamilovtim Jul 8, 2024
4f2491b
check in wip
shamilovtim Jul 8, 2024
5cae467
add correct wallet uri
shamilovtim Jul 9, 2024
4bafc56
comment
shamilovtim Jul 9, 2024
48e2895
updates
shamilovtim Jul 10, 2024
b04c3cc
cleanup
shamilovtim Jul 10, 2024
5b406ce
cleanup
shamilovtim Jul 10, 2024
4e5fd5d
Merge branch 'main' into tshamilov/connect-v2
shamilovtim Jul 12, 2024
6e79b2e
add nearly finished latest wip
shamilovtim Jul 13, 2024
a5391db
cleanup. add walletUri.
shamilovtim Jul 13, 2024
718ded0
feedback
shamilovtim Jul 16, 2024
59e8535
feedback
shamilovtim Jul 17, 2024
785e12b
feedback
shamilovtim Jul 17, 2024
8017486
refactor out nonce
shamilovtim Jul 17, 2024
b2959cc
feedback
shamilovtim Jul 17, 2024
29009fb
feedback: add better docs for walletUri
shamilovtim Jul 17, 2024
4de6618
remove unnecessary clientUri
shamilovtim Jul 17, 2024
da32d29
feedback
shamilovtim Jul 17, 2024
1e3fbcb
Merge branch 'main' into tshamilov/connect-v2
shamilovtim Jul 22, 2024
e64dca5
resolve merge conflict
shamilovtim Jul 22, 2024
f18921b
feedback: client_id should contain the did
shamilovtim Jul 22, 2024
0dfd16c
improve comment about walletconnectoptions
shamilovtim Jul 22, 2024
8f08091
feedback: unabstract nonce creation
shamilovtim Jul 22, 2024
420a9e7
remove unused imports
shamilovtim Jul 22, 2024
10aa3e9
feedback: slim down queryparams
shamilovtim Jul 22, 2024
d0b09be
Merge branch 'main' into tshamilov/connect-v2
shamilovtim Jul 23, 2024
8adfb58
merged lockfile
shamilovtim Jul 23, 2024
7981ab0
clarify comment about the grants
shamilovtim Jul 23, 2024
bd646dc
feedback: fail fast and let users catch errors
shamilovtim Jul 23, 2024
94dcb14
feedback
shamilovtim Jul 25, 2024
065ecda
push up finalizations
shamilovtim Aug 4, 2024
85ee03a
bump crypto
shamilovtim Aug 4, 2024
69bc147
examples
shamilovtim Aug 4, 2024
d53bd82
bump sinon
shamilovtim Aug 4, 2024
d231207
fix dependabot mess
shamilovtim Aug 4, 2024
f57e605
Merge branch 'main' into tshamilov/connect-v2
shamilovtim Aug 4, 2024
3a58665
try to fix builds
shamilovtim Aug 4, 2024
d63c468
try to fix builds
shamilovtim Aug 4, 2024
0e3a881
use v9 lockfile
shamilovtim Aug 4, 2024
73af680
Revert "try to fix builds"
shamilovtim Aug 4, 2024
c6ed5b3
Revert "try to fix builds"
shamilovtim Aug 4, 2024
706752f
Create flat-students-compare.md
shamilovtim Aug 4, 2024
6585fb2
fix ci
shamilovtim Aug 4, 2024
775d15a
fix lockfile
shamilovtim Aug 4, 2024
c24870d
Revert "fix lockfile"
shamilovtim Aug 4, 2024
a4cae06
fix lockfile
shamilovtim Aug 4, 2024
7a882d3
cleanup
shamilovtim Aug 4, 2024
4dcd49a
fix ci
shamilovtim Aug 4, 2024
7c251fc
Delete authServer.js
shamilovtim Aug 4, 2024
b3c4dbc
test ci
shamilovtim Aug 4, 2024
0ebdcf8
fix build order
shamilovtim Aug 5, 2024
4e064cb
fix cve
shamilovtim Aug 5, 2024
bb648f9
fix eslint
shamilovtim Aug 5, 2024
e09f77f
bump lockfile
shamilovtim Aug 5, 2024
3c21f1f
feedback
shamilovtim Aug 5, 2024
f3ab1e2
use dwn server default port
shamilovtim Aug 5, 2024
616a429
Update flat-students-compare.md
shamilovtim Aug 5, 2024
a084f5b
Update docs-ci.yml
shamilovtim Aug 5, 2024
83c999a
Update flat-students-compare.md
shamilovtim Aug 5, 2024
83071fc
stub globalthis fetch
shamilovtim Aug 5, 2024
4faed25
Update tests-ci.yml
shamilovtim Aug 5, 2024
9b2e2d3
fix regex
shamilovtim Aug 5, 2024
8fa6d18
cleanup
shamilovtim Aug 5, 2024
c230899
cleanup
shamilovtim Aug 5, 2024
d281a69
add some patch tests
shamilovtim Aug 5, 2024
3141b22
cleanup some changes
shamilovtim Aug 5, 2024
f8472e5
satisfy codecov patch
shamilovtim Aug 5, 2024
3ef83fc
fix codecov bot
shamilovtim Aug 6, 2024
4620aa6
Update tests-ci.yml
shamilovtim Aug 6, 2024
db79454
latest
shamilovtim Aug 6, 2024
33a1f00
prettier fmt
shamilovtim Aug 6, 2024
b2d21bc
Update wallet-connect.html
shamilovtim Aug 6, 2024
2161594
Update codecov.yml
shamilovtim Aug 6, 2024
ce7a00a
add wallet connect example. change to portableDid data structure and …
shamilovtim Aug 7, 2024
44dfc39
Merge branch 'main' into tshamilov/connect-v2
shamilovtim Aug 7, 2024
b50a931
add connectedDid
shamilovtim Aug 7, 2024
f9d9842
cleanup example
shamilovtim Aug 7, 2024
98ce59c
cleanup
shamilovtim Aug 7, 2024
e1eb715
Update wallet-connect.html
shamilovtim Aug 8, 2024
a8382f0
add word wrap and viewport sizing
shamilovtim Aug 8, 2024
a3d7c2b
remove conditional returns in buildOidcUrl
shamilovtim Aug 8, 2024
56cd235
timeout
shamilovtim Aug 9, 2024
35a4d22
feedback
shamilovtim Aug 9, 2024
4a88f3f
Update oidc.ts
shamilovtim Aug 9, 2024
c52ce83
Update connect.ts
shamilovtim Aug 9, 2024
ce27402
Update connect.ts
shamilovtim Aug 9, 2024
ed710c7
only one did for selection
shamilovtim Aug 9, 2024
40988ce
feedback
shamilovtim Aug 9, 2024
caa0cbf
Update packages/crypto/tests/utils.spec.ts
shamilovtim Aug 9, 2024
5fd3142
Update packages/crypto/tests/utils.spec.ts
shamilovtim Aug 9, 2024
5b84240
fix flakes
shamilovtim Aug 9, 2024
619c09b
Merge branch 'tshamilov/connect-v2' of github.com:TBD54566975/web5-js…
shamilovtim Aug 9, 2024
5f7e5f4
Update connect.ts
shamilovtim Aug 9, 2024
8819144
Update connect.ts
shamilovtim Aug 9, 2024
0727a7b
run prettier and eslint
shamilovtim Aug 9, 2024
b7f6572
remove corepack
shamilovtim Aug 9, 2024
d987b96
delegate did should use a did jwk
shamilovtim Aug 11, 2024
ee661ce
client should use a did jwk
shamilovtim Aug 11, 2024
ac5447a
better comments
shamilovtim Aug 11, 2024
3214905
Update oidc.ts
shamilovtim Aug 11, 2024
c9dd462
add comments
shamilovtim Aug 12, 2024
c2601d6
Update oidc.ts
shamilovtim Aug 12, 2024
290ae24
cleanup comments
shamilovtim Aug 13, 2024
cc0602c
add some coverage
shamilovtim Aug 13, 2024
3334149
reorganize
shamilovtim Aug 13, 2024
5343d64
Update web5.spec.ts
shamilovtim Aug 13, 2024
0cf9661
feedback: dont encrypt with the code challenge
shamilovtim Aug 13, 2024
5d03bc7
feedback disable code challenge
shamilovtim Aug 13, 2024
70cfa50
clean out todo
shamilovtim Aug 13, 2024
f4d5d6f
Update connect.spec.ts
shamilovtim Aug 13, 2024
cfb05a9
feedback didjwk
shamilovtim Aug 13, 2024
fc234c3
cleanup crypto utils (#830)
shamilovtim Aug 13, 2024
8a3c645
add docs errors back
shamilovtim Aug 13, 2024
3f21c08
disable rule until typedoc is bumped
shamilovtim Aug 13, 2024
9b8cfa7
Revert "cleanup crypto utils (#830)"
shamilovtim Aug 13, 2024
729ae89
renable typedoc
shamilovtim Aug 13, 2024
347d1c3
Update docs-ci.yml
shamilovtim Aug 13, 2024
ab59af9
update codeowners
shamilovtim Aug 13, 2024
19bd7b6
Update CODEOWNERS
shamilovtim Aug 13, 2024
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
41 changes: 24 additions & 17 deletions packages/agent/src/connect.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { CryptoUtils } from '@web5/crypto';
import { DwnProtocolDefinition, DwnRecordsPermissionScope } from './index.js';
import {
Web5ConnectAuthResponse,
Oidc,
type PushedAuthResponse,
} from './oidc.js';
import { pollWithTtl } from './utils.js';
import { DidDht } from '@web5/dids';
import { DidJwk } from '@web5/dids';
import { Convert } from '@web5/common';

/**
* Initiates the wallet connect process. Used when a client wants to obtain
* a did from a provider.
*/
async function initClient({
connectServerUrl,
walletUri,
Expand All @@ -16,13 +22,14 @@
}: WalletConnectOptions) {
// ephemeral client did for ECDH, signing, verification
// TODO: use separate keys for ECDH vs. sign/verify. could maybe use secp256k1.
const clientDid = await DidDht.create();
const clientDid = await DidJwk.create();

// TODO: properly implement PKCE. this implementation is lacking server side validations and more.
// https://github.com/TBD54566975/web5-js/issues/829
// Derive the code challenge based on the code verifier
const { codeChallengeBytes, codeChallengeBase64Url } =
await Oidc.generateCodeChallenge();
// const { codeChallengeBytes, codeChallengeBase64Url } =
// await Oidc.generateCodeChallenge();
const encryptionKey = CryptoUtils.randomBytes(32);

// build callback URL to pass into the auth request
const callbackEndpoint = Oidc.buildOidcUrl({
Expand All @@ -32,12 +39,12 @@

// build the PAR request
const request = await Oidc.createAuthRequest({
client_id : clientDid.uri,
scope : 'web5', // TODO: clear with frank
code_challenge : codeChallengeBase64Url,
code_challenge_method : 'S256',
permissionRequests : permissionRequests,
redirect_uri : callbackEndpoint,
client_id : clientDid.uri,
scope : 'web5', // TODO: clear with frank
thehenrytsai marked this conversation as resolved.
Show resolved Hide resolved
// code_challenge : codeChallengeBase64Url,
// code_challenge_method : 'S256',
permissionRequests : permissionRequests,
redirect_uri : callbackEndpoint,
});

// Sign the Request Object using the Client DID's signing key.
Expand All @@ -47,12 +54,12 @@
});

if (!requestJwt) {
throw new Error('Unable to sign requestObject');
}

Check warning on line 58 in packages/agent/src/connect.ts

View check run for this annotation

Codecov / codecov/patch

packages/agent/src/connect.ts#L57-L58

Added lines #L57 - L58 were not covered by tests
// Encrypt the Request Object JWT using the code challenge.
const requestObjectJwe = await Oidc.encryptAuthRequest({
jwt : requestJwt,
codeChallenge : codeChallengeBytes,
jwt: requestJwt,
encryptionKey,
});

// Convert the encrypted Request Object to URLSearchParams for form encoding.
Expand All @@ -74,8 +81,8 @@
});

if (!parResponse.ok) {
throw new Error(`${parResponse.status}: ${parResponse.statusText}`);
}

Check warning on line 85 in packages/agent/src/connect.ts

View check run for this annotation

Codecov / codecov/patch

packages/agent/src/connect.ts#L84-L85

Added lines #L84 - L85 were not covered by tests

const parData: PushedAuthResponse = await parResponse.json();

Expand All @@ -83,7 +90,7 @@
// a route to its web5 connect provider flow and the params of where to fetch the auth request.
const generatedWalletUri = new URL(walletUri);
generatedWalletUri.searchParams.set('request_uri', parData.request_uri);
generatedWalletUri.searchParams.set('code_challenge', codeChallengeBase64Url);
generatedWalletUri.searchParams.set('encryption_key', Convert.uint8Array(encryptionKey).toBase64Url());

// call user's callback so they can send the URI to the wallet as they see fit
onWalletUriReady(generatedWalletUri.toString());
Expand Down Expand Up @@ -116,8 +123,8 @@
}

/**
* Initiates the wallet connect process. Used when the app (client) wants to import
* a delegated identity DID from a wallet (provider).
* Initiates the wallet connect process. Used when a client wants to obtain
* a did from a provider.
*/
export type WalletConnectOptions = {
/** The URL of the intermediary server which relays messages between the client and provider */
Expand All @@ -140,9 +147,9 @@
/**
* The Web5 API provides a URI to the wallet based on the `walletUri` plus a query params payload valid for 5 minutes.
* The link can either be used as a deep link on the same device or a QR code for cross device or both.
* The query params are `{ request_uri: string; code_challenge: string; }`
* The query params are `{ request_uri: string; encryption_key: string; }`
* The wallet will use the `request_uri to contact the intermediary server's `authorize` endpoint
* and pull down the {@link Web5ConnectAuthRequest} and use the `code_challenge` to decrypt it.
* and pull down the {@link Web5ConnectAuthRequest} and use the `encryption_key` to decrypt it.
*
* @param uri - The URI returned by the web5 connect API to be passed to a provider.
*/
Expand Down
Loading
Loading