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