@@ -7,14 +7,22 @@ import { Wallet } from '../../wallet/Wallet';
7
7
export class LedgerService {
8
8
private wallet : Wallet ;
9
9
private indy : typeof Indy ;
10
- private poolHandle ?: PoolHandle ;
10
+ private _poolHandle ?: PoolHandle ;
11
11
private authorAgreement ?: AuthorAgreement | null ;
12
12
13
13
public constructor ( wallet : Wallet , indy : typeof Indy ) {
14
14
this . wallet = wallet ;
15
15
this . indy = indy ;
16
16
}
17
17
18
+ private get poolHandle ( ) {
19
+ if ( ! this . _poolHandle ) {
20
+ throw new Error ( 'Pool has not been initialized yet.' ) ;
21
+ }
22
+
23
+ return this . _poolHandle ;
24
+ }
25
+
18
26
public async connect ( poolName : string , poolConfig : PoolConfig ) {
19
27
try {
20
28
logger . log ( `Creating pool config with name "${ poolName } ".` ) ;
@@ -31,13 +39,10 @@ export class LedgerService {
31
39
await this . indy . setProtocolVersion ( 2 ) ;
32
40
33
41
logger . log ( 'Opening pool' ) ;
34
- this . poolHandle = await this . indy . openPoolLedger ( poolName ) ;
42
+ this . _poolHandle = await this . indy . openPoolLedger ( poolName ) ;
35
43
}
36
44
37
45
public async getPublicDid ( did : Did ) {
38
- if ( ! this . poolHandle ) {
39
- throw new Error ( 'Pool has not been initialized.' ) ;
40
- }
41
46
const request = await this . indy . buildGetNymRequest ( null , did ) ;
42
47
logger . log ( 'request' , request ) ;
43
48
@@ -51,9 +56,6 @@ export class LedgerService {
51
56
}
52
57
53
58
public async registerSchema ( did : Did , schemaTemplate : SchemaTemplate ) : Promise < [ SchemaId , Schema ] > {
54
- if ( ! this . poolHandle ) {
55
- throw new Error ( 'Pool has not been initialized.' ) ;
56
- }
57
59
const { name, attributes, version } = schemaTemplate ;
58
60
const [ schemaId , schema ] = await this . indy . issuerCreateSchema ( did , name , version , attributes ) ;
59
61
logger . log ( `Register schema with ID = ${ schemaId } :` , schema ) ;
@@ -67,13 +69,15 @@ export class LedgerService {
67
69
const response = await this . indy . submitRequest ( this . poolHandle , signedRequest ) ;
68
70
logger . log ( 'Register schema response' , response ) ;
69
71
72
+ const seqNo = response . result . txnMetadata ?. seqNo ;
73
+
74
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
75
+ schema . seqNo = seqNo ! ;
76
+
70
77
return [ schemaId , schema ] ;
71
78
}
72
79
73
80
public async getCredentialSchema ( schemaId : SchemaId ) {
74
- if ( ! this . poolHandle ) {
75
- throw new Error ( 'Pool has not been initialized.' ) ;
76
- }
77
81
const request = await this . indy . buildGetSchemaRequest ( null , schemaId ) ;
78
82
logger . log ( 'Get schema request' , request ) ;
79
83
@@ -90,12 +94,11 @@ export class LedgerService {
90
94
did : Did ,
91
95
credentialDefinitionTemplate : CredDefTemplate
92
96
) : Promise < [ CredDefId , CredDef ] > {
93
- if ( ! this . poolHandle ) {
94
- throw new Error ( 'Pool has not been initialized.' ) ;
95
- }
96
97
const { schema, tag, signatureType, config } = credentialDefinitionTemplate ;
97
98
98
- const [ credDefId , credDef ] = await this . wallet . createCredentialDefinition ( did , schema , tag , signatureType , config ) ;
99
+ const [ credDefId , credDef ] = await this . wallet . createCredentialDefinition ( did , schema , tag , signatureType , {
100
+ support_revocation : config . supportRevocation ,
101
+ } ) ;
99
102
logger . log ( `Register credential definition with ID = ${ credDefId } :` , credDef ) ;
100
103
101
104
const request = await this . indy . buildCredDefRequest ( did , credDef ) ;
@@ -111,9 +114,6 @@ export class LedgerService {
111
114
}
112
115
113
116
public async getCredentialDefinition ( credDefId : CredDefId ) {
114
- if ( ! this . poolHandle ) {
115
- throw new Error ( 'Pool has not been initialized.' ) ;
116
- }
117
117
const request = await this . indy . buildGetCredDefRequest ( null , credDefId ) ;
118
118
logger . log ( 'Get credential definition request:' , request ) ;
119
119
@@ -154,10 +154,6 @@ export class LedgerService {
154
154
return this . authorAgreement ;
155
155
}
156
156
157
- if ( ! this . poolHandle ) {
158
- throw new Error ( 'Pool has not been initialized.' ) ;
159
- }
160
-
161
157
const taaRequest = await this . indy . buildGetTxnAuthorAgreementRequest ( null ) ;
162
158
const taaResponse = await this . indy . submitRequest ( this . poolHandle , taaRequest ) ;
163
159
const acceptanceMechanismRequest = await this . indy . buildGetAcceptanceMechanismsRequest ( null ) ;
@@ -195,7 +191,7 @@ export interface CredDefTemplate {
195
191
schema : Schema ;
196
192
tag : string ;
197
193
signatureType : string ;
198
- config : { support_revocation : boolean } ;
194
+ config : { supportRevocation : boolean } ;
199
195
}
200
196
201
197
interface AuthorAgreement {
0 commit comments