Skip to content
This repository was archived by the owner on Sep 26, 2025. It is now read-only.

Commit f537e96

Browse files
Talha AliTalha Ali
authored andcommitted
Refactored Pairing API to a single array of inner arrays
1 parent be777c8 commit f537e96

6 files changed

Lines changed: 40 additions & 56 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@
1818
npm-debug.log*
1919
yarn-debug.log*
2020
yarn-error.log*
21+
22+
# Jetbrains IDEs
23+
.idea/

docs/specs/clients/core/pairing/data-structures.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,14 @@ Relay is defined by the transport protocol used for the two clients to publish a
5656
"data": string, // optional
5757
}
5858
```
59+
60+
## Protocol Types
61+
62+
```jsonc
63+
const ProtocolType = {
64+
Sign: "sign",
65+
Auth: "auth",
66+
Chat: "chat",
67+
Push: "push"
68+
}
69+
```

docs/specs/clients/core/pairing/pairing-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ abstract class PairingClient {
1717
public abstract activate(params: { topic: string }): Promise<void>;
1818

1919
// for both to subscribe on methods requests
20-
public abstract register(params: { reqMethods: string[], optMethods: string[] }): Promise<void>;
20+
public abstract register(params: { method: string, type: ProtocolType }): Promise<void>;
2121

2222
// for either to update the expiry of an existing pairing.
2323
public abstract updateExpiry(params: { topic: string, expiry: number }): Promise<void>;
Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,70 @@
11
# Pairing Methods Validation Test Cases
22

33

4-
## 1. Peer B matches the required list and the optional list
4+
## 1. Peer B matches URI's list exactly
55

66
### Peer A's pairing uri:
7-
uri = "...req-methods="wc_sessionPropose,wc_authRequest"&opt-methods="wc_authBatchRequest""
7+
uri = "...methods=[wc_sessionPropose],[wc_authRequest,wc_authBatchRequest]"
8+
89

910
### Peer B's registered methods:
10-
var requiredList = ["wc_sessionPropose", "wc_authRequest"]
11-
var optionalList = ["wc_authBatchRequest"]
11+
var registeredMethods = [{ method = "wc_sessionPropose", type = ProtocolType.Sign }, { method = "wc_authRequest", type = ProtocolType.Auth }, { method = "wc_authBatchRequest", type = ProtocolType.Auth }]
1212

1313

1414
is valid? Yes
1515

1616
---
1717

18-
## 2. Peer B matches the required list and partially matches the optional list
18+
## 2. Peer B matches one inner array exactly and partially matches another inner array
1919

2020
### Peer A's pairing uri:
21-
uri = "...req-methods="wc_sessionPropose"&opt-methods="wc_authBatchRequest,wc_pushMessage""
21+
uri = "...methods=[wc_sessionPropose],[wc_authBatchRequest]"
22+
2223

2324
### Peer B's registered methods:
24-
var requiredList = ["wc_sessionPropose"]
25-
var optionalList = ["wc_authBatchRequest"]
25+
var registeredMethods = [{ method = "wc_sessionPropose", type = ProtocolType.Sign }, { method = "wc_authRequest", type = ProtocolType.Auth }, { method = "wc_authBatchRequest", type = ProtocolType.Auth }]
2626

2727

2828
is valid? Yes
2929

3030
---
3131

32-
## 3. Peer B matches the required list and does not paritially match the optional list
32+
## 3. Peer B contains more methods than URI's list of methods
3333

3434
### Peer A's pairing uri:
35-
uri = "...req-methods="wc_sessionPropose"&opt-methods="wc_authBatchRequest,wc_pushMessage""
35+
uri = "...methods=[wc_sessionPropose]"
36+
3637

3738
### Peer B's registered methods:
38-
var requiredList = ["wc_sessionPropose"]
39-
var optionalList = []
39+
var registeredMethods = [{ method = "wc_sessionPropose", type = ProtocolType.Sign }, { method = "wc_authRequest", type = ProtocolType.Auth }, { method = "wc_authBatchRequest", type = ProtocolType.Auth }]
4040

4141

4242
is valid? Yes
4343

4444
---
4545

46-
## 4. Required list is empty and Peer B's paritially matches the optional list
46+
## 4. Peer B matches an inner array and does not partically match the other inner array
4747

4848
### Peer A's pairing uri:
49-
uri = "...opt-methods="wc_authBatchRequest,wc_pushMessage""
50-
51-
### Peer B's registered methods:
52-
var requiredList = []
53-
var optionalList = ["wc_pushMessage"]
49+
uri = "...methods=[wc_sessionPropose],[wc_authRequest]"
5450

5551

56-
is valid? Yes
57-
58-
---
59-
60-
## 5. Peer B does not match the required list and matches the optional list
61-
62-
### Peer A's pairing uri:
63-
uri = "...req-methods="wc_sessionRequest"&opt-methods="wc_authBatchRequest,wc_pushMessage""
64-
6552
### Peer B's registered methods:
66-
var requiredList = ["wc_sessionPropose"]
67-
var optionalList = ["wc_authBatchRequest","wc_pushMessage"]
53+
var registeredMethods = [{ method = "wc_sessionPropose", type = ProtocolType.Sign }]
6854

6955

7056
is valid? No
7157

7258
---
7359

74-
## 6. Peer B does not match the required list and partially matches the optional list
60+
## 5. Peer B does not match any inner arrays
7561

7662
### Peer A's pairing uri:
77-
uri = "...req-methods="wc_sessionRequest"&opt-methods="wc_authBatchRequest,wc_pushMessage""
78-
79-
### Peer B's registered methods:
80-
var requiredList = ["wc_sessionPropose"]
81-
var optionalList = ["wc_authBatchRequest"]
82-
83-
84-
is valid? No
85-
86-
---
63+
uri = "...methods=[wc_sessionPropose],[wc_authRequest]"
8764

88-
## 7. Peer B does not match the required list and does not partially matches the optional list
8965

90-
### Peer A's pairing uri:
91-
uri = "...req-methods="wc_sessionRequest"&opt-methods="wc_authBatchRequest,wc_pushMessage""
92-
9366
### Peer B's registered methods:
94-
var requiredList = ["wc_sessionPropose"]
95-
var optionalList = []
67+
var registeredMethods = [{ method = "wc_sessionProposeV2", type = ProtocolType.Sign },{ method = "wc_authBatchRequest", type = ProtocolType.Auth }]
9668

9769

9870
is valid? No

docs/specs/clients/core/pairing/pairing-uri.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717

1818
- `symKey` (STRING) = symmetric key used for pairing encryption
1919
- `relay-protocol` (STRING) = protocol name used for relay
20-
- `req-methods` (STRING) = comma separated list of methods that are all required when registered with the Pairing API's `register` method
21-
- `opt-methods` (STRING) = comma separated list of methods that are optional when registered with the Pairing API's `register` method
20+
- `methods` (STRING) = comma separated array of inner arrays of methods. Inner arrays are grouped by `ProtocolType`
2221

2322
### Optional
2423

@@ -30,9 +29,8 @@
3029
version = 2
3130
symKey = "587d5484ce2a2a6ee3ba1962fdd7e8588e06200c46823bd18fbd67def96ad303"
3231
relay = { protocol: "irn", data: "" }
33-
req-methods = ["wc_sessionPropose"]
34-
opt-methods = ["wc_authBatchRequest","wc_authRequest"]
32+
req-methods = [wc_sessionPropose],[wc_authRequest,wc_authBatchRequest]
3533

3634
```
37-
uri = "wc:7f6e504bfad60b485450578e05678ed3e8e8c4751d3c6160be17160d63ec90f9@2?relay-protocol=irn&symKey=587d5484ce2a2a6ee3ba1962fdd7e8588e06200c46823bd18fbd67def96ad303&req-methods=["wc_sessionPropose"]&opt-methods=["wc_authBatchRequest","wc_authRequest"]"
35+
uri = "wc:7f6e504bfad60b485450578e05678ed3e8e8c4751d3c6160be17160d63ec90f9@2?relay-protocol=irn&symKey=587d5484ce2a2a6ee3ba1962fdd7e8588e06200c46823bd18fbd67def96ad303&methods=[wc_sessionPropose],[wc_authRequest,wc_authBatchRequest]"
3836
```

docs/specs/clients/core/pairing/readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ User visits a new website that requires a Sign session for submitting transactio
3030
2. A's pairing client registers protocol P by passing the list of methods required for protocol P
3131
3. A encrypts request with symKey S. Pairing client does not expects any response. P is responsible for response subscription.
3232
4. A sends request on pairing topic.
33-
5. A generates URI and appends the query parameter with the keys "req-methods" and "opt-methods", the value of each being an array.
33+
5. A generates URI and appends the query parameter with the keys "methods" and the value is an array of inner arrays.
3434
6. B's pairing client registers protocol P by passing lists of methods needed for Protocol P
35-
7. B verifies that the URI's "req-methods" query parameter's value equals B's cached "required" list of protocol methods along with checking if B's cached "optional" list matches any values in the URI's "opt-methods' query parameter's value and then subscribes to pairing topic from provided URI
35+
7. B verifies that the URI's "methods" query parameter's value against B's cached "registered methods" list of protocol methods. If verification being valid then B subscribes to pairing topic from provided URI
3636
8. B receives protocol P request.
3737

3838

@@ -42,9 +42,9 @@ User visits a new website that requires a Sign session for submitting transactio
4242
2. A's pairing client registers protocol P by passing the list of methods needed for protocol P
4343
3. A encrypts request with symKey S. Pairing client does not expects any response. P is responsible for response subscription.
4444
4. A sends request on pairing topic.
45-
5. A generates URI and appends the query parameter with a key "req-methods" with the value being a list of the required methods registered and a key "opt-methods" with the value being a list of optional methods.
45+
5. A generates URI and appends the query parameter with a key "methods" with the value being a list of the required methods registered.
4646
6. B's pairing client registers protocol P by passing the list of methods needed for Protocol P
47-
7. B verifies that the URI's "req-methods" query parameter's value equals B's cached "required" list of protocol methods along with checking if B's cached "optional" list matches any values in the URI's "opt-methods' query parameter's value. The verification fails by either not having all of the required methods or missing any of the optional methods. B will notify user that it cannot pair with A, and internally publish a wc_deletePairing with a reason.
47+
7. B verifies that the URI's "methods" query parameter equals B's cached "registered methods" list of protocol methods. The verification fails by based on any of the cases in [Pairing Methods](/docs/specs/clients/core/pairing/pairing-methods.md). B will notify user that it cannot pair with A, and internally publish a wc_deletePairing with a reason.
4848

4949
## Pairing lifecycle
5050

0 commit comments

Comments
 (0)