signify-ts 0.2.0 → 0.3.0-dev.e31e78d

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 (129) hide show
  1. package/README.md +104 -34
  2. package/dist/exports.d.ts +40 -40
  3. package/dist/exports.js +40 -0
  4. package/dist/index.d.ts +2 -3
  5. package/dist/index.js +3 -8
  6. package/dist/keri/app/aiding.d.ts +54 -18
  7. package/{src/keri/app/aiding.ts → dist/keri/app/aiding.js} +130 -236
  8. package/dist/keri/app/clienting.d.ts +59 -22
  9. package/{src/keri/app/clienting.ts → dist/keri/app/clienting.js} +146 -235
  10. package/dist/keri/app/contacting.d.ts +30 -23
  11. package/{src/keri/app/contacting.ts → dist/keri/app/contacting.js} +26 -63
  12. package/dist/keri/app/controller.d.ts +49 -6
  13. package/{src/keri/app/controller.ts → dist/keri/app/controller.js} +80 -186
  14. package/dist/keri/app/coring.d.ts +134 -25
  15. package/{src/keri/app/coring.ts → dist/keri/app/coring.js} +83 -56
  16. package/dist/keri/app/credentialing.d.ts +191 -67
  17. package/dist/keri/app/credentialing.js +540 -0
  18. package/dist/keri/app/delegating.d.ts +18 -0
  19. package/dist/keri/app/delegating.js +24 -0
  20. package/dist/keri/app/escrowing.d.ts +5 -3
  21. package/{src/keri/app/escrowing.ts → dist/keri/app/escrowing.js} +3 -9
  22. package/dist/keri/app/exchanging.d.ts +243 -11
  23. package/dist/keri/app/exchanging.js +242 -0
  24. package/dist/keri/app/grouping.d.ts +11 -9
  25. package/{src/keri/app/grouping.ts → dist/keri/app/grouping.js} +10 -29
  26. package/dist/keri/app/habery.d.ts +2 -2
  27. package/dist/keri/app/habery.js +117 -0
  28. package/dist/keri/app/notifying.d.ts +2 -2
  29. package/{src/keri/app/notifying.ts → dist/keri/app/notifying.js} +7 -17
  30. package/dist/keri/core/authing.d.ts +2 -2
  31. package/{src/keri/core/authing.ts → dist/keri/core/authing.js} +26 -42
  32. package/dist/keri/core/base64.d.ts +2 -0
  33. package/dist/keri/core/base64.js +16 -0
  34. package/dist/keri/core/bexter.d.ts +1 -1
  35. package/{src/keri/core/bexter.ts → dist/keri/core/bexter.js} +18 -32
  36. package/dist/keri/core/cigar.d.ts +2 -2
  37. package/dist/keri/core/cigar.js +13 -0
  38. package/dist/keri/core/cipher.d.ts +1 -1
  39. package/{src/keri/core/cipher.ts → dist/keri/core/cipher.js} +10 -19
  40. package/dist/keri/core/core.d.ts +117 -9
  41. package/dist/keri/core/core.js +385 -0
  42. package/dist/keri/core/counter.d.ts +2 -2
  43. package/dist/keri/core/counter.js +221 -0
  44. package/dist/keri/core/decrypter.d.ts +4 -4
  45. package/{src/keri/core/decrypter.ts → dist/keri/core/decrypter.js} +23 -40
  46. package/dist/keri/core/diger.d.ts +3 -3
  47. package/{src/keri/core/diger.ts → dist/keri/core/diger.js} +18 -33
  48. package/dist/keri/core/encrypter.d.ts +2 -2
  49. package/{src/keri/core/encrypter.ts → dist/keri/core/encrypter.js} +18 -38
  50. package/dist/keri/core/eventing.d.ts +6 -6
  51. package/dist/keri/core/eventing.js +383 -0
  52. package/dist/keri/core/httping.d.ts +11 -4
  53. package/{src/keri/core/httping.ts → dist/keri/core/httping.js} +36 -101
  54. package/dist/keri/core/indexer.d.ts +1 -1
  55. package/dist/keri/core/indexer.js +407 -0
  56. package/dist/keri/core/keeping.d.ts +113 -46
  57. package/dist/keri/core/keeping.js +347 -0
  58. package/{src/keri/core/kering.ts → dist/keri/core/kering.js} +1 -3
  59. package/dist/keri/core/keyState.d.ts +98 -0
  60. package/dist/keri/core/manager.d.ts +147 -12
  61. package/dist/keri/core/manager.js +880 -0
  62. package/dist/keri/core/matter.d.ts +1 -1
  63. package/dist/keri/core/matter.js +460 -0
  64. package/dist/keri/core/number.d.ts +2 -2
  65. package/{src/keri/core/number.ts → dist/keri/core/number.js} +26 -32
  66. package/dist/keri/core/pather.d.ts +2 -2
  67. package/{src/keri/core/pather.ts → dist/keri/core/pather.js} +12 -27
  68. package/dist/keri/core/prefixer.d.ts +10 -10
  69. package/dist/keri/core/prefixer.js +182 -0
  70. package/dist/keri/core/saider.d.ts +2 -12
  71. package/dist/keri/core/saider.js +107 -0
  72. package/dist/keri/core/salter.d.ts +44 -9
  73. package/dist/keri/core/salter.js +110 -0
  74. package/dist/keri/core/seqner.d.ts +1 -1
  75. package/{src/keri/core/seqner.ts → dist/keri/core/seqner.js} +20 -21
  76. package/dist/keri/core/serder.d.ts +25 -12
  77. package/dist/keri/core/serder.js +133 -0
  78. package/dist/keri/core/siger.d.ts +2 -2
  79. package/{src/keri/core/siger.ts → dist/keri/core/siger.js} +4 -14
  80. package/dist/keri/core/signer.d.ts +4 -4
  81. package/dist/keri/core/signer.js +84 -0
  82. package/{src/keri/core/tholder.ts → dist/keri/core/tholder.js} +69 -94
  83. package/dist/keri/core/utils.d.ts +1 -1
  84. package/{src/keri/core/utils.ts → dist/keri/core/utils.js} +30 -60
  85. package/dist/keri/core/vdring.d.ts +2 -2
  86. package/dist/keri/core/vdring.js +61 -0
  87. package/dist/keri/core/verfer.d.ts +2 -6
  88. package/dist/keri/core/verfer.js +37 -0
  89. package/dist/keri/end/ending.d.ts +10 -8
  90. package/dist/keri/end/ending.js +136 -0
  91. package/{src/ready.ts → dist/ready.js} +1 -2
  92. package/dist/types/keria-api-schema.d.ts +1158 -0
  93. package/dist/types/keria-api-schema.js +34 -0
  94. package/package.json +53 -52
  95. package/dist/math.d.ts +0 -1
  96. package/dist/signify-ts.cjs +0 -7835
  97. package/dist/signify-ts.cjs.development.js +0 -9501
  98. package/dist/signify-ts.cjs.development.js.map +0 -1
  99. package/dist/signify-ts.cjs.map +0 -7
  100. package/dist/signify-ts.cjs.production.min.js +0 -2
  101. package/dist/signify-ts.cjs.production.min.js.map +0 -1
  102. package/dist/signify-ts.esm.js +0 -9345
  103. package/dist/signify-ts.esm.js.map +0 -1
  104. package/dist/signify-ts.mjs +0 -7811
  105. package/dist/signify-ts.mjs.map +0 -7
  106. package/src/buffer-polyfill.ts +0 -5
  107. package/src/exports.ts +0 -44
  108. package/src/index.ts +0 -4
  109. package/src/keri/app/credentialing.ts +0 -820
  110. package/src/keri/app/exchanging.ts +0 -220
  111. package/src/keri/app/habery.ts +0 -185
  112. package/src/keri/core/cigar.ts +0 -18
  113. package/src/keri/core/core.ts +0 -326
  114. package/src/keri/core/counter.ts +0 -273
  115. package/src/keri/core/eventing.ts +0 -581
  116. package/src/keri/core/indexer.ts +0 -509
  117. package/src/keri/core/keeping.ts +0 -684
  118. package/src/keri/core/manager.ts +0 -1183
  119. package/src/keri/core/matter.ts +0 -521
  120. package/src/keri/core/prefixer.ts +0 -233
  121. package/src/keri/core/saider.ts +0 -186
  122. package/src/keri/core/salter.ts +0 -120
  123. package/src/keri/core/serder.ts +0 -163
  124. package/src/keri/core/signer.ts +0 -133
  125. package/src/keri/core/vdring.ts +0 -94
  126. package/src/keri/core/verfer.ts +0 -47
  127. package/src/keri/end/ending.ts +0 -170
  128. package/src/math.ts +0 -3
  129. /package/dist/{buffer-polyfill.d.ts → keri/core/keyState.js} +0 -0
