signify-ts 0.2.1 → 0.3.0-rc2

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 (128) 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 +34 -14
  7. package/{src/keri/app/aiding.ts → dist/keri/app/aiding.js} +104 -235
  8. package/dist/keri/app/clienting.d.ts +57 -22
  9. package/{src/keri/app/clienting.ts → dist/keri/app/clienting.js} +145 -234
  10. package/dist/keri/app/contacting.d.ts +33 -21
  11. package/{src/keri/app/contacting.ts → dist/keri/app/contacting.js} +25 -62
  12. package/dist/keri/app/controller.d.ts +49 -6
  13. package/{src/keri/app/controller.ts → dist/keri/app/controller.js} +79 -185
  14. package/dist/keri/app/coring.d.ts +30 -8
  15. package/{src/keri/app/coring.ts → dist/keri/app/coring.js} +62 -51
  16. package/dist/keri/app/credentialing.d.ts +183 -65
  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 +1 -1
  21. package/{src/keri/app/escrowing.ts → dist/keri/app/escrowing.js} +2 -8
  22. package/dist/keri/app/exchanging.d.ts +7 -6
  23. package/{src/keri/app/exchanging.ts → dist/keri/app/exchanging.js} +33 -110
  24. package/dist/keri/app/grouping.d.ts +2 -2
  25. package/{src/keri/app/grouping.ts → dist/keri/app/grouping.js} +6 -25
  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 +4 -4
  51. package/{src/keri/core/eventing.ts → dist/keri/core/eventing.js} +134 -321
  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 +98 -46
  57. package/dist/keri/core/keeping.js +365 -0
  58. package/{src/keri/core/kering.ts → dist/keri/core/kering.js} +1 -3
  59. package/dist/keri/core/keyState.d.ts +85 -0
  60. package/dist/keri/core/keyState.js +1 -0
  61. package/dist/keri/core/manager.d.ts +147 -12
  62. package/dist/keri/core/manager.js +880 -0
  63. package/dist/keri/core/matter.d.ts +1 -1
  64. package/dist/keri/core/matter.js +460 -0
  65. package/dist/keri/core/number.d.ts +1 -1
  66. package/{src/keri/core/number.ts → dist/keri/core/number.js} +21 -30
  67. package/dist/keri/core/pather.d.ts +2 -2
  68. package/{src/keri/core/pather.ts → dist/keri/core/pather.js} +12 -27
  69. package/dist/keri/core/prefixer.d.ts +10 -10
  70. package/dist/keri/core/prefixer.js +182 -0
  71. package/dist/keri/core/saider.d.ts +2 -12
  72. package/dist/keri/core/saider.js +107 -0
  73. package/dist/keri/core/salter.d.ts +45 -3
  74. package/dist/keri/core/salter.js +117 -0
  75. package/dist/keri/core/seqner.d.ts +1 -1
  76. package/{src/keri/core/seqner.ts → dist/keri/core/seqner.js} +20 -21
  77. package/dist/keri/core/serder.d.ts +25 -12
  78. package/dist/keri/core/serder.js +133 -0
  79. package/dist/keri/core/siger.d.ts +2 -2
  80. package/{src/keri/core/siger.ts → dist/keri/core/siger.js} +4 -14
  81. package/dist/keri/core/signer.d.ts +4 -4
  82. package/dist/keri/core/signer.js +84 -0
  83. package/{src/keri/core/tholder.ts → dist/keri/core/tholder.js} +69 -94
  84. package/dist/keri/core/utils.d.ts +1 -1
  85. package/{src/keri/core/utils.ts → dist/keri/core/utils.js} +30 -60
  86. package/dist/keri/core/vdring.d.ts +2 -2
  87. package/dist/keri/core/vdring.js +61 -0
  88. package/dist/keri/core/verfer.d.ts +2 -6
  89. package/dist/keri/core/verfer.js +37 -0
  90. package/dist/keri/end/ending.d.ts +10 -8
  91. package/dist/keri/end/ending.js +136 -0
  92. package/{src/ready.ts → dist/ready.js} +1 -2
  93. package/dist/types/keria-api-schema.d.ts +304 -0
  94. package/dist/types/keria-api-schema.js +2 -0
  95. package/package.json +53 -50
  96. package/dist/buffer-polyfill.d.ts +0 -1
  97. package/dist/math.d.ts +0 -1
  98. package/dist/signify-ts.cjs +0 -7842
  99. package/dist/signify-ts.cjs.development.js +0 -9501
  100. package/dist/signify-ts.cjs.development.js.map +0 -1
  101. package/dist/signify-ts.cjs.map +0 -7
  102. package/dist/signify-ts.cjs.production.min.js +0 -2
  103. package/dist/signify-ts.cjs.production.min.js.map +0 -1
  104. package/dist/signify-ts.esm.js +0 -9345
  105. package/dist/signify-ts.esm.js.map +0 -1
  106. package/dist/signify-ts.mjs +0 -7818
  107. package/dist/signify-ts.mjs.map +0 -7
  108. package/src/buffer-polyfill.ts +0 -5
  109. package/src/exports.ts +0 -44
  110. package/src/index.ts +0 -4
  111. package/src/keri/app/credentialing.ts +0 -841
  112. package/src/keri/app/habery.ts +0 -185
  113. package/src/keri/core/cigar.ts +0 -18
  114. package/src/keri/core/core.ts +0 -326
  115. package/src/keri/core/counter.ts +0 -273
  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
