signify-ts 0.3.0-rc2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/keri/app/aiding.d.ts +20 -4
  2. package/dist/keri/app/aiding.js +27 -2
  3. package/dist/keri/app/clienting.d.ts +2 -0
  4. package/dist/keri/app/clienting.js +1 -1
  5. package/dist/keri/app/contacting.d.ts +9 -14
  6. package/dist/keri/app/contacting.js +2 -2
  7. package/dist/keri/app/controller.js +2 -2
  8. package/dist/keri/app/coring.d.ts +119 -25
  9. package/dist/keri/app/coring.js +40 -13
  10. package/dist/keri/app/credentialing.d.ts +10 -10
  11. package/dist/keri/app/didwebing.d.ts +146 -0
  12. package/dist/keri/app/didwebing.js +359 -0
  13. package/dist/keri/app/escrowing.d.ts +4 -2
  14. package/dist/keri/app/escrowing.js +1 -1
  15. package/dist/keri/app/exchanging.d.ts +238 -7
  16. package/dist/keri/app/exchanging.js +102 -3
  17. package/dist/keri/app/grouping.d.ts +10 -8
  18. package/dist/keri/app/grouping.js +4 -4
  19. package/dist/keri/app/signaling.d.ts +50 -0
  20. package/dist/keri/app/signaling.js +52 -0
  21. package/dist/keri/app/w3cing.d.ts +137 -0
  22. package/dist/keri/app/w3cing.js +337 -0
  23. package/dist/keri/core/eventing.d.ts +2 -2
  24. package/dist/keri/core/eventing.js +7 -18
  25. package/dist/keri/core/keeping.d.ts +111 -8
  26. package/dist/keri/core/keeping.js +133 -54
  27. package/dist/keri/core/keyState.d.ts +84 -70
  28. package/dist/keri/core/keyState.js +1 -1
  29. package/dist/keri/core/manager.d.ts +1 -1
  30. package/dist/keri/core/manager.js +3 -3
  31. package/dist/keri/core/number.d.ts +1 -1
  32. package/dist/keri/core/number.js +7 -4
  33. package/dist/keri/core/salter.d.ts +2 -9
  34. package/dist/keri/core/salter.js +2 -9
  35. package/dist/types/keria-api-schema.d.ts +889 -35
  36. package/dist/types/keria-api-schema.js +34 -2
  37. package/package.json +3 -5
@@ -3,11 +3,12 @@ import { Algos } from '../core/manager.ts';
3
3
  import { Serder } from '../core/serder.ts';
4
4
  import { IdentifierManagerFactory } from '../core/keeping.ts';
5
5
  import { HabState } from '../core/keyState.ts';
6
+ import { components } from '../../types/keria-api-schema.ts';
6
7
  /** Arguments required to create an identfier */
