Skip to content

Commit 75e8d97

Browse files
authored
Merge pull request #23 from anoncreds/fix/anoncreds-registration
2 parents 2eaffda + 79a9cbd commit 75e8d97

23 files changed

+139
-81
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { registerAnoncreds } from '@hyperledger/anoncreds-shared'
1+
import { NativeAnoncreds } from '@hyperledger/anoncreds-shared'
22

33
import { NodeJSAnoncreds } from './NodeJSAnoncreds'
44

55
export const anoncredsNodeJS = new NodeJSAnoncreds()
6-
registerAnoncreds({ lib: anoncredsNodeJS })
6+
NativeAnoncreds.register(anoncredsNodeJS)
77

88
export * from '@hyperledger/anoncreds-shared'
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { registerAnoncreds } from '@hyperledger/anoncreds-shared'
1+
import { NativeAnoncreds } from '@hyperledger/anoncreds-shared'
22

33
import { ReactNativeAnoncreds } from './ReactNativeAnoncreds'
44
import { register } from './register'
55

66
export * from '@hyperledger/anoncreds-shared'
77

8-
registerAnoncreds({ lib: new ReactNativeAnoncreds(register()) })
8+
NativeAnoncreds.register(new ReactNativeAnoncreds(register()))
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { JsonObject } from './types'
22

33
import { ObjectHandle } from './ObjectHandle'
4-
import { anoncreds } from './register'
4+
import { NativeAnoncreds } from './register'
55

66
export class AnoncredsObject {
77
public handle: ObjectHandle
@@ -11,6 +11,6 @@ export class AnoncredsObject {
1111
}
1212

1313
public toJson() {
14-
return JSON.parse(anoncreds.getJson({ objectHandle: this.handle })) as JsonObject
14+
return JSON.parse(NativeAnoncreds.instance.getJson({ objectHandle: this.handle })) as JsonObject
1515
}
1616
}

packages/anoncreds-shared/src/ObjectHandle.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { anoncreds } from './register'
1+
import { NativeAnoncreds } from './register'
22

33
export class ObjectHandle {
44
private readonly _handle: number
@@ -12,11 +12,11 @@ export class ObjectHandle {
1212
}
1313

1414
public typeName() {
15-
return anoncreds.getTypeName({ objectHandle: this })
15+
return NativeAnoncreds.instance.getTypeName({ objectHandle: this })
1616
}
1717

1818
// TODO: do we need this?
1919
public clear() {
20-
anoncreds.objectFree({ objectHandle: this })
20+
NativeAnoncreds.instance.objectFree({ objectHandle: this })
2121
}
2222
}

packages/anoncreds-shared/src/api/Credential.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { CredentialRevocationConfig } from './CredentialRevocationConfig'
44
import type { RevocationStatusList } from './RevocationStatusList'
55

66
import { AnoncredsObject } from '../AnoncredsObject'
7-
import { anoncreds } from '../register'
7+
import { NativeAnoncreds } from '../register'
88