@@ -1,31 +1,23 @@
1
- import { SaltyCreator } from '../core/manager';
2
- import { Salter, Tier } from '../core/salter';
3
- import { MtrDex } from '../core/matter';
4
- import { Diger } from '../core/diger';
5
- import { incept, rotate, interact } from '../core/eventing';
6
- import { Serder } from '../core/serder';
7
- import { Tholder } from '../core/tholder';
8
- import { Ilks, b, Serials, Versionage } from '../core/core';
9
- import { Verfer } from '../core/verfer';
10
- import { Encrypter } from '../core/encrypter';
11
- import { Decrypter } from '../core/decrypter';
12
- import { Cipher } from '../core/cipher';
13
- import { Seqner } from '../core/seqner';
14
- import { CesrNumber } from '../core/number';
15
-
1
+ import { SaltyCreator } from "../core/manager.js";
2
+ import { Salter } from "../core/salter.js";
3
+ import { MtrDex } from "../core/matter.js";
4
+ import { Diger } from "../core/diger.js";
5
+ import { incept, rotate, interact } from "../core/eventing.js";
6
+ import { Serder } from "../core/serder.js";
7
+ import { Tholder } from "../core/tholder.js";
8
+ import { Ilks, b, Serials, Vrsn_1_0 } from "../core/core.js";
9
+ import { Verfer } from "../core/verfer.js";
10
+ import { Encrypter } from "../core/encrypter.js";
11
+ import { Decrypter } from "../core/decrypter.js";
12
+ import { Cipher } from "../core/cipher.js";
13
+ import { Seqner } from "../core/seqner.js";
14
+ import { CesrNumber } from "../core/number.js";
16
15
  /**
17
16
  * Agent is a custodial entity that can be used in conjuntion with a local Client to establish the
18
17
  * KERI "signing at the edge" semantic
19
18
  */