7
8
  export interface CreateIdentiferArgs {
8
9
  transferable?: boolean;
9
- isith?: string | number | string[];
10
- nsith?: string | number | string[];
10
+ isith?: string | number | string[] | string[][];
11
+ nsith?: string | number | string[] | string[][];
11
12
  wits?: string[];
12
13
  toad?: number;
13
14
  proxy?: string;
@@ -58,6 +59,13 @@ export interface IdentifierDeps {
58
59
  export interface IdentifierInfo {
59
60
  name: string;
60
61
  }
62
+ export interface LocSchemeArgs {
63
+ url: string;
64
+ scheme?: string;
65
+ eid?: string;
66
+ stamp?: string;
67
+ }
68
+ export type GroupMembers = components['schemas']['GroupMember'];
61
69
  /** Identifier */
62
70
  export declare class Identifier {
63
71
  client: IdentifierDeps;
@@ -138,13 +146,21 @@ export declare class Identifier {
138
146
  * @returns {Serder} The reply message
139
147
  */
140
148
  private makeEndRole;
149
+ /**
150
+ * Authorises a new location scheme (endpoint) for a particular endpoint identifier.
151
+ * @param {LocSchemeArgs} args
152
+ * @param name Name or alias of the identifier to sign reply message
153
+ * @param args Arguments to create authorising reply message from
154
+ * @returns A promise to the result of the authorization
155
+ */
156
+ addLocScheme(name: string, args: LocSchemeArgs): Promise<EventResult>;
141
157
  /**
142
158
  * Get the members of a group identifier
143
159
  * @async
144
160
  * @param {string} name - Name or alias of the identifier
145
- * @returns {Promise<any>} - A promise to the list of members
161
+ * @returns {Promise<GroupMembers>} - A promise to the list of members
146
162
  */
147
- members(name: string): Promise<any>;
163
+ members(name: string): Promise<GroupMembers>;
148
164
  }
149
165
  /** Event Result */
150
166
  export declare class EventResult {
@@ -274,7 +274,7 @@ export class Identifier {
274
274
  adds: adds,
275
275
  data: data,
276
276
  });
277
- const sigs = await keeper.sign(b(serder.raw));
277
+ const sigs = await keeper.sign(b(serder.raw), true, undefined, undefined, true);
278
278
  const jsondata = {
279
279
  rot: serder.sad,
280
280
  sigs: sigs,
@@ -332,11 +332,36 @@ export class Identifier {
332
332
  const route = '/end/role/add';
333
333
  return reply(route, data, stamp, undefined, Serials.JSON);
334
334
  }
335
+ /**
336
+ * Authorises a new location scheme (endpoint) for a particular endpoint identifier.
337
+ * @param {LocSchemeArgs} args
338
+ * @param name Name or alias of the identifier to sign reply message
339
+ * @param args Arguments to create authorising reply message from
340
+ * @returns A promise to the result of the authorization
341
+ */
342
+ async addLocScheme(name, args) {
343
+ const { url, scheme, eid, stamp } = args;
344
+ const hab = await this.get(name);
345
+ const rpyData = {
346
+ eid: eid !== null && eid !== void 0 ? eid : hab.prefix,
347
+ url,
348
+ scheme: scheme !== null && scheme !== void 0 ? scheme : 'http',
349
+ };
350
+ const rpy = reply('/loc/scheme', rpyData, stamp, undefined, Serials.JSON);
351
+ const keeper = this.client.manager.get(hab);
352
+ const sigs = await keeper.sign(b(rpy.raw));
353
+ const jsondata = {
354
+ rpy: rpy.sad,
355
+ sigs: sigs,
356
+ };
357
+ const res = await this.client.fetch('/identifiers/' + name + '/locschemes', 'POST', jsondata);
358
+ return new EventResult(rpy, sigs, res);
359
+ }
335
360
  /**
336
361
  * Get the members of a group identifier
337
362
  * @async
338
363
  * @param {string} name - Name or alias of the identifier
339
- * @returns {Promise<any>} - A promise to the list of members
364
+ * @returns {Promise<GroupMembers>} - A promise to the list of members
340
365
  */
341
366
  async members(name) {
342
367
  const res = await this.client.fetch('/identifiers/' + name + '/members', 'GET', undefined);
@@ -1,3 +1,4 @@
1
+ import { components } from '../../types/keria-api-schema.ts';
1
2
  import { Authenticater } from '../core/authing.ts';
2
3
  import { ExternalModule, IdentifierManagerFactory } from '../core/keeping.ts';
3
4
  import { Tier } from '../core/salter.ts';
@@ -11,6 +12,7 @@ import { Escrows } from './escrowing.ts';
11
12
  import { Exchanges } from './exchanging.ts';
12
13
  import { Groups } from './grouping.ts';
13
14
  import { Notifications } from './notifying.ts';
15
+ export type AgentResourceResult = components['schemas']['AgentResourceResult'];
14
16
  declare class State {
15
17
  agent: any | null;
16
18
  controller: any | null;
@@ -104,7 +104,7 @@ export class SignifyClient {
104
104
  if (res.status == 404) {
105
105
  throw new Error(`agent does not exist for controller ${caid}`);
106
106
  }
107
- const data = await res.json();
107
+ const data = (await res.json());
108
108
  const state = new State();
109
109
  state.agent = (_b = data.agent) !== null && _b !== void 0 ? _b : {};
110
110
  state.controller = (_c = data.controller) !== null && _c !== void 0 ? _c : {};
@@ -1,11 +1,8 @@
1
1
  import { SignifyClient } from './clienting.ts';
2
- import { Operation } from './coring.ts';
3
- export interface Contact {
4
- alias: string;
5
- oobi: string;
6
- id: string;
7
- [key: string]: unknown;
8
- }
2
+ import { components } from '../../types/keria-api-schema.ts';
3
+ import { ChallengeOperation } from '../core/keyState.ts';
4
+ import { Exn } from './exchanging.ts';
5
+ export type Contact = components['schemas']['Contact'];
9
6
  export interface ContactInfo {
10
7
  [key: string]: unknown;
11
8
  }
@@ -59,9 +56,7 @@ export declare class Contacts {
59
56
  */
60
57
  update(pre: string, info: ContactInfo): Promise<Contact>;
61
58
  }
62
- export interface Challenge {
63
- words: string[];
64
- }
59
+ export type Challenge = components['schemas']['Challenge'];
65
60
  /**
66
61
  * Challenges
67
62
  */
@@ -76,7 +71,7 @@ export declare class Challenges {
76
71
  * Generate a random challenge word list based on BIP39
77
72
  * @async
78
73
  * @param {number} strength Integer representing the strength of the challenge. Typically 128 or 256
79
- * @returns {Promise<any>} A promise to the list of random words
74
+ * @returns {Promise<Challenge>} A promise to the generated challenge
80
75
  */
81
76
  generate(strength?: number): Promise<Challenge>;
82
77
  /**
@@ -85,16 +80,16 @@ export declare class Challenges {
85
80
  * @param name Name or alias of the identifier
86
81
  * @param recipient Prefix of the recipient of the response
87
82
  * @param words List of words to embed in the signed response
88
- * @returns A promise to the result of the response
83
+ * @returns {Promise<Exn>} A promise to the signed response exn message
89
84
  */
90
- respond(name: string, recipient: string, words: string[]): Promise<unknown>;
85
+ respond(name: string, recipient: string, words: string[]): Promise<Exn>;
91
86
  /**
92
87
  * Ask Agent to verify a given sender signed the provided words
93
88
  * @param source Prefix of the identifier that was challenged
94
89
  * @param words List of challenge words to check for
95
90
  * @returns A promise to the long running operation
96
91
  */
97
- verify(source: string, words: string[]): Promise<Operation<unknown>>;
92
+ verify(source: string, words: string[]): Promise<ChallengeOperation>;
98
93
  /**
99
94
  * Mark challenge response as signed and accepted
100
95
  * @param source Prefix of the identifier that was challenged
@@ -96,7 +96,7 @@ export class Challenges {
96
96
  * Generate a random challenge word list based on BIP39
97
97
  * @async
98
98
  * @param {number} strength Integer representing the strength of the challenge. Typically 128 or 256
99
- * @returns {Promise<any>} A promise to the list of random words
99
+ * @returns {Promise<Challenge>} A promise to the generated challenge
100
100
  */
101
101
  async generate(strength = 128) {
102
102
  const path = `/challenges?strength=${strength.toString()}`;
@@ -110,7 +110,7 @@ export class Challenges {
110
110
  * @param name Name or alias of the identifier
111
111
  * @param recipient Prefix of the recipient of the response
112
112
  * @param words List of words to embed in the signed response
113
- * @returns A promise to the result of the response
113
+ * @returns {Promise<Exn>} A promise to the signed response exn message
114
114
  */
115
115
  async respond(name, recipient, words) {
116
116
  const hab = await this.client.identifiers().get(name);
@@ -28,7 +28,7 @@ export class Agent {
28
28
  }
29
29
  parse(agent) {
30
30
  const [state, verfer] = this.event(agent);
31
- this.sn = new CesrNumber({}, undefined, state['s']).num;
31
+ this.sn = new CesrNumber({}, state['s']).num;
32
32
  this.said = state['d'];
33
33
  if (state['et'] !== Ilks.dip) {
34
34
  throw new Error(`invalid inception event type ${state['et']}`);
@@ -125,7 +125,7 @@ export class Controller {
125
125
  approveDelegation(_agent) {
126
126
  const seqner = new Seqner({ sn: _agent.sn });
127
127
  const anchor = { i: _agent.pre, s: seqner.snh, d: _agent.said };
128
- const sn = new CesrNumber({}, undefined, this.serder.sad['s']).num + 1;
128
+ const sn = new CesrNumber({}, this.serder.sad['s']).num + 1;
129
129
  this.serder = interact({
130
130
  pre: this.serder.pre,
131
131
  dig: this.serder.sad['d'],
@@ -1,5 +1,10 @@
1
1
  import { SignifyClient } from './clienting.ts';
2
2
  import { components } from '../../types/keria-api-schema.ts';
3
+ import { OOBIOperation, QueryOperation, EndRoleOperation, WitnessOperation, DelegationOperation, RegistryOperation, LocSchemeOperation, ChallengeOperation, ExchangeOperation, SubmitOperation, DoneOperation, CredentialOperation, GroupOperation, DelegatorOperation, CompletedOOBIOperation, CompletedQueryOperation, CompletedEndRoleOperation, CompletedWitnessOperation, CompletedDelegationOperation, CompletedRegistryOperation, CompletedLocSchemeOperation, CompletedChallengeOperation, CompletedExchangeOperation, CompletedSubmitOperation, CompletedDoneOperation, CompletedCredentialOperation, CompletedGroupOperation, CompletedDelegatorOperation, CompletedOperation, EndRole } from '../core/keyState.ts';
4
+ type OOBI = components['schemas']['OOBI'];
5
+ type KeyState = components['schemas']['KeyStateRecord'];
6
+ type KeyEventRecord = components['schemas']['KeyEventRecord'];
7
+ type AgentConfig = components['schemas']['AgentConfig'];
3
8
  export declare function randomPasscode(): string;
4
9
  export declare function randomNonce(): string;
5
10
  export declare class Oobis {
@@ -13,31 +18,29 @@ export declare class Oobis {
13
18
  * Get the OOBI(s) for a managed indentifier for a given role
14
19
  * @param {string} name Name or alias of the identifier
15
20
  * @param {string} role Authorized role
16
- * @returns {Promise<any>} A promise to the OOBI(s)
21
+ * @returns {Promise<OOBI>} A promise to the OOBI(s)
17
22
  */
18
- get(name: string, role?: string): Promise<any>;
23
+ get(name: string, role?: string): Promise<OOBI>;
19
24
  /**
20
25
  * Resolve an OOBI
21
26
  * @async
22
27
  * @param {string} oobi The OOBI to be resolver
23
28
  * @param {string} [alias] Optional name or alias to link the OOBI resolution to a contact
24
- * @returns {Promise<any>} A promise to the long-running operation
29
+ * @returns {Promise<OOBIOperation>} A promise to the long-running operation
25
30
  */
26
- resolve(oobi: string, alias?: string): Promise<any>;
31
+ resolve(oobi: string, alias?: string): Promise<OOBIOperation>;
32
+ /**
33
+ * Get end roles for an AID by prefix
34
+ * @param {string} aid AID prefix
35
+ * @param {string} [role] Optional role to filter by
36
+ * @returns {Promise<EndRole[]>} A promise to the list of end roles
37
+ */
38
+ endroles(aid: string, role?: string): Promise<EndRole[]>;
27
39
  }
28
- export type Operation<T = unknown> = Omit<components['schemas']['Operation'], 'response' | 'metadata'> & {
29
- response?: T;
30
- metadata?: {
31
- depends?: Operation;
32
- [property: string]: any;
33
- };
34
- };
40
+ export type Operation = OOBIOperation | QueryOperation | EndRoleOperation | WitnessOperation | DelegationOperation | RegistryOperation | LocSchemeOperation | ChallengeOperation | ExchangeOperation | SubmitOperation | DoneOperation | CredentialOperation | GroupOperation | DelegatorOperation;
35
41
  export interface OperationsDeps {
36
42
  fetch(pathname: string, method: string, body: unknown, headers?: Headers): Promise<Response>;
37
43
  }
38
- export interface AgentConfig {
39
- iurls?: string[];
40
- }
41
44
  /**
42
45
  * Operations
43
46
  * @remarks
@@ -50,20 +53,26 @@ export declare class Operations {
50
53
  * @param {SignifyClient} client
51
54
  */
52
55
  constructor(client: OperationsDeps);
56
+ private hasDepends;
57
+ /**
58
+ * Check if operation failed and throw error with details
59
+ * @throws {Error} If operation has an error
60
+ */
61
+ private throwIfFailed;
53
62
  /**
54
63
  * Get operation status
55
64
  * @async
56
65
  * @param {string} name Name of the operation
57
66
  * @returns {Promise<Operation>} A promise to the status of the operation
58
67
  */
59
- get<T = unknown>(name: string): Promise<Operation<T>>;
68
+ get(name: string): Promise<Operation>;
60
69
  /**
61
70
  * List operations
62
71
  * @async
63
72
  * @param {string} type Select operations by type
64
73
  * @returns {Promise<Operation[]>} A list of operations
65
74
  */
66
- list(type?: string): Promise<Operation<any>[]>;
75
+ list(type?: string): Promise<Operation[]>;
67
76
  /**
68
77
  * Delete operation
69
78
  * @async
@@ -73,12 +82,96 @@ export declare class Operations {
73
82
  /**
74
83
  * Poll for operation to become completed.
75
84
  */
76
- wait<T>(op: Operation<T>, options?: {
85
+ wait(op: OOBIOperation, options?: {
86
+ signal?: AbortSignal;
87
+ minSleep?: number;
88
+ maxSleep?: number;
89
+ increaseFactor?: number;
90
+ }): Promise<CompletedOOBIOperation>;
91
+ wait(op: QueryOperation, options?: {
92
+ signal?: AbortSignal;
93
+ minSleep?: number;
94
+ maxSleep?: number;
95
+ increaseFactor?: number;
96
+ }): Promise<CompletedQueryOperation>;
97
+ wait(op: EndRoleOperation, options?: {
98
+ signal?: AbortSignal;
99
+ minSleep?: number;
100
+ maxSleep?: number;
101
+ increaseFactor?: number;
102
+ }): Promise<CompletedEndRoleOperation>;
103
+ wait(op: WitnessOperation, options?: {
104
+ signal?: AbortSignal;
105
+ minSleep?: number;
106
+ maxSleep?: number;
107
+ increaseFactor?: number;
108
+ }): Promise<CompletedWitnessOperation>;
109
+ wait(op: DelegationOperation, options?: {
110
+ signal?: AbortSignal;
111
+ minSleep?: number;
112
+ maxSleep?: number;
113
+ increaseFactor?: number;
114
+ }): Promise<CompletedDelegationOperation>;
115
+ wait(op: RegistryOperation, options?: {
116
+ signal?: AbortSignal;
117
+ minSleep?: number;
118
+ maxSleep?: number;
119
+ increaseFactor?: number;
120
+ }): Promise<CompletedRegistryOperation>;
121
+ wait(op: LocSchemeOperation, options?: {
122
+ signal?: AbortSignal;
123
+ minSleep?: number;
124
+ maxSleep?: number;
125
+ increaseFactor?: number;
126
+ }): Promise<CompletedLocSchemeOperation>;
127
+ wait(op: ChallengeOperation, options?: {
128
+ signal?: AbortSignal;
129
+ minSleep?: number;
130
+ maxSleep?: number;
131
+ increaseFactor?: number;
132
+ }): Promise<CompletedChallengeOperation>;
133
+ wait(op: ExchangeOperation, options?: {
134
+ signal?: AbortSignal;
135
+ minSleep?: number;
136
+ maxSleep?: number;
137
+ increaseFactor?: number;
138
+ }): Promise<CompletedExchangeOperation>;
139
+ wait(op: SubmitOperation, options?: {
140
+ signal?: AbortSignal;
141
+ minSleep?: number;
142
+ maxSleep?: number;
143
+ increaseFactor?: number;
144
+ }): Promise<CompletedSubmitOperation>;
145
+ wait(op: DoneOperation, options?: {
77
146
  signal?: AbortSignal;
78
147
  minSleep?: number;
79
148
  maxSleep?: number;
80
149
  increaseFactor?: number;
81
- }): Promise<Operation<T>>;
150
+ }): Promise<CompletedDoneOperation>;
151
+ wait(op: CredentialOperation, options?: {
152
+ signal?: AbortSignal;
153
+ minSleep?: number;
154
+ maxSleep?: number;
155
+ increaseFactor?: number;
156
+ }): Promise<CompletedCredentialOperation>;
157
+ wait(op: GroupOperation, options?: {
158
+ signal?: AbortSignal;
159
+ minSleep?: number;
160
+ maxSleep?: number;
161
+ increaseFactor?: number;
162
+ }): Promise<CompletedGroupOperation>;
163
+ wait(op: DelegatorOperation, options?: {
164
+ signal?: AbortSignal;
165
+ minSleep?: number;
166
+ maxSleep?: number;
167
+ increaseFactor?: number;
168
+ }): Promise<CompletedDelegatorOperation>;
169
+ wait(op: Operation, options?: {
170
+ signal?: AbortSignal;
171
+ minSleep?: number;
172
+ maxSleep?: number;
173
+ increaseFactor?: number;
174
+ }): Promise<CompletedOperation>;
82
175
  }
83
176
  /**
84
177
  * KeyEvents
@@ -94,9 +187,9 @@ export declare class KeyEvents {
94
187
  * Retrieve key events for an identifier
95
188
  * @async
96
189
  * @param {string} pre Identifier prefix
97
- * @returns {Promise<any>} A promise to the key events
190
+ * @returns {Promise<KeyEventRecord[]>} A promise to the key events
98
191
  */
99
- get(pre: string): Promise<any>;
192
+ get(pre: string): Promise<KeyEventRecord[]>;
100
193
  }
101
194
  /**
102
195
  * KeyStates
@@ -112,25 +205,25 @@ export declare class KeyStates {
112
205
  * Retriene the key state for an identifier
113
206
  * @async
114
207
  * @param {string} pre Identifier prefix
115
- * @returns {Promise<any>} A promise to the key states
208
+ * @returns {Promise<KeyState[]>} A promise to the key states
116
209
  */
117
- get(pre: string): Promise<any>;
210
+ get(pre: string): Promise<KeyState[]>;
118
211
  /**
119
212
  * Retrieve the key state for a list of identifiers
120
213
  * @async
121
214
  * @param {Array<string>} pres List of identifier prefixes
122
215
  * @returns {Promise<any>} A promise to the key states
123
216
  */
124
- list(pres: string[]): Promise<any>;
217
+ list(pres: string[]): Promise<KeyState[]>;
125
218
  /**
126
219
  * Query the key state of an identifier for a given sequence number or anchor
127
220
  * @async
128
221
  * @param {string} pre Identifier prefix
129
222
  * @param {number} [sn] Optional sequence number
130
223
  * @param {any} [anchor] Optional anchor
131
- * @returns {Promise<any>} A promise to the long-running operation
224
+ * @returns {Promise<QueryOperation>} A promise to the long-running operation
132
225
  */
133
- query(pre: string, sn?: string, anchor?: any): Promise<any>;
226
+ query(pre: string, sn?: string, anchor?: any): Promise<QueryOperation>;
134
227
  }
135
228
  export declare class Config {
136
229
  client: SignifyClient;
@@ -141,3 +234,4 @@ export declare class Config {
141
234
  constructor(client: SignifyClient);
142
235
  get(): Promise<AgentConfig>;
143
236
  }
237
+ export {};
@@ -24,7 +24,7 @@ export class Oobis {
24
24
  * Get the OOBI(s) for a managed indentifier for a given role
25
25
  * @param {string} name Name or alias of the identifier
26
26
  * @param {string} role Authorized role
27
- * @returns {Promise<any>} A promise to the OOBI(s)
27
+ * @returns {Promise<OOBI>} A promise to the OOBI(s)
28
28
  */
29
29
  async get(name, role = 'agent') {
30
30
  const path = `/identifiers/${name}/oobis?role=${role}`;
@@ -37,7 +37,7 @@ export class Oobis {
37
37
  * @async
38
38
  * @param {string} oobi The OOBI to be resolver
39
39
  * @param {string} [alias] Optional name or alias to link the OOBI resolution to a contact
40
- * @returns {Promise<any>} A promise to the long-running operation
40
+ * @returns {Promise<OOBIOperation>} A promise to the long-running operation
41
41
  */
42
42
  async resolve(oobi, alias) {
43
43
  const path = `/oobis`;
@@ -51,6 +51,17 @@ export class Oobis {
51
51
  const res = await this.client.fetch(path, method, data);
52
52
  return await res.json();
53
53
  }
54
+ /**
55
+ * Get end roles for an AID by prefix
56
+ * @param {string} aid AID prefix
57
+ * @param {string} [role] Optional role to filter by
58
+ * @returns {Promise<EndRole[]>} A promise to the list of end roles
59
+ */
60
+ async endroles(aid, role) {
61
+ const path = role ? `/endroles/${aid}/${role}` : `/endroles/${aid}`;
62
+ const res = await this.client.fetch(path, 'GET', null);
63
+ return await res.json();
64
+ }
54
65
  }
55
66
  /**
56
67
  * Operations
@@ -65,6 +76,21 @@ export class Operations {
65
76
  constructor(client) {
66
77
  this.client = client;
67
78
  }
79
+ hasDepends(op) {
80
+ return op.metadata !== undefined && 'depends' in op.metadata;
81
+ }
82
+ /**
83
+ * Check if operation failed and throw error with details
84
+ * @throws {Error} If operation has an error
85
+ */
86
+ throwIfFailed(op) {
87
+ if ('error' in op && op.error !== null) {
88
+ const details = op.error.details
89
+ ? ` Details: ${JSON.stringify(op.error.details)}`
90
+ : '';
91
+ throw new Error(`Operation '${op.name}' failed [Code ${op.error.code}]: ${op.error.message}${details}`);
92
+ }
93
+ }
68
94
  /**
69
95
  * Get operation status
70
96
  * @async
@@ -106,30 +132,31 @@ export class Operations {
106
132
  const method = 'DELETE';
107
133
  await this.client.fetch(path, method, data);
108
134
  }
109
- /**
110
- * Poll for operation to become completed.
111
- */
112
135
  async wait(op, options = {}) {
113
- var _a, _b, _c, _d, _e, _f;
136
+ var _a, _b, _c, _d;
114
137
  const minSleep = (_a = options.minSleep) !== null && _a !== void 0 ? _a : 10;
115
138
  const maxSleep = (_b = options.maxSleep) !== null && _b !== void 0 ? _b : 10000;
116
139
  const increaseFactor = (_c = options.increaseFactor) !== null && _c !== void 0 ? _c : 50;
117
- if (((_e = (_d = op.metadata) === null || _d === void 0 ? void 0 : _d.depends) === null || _e === void 0 ? void 0 : _e.done) === false) {
140
+ if (this.hasDepends(op) &&
141
+ op.metadata.depends &&
142
+ !op.metadata.depends.done) {
118
143
  await this.wait(op.metadata.depends, options);
119
144
  }
120
145
  if (op.done === true) {
146
+ this.throwIfFailed(op);
121
147
  return op;
122
148
  }
123
149
  let retries = 0;
124
150
  while (true) {
125
151
  op = await this.get(op.name);
126
- const delay = Math.max(minSleep, Math.min(maxSleep, 2 ** retries * increaseFactor));
127
- retries++;
128
152
  if (op.done === true) {
153
+ this.throwIfFailed(op);
129
154
  return op;
130
155
  }
156
+ const delay = Math.max(minSleep, Math.min(maxSleep, 2 ** retries * increaseFactor));
157
+ retries++;
131
158
  await new Promise((resolve) => setTimeout(resolve, delay));
132
- (_f = options.signal) === null || _f === void 0 ? void 0 : _f.throwIfAborted();
159
+ (_d = options.signal) === null || _d === void 0 ? void 0 : _d.throwIfAborted();
133
160
  }
134
161
  }
135
162
  }
@@ -148,7 +175,7 @@ export class KeyEvents {
148
175
  * Retrieve key events for an identifier
149
176
  * @async
150
177
  * @param {string} pre Identifier prefix
151
- * @returns {Promise<any>} A promise to the key events
178
+ * @returns {Promise<KeyEventRecord[]>} A promise to the key events
152
179
  */
153
180
  async get(pre) {
154
181
  const path = `/events?pre=${pre}`;
@@ -173,7 +200,7 @@ export class KeyStates {
173
200
  * Retriene the key state for an identifier
174
201
  * @async
175
202
  * @param {string} pre Identifier prefix
176
- * @returns {Promise<any>} A promise to the key states
203
+ * @returns {Promise<KeyState[]>} A promise to the key states
177
204
  */
178
205
  async get(pre) {
179
206
  const path = `/states?pre=${pre}`;
@@ -201,7 +228,7 @@ export class KeyStates {
201
228
  * @param {string} pre Identifier prefix
202
229
  * @param {number} [sn] Optional sequence number
203
230
  * @param {any} [anchor] Optional anchor
204
- * @returns {Promise<any>} A promise to the long-running operation
231
+ * @returns {Promise<QueryOperation>} A promise to the long-running operation
205
232
  */
206
233
  async query(pre, sn, anchor) {
207
234
  const path = `/queries`;
@@ -1,8 +1,7 @@
1
1
  import { SignifyClient } from './clienting.ts';
2
2
  import { Dict } from '../core/core.ts';
3
3
  import { Serder } from '../core/serder.ts';
4
- import { Operation } from './coring.ts';
5
- import { HabState } from '../core/keyState.ts';
4
+ import { ExchangeOperation, CredentialOperation, GroupOperation, DelegationOperation, WitnessOperation, DoneOperation, HabState, RegistryOperation } from '../core/keyState.ts';
6
5
  import { components } from '../../types/keria-api-schema.ts';
7
6
  export type CredentialResult = components['schemas']['Credential'];
8
7
  export type Registry = components['schemas']['Registry'];
@@ -74,12 +73,12 @@ export interface IssueCredentialResult {
74
73
  acdc: Serder;
75
74
  anc: Serder;
76
75
  iss: Serder;
77
- op: Operation;
76
+ op: CredentialOperation;
78
77
  }
79
78
  export interface RevokeCredentialResult {
80
79
  anc: Serder;
81
80
  rev: Serder;
82
- op: Operation;
81
+ op: GroupOperation | DelegationOperation | WitnessOperation | DoneOperation;
83
82
  }
84
83
  export interface IpexApplyArgs {
85
84
  /**
@@ -218,6 +217,7 @@ export declare class Credentials {
218
217
  get(said: string): Promise<CredentialResult>;
219
218
  get(said: string, includeCESR: false): Promise<CredentialResult>;
220
219
  get(said: string, includeCESR: true): Promise<string>;
220
+ get(said: string, includeCESR: boolean): Promise<CredentialResult | string>;
221
221
  /**
222
222
  * Delete a credential from the DB
223
223
  * @async
@@ -264,7 +264,7 @@ export declare class RegistryResult {
264
264
  get regser(): any;
265
265
  get serder(): Serder;
266
266
  get sigs(): string[];
267
- op(): Promise<Registry>;
267
+ op(): Promise<RegistryOperation>;
268
268
  }
269
269
  /**
270
270
  * Registries
@@ -339,25 +339,25 @@ export declare class Ipex {
339
339
  * Create an IPEX apply EXN message
340
340
  */
341
341
  apply(args: IpexApplyArgs): Promise<[Serder, string[], string]>;
342
- submitApply(name: string, exn: Serder, sigs: string[], recp: string[]): Promise<any>;
342
+ submitApply(name: string, exn: Serder, sigs: string[], recp: string[]): Promise<ExchangeOperation>;
343
343
  /**
344
344
  * Create an IPEX offer EXN message
345
345
  */
346
346
  offer(args: IpexOfferArgs): Promise<[Serder, string[], string]>;
347
- submitOffer(name: string, exn: Serder, sigs: string[], atc: string, recp: string[]): Promise<any>;
347
+ submitOffer(name: string, exn: Serder, sigs: string[], atc: string, recp: string[]): Promise<ExchangeOperation>;
348
348
  /**
349
349
  * Create an IPEX agree EXN message
350
350
  */
351
351
  agree(args: IpexAgreeArgs): Promise<[Serder, string[], string]>;
352
- submitAgree(name: string, exn: Serder, sigs: string[], recp: string[]): Promise<any>;
352
+ submitAgree(name: string, exn: Serder, sigs: string[], recp: string[]): Promise<ExchangeOperation>;
353
353
  /**
354
354
  * Create an IPEX grant EXN message
355
355
  */
356
356
  grant(args: IpexGrantArgs): Promise<[Serder, string[], string]>;
357
- submitGrant(name: string, exn: Serder, sigs: string[], atc: string, recp: string[]): Promise<any>;
357
+ submitGrant(name: string, exn: Serder, sigs: string[], atc: string, recp: string[]): Promise<ExchangeOperation>;
358
358
  /**
359
359
  * Create an IPEX admit EXN message
360
360
  */
361
361
  admit(args: IpexAdmitArgs): Promise<[Serder, string[], string]>;
362
- submitAdmit(name: string, exn: Serder, sigs: string[], atc: string, recp: string[]): Promise<any>;
362
+ submitAdmit(name: string, exn: Serder, sigs: string[], atc: string, recp: string[]): Promise<ExchangeOperation>;
363
363
  }