99
import { CredentialDefinition } from './CredentialDefinition'
1010
import { CredentialDefinitionPrivate } from './CredentialDefinitionPrivate'
@@ -69,7 +69,7 @@ export class Credential extends AnoncredsObject {
6969
? options.credentialRequest.handle
7070
: pushToArray(CredentialRequest.fromJson(options.credentialRequest).handle, objectHandles)
7171

72-
credential = anoncreds.createCredential({
72+
credential = NativeAnoncreds.instance.createCredential({
7373
credentialDefinition,
7474
credentialDefinitionPrivate,
7575
credentialOffer,
@@ -87,7 +87,7 @@ export class Credential extends AnoncredsObject {
8787
}
8888

8989
public static fromJson(json: JsonObject) {
90-
return new Credential(anoncreds.credentialFromJson({ json: JSON.stringify(json) }).handle)
90+
return new Credential(NativeAnoncreds.instance.credentialFromJson({ json: JSON.stringify(json) }).handle)
9191
}
9292

9393
public process(options: ProcessCredentialOptions) {
@@ -115,7 +115,7 @@ export class Credential extends AnoncredsObject {
115115
)
116116
: undefined
117117

118-
credential = anoncreds.processCredential({
118+
credential = NativeAnoncreds.instance.processCredential({
119119
credential: this.handle,
120120
credentialDefinition,
121121
credentialRequestMetadata,
@@ -134,25 +134,25 @@ export class Credential extends AnoncredsObject {
134134
return this
135135
}
136136
public get schemaId() {
137-
return anoncreds.credentialGetAttribute({ objectHandle: this.handle, name: 'schema_id' })
137+
return NativeAnoncreds.instance.credentialGetAttribute({ objectHandle: this.handle, name: 'schema_id' })
138138
}
139139

140140
public get credentialDefinitionId() {
141-
return anoncreds.credentialGetAttribute({ objectHandle: this.handle, name: 'cred_def_id' })
141+
return NativeAnoncreds.instance.credentialGetAttribute({ objectHandle: this.handle, name: 'cred_def_id' })
142142
}
143143

144144
public get revocationRegistryId() {
145-
return anoncreds.credentialGetAttribute({ objectHandle: this.handle, name: 'rev_reg_id' })
145+
return NativeAnoncreds.instance.credentialGetAttribute({ objectHandle: this.handle, name: 'rev_reg_id' })
146146
}
147147

148148
public get revocationRegistryIndex() {
149-
const index = anoncreds.credentialGetAttribute({ objectHandle: this.handle, name: 'rev_reg_index' })
149+
const index = NativeAnoncreds.instance.credentialGetAttribute({ objectHandle: this.handle, name: 'rev_reg_index' })
150150
return index ? Number(index) : undefined
151151
}
152152

153153
public toW3c(options: CredentialToW3cOptions): W3cCredential {
154154
return new W3cCredential(
155-
anoncreds.credentialToW3c({
155+
NativeAnoncreds.instance.credentialToW3c({
156156
objectHandle: this.handle,
157157
issuerId: options.issuerId,
158158
w3cVersion: options.w3cVersion,
@@ -161,6 +161,8 @@ export class Credential extends AnoncredsObject {
161161
}
162162

163163
public static fromW3c(options: CredentialFromW3cOptions) {
164-
return new Credential(anoncreds.credentialFromW3c({ objectHandle: options.credential.handle }).handle)
164+
return new Credential(
165+
NativeAnoncreds.instance.credentialFromW3c({ objectHandle: options.credential.handle }).handle
166+
)
165167
}
166168
}

packages/anoncreds-shared/src/api/CredentialDefinition.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ObjectHandle } from '../ObjectHandle'
22
import type { JsonObject } from '../types'
33

44
import { AnoncredsObject } from '../AnoncredsObject'
5-
import { anoncreds } from '../register'
5+
import { NativeAnoncreds } from '../register'
66

77
import { CredentialDefinitionPrivate } from './CredentialDefinitionPrivate'
88
import { KeyCorrectnessProof } from './KeyCorrectnessProof'
@@ -33,7 +33,7 @@ export class CredentialDefinition extends AnoncredsObject {
3333
options.schema instanceof Schema
3434
? options.schema.handle
3535
: pushToArray(Schema.fromJson(options.schema).handle, objectHandles)
36-
createReturnObj = anoncreds.createCredentialDefinition({
36+
createReturnObj = NativeAnoncreds.instance.createCredentialDefinition({
3737
schemaId: options.schemaId,
3838
schema,
3939
signatureType: options.signatureType,
@@ -54,6 +54,8 @@ export class CredentialDefinition extends AnoncredsObject {
5454
}
5555

5656
public static fromJson(json: JsonObject) {
57-
return new CredentialDefinition(anoncreds.credentialDefinitionFromJson({ json: JSON.stringify(json) }).handle)
57+
return new CredentialDefinition(
58+
NativeAnoncreds.instance.credentialDefinitionFromJson({ json: JSON.stringify(json) }).handle
59+
)
5860
}
5961
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import type { JsonObject } from '../types'
22

33
import { AnoncredsObject } from '../AnoncredsObject'
4-
import { anoncreds } from '../register'
4+
import { NativeAnoncreds } from '../register'
55

66
export class CredentialDefinitionPrivate extends AnoncredsObject {
77
public static fromJson(json: JsonObject) {
88
return new CredentialDefinitionPrivate(
9-
anoncreds.credentialDefinitionPrivateFromJson({ json: JSON.stringify(json) }).handle
9+
NativeAnoncreds.instance.credentialDefinitionPrivateFromJson({ json: JSON.stringify(json) }).handle
1010
)
1111
}
1212
}

packages/anoncreds-shared/src/api/CredentialOffer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ObjectHandle } from '../ObjectHandle'
22
import type { JsonObject } from '../types'
33

44
import { AnoncredsObject } from '../AnoncredsObject'
5-
import { anoncreds } from '../register'
5+
import { NativeAnoncreds } from '../register'
66

77
import { KeyCorrectnessProof } from './KeyCorrectnessProof'
88
import { pushToArray } from './utils'
@@ -24,7 +24,7 @@ export class CredentialOffer extends AnoncredsObject {
2424
? options.keyCorrectnessProof.handle
2525
: pushToArray(KeyCorrectnessProof.fromJson(options.keyCorrectnessProof).handle, objectHandles)
2626

27-
credentialOfferHandle = anoncreds.createCredentialOffer({
27+
credentialOfferHandle = NativeAnoncreds.instance.createCredentialOffer({
2828
schemaId: options.schemaId,
2929
credentialDefinitionId: options.credentialDefinitionId,
3030
keyCorrectnessProof,
@@ -38,6 +38,6 @@ export class CredentialOffer extends AnoncredsObject {
3838
}
3939

4040
public static fromJson(json: JsonObject) {
41-
return new CredentialOffer(anoncreds.credentialOfferFromJson({ json: JSON.stringify(json) }).handle)
41+
return new CredentialOffer(NativeAnoncreds.instance.credentialOfferFromJson({ json: JSON.stringify(json) }).handle)
4242
}
4343
}

packages/anoncreds-shared/src/api/CredentialRequest.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ObjectHandle } from '../ObjectHandle'
22
import type { JsonObject } from '../types'
33

44
import { AnoncredsObject } from '../AnoncredsObject'
5-
import { anoncreds } from '../register'
5+
import { NativeAnoncreds } from '../register'
66

77
import { CredentialDefinition } from './CredentialDefinition'
88
import { CredentialOffer } from './CredentialOffer'
@@ -37,7 +37,7 @@ export class CredentialRequest extends AnoncredsObject {
3737
? options.credentialOffer.handle
3838
: pushToArray(CredentialOffer.fromJson(options.credentialOffer).handle, objectHandles)
3939

40-
createReturnObj = anoncreds.createCredentialRequest({
40+
createReturnObj = NativeAnoncreds.instance.createCredentialRequest({
4141
entropy: options.entropy,
4242
proverDid: options.proverDid,
4343
credentialDefinition,
@@ -57,6 +57,8 @@ export class CredentialRequest extends AnoncredsObject {
5757
}
5858

5959
public static fromJson(json: JsonObject) {
60-
return new CredentialRequest(anoncreds.credentialRequestFromJson({ json: JSON.stringify(json) }).handle)
60+
return new CredentialRequest(
61+
NativeAnoncreds.instance.credentialRequestFromJson({ json: JSON.stringify(json) }).handle
62+
)
6163
}
6264
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import type { JsonObject } from '../types'
22

33
import { AnoncredsObject } from '../AnoncredsObject'
4-
import { anoncreds } from '../register'
4+
import { NativeAnoncreds } from '../register'
55

66
export class CredentialRequestMetadata extends AnoncredsObject {
77
public static fromJson(json: JsonObject) {
88
return new CredentialRequestMetadata(
9-
anoncreds.credentialRequestMetadataFromJson({ json: JSON.stringify(json) }).handle
9+
NativeAnoncreds.instance.credentialRequestMetadataFromJson({ json: JSON.stringify(json) }).handle
1010
)
1111
}
1212
}

0 commit comments

Comments
 (0)