20
19
  export class Agent {
21
- pre: string;
22
- anchor: string;
23
- verfer: Verfer | null;
24
- state: any | null;
25
- sn: number | undefined;
26
- said: string | undefined;
27
-
28
- constructor(agent: any) {
20
+ constructor(agent) {
29
21
  this.pre = '';
30
22
  this.anchor = '';
31
23
  this.verfer = null;
@@ -34,121 +26,87 @@ export class Agent {
34
26
  this.said = '';
35
27
  this.parse(agent);
36
28
  }
37
-
38
- private parse(agent: Agent) {
29
+ parse(agent) {
39
30
  const [state, verfer] = this.event(agent);
40
-
41
- this.sn = new CesrNumber({}, undefined, state['s']).num;
31
+ this.sn = new CesrNumber({}, state['s']).num;
42
32
  this.said = state['d'];
43
-
44
33
  if (state['et'] !== Ilks.dip) {
45
34
  throw new Error(`invalid inception event type ${state['et']}`);
46
35
  }
47
-
48
36
  this.pre = state['i'];
49
37
  if (!state['di']) {
50
38
  throw new Error('no anchor to controller AID');
51
39
  }
52
-
53
40
  this.anchor = state['di'];
54
-
55
41
  this.verfer = verfer;
56
42
  this.state = state;
57
43
  }
58
-
59
- private event(evt: any): [any, Verfer, Diger] {
44
+ event(evt) {
60
45
  if (evt['k'].length !== 1) {
61
46
  throw new Error(`agent inception event can only have one key`);
62
47
  }
63
-
64
48
  const verfer = new Verfer({ qb64: evt['k'][0] });
65
-
66
49
  if (evt['n'].length !== 1) {
67
50
  throw new Error(`agent inception event can only have one next key`);
68
51
  }
69
-
70
52
  const diger = new Diger({ qb64: evt['n'][0] });
71
-
72
53
  const tholder = new Tholder({ sith: evt['kt'] });
73
54
  if (tholder.num !== 1) {
74
55
  throw new Error(`invalid threshold ${tholder.num}, must be 1`);
75
56
  }
76
-
77
57
  const ntholder = new Tholder({ sith: evt['nt'] });
78
58
  if (ntholder.num !== 1) {
79
- throw new Error(
80
- `invalid next threshold ${ntholder.num}, must be 1`
81
- );
59
+ throw new Error(`invalid next threshold ${ntholder.num}, must be 1`);
82
60
  }
83
61
  return [evt, verfer, diger];
84
62
  }
85
63
  }
86
-
87
64
  /**
88
65
  * Controller is responsible for managing signing keys for the client and agent. The client
89
66
  * signing key represents the Account for the client on the agent
90
67
  */
91
68
  export class Controller {
92
- private bran: string;
93
- public stem: string;
94
- public tier: Tier;
95
- public ridx: number;
96
- public salter: any;
97
- public signer: any;
98
- private nsigner: any;
99
- public serder: Serder;
100
- private keys: string[];
101
- public ndigs: string[];
102
-
103
- constructor(
104
- bran: string,
105
- tier: Tier,
106
- ridx: number = 0,
107
- state: any | null = null
108
- ) {
69
+ /**
70
+ * Creates a Signify Controller starting at key index 0 that generates keys in
71
+ * memory based on the provided seed, or bran, the tier, and the rotation index.
72
+ *
73
+ * The rotation index is used as follows:
74
+ *
75
+ * @param bran
76
+ * @param tier
77
+ * @param ridx
78
+ * @param state
79
+ */
80
+ constructor(bran, tier, ridx = 0, state = null) {
109
81
  this.bran = MtrDex.Salt_128 + 'A' + bran.substring(0, 21); // qb64 salt for seed
110
82
  this.stem = 'signify:controller';
111
83
  this.tier = tier;
112
84
  this.ridx = ridx;
113
-
85
+ const codes = undefined; // Defines the types of seeds that the SaltyCreator will create. Defaults to undefined.
86
+ const keyCount = 1; // The number of keys to create. Defaults to 1.
87
+ const transferable = true; // Whether the keys are transferable. Defaults to true.
88
+ const code = MtrDex.Ed25519_Seed; // The type cryptographic seed to create by default when not overiddeen by "codes".
89
+ const pidx = 0; // The index of this identifier prefix of all managed identifiers created for this SignifyClient Controller. Defaults to 0.
90
+ const kidx = 0; // The overall starting key index for the first key this rotation set of keys. This is not a local index to this set of keys but an index in the overall set of keys for all keys in this sequence.
91
+ // Defaults to 0. Multiply rotation index (ridx) times key count to get the overall key index.
114
92
  this.salter = new Salter({ qb64: this.bran, tier: this.tier });
115
-
116
- const creator = new SaltyCreator(
117
- this.salter.qb64,
118
- this.tier,
119
- this.stem
120
- );
121
-
93
+ const creator = new SaltyCreator(this.salter.qb64, this.tier, this.stem);
94
+ // Creates the first key pair used to sign the inception event.
95
+ // noinspection UnnecessaryLocalVariableJS
96
+ const initialKeyIndex = ridx; // will be zero for inception
122
97
  this.signer = creator
123
- .create(
124
- undefined,
125
- 1,
126
- MtrDex.Ed25519_Seed,
127
- true,
128
- 0,
129
- this.ridx,
130
- 0,
131
- false
132
- )
133
- .signers.pop();
98
+ .create(codes, keyCount, code, transferable, pidx, initialKeyIndex, kidx)
99
+ .signers.pop(); // assumes only one key pair is created because keyCount is 1
100
+ // Creates the second key pair which a digest of the public key is committed to in the inception event.
101
+ const nextKeyIndex = ridx + 1;
134
102
  this.nsigner = creator
135
- .create(
136
- undefined,
137
- 1,
138
- MtrDex.Ed25519_Seed,
139
- true,
140
- 0,
141
- this.ridx + 1,
142
- 0,
143
- false
144
- )
145
- .signers.pop();
103
+ .create(codes, keyCount, code, transferable, pidx, nextKeyIndex, kidx)
104
+ .signers.pop(); // assumes only one key pair is created because keyCount is 1
146
105
  this.keys = [this.signer.verfer.qb64];
147
106
  this.ndigs = [
148
107
  new Diger({ code: MtrDex.Blake3_256 }, this.nsigner.verfer.qb64b)
149
108
  .qb64,
150
109
  ];
151
-
152
110
  if (state == null || state['ee']['s'] == 0) {
153
111
  this.serder = incept({
154
112
  keys: this.keys,
@@ -159,40 +117,36 @@ export class Controller {
159
117
  toad: '0',
160
118
  wits: [],
161
119
  });
162
- } else {
120
+ }
121
+ else {
163
122
  this.serder = new Serder(state['ee']);
164
123
  }
165
124
  }
166
-
167
- approveDelegation(_agent: Agent) {
125
+ approveDelegation(_agent) {
168
126
  const seqner = new Seqner({ sn: _agent.sn });
169
127
  const anchor = { i: _agent.pre, s: seqner.snh, d: _agent.said };
170
- const sn = new CesrNumber({}, undefined, this.serder.ked['s']).num + 1;
128
+ const sn = new CesrNumber({}, this.serder.sad['s']).num + 1;
171
129
  this.serder = interact({
172
130
  pre: this.serder.pre,
173
- dig: this.serder.ked['d'],
131
+ dig: this.serder.sad['d'],
174
132
  sn: sn,
175
133
  data: [anchor],
176
- version: Versionage,
134
+ version: Vrsn_1_0,
177
135
  kind: Serials.JSON,
178
136
  });
179
137
  return [this.signer.sign(this.serder.raw, 0).qb64];
180
138
  }
181
-
182
- get pre(): string {
139
+ get pre() {
183
140
  return this.serder.pre;
184
141
  }
185
-
186
142
  get event() {
187
143
  const siger = this.signer.sign(this.serder.raw, 0);
188
144
  return [this.serder, siger];
189
145
  }
190
-
191
- get verfers(): [] {
146
+ get verfers() {
192
147
  return this.signer.verfer();
193
148
  }
194
-
195
- derive(state: any) {
149
+ derive(state) {
196
150
  if (state != undefined && state['ee']['s'] === '0') {
197
151
  return incept({
198
152
  keys: this.keys,
@@ -203,124 +157,70 @@ export class Controller {
203
157
  toad: '0',
204
158
  wits: [],
205
159
  });
206
- } else {
207
- return new Serder({ ked: state.controller['ee'] });
160
+ }
161
+ else {
162
+ return new Serder({ sad: state.controller['ee'] });
208
163
  }
209
164
  }
210
-
211
- rotate(bran: string, aids: Array<any>) {
165
+ rotate(bran, aids) {
212
166
  const nbran = MtrDex.Salt_128 + 'A' + bran.substring(0, 21); // qb64 salt for seed
213
167
  const nsalter = new Salter({ qb64: nbran, tier: this.tier });
214
168
  const nsigner = this.salter.signer(undefined, false);
215
-
216
- const creator = new SaltyCreator(
217
- this.salter.qb64,
218
- this.tier,
219
- this.stem
220
- );
169
+ const creator = new SaltyCreator(this.salter.qb64, this.tier, this.stem);
221
170
  const signer = creator
222
- .create(
223
- undefined,
224
- 1,
225
- MtrDex.Ed25519_Seed,
226
- true,
227
- 0,
228
- this.ridx + 1,
229
- 0,
230
- false
231
- )
171
+ .create(undefined, 1, MtrDex.Ed25519_Seed, true, 0, this.ridx + 1, 0, false)
232
172
  .signers.pop();
233
-
234
173
  const ncreator = new SaltyCreator(nsalter.qb64, this.tier, this.stem);
235
174
  this.signer = ncreator
236
- .create(
237
- undefined,
238
- 1,
239
- MtrDex.Ed25519_Seed,
240
- true,
241
- 0,
242
- this.ridx,
243
- 0,
244
- false
245
- )
175
+ .create(undefined, 1, MtrDex.Ed25519_Seed, true, 0, this.ridx, 0, false)
246
176
  .signers.pop();
247
177
  this.nsigner = ncreator
248
- .create(
249
- undefined,
250
- 1,
251
- MtrDex.Ed25519_Seed,
252
- true,
253
- 0,
254
- this.ridx + 1,
255
- 0,
256
- false
257
- )
178
+ .create(undefined, 1, MtrDex.Ed25519_Seed, true, 0, this.ridx + 1, 0, false)
258
179
  .signers.pop();
259
-
260
- this.keys = [this.signer.verfer.qb64, signer?.verfer.qb64];
180
+ this.keys = [this.signer.verfer.qb64, signer === null || signer === void 0 ? void 0 : signer.verfer.qb64];
261
181
  this.ndigs = [new Diger({}, this.nsigner.verfer.qb64b).qb64];
262
-
263
182
  const rot = rotate({
264
183
  pre: this.pre,
265
184
  keys: this.keys,
266
- dig: this.serder.ked['d'],
185
+ dig: this.serder.sad['d'],
267
186
  isith: ['1', '0'],
268
187
  nsith: '1',
269
188
  ndigs: this.ndigs,
270
189
  });
271
-
272
190
  const sigs = [
273
- signer?.sign(b(rot.raw), 1, false, 0).qb64,
191
+ signer === null || signer === void 0 ? void 0 : signer.sign(b(rot.raw), 1, false, 0).qb64,
274
192
  this.signer.sign(rot.raw, 0).qb64,
275
193
  ];
276
194
  const encrypter = new Encrypter({}, b(nsigner.verfer.qb64));
277
195
  const decrypter = new Decrypter({}, nsigner.qb64b);
278
196
  const sxlt = encrypter.encrypt(b(this.bran)).qb64;
279
-
280
- const keys: Record<any, any> = {};
281
-
197
+ const keys = {};
282
198
  for (const aid of aids) {
283
- const pre: string = aid['prefix'] as string;
199
+ const pre = aid['prefix'];
284
200
  if ('salty' in aid) {
285
- const salty: any = aid['salty'];
201
+ const salty = aid['salty'];
286
202
  const cipher = new Cipher({ qb64: salty['sxlt'] });
287
203
  const dnxt = decrypter.decrypt(null, cipher).qb64;
288
-
289
204
  // Now we have the AID salt, use it to verify against the current public keys
290
- const acreator = new SaltyCreator(
291
- dnxt,
292
- salty['tier'],
293
- salty['stem']
294
- );
295
- const signers = acreator.create(
296
- salty['icodes'],
297
- undefined,
298
- MtrDex.Ed25519_Seed,
299
- salty['transferable'],
300
- salty['pidx'],
301
- 0,
302
- salty['kidx'],
303
- false
304
- );
205
+ const acreator = new SaltyCreator(dnxt, salty['tier'], salty['stem']);
206
+ const signers = acreator.create(salty['icodes'], undefined, MtrDex.Ed25519_Seed, salty['transferable'], salty['pidx'], 0, salty['kidx'], false);
305
207
  const _signers = [];
306
208
  for (const signer of signers.signers) {
307
209
  _signers.push(signer.verfer.qb64);
308
210
  }
309
211
  const pubs = aid['state']['k'];
310
-
311
212
  if (pubs.join(',') != _signers.join(',')) {
312
213
  throw new Error('Invalid Salty AID');
313
214
  }
314
-
315
215
  const asxlt = encrypter.encrypt(b(dnxt)).qb64;
316
216
  keys[pre] = {
317
217
  sxlt: asxlt,
318
218
  };
319
- } else if ('randy' in aid) {
219
+ }
220
+ else if ('randy' in aid) {
320
221
  const randy = aid['randy'];
321
222
  const prxs = randy['prxs'];
322
223
  const nxts = randy['nxts'];
323
-
324
224
  const nprxs = [];
325
225
  const signers = [];
326
226
  for (const prx of prxs) {
@@ -334,37 +234,31 @@ export class Controller {
334
234
  for (const signer of signers) {
335
235
  _signers.push(signer.verfer.qb64);
336
236
  }
337
-
338
237
  if (pubs.join(',') != _signers.join(',')) {
339
- throw new Error(
340
- `unable to rotate, validation of encrypted public keys ${pubs} failed`
341
- );
238
+ throw new Error(`unable to rotate, validation of encrypted public keys ${pubs} failed`);
342
239
  }
343
-
344
240
  const nnxts = [];
345
241
  for (const nxt of nxts) {
346
242
  nnxts.push(this.recrypt(nxt, decrypter, encrypter));
347
243
  }
348
-
349
244
  keys[pre] = {
350
245
  prxs: nprxs,
351
246
  nxts: nnxts,
352
247
  };
353
- } else {
248
+ }
249
+ else {
354
250
  throw new Error('invalid aid type ');
355
251
  }
356
252
  }
357
-
358
253
  const data = {
359
- rot: rot.ked,
254
+ rot: rot.sad,
360
255
  sigs: sigs,
361
256
  sxlt: sxlt,
362
257
  keys: keys,
363
258
  };
364
259
  return data;
365
260
  }
366
-
367
- recrypt(enc: string, decrypter: Decrypter, encrypter: Encrypter) {
261
+ recrypt(enc, decrypter, encrypter) {
368
262
  const cipher = new Cipher({ qb64: enc });
369
263
  const dnxt = decrypter.decrypt(null, cipher).qb64;
370
264
  return encrypter.encrypt(b(dnxt)).qb64;
@@ -1,4 +1,10 @@
1
- import { SignifyClient } from './clienting';
1
+ import { SignifyClient } from './clienting.ts';
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 } 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'];
2
8
  export declare function randomPasscode(): string;
3
9
  export declare function randomNonce(): string;
4
10
  export declare class Oobis {
@@ -12,27 +18,21 @@ export declare class Oobis {
12
18
  * Get the OOBI(s) for a managed indentifier for a given role
13
19
  * @param {string} name Name or alias of the identifier
14
20
  * @param {string} role Authorized role
15
- * @returns {Promise<any>} A promise to the OOBI(s)
21
+ * @returns {Promise<OOBI>} A promise to the OOBI(s)
16
22
  */
17
- get(name: string, role?: string): Promise<any>;
23
+ get(name: string, role?: string): Promise<OOBI>;
18
24
  /**
19
25
  * Resolve an OOBI
20
26
  * @async
21
27
  * @param {string} oobi The OOBI to be resolver
22
28
  * @param {string} [alias] Optional name or alias to link the OOBI resolution to a contact
23
- * @returns {Promise<any>} A promise to the long-running operation
29
+ * @returns {Promise<OOBIOperation>} A promise to the long-running operation
24
30
  */
25
- resolve(oobi: string, alias?: string): Promise<any>;
31
+ resolve(oobi: string, alias?: string): Promise<OOBIOperation>;
26
32
  }
27
- export interface Operation<T = unknown> {
28
- name: string;
29
- metadata?: {
30
- depends?: Operation;
31
- [property: string]: any;
32
- };
33
- done?: boolean;
34
- error?: any;
35
- response?: T;
33
+ export type Operation = OOBIOperation | QueryOperation | EndRoleOperation | WitnessOperation | DelegationOperation | RegistryOperation | LocSchemeOperation | ChallengeOperation | ExchangeOperation | SubmitOperation | DoneOperation | CredentialOperation | GroupOperation | DelegatorOperation;
34
+ export interface OperationsDeps {
35
+ fetch(pathname: string, method: string, body: unknown, headers?: Headers): Promise<Response>;
36
36
  }
37
37
  /**
38
38
  * Operations
@@ -40,32 +40,131 @@ export interface Operation<T = unknown> {
40
40
  * Operations represent the status and result of long running tasks performed by KERIA agent
41
41
  */
42
42
  export declare class Operations {
43
- client: SignifyClient;
43
+ client: OperationsDeps;
44
44
  /**
45
45
  * Operations
46
46
  * @param {SignifyClient} client
47
47
  */
48
- constructor(client: SignifyClient);
48
+ constructor(client: OperationsDeps);
49
+ private hasDepends;
50
+ /**
51
+ * Check if operation failed and throw error with details
52
+ * @throws {Error} If operation has an error
53
+ */
54
+ private throwIfFailed;
49
55
  /**
50
56
  * Get operation status
51
57
  * @async
52
58
  * @param {string} name Name of the operation
53
59
  * @returns {Promise<Operation>} A promise to the status of the operation
54
60
  */
55
- get<T = unknown>(name: string): Promise<Operation<T>>;
61
+ get(name: string): Promise<Operation>;
56
62
  /**
57
63
  * List operations
58
64
  * @async
59
65
  * @param {string} type Select operations by type
60
66
  * @returns {Promise<Operation[]>} A list of operations
61
67
  */
62
- list(type?: string): Promise<Operation<any>[]>;
68
+ list(type?: string): Promise<Operation[]>;
63
69
  /**
64
70
  * Delete operation
65
71
  * @async
66
72
  * @param {string} name Name of the operation
67
73
  */
68
74
  delete(name: string): Promise<void>;
75
+ /**
76
+ * Poll for operation to become completed.
77
+ */
78
+ wait(op: OOBIOperation, options?: {
79
+ signal?: AbortSignal;
80
+ minSleep?: number;
81
+ maxSleep?: number;
82
+ increaseFactor?: number;
83
+ }): Promise<CompletedOOBIOperation>;
84
+ wait(op: QueryOperation, options?: {
85
+ signal?: AbortSignal;
86
+ minSleep?: number;
87
+ maxSleep?: number;
88
+ increaseFactor?: number;
89
+ }): Promise<CompletedQueryOperation>;
90
+ wait(op: EndRoleOperation, options?: {
91
+ signal?: AbortSignal;
92
+ minSleep?: number;
93
+ maxSleep?: number;
94
+ increaseFactor?: number;
95
+ }): Promise<CompletedEndRoleOperation>;
96
+ wait(op: WitnessOperation, options?: {
97
+ signal?: AbortSignal;
98
+ minSleep?: number;
99
+ maxSleep?: number;
100
+ increaseFactor?: number;
101
+ }): Promise<CompletedWitnessOperation>;
102
+ wait(op: DelegationOperation, options?: {
103
+ signal?: AbortSignal;
104
+ minSleep?: number;
105
+ maxSleep?: number;
106
+ increaseFactor?: number;
107
+ }): Promise<CompletedDelegationOperation>;
108
+ wait(op: RegistryOperation, options?: {
109
+ signal?: AbortSignal;
110
+ minSleep?: number;
111
+ maxSleep?: number;
112
+ increaseFactor?: number;
113
+ }): Promise<CompletedRegistryOperation>;
114
+ wait(op: LocSchemeOperation, options?: {
115
+ signal?: AbortSignal;
116
+ minSleep?: number;
117
+ maxSleep?: number;
118
+ increaseFactor?: number;
119
+ }): Promise<CompletedLocSchemeOperation>;
120
+ wait(op: ChallengeOperation, options?: {
121
+ signal?: AbortSignal;
122
+ minSleep?: number;
123
+ maxSleep?: number;
124
+ increaseFactor?: number;
125
+ }): Promise<CompletedChallengeOperation>;
126
+ wait(op: ExchangeOperation, options?: {
127
+ signal?: AbortSignal;
128
+ minSleep?: number;
129
+ maxSleep?: number;
130
+ increaseFactor?: number;
131
+ }): Promise<CompletedExchangeOperation>;
132
+ wait(op: SubmitOperation, options?: {
133
+ signal?: AbortSignal;
134
+ minSleep?: number;
135
+ maxSleep?: number;
136
+ increaseFactor?: number;
137
+ }): Promise<CompletedSubmitOperation>;
138
+ wait(op: DoneOperation, options?: {
139
+ signal?: AbortSignal;
140
+ minSleep?: number;
141
+ maxSleep?: number;
142
+ increaseFactor?: number;
143
+ }): Promise<CompletedDoneOperation>;
144
+ wait(op: CredentialOperation, options?: {
145
+ signal?: AbortSignal;
146
+ minSleep?: number;
147
+ maxSleep?: number;
148
+ increaseFactor?: number;
149
+ }): Promise<CompletedCredentialOperation>;
150
+ wait(op: GroupOperation, options?: {
151
+ signal?: AbortSignal;
152
+ minSleep?: number;
153
+ maxSleep?: number;
154
+ increaseFactor?: number;
155
+ }): Promise<CompletedGroupOperation>;
156
+ wait(op: DelegatorOperation, options?: {
157
+ signal?: AbortSignal;
158
+ minSleep?: number;
159
+ maxSleep?: number;
160
+ increaseFactor?: number;
161
+ }): Promise<CompletedDelegatorOperation>;
162
+ wait(op: Operation, options?: {
163
+ signal?: AbortSignal;
164
+ minSleep?: number;
165
+ maxSleep?: number;
166
+ increaseFactor?: number;
167
+ }): Promise<CompletedOperation>;
69
168
  }
70
169
  /**
71
170
  * KeyEvents
@@ -81,9 +180,9 @@ export declare class KeyEvents {
81
180
  * Retrieve key events for an identifier
82
181
  * @async
83
182
  * @param {string} pre Identifier prefix
84
- * @returns {Promise<any>} A promise to the key events
183
+ * @returns {Promise<KeyEventRecord[]>} A promise to the key events
85
184
  */
86
- get(pre: string): Promise<any>;
185
+ get(pre: string): Promise<KeyEventRecord[]>;
87
186
  }
88
187
  /**
89
188
  * KeyStates
@@ -99,23 +198,33 @@ export declare class KeyStates {
99
198
  * Retriene the key state for an identifier
100
199
  * @async
101
200
  * @param {string} pre Identifier prefix
102
- * @returns {Promise<any>} A promise to the key states
201
+ * @returns {Promise<KeyState[]>} A promise to the key states
103
202
  */
104
- get(pre: string): Promise<any>;
203
+ get(pre: string): Promise<KeyState[]>;
105
204
  /**
106
205
  * Retrieve the key state for a list of identifiers
107
206
  * @async
108
207
  * @param {Array<string>} pres List of identifier prefixes
109
208
  * @returns {Promise<any>} A promise to the key states
110
209
  */
111
- list(pres: string[]): Promise<any>;
210
+ list(pres: string[]): Promise<KeyState[]>;
112
211
  /**
113
212
  * Query the key state of an identifier for a given sequence number or anchor
114
213
  * @async
115
214
  * @param {string} pre Identifier prefix
116
215
  * @param {number} [sn] Optional sequence number
117
216
  * @param {any} [anchor] Optional anchor
118
- * @returns {Promise<any>} A promise to the long-running operation
217
+ * @returns {Promise<QueryOperation>} A promise to the long-running operation
119
218
  */
120
- query(pre: string, sn?: string, anchor?: any): Promise<any>;
219
+ query(pre: string, sn?: string, anchor?: any): Promise<QueryOperation>;
220
+ }
221
+ export declare class Config {
222
+ client: SignifyClient;
223
+ /**
224
+ * Config
225
+ * @param {SignifyClient} client
226
+ */
227
+ constructor(client: SignifyClient);
228
+ get(): Promise<AgentConfig>;
121
229
  }
230
+ export {};