@@ -1,841 +0,0 @@
1
- import { SignifyClient } from './clienting';
2
- import { Salter } from '../core/salter';
3
- import { interact, messagize } from '../core/eventing';
4
- import { vdr } from '../core/vdring';
5
- import {
6
- b,
7
- d,
8
- Dict,
9
- Ident,
10
- Ilks,
11
- Serials,
12
- versify,
13
- Versionage,
14
- } from '../core/core';
15
- import { Saider } from '../core/saider';
16
- import { Serder } from '../core/serder';
17
- import { Siger } from '../core/siger';
18
- import { TraitDex } from './habery';
19
- import {
20
- serializeACDCAttachment,
21
- serializeIssExnAttachment,
22
- } from '../core/utils';
23
- import { Operation } from './coring';
24
-
25
- /** Types of credentials */
26
- export class CredentialTypes {
27
- static issued = 'issued';
28
- static received = 'received';
29
- }
30
-
31
- /** Credential filter parameters */
32
- export interface CredentialFilter {
33
- filter?: object;
34
- sort?: object[];
35
- skip?: number;
36
- limit?: number;
37
- }
38
-
39
- export interface IssueCredentialArgs {
40
- /**
41
- * Name of the issuer identifier
42
- */
43
- issuerName: string;
44
-
45
- /**
46
- * QB64 AID of credential registry
47
- */
48
- registryId: string;
49
-
50
- /**
51
- * SAID Of the schema
52
- */
53
- schemaId: string;
54
-
55
- /**
56
- * Prefix of recipient identifier
57
- */
58
- recipient?: string;
59
-
60
- /**
61
- * Credential data
62
- */
63
- data?: Record<string, unknown>;
64
-
65
- /**
66
- * Credential rules
67
- */
68
- rules?: string | Record<string, unknown>;
69
-
70
- /**
71
- * Credential sources
72
- */
73
- source?: Record<string, unknown>;
74
-
75
- /**
76
- * Datetime to set for the credential
77
- */
78
- datetime?: string;
79
-
80
- /**
81
- * Flag to issue a credential with privacy preserving features
82
- */
83
- privacy?: boolean;
84
- }
85
-
86
- export interface IssueCredentialResult {
87
- acdc: Serder;
88
- anc: Serder;
89
- iss: Serder;
90
- op: Operation;
91
- }
92
-
93
- export interface RevokeCredentialResult {
94
- anc: Serder;
95
- rev: Serder;
96
- op: Operation;
97
- }
98
-
99
- export interface IpexGrantArgs {
100
- /**
101
- * Alias for the IPEX sender AID
102
- */
103
- senderName: string;
104
-
105
- /**
106
- * Prefix of the IPEX recipient AID
107
- */
108
- recipient: string;
109
-
110
- /**
111
- * Message to send
112
- */
113
- message?: string;
114
-
115
- /**
116
- * qb64 SAID of agree message this grant is responding to
117
- */
118
- agree?: string;
119
- datetime?: string;
120
- acdc: Serder;
121
- acdcAttachment?: string;
122
- iss: Serder;
123
- issAttachment?: string;
124
- anc: Serder;
125
- ancAttachment?: string;
126
- }
127
-
128
- /**
129
- * Credentials
130
- */
131
- export class Credentials {
132
- public client: SignifyClient;
133
- /**
134
- * Credentials
135
- * @param {SignifyClient} client
136
- */
137
- constructor(client: SignifyClient) {
138
- this.client = client;
139
- }
140
-
141
- /**
142
- * List credentials
143
- * @async
144
- * @param {CredentialFilter} [kargs] Optional parameters to filter the credentials
145
- * @returns {Promise<any>} A promise to the list of credentials
146
- */
147
- async list(kargs: CredentialFilter = {}): Promise<any> {
148
- const path = `/credentials/query`;
149
- const filtr = kargs.filter === undefined ? {} : kargs.filter;
150
- const sort = kargs.sort === undefined ? [] : kargs.sort;
151
- const limit = kargs.limit === undefined ? 25 : kargs.limit;
152
- const skip = kargs.skip === undefined ? 0 : kargs.skip;
153
-
154
- const data = {
155
- filter: filtr,
156
- sort: sort,
157
- skip: skip,
158
- limit: limit,
159
- };
160
- const method = 'POST';
161
-
162
- const res = await this.client.fetch(path, method, data, undefined);
163
- return await res.json();
164
- }
165
-
166
- /**
167
- * Get a credential
168
- * @async
169
- * @param {string} said - SAID of the credential
170
- * @param {boolean} [includeCESR=false] - Optional flag export the credential in CESR format
171
- * @returns {Promise<any>} A promise to the credential
172
- */
173
- async get(said: string, includeCESR: boolean = false): Promise<any> {
174
- const path = `/credentials/${said}`;
175
- const method = 'GET';
176
- const headers = includeCESR
177
- ? new Headers({ Accept: 'application/json+cesr' })
178
- : new Headers({ Accept: 'application/json' });
179
- const res = await this.client.fetch(path, method, null, headers);
180
-
181
- return includeCESR ? await res.text() : await res.json();
182
- }
183
-
184
- /**
185
- * Issue a credential
186
- */
187
- async issue(args: IssueCredentialArgs): Promise<IssueCredentialResult> {
188
- const hab = await this.client.identifiers().get(args.issuerName);
189
- const estOnly = hab.state.c !== undefined && hab.state.c.includes('EO');
190
- if (estOnly) {
191
- // TODO implement rotation event
192
- throw new Error('Establishment only not implemented');
193
- }
194
- if (!this.client.manager) {
195
- throw new Error('No manager on client');
196
- }
197
-
198
- const keeper = this.client.manager.get(hab);
199
-
200
- const dt =
201
- args.datetime ?? new Date().toISOString().replace('Z', '000+00:00');
202
-
203
- const [, subject] = Saider.saidify({
204
- d: '',
205
- u: args.privacy ? new Salter({}).qb64 : undefined,
206
- i: args.recipient,
207
- dt: dt,
208
- ...args.data,
209
- });
210
-
211
- const [, acdc] = Saider.saidify({
212
- v: versify(Ident.ACDC, undefined, Serials.JSON, 0),
213
- d: '',
214
- u: args.privacy ? new Salter({}).qb64 : undefined,
215
- i: hab.prefix,
216
- ri: args.registryId,
217
- s: args.schemaId,
218
- a: subject,
219
- e: args.source,
220
- r: args.rules,
221
- });
222
-
223
- const [, iss] = Saider.saidify({
224
- v: versify(Ident.KERI, undefined, Serials.JSON, 0),
225
- t: Ilks.iss,
226
- d: '',
227
- i: acdc.d,
228
- s: '0',
229
- ri: args.registryId,
230
- dt: dt,
231
- });
232
-
233
- const sn = Number(hab.state.s);
234
- const anc = interact({
235
- pre: hab.prefix,
236
- sn: sn + 1,
237
- data: [
238
- {
239
- i: iss.i,
240
- s: iss.s,
241
- d: iss.d,
242
- },
243
- ],
244
- dig: hab.state.d,
245
- version: undefined,
246
- kind: undefined,
247
- });
248
-
249
- const sigs = await keeper.sign(b(anc.raw));
250
-
251
- const path = `/identifiers/${hab.name}/credentials`;
252
- const method = 'POST';
253
- const body = {
254
- acdc: acdc,
255
- iss: iss,
256
- ixn: anc.ked,
257
- sigs,
258
- [keeper.algo]: keeper.params(),
259
- };
260
-
261
- const headers = new Headers({
262
- Accept: 'application/json+cesr',
263
- });
264
-
265
- const res = await this.client.fetch(path, method, body, headers);
266
- const op = await res.json();
267
-
268
- return {
269
- acdc: new Serder(acdc),
270
- iss: new Serder(iss),
271
- anc,
272
- op,
273
- };
274
- }
275
-
276
- /**
277
- * Revoke credential
278
- * @async
279
- * @param {string} name Name or alias of the identifier
280
- * @param {string} said SAID of the credential
281
- * @param {string} datetime date time of revocation
282
- * @returns {Promise<any>} A promise to the long-running operation
283
- */
284
- async revoke(
285
- name: string,
286
- said: string,
287
- datetime?: string
288
- ): Promise<RevokeCredentialResult> {
289
- const hab = await this.client.identifiers().get(name);
290
- const pre: string = hab.prefix;
291
-
292
- const vs = versify(Ident.KERI, undefined, Serials.JSON, 0);
293
- const dt =
294
- datetime ?? new Date().toISOString().replace('Z', '000+00:00');
295
-
296
- const cred = await this.get(said);
297
-
298
- // Create rev
299
- const _rev = {
300
- v: vs,
301
- t: Ilks.rev,
302
- d: '',
303
- i: said,
304
- s: '1',
305
- ri: cred.sad.ri,
306
- p: cred.status.d,
307
- dt: dt,
308
- };
309
-
310
- const [, rev] = Saider.saidify(_rev);
311
-
312
- // create ixn
313
- let ixn = {};
314
- let sigs = [];
315
-
316
- const state = hab.state;
317
- if (state.c !== undefined && state.c.includes('EO')) {
318
- var estOnly = true;
319
- } else {
320
- var estOnly = false;
321
- }
322
-
323
- const sn = Number(state.s);
324
- const dig = state.d;
325
-
326
- const data: any = [
327
- {
328
- i: rev.i,
329
- s: rev.s,
330
- d: rev.d,
331
- },
332
- ];
333
-
334
- const keeper = this.client!.manager!.get(hab);
335
-
336
- if (estOnly) {
337
- // TODO implement rotation event
338
- throw new Error('Establishment only not implemented');
339
- } else {
340
- const serder = interact({
341
- pre: pre,
342
- sn: sn + 1,
343
- data: data,
344
- dig: dig,
345
- version: undefined,
346
- kind: undefined,
347
- });
348
- sigs = await keeper.sign(b(serder.raw));
349
- ixn = serder.ked;
350
- }
351
-
352
- const body = {
353
- rev: rev,
354
- ixn: ixn,
355
- sigs: sigs,
356
- [keeper.algo]: keeper.params(),
357
- };
358
-
359
- const path = `/identifiers/${name}/credentials/${said}`;
360
- const method = 'DELETE';
361
- const headers = new Headers({
362
- Accept: 'application/json+cesr',
363
- });
364
- const res = await this.client.fetch(path, method, body, headers);
365
- const op = await res.json();
366
-
367
- return {
368
- rev: new Serder(rev),
369
- anc: new Serder(ixn),
370
- op,
371
- };
372
- }
373
-
374
- /**
375
- * Present a credential
376
- * @async
377
- * @param {string} name Name or alias of the identifier
378
- * @param {string} said SAID of the credential
379
- * @param {string} recipient Identifier prefix of the receiver of the presentation
380
- * @param {boolean} [include=true] Flag to indicate whether to stream credential alongside presentation exchange message
381
- * @returns {Promise<string>} A promise to the long-running operation
382
- */
383
- async present(
384
- name: string,
385
- said: string,
386
- recipient: string,
387
- include: boolean = true
388
- ): Promise<string> {
389
- const hab = await this.client.identifiers().get(name);
390
- const pre: string = hab.prefix;
391
-
392
- const cred = await this.get(said);
393
- const data = {
394
- i: cred.sad.i,
395
- s: cred.sad.s,
396
- n: said,
397
- };
398
-
399
- const vs = versify(Ident.KERI, undefined, Serials.JSON, 0);
400
-
401
- const _sad = {
402
- v: vs,
403
- t: Ilks.exn,
404
- d: '',
405
- dt: new Date().toISOString().replace('Z', '000+00:00'),
406
- r: '/presentation',
407
- q: {},
408
- a: data,
409
- };
410
- const [, sad] = Saider.saidify(_sad);
411
- const exn = new Serder(sad);
412
-
413
- const keeper = this.client!.manager!.get(hab);
414
-
415
- const sig = keeper.sign(b(exn.raw), true);
416
-
417
- const siger = new Siger({ qb64: sig[0] });
418
- const seal = ['SealLast', { i: pre }];
419
- let ims = messagize(exn, [siger], seal, undefined, undefined, true);
420
- ims = ims.slice(JSON.stringify(exn.ked).length);
421
-
422
- const body = {
423
- exn: exn.ked,
424
- sig: new TextDecoder().decode(ims),
425
- recipient: recipient,
426
- include: include,
427
- };
428
-
429
- const path = `/identifiers/${name}/credentials/${said}/presentations`;
430
- const method = 'POST';
431
- const headers = new Headers({
432
- Accept: 'application/json+cesr',
433
- });
434
- const res = await this.client.fetch(path, method, body, headers);
435
- return await res.text();
436
- }
437
-
438
- /**
439
- * Request a presentation of a credential
440
- * @async
441
- * @param {string} name Name or alias of the identifier
442
- * @param {string} recipient Identifier prefix of the receiver of the presentation
443
- * @param {string} schema SAID of the schema
444
- * @param {string} [issuer] Optional prefix of the issuer of the credential
445
- * @returns {Promise<string>} A promise to the long-running operation
446
- */
447
- async request(
448
- name: string,
449
- recipient: string,
450
- schema: string,
451
- issuer?: string
452
- ): Promise<string> {
453
- const hab = await this.client.identifiers().get(name);
454
- const pre: string = hab.prefix;
455
-
456
- const data: any = {
457
- s: schema,
458
- };
459
- if (issuer !== undefined) {
460
- data['i'] = issuer;
461
- }
462
-
463
- const vs = versify(Ident.KERI, undefined, Serials.JSON, 0);
464
-
465
- const _sad = {
466
- v: vs,
467
- t: Ilks.exn,
468
- d: '',
469
- dt: new Date().toISOString().replace('Z', '000+00:00'),
470
- r: '/presentation/request',
471
- q: {},
472
- a: data,
473
- };
474
- const [, sad] = Saider.saidify(_sad);
475
- const exn = new Serder(sad);
476
-
477
- const keeper = this.client!.manager!.get(hab);
478
-
479
- const sig = await keeper.sign(b(exn.raw), true);
480
-
481
- const siger = new Siger({ qb64: sig[0] });
482
- const seal = ['SealLast', { i: pre }];
483
- let ims = messagize(exn, [siger], seal, undefined, undefined, true);
484
- ims = ims.slice(JSON.stringify(exn.ked).length);
485
-
486
- const body = {
487
- exn: exn.ked,
488
- sig: new TextDecoder().decode(ims),
489
- recipient: recipient,
490
- };
491
-
492
- const path = `/identifiers/${name}/requests`;
493
- const method = 'POST';
494
- const headers = new Headers({
495
- Accept: 'application/json+cesr',
496
- });
497
- const res = await this.client.fetch(path, method, body, headers);
498
- return await res.text();
499
- }
500
- }
501
-
502
- export interface CreateRegistryArgs {
503
- name: string;
504
- registryName: string;
505
- toad?: string | number | undefined;
506
- noBackers?: boolean;
507
- baks?: string[];
508
- nonce?: string;
509
- }
510
-
511
- export class RegistryResult {
512
- private readonly _regser: any;
513
- private readonly _serder: Serder;
514
- private readonly _sigs: string[];
515
- private readonly promise: Promise<Response>;
516
-
517
- constructor(
518
- regser: Serder,
519
- serder: Serder,
520
- sigs: any[],
521
- promise: Promise<Response>
522
- ) {
523
- this._regser = regser;
524
- this._serder = serder;
525
- this._sigs = sigs;
526
- this.promise = promise;
527
- }
528
-
529
- get regser() {
530
- return this._regser;
531
- }
532
-
533
- get serder() {
534
- return this._serder;
535
- }
536
-
537
- get sigs() {
538
- return this._sigs;
539
- }
540
-
541
- async op(): Promise<any> {
542
- const res = await this.promise;
543
- return await res.json();
544
- }
545
- }
546
-
547
- /**
548
- * Registries
549
- */
550
- export class Registries {
551
- public client: SignifyClient;
552
- /**
553
- * Registries
554
- * @param {SignifyClient} client
555
- */
556
- constructor(client: SignifyClient) {
557
- this.client = client;
558
- }
559
-
560
- /**
561
- * List registries
562
- * @async
563
- * @param {string} name Name or alias of the identifier
564
- * @returns {Promise<any>} A promise to the list of registries
565
- */
566
- async list(name: string): Promise<any> {
567
- const path = `/identifiers/${name}/registries`;
568
- const method = 'GET';
569
- const res = await this.client.fetch(path, method, null);
570
- return await res.json();
571
- }
572
-
573
- /**
574
- * Create a registry
575
- * @async
576
- * @param {CreateRegistryArgs}
577
- * @returns {Promise<[any, Serder, any[], object]> } A promise to the long-running operation
578
- */
579
- async create({
580
- name,
581
- registryName,
582
- noBackers = true,
583
- toad = 0,
584
- baks = [],
585
- nonce,
586
- }: CreateRegistryArgs): Promise<RegistryResult> {
587
- const hab = await this.client.identifiers().get(name);
588
- const pre: string = hab.prefix;
589
-
590
- const cnfg: string[] = [];
591
- if (noBackers) {
592
- cnfg.push(TraitDex.NoBackers);
593
- }
594
-
595
- const state = hab.state;
596
- const estOnly = state.c !== undefined && state.c.includes('EO');
597
- if (estOnly) {
598
- cnfg.push(TraitDex.EstOnly);
599
- }
600
-
601
- const regser = vdr.incept({ pre, baks, toad, nonce, cnfg });
602
-
603
- if (estOnly) {
604
- throw new Error('establishment only not implemented');
605
- } else {
606
- const state = hab.state;
607
- const sn = Number(state.s);
608
- const dig = state.d;
609
-
610
- const data: any = [
611
- {
612
- i: regser.pre,
613
- s: '0',
614
- d: regser.pre,
615
- },
616
- ];
617
-
618
- const serder = interact({
619
- pre: pre,
620
- sn: sn + 1,
621
- data: data,
622
- dig: dig,
623
- version: Versionage,
624
- kind: Serials.JSON,
625
- });
626
- const keeper = this.client.manager!.get(hab);
627
- const sigs = await keeper.sign(b(serder.raw));
628
- const res = this.createFromEvents(
629
- hab,
630
- name,
631
- registryName,
632
- regser.ked,
633
- serder.ked,
634
- sigs
635
- );
636
- return new RegistryResult(regser, serder, sigs, res);
637
- }
638
- }
639
-
640
- createFromEvents(
641
- hab: Dict<any>,
642
- name: string,
643
- registryName: string,
644
- vcp: Dict<any>,
645
- ixn: Dict<any>,
646
- sigs: any[]
647
- ) {
648
- const path = `/identifiers/${name}/registries`;
649
- const method = 'POST';
650
-
651
- const data: any = {
652
- name: registryName,
653
- vcp: vcp,
654
- ixn: ixn,
655
- sigs: sigs,
656
- };
657
- const keeper = this.client!.manager!.get(hab);
658
- data[keeper.algo] = keeper.params();
659
-
660
- return this.client.fetch(path, method, data);
661
- }
662
- }
663
- /**
664
- * Schemas
665
- */
666
- export class Schemas {
667
- client: SignifyClient;
668
- /**
669
- * Schemas
670
- * @param {SignifyClient} client
671
- */
672
- constructor(client: SignifyClient) {
673
- this.client = client;
674
- }
675
-
676
- /**
677
- * Get a schema
678
- * @async
679
- * @param {string} said SAID of the schema
680
- * @returns {Promise<any>} A promise to the schema
681
- */
682
- async get(said: string): Promise<any> {
683
- const path = `/schema/${said}`;
684
- const method = 'GET';
685
- const res = await this.client.fetch(path, method, null);
686
- return await res.json();
687
- }
688
-
689
- /**
690
- * List schemas
691
- * @async
692
- * @returns {Promise<any>} A promise to the list of schemas
693
- */
694
- async list(): Promise<any> {
695
- const path = `/schema`;
696
- const method = 'GET';
697
- const res = await this.client.fetch(path, method, null);
698
- return await res.json();
699
- }
700
- }
701
-
702
- /**
703
- * Ipex
704
- */
705
-
706
- export class Ipex {
707
- client: SignifyClient;
708
- /**
709
- * Schemas
710
- * @param {SignifyClient} client
711
- */
712
- constructor(client: SignifyClient) {
713
- this.client = client;
714
- }
715
-
716
- /**
717
- * Create an IPEX grant EXN message
718
- */
719
- async grant(args: IpexGrantArgs): Promise<[Serder, string[], string]> {
720
- const hab = await this.client.identifiers().get(args.senderName);
721
- const data = {
722
- m: args.message ?? '',
723
- i: args.recipient,
724
- };
725
-
726
- let atc = args.ancAttachment;
727
- if (atc === undefined) {
728
- const keeper = this.client.manager?.get(hab);
729
- const sigs = await keeper.sign(b(args.anc.raw));
730
- const sigers = sigs.map((sig: string) => new Siger({ qb64: sig }));
731
- const ims = d(messagize(args.anc, sigers));
732
- atc = ims.substring(args.anc.size);
733
- }
734
-
735
- const acdcAtc =
736
- args.acdcAttachment === undefined
737
- ? d(serializeACDCAttachment(args.iss))
738
- : args.acdcAttachment;
739
- const issAtc =
740
- args.issAttachment === undefined
741
- ? d(serializeIssExnAttachment(args.anc))
742
- : args.issAttachment;
743
-
744
- const embeds: Record<string, [Serder, string]> = {
745
- acdc: [args.acdc, acdcAtc],
746
- iss: [args.iss, issAtc],
747
- anc: [args.anc, atc],
748
- };
749
-
750
- return this.client
751
- .exchanges()
752
- .createExchangeMessage(
753
- hab,
754
- '/ipex/grant',
755
- data,
756
- embeds,
757
- undefined,
758
- args.datetime,
759
- args.agree
760
- );
761
- }
762
-
763
- async submitGrant(
764
- name: string,
765
- exn: Serder,
766
- sigs: string[],
767
- atc: string,
768
- recp: string[]
769
- ): Promise<any> {
770
- const body = {
771
- exn: exn.ked,
772
- sigs: sigs,
773
- atc: atc,
774
- rec: recp,
775
- };
776
-
777
- const response = await this.client.fetch(
778
- `/identifiers/${name}/ipex/grant`,
779
- 'POST',
780
- body
781
- );
782
-
783
- return response.json();
784
- }
785
-
786
- /**
787
- * Create an IPEX admit EXN message
788
- * @async
789
- * @param {string} name Name or alias of the identifier
790
- * @param {string} message accompany human readable description of the credential being admitted
791
- * @param {string} grant qb64 SAID of grant message this admit is responding to
792
- * @param {string} datetime Optional datetime to set for the credential
793
- * @returns {Promise<[Serder, string[], string]>} A promise to the long-running operation
794
- */
795
- async admit(
796
- name: string,
797
- message: string,
798
- grant: string,
799
- datetime?: string
800
- ): Promise<[Serder, string[], string]> {
801
- const hab = await this.client.identifiers().get(name);
802
- const data: any = {
803
- m: message,
804
- };
805
-
806
- return this.client
807
- .exchanges()
808
- .createExchangeMessage(
809
- hab,
810
- '/ipex/admit',
811
- data,
812
- {},
813
- undefined,
814
- datetime,
815
- grant
816
- );
817
- }
818
-
819
- async submitAdmit(
820
- name: string,
821
- exn: Serder,
822
- sigs: string[],
823
- atc: string,
824
- recp: string[]
825
- ): Promise<any> {
826
- const body = {
827
- exn: exn.ked,
828
- sigs: sigs,
829
- atc: atc,
830
- rec: recp,
831
- };
832
-
833
- const response = await this.client.fetch(
834
- `/identifiers/${name}/ipex/admit`,
835
- 'POST',
836
- body
837
- );
838
-
839
- return response.json();
840
- }
841
- }