1
1
import { SignifyClient } from './clienting' ;
2
2
import { Operation } from './coring' ;
3
3
4
+ export interface Contact {
5
+ alias : string ;
6
+ oobi : string ;
7
+ id : string ;
8
+ [ key : string ] : unknown ;
9
+ }
10
+
11
+ export interface ContactInfo {
12
+ [ key : string ] : unknown ;
13
+ }
14
+
4
15
/**
5
16
* Contacts
6
17
*/
7
18
export class Contacts {
8
19
client : SignifyClient ;
20
+
9
21
/**
10
22
* Contacts
11
23
* @param {SignifyClient } client
@@ -26,7 +38,7 @@ export class Contacts {
26
38
group ?: string ,
27
39
filterField ?: string ,
28
40
filterValue ?: string
29
- ) : Promise < any > {
41
+ ) : Promise < Contact [ ] > {
30
42
const params = new URLSearchParams ( ) ;
31
43
if ( group !== undefined ) {
32
44
params . append ( 'group' , group ) ;
@@ -48,7 +60,7 @@ export class Contacts {
48
60
* @param {string } pre Prefix of the contact
49
61
* @returns {Promise<any> } A promise to the contact
50
62
*/
51
- async get ( pre : string ) : Promise < any > {
63
+ async get ( pre : string ) : Promise < Contact > {
52
64
const path = `/contacts/` + pre ;
53
65
const method = 'GET' ;
54
66
const res = await this . client . fetch ( path , method , null ) ;
@@ -58,11 +70,11 @@ export class Contacts {
58
70
/**
59
71
* Add a contact
60
72
* @async
61
- * @param { string } pre Prefix of the contact
62
- * @param { any } info Information about the contact
63
- * @returns { Promise<any> } A promise to the result of the addition
73
+ * @param pre Prefix of the contact
74
+ * @param info Information about the contact
75
+ * @returns A promise to the result of the addition
64
76
*/
65
- async add ( pre : string , info : any ) : Promise < any > {
77
+ async add ( pre : string , info : ContactInfo ) : Promise < Contact > {
66
78
const path = `/contacts/` + pre ;
67
79
const method = 'POST' ;
68
80
@@ -90,7 +102,7 @@ export class Contacts {
90
102
* @param {any } info Updated information about the contact
91
103
* @returns {Promise<any> } A promise to the result of the update
92
104
*/
93
- async update ( pre : string , info : any ) : Promise < any > {
105
+ async update ( pre : string , info : ContactInfo ) : Promise < Contact > {
94
106
const path = `/contacts/` + pre ;
95
107
const method = 'PUT' ;
96
108
@@ -99,6 +111,10 @@ export class Contacts {
99
111
}
100
112
}
101
113
114
+ export interface Challenge {
115
+ words : string [ ] ;
116
+ }
117
+
102
118
/**
103
119
* Challenges
104
120
*/
@@ -118,7 +134,7 @@ export class Challenges {
118
134
* @param {number } strength Integer representing the strength of the challenge. Typically 128 or 256
119
135
* @returns {Promise<any> } A promise to the list of random words
120
136
*/
121
- async generate ( strength : number = 128 ) : Promise < any > {
137
+ async generate ( strength : number = 128 ) : Promise < Challenge > {
122
138
const path = `/challenges?strength=${ strength . toString ( ) } ` ;
123
139
const method = 'GET' ;
124
140
const res = await this . client . fetch ( path , method , null ) ;
@@ -128,16 +144,16 @@ export class Challenges {
128
144
/**
129
145
* Respond to a challenge by signing a message with the list of words
130
146
* @async
131
- * @param { string } name Name or alias of the identifier
132
- * @param { string } recipient Prefix of the recipient of the response
133
- * @param { Array<string> } words List of words to embed in the signed response
134
- * @returns { Promise<Response> } A promise to the result of the response
147
+ * @param name Name or alias of the identifier
148
+ * @param recipient Prefix of the recipient of the response
149
+ * @param words List of words to embed in the signed response
150
+ * @returns A promise to the result of the response
135
151
*/
136
152
async respond (
137
153
name : string ,
138
154
recipient : string ,
139
155
words : string [ ]
140
- ) : Promise < Response > {
156
+ ) : Promise < unknown > {
141
157
const hab = await this . client . identifiers ( ) . get ( name ) ;
142
158
const exchanges = this . client . exchanges ( ) ;
143
159
const resp = await exchanges . send (
@@ -154,8 +170,8 @@ export class Challenges {
154
170
155
171
/**
156
172
* Ask Agent to verify a given sender signed the provided words
157
- * @param { string } source Prefix of the identifier that was challenged
158
- * @param { Array<string> } words List of challenge words to check for
173
+ * @param source Prefix of the identifier that was challenged
174
+ * @param words List of challenge words to check for
159
175
* @returns A promise to the long running operation
160
176
*/
161
177
async verify ( source : string , words : string [ ] ) : Promise < Operation < unknown > > {
@@ -171,8 +187,8 @@ export class Challenges {
171
187
172
188
/**
173
189
* Mark challenge response as signed and accepted
174
- * @param { string } source Prefix of the identifier that was challenged
175
- * @param { string } said qb64 AID of exn message representing the signed response
190
+ * @param source Prefix of the identifier that was challenged
191
+ * @param said qb64 AID of exn message representing the signed response
176
192
* @returns {Promise<Response> } A promise to the result
177
193
*/
178
194
async responded ( source : string , said : string ) : Promise < Response > {
0 commit comments