@@ -21,6 +21,7 @@ import {
21
21
} from '../core/utils' ;
22
22
import { Operation } from './coring' ;
23
23
import { HabState } from '../core/state' ;
24
+ import { CesrNumber } from '../core/number' ;
24
25
25
26
/** Types of credentials */
26
27
export class CredentialTypes {
@@ -85,6 +86,29 @@ export interface CredentialData {
85
86
r ?: { [ key : string ] : unknown } ;
86
87
}
87
88
89
+ export interface IssueCredentialArgs {
90
+ /**
91
+ * The credential data.
92
+ */
93
+ acdc : CredentialData ;
94
+
95
+ /**
96
+ * The issuance event to be anchored to the credential registry. If not provided, the issuance event will be derived
97
+ * from the credential data.
98
+ *
99
+ * If a credential is created as part of a multisig exchanged, the anchoring event can be found in the exchange message.
100
+ */
101
+ iss ?: Record < string , unknown > ;
102
+
103
+ /**
104
+ * The anchoring event for the credential issuance. If not provided, the anchor event will be calculated from
105
+ * from the credential data and the issuance event.
106
+ *
107
+ * If a credential is created as part of a multisig exchanged, the anchoring event can be found in the exchange message.
108
+ */
109
+ anc ?: Record < string , unknown > ;
110
+ }
111
+
88
112
export interface IssueCredentialResult {
89
113
acdc : Serder ;
90
114
anc : Serder ;
@@ -290,7 +314,7 @@ export class Credentials {
290
314
*/
291
315
async issue (
292
316
name : string ,
293
- args : CredentialData
317
+ args : IssueCredentialArgs
294
318
) : Promise < IssueCredentialResult > {
295
319
const hab = await this . client . identifiers ( ) . get ( name ) ;
296
320
const estOnly = hab . state . c !== undefined && hab . state . c . includes ( 'EO' ) ;
@@ -306,55 +330,65 @@ export class Credentials {
306
330
307
331
const [ , subject ] = Saider . saidify ( {
308
332
d : '' ,
309
- ...args . a ,
310
- dt : args . a . dt ?? new Date ( ) . toISOString ( ) . replace ( 'Z' , '000+00:00' ) ,
333
+ ...args . acdc . a ,
334
+ dt :
335
+ args . acdc . a . dt ??
336
+ new Date ( ) . toISOString ( ) . replace ( 'Z' , '000+00:00' ) ,
311
337
} ) ;
312
338
313
- const [ , acdc ] = Saider . saidify ( {
314
- v : versify ( Ident . ACDC , undefined , Serials . JSON , 0 ) ,
315
- d : '' ,
316
- u : args . u ,
317
- i : args . i ?? hab . prefix ,
318
- ri : args . ri ,
319
- s : args . s ,
320
- a : subject ,
321
- e : args . e ,
322
- r : args . r ,
323
- } ) ;
339
+ const acdc = new Serder (
340
+ Saider . saidify ( {
341
+ v : versify ( Ident . ACDC , undefined , Serials . JSON , 0 ) ,
342
+ d : '' ,
343
+ u : args . acdc . u ,
344
+ i : args . acdc . i ?? hab . prefix ,
345
+ ri : args . acdc . ri ,
346
+ s : args . acdc . s ,
347
+ a : subject ,
348
+ e : args . acdc . e ,
349
+ r : args . acdc . r ,
350
+ } ) [ 1 ]
351
+ ) ;
324
352
325
- const [ , iss ] = Saider . saidify ( {
326
- v : versify ( Ident . KERI , undefined , Serials . JSON , 0 ) ,
327
- t : Ilks . iss ,
328
- d : '' ,
329
- i : acdc . d ,
330
- s : '0' ,
331
- ri : args . ri ,
332
- dt : subject . dt ,
333
- } ) ;
353
+ const iss = new Serder (
354
+ args . iss ??
355
+ Saider . saidify ( {
356
+ v : versify ( Ident . KERI , undefined , Serials . JSON , 0 ) ,
357
+ t : Ilks . iss ,
358
+ d : '' ,
359
+ i : acdc . ked . d ,
360
+ s : '0' ,
361
+ ri : args . acdc . ri ,
362
+ dt : subject . dt ,
363
+ } ) [ 1 ]
364
+ ) ;
334
365
335
- const sn = parseInt ( hab . state . s , 16 ) ;
336
- const anc = interact ( {
337
- pre : hab . prefix ,
338
- sn : sn + 1 ,
339
- data : [
340
- {
341
- i : iss . i ,
342
- s : iss . s ,
343
- d : iss . d ,
344
- } ,
345
- ] ,
346
- dig : hab . state . d ,
347
- version : undefined ,
348
- kind : undefined ,
349
- } ) ;
366
+ const sn = new CesrNumber ( { } , parseInt ( hab . state . s , 16 ) + 1 ) ;
367
+ const anc = new Serder (
368
+ args . anc ??
369
+ Saider . saidify ( {
370
+ v : versify ( Ident . KERI , undefined , Serials . JSON , 0 ) ,
371
+ t : Ilks . ixn ,
372
+ d : '' ,
373
+ i : hab . prefix ,
374
+ s : sn . numh ,
375
+ p : hab . state . d ,
376
+ a : [
377
+ {
378
+ i : iss . ked . i ,
379
+ s : iss . ked . s ,
380
+ d : iss . ked . d ,
381
+ } ,
382
+ ] ,
383
+ } ) [ 1 ]
384
+ ) ;
350
385
351
386
const sigs = await keeper . sign ( b ( anc . raw ) ) ;
352
-
353
387
const path = `/identifiers/${ hab . name } /credentials` ;
354
388
const method = 'POST' ;
355
389
const body = {
356
- acdc : acdc ,
357
- iss : iss ,
390
+ acdc : acdc . ked ,
391
+ iss : iss . ked ,
358
392
ixn : anc . ked ,
359
393
sigs,
360
394
[ keeper . algo ] : keeper . params ( ) ,
@@ -368,8 +402,8 @@ export class Credentials {
368
402
const op = await res . json ( ) ;
369
403
370
404
return {
371
- acdc : new Serder ( acdc ) ,
372
- iss : new Serder ( iss ) ,
405
+ acdc,
406
+ iss,
373
407
anc,
374
408
op,
375
409
} ;
0 commit comments