Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/anoncreds-nodejs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { registerAnoncreds } from '@hyperledger/anoncreds-shared'
import { NativeAnoncreds } from '@hyperledger/anoncreds-shared'

import { NodeJSAnoncreds } from './NodeJSAnoncreds'

export const anoncredsNodeJS = new NodeJSAnoncreds()
registerAnoncreds({ lib: anoncredsNodeJS })
NativeAnoncreds.register(anoncredsNodeJS)

export * from '@hyperledger/anoncreds-shared'
4 changes: 2 additions & 2 deletions packages/anoncreds-react-native/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { registerAnoncreds } from '@hyperledger/anoncreds-shared'
import { NativeAnoncreds } from '@hyperledger/anoncreds-shared'

import { ReactNativeAnoncreds } from './ReactNativeAnoncreds'
import { register } from './register'

export * from '@hyperledger/anoncreds-shared'

registerAnoncreds({ lib: new ReactNativeAnoncreds(register()) })
NativeAnoncreds.register(new ReactNativeAnoncreds(register()))
4 changes: 2 additions & 2 deletions packages/anoncreds-shared/src/AnoncredsObject.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { JsonObject } from './types'

import { ObjectHandle } from './ObjectHandle'
import { anoncreds } from './register'
import { NativeAnoncreds } from './register'

export class AnoncredsObject {
public handle: ObjectHandle
Expand All @@ -11,6 +11,6 @@ export class AnoncredsObject {
}

public toJson() {
return JSON.parse(anoncreds.getJson({ objectHandle: this.handle })) as JsonObject
return JSON.parse(NativeAnoncreds.instance.getJson({ objectHandle: this.handle })) as JsonObject
}
}
6 changes: 3 additions & 3 deletions packages/anoncreds-shared/src/ObjectHandle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { anoncreds } from './register'
import { NativeAnoncreds } from './register'

export class ObjectHandle {
private readonly _handle: number
Expand All @@ -12,11 +12,11 @@ export class ObjectHandle {
}

public typeName() {
return anoncreds.getTypeName({ objectHandle: this })
return NativeAnoncreds.instance.getTypeName({ objectHandle: this })
}

// TODO: do we need this?
public clear() {
anoncreds.objectFree({ objectHandle: this })
NativeAnoncreds.instance.objectFree({ objectHandle: this })
}
}
22 changes: 12 additions & 10 deletions packages/anoncreds-shared/src/api/Credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { CredentialRevocationConfig } from './CredentialRevocationConfig'
import type { RevocationStatusList } from './RevocationStatusList'

import { AnoncredsObject } from '../AnoncredsObject'
import { anoncreds } from '../register'
import { NativeAnoncreds } from '../register'

import { CredentialDefinition } from './CredentialDefinition'
import { CredentialDefinitionPrivate } from './CredentialDefinitionPrivate'
Expand Down Expand Up @@ -69,7 +69,7 @@ export class Credential extends AnoncredsObject {
? options.credentialRequest.handle
: pushToArray(CredentialRequest.fromJson(options.credentialRequest).handle, objectHandles)

credential = anoncreds.createCredential({
credential = NativeAnoncreds.instance.createCredential({
credentialDefinition,
credentialDefinitionPrivate,
credentialOffer,
Expand All @@ -87,7 +87,7 @@ export class Credential extends AnoncredsObject {
}

public static fromJson(json: JsonObject) {
return new Credential(anoncreds.credentialFromJson({ json: JSON.stringify(json) }).handle)
return new Credential(NativeAnoncreds.instance.credentialFromJson({ json: JSON.stringify(json) }).handle)
}

public process(options: ProcessCredentialOptions) {
Expand Down Expand Up @@ -115,7 +115,7 @@ export class Credential extends AnoncredsObject {
)
: undefined

credential = anoncreds.processCredential({
credential = NativeAnoncreds.instance.processCredential({
credential: this.handle,
credentialDefinition,
credentialRequestMetadata,
Expand All @@ -134,25 +134,25 @@ export class Credential extends AnoncredsObject {
return this
}
public get schemaId() {
return anoncreds.credentialGetAttribute({ objectHandle: this.handle, name: 'schema_id' })
return NativeAnoncreds.instance.credentialGetAttribute({ objectHandle: this.handle, name: 'schema_id' })
}

public get credentialDefinitionId() {
return anoncreds.credentialGetAttribute({ objectHandle: this.handle, name: 'cred_def_id' })
return NativeAnoncreds.instance.credentialGetAttribute({ objectHandle: this.handle, name: 'cred_def_id' })
}

public get revocationRegistryId() {
return anoncreds.credentialGetAttribute({ objectHandle: this.handle, name: 'rev_reg_id' })
return NativeAnoncreds.instance.credentialGetAttribute({ objectHandle: this.handle, name: 'rev_reg_id' })
}

public get revocationRegistryIndex() {
const index = anoncreds.credentialGetAttribute({ objectHandle: this.handle, name: 'rev_reg_index' })
const index = NativeAnoncreds.instance.credentialGetAttribute({ objectHandle: this.handle, name: 'rev_reg_index' })
return index ? Number(index) : undefined
}

public toW3c(options: CredentialToW3cOptions): W3cCredential {
return new W3cCredential(
anoncreds.credentialToW3c({
NativeAnoncreds.instance.credentialToW3c({
objectHandle: this.handle,
issuerId: options.issuerId,
w3cVersion: options.w3cVersion,
Expand All @@ -161,6 +161,8 @@ export class Credential extends AnoncredsObject {
}

public static fromW3c(options: CredentialFromW3cOptions) {
return new Credential(anoncreds.credentialFromW3c({ objectHandle: options.credential.handle }).handle)
return new Credential(
NativeAnoncreds.instance.credentialFromW3c({ objectHandle: options.credential.handle }).handle
)
}
}
8 changes: 5 additions & 3 deletions packages/anoncreds-shared/src/api/CredentialDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ObjectHandle } from '../ObjectHandle'
import type { JsonObject } from '../types'

import { AnoncredsObject } from '../AnoncredsObject'
import { anoncreds } from '../register'
import { NativeAnoncreds } from '../register'

import { CredentialDefinitionPrivate } from './CredentialDefinitionPrivate'
import { KeyCorrectnessProof } from './KeyCorrectnessProof'
Expand Down Expand Up @@ -33,7 +33,7 @@ export class CredentialDefinition extends AnoncredsObject {
options.schema instanceof Schema
? options.schema.handle
: pushToArray(Schema.fromJson(options.schema).handle, objectHandles)
createReturnObj = anoncreds.createCredentialDefinition({
createReturnObj = NativeAnoncreds.instance.createCredentialDefinition({
schemaId: options.schemaId,
schema,
signatureType: options.signatureType,
Expand All @@ -54,6 +54,8 @@ export class CredentialDefinition extends AnoncredsObject {
}

public static fromJson(json: JsonObject) {
return new CredentialDefinition(anoncreds.credentialDefinitionFromJson({ json: JSON.stringify(json) }).handle)
return new CredentialDefinition(
NativeAnoncreds.instance.credentialDefinitionFromJson({ json: JSON.stringify(json) }).handle
)
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { JsonObject } from '../types'

import { AnoncredsObject } from '../AnoncredsObject'
import { anoncreds } from '../register'
import { NativeAnoncreds } from '../register'

export class CredentialDefinitionPrivate extends AnoncredsObject {
public static fromJson(json: JsonObject) {
return new CredentialDefinitionPrivate(
anoncreds.credentialDefinitionPrivateFromJson({ json: JSON.stringify(json) }).handle
NativeAnoncreds.instance.credentialDefinitionPrivateFromJson({ json: JSON.stringify(json) }).handle
)
}
}
6 changes: 3 additions & 3 deletions packages/anoncreds-shared/src/api/CredentialOffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ObjectHandle } from '../ObjectHandle'
import type { JsonObject } from '../types'

import { AnoncredsObject } from '../AnoncredsObject'
import { anoncreds } from '../register'
import { NativeAnoncreds } from '../register'

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

credentialOfferHandle = anoncreds.createCredentialOffer({
credentialOfferHandle = NativeAnoncreds.instance.createCredentialOffer({
schemaId: options.schemaId,
credentialDefinitionId: options.credentialDefinitionId,
keyCorrectnessProof,
Expand All @@ -38,6 +38,6 @@ export class CredentialOffer extends AnoncredsObject {
}

public static fromJson(json: JsonObject) {
return new CredentialOffer(anoncreds.credentialOfferFromJson({ json: JSON.stringify(json) }).handle)
return new CredentialOffer(NativeAnoncreds.instance.credentialOfferFromJson({ json: JSON.stringify(json) }).handle)
}
}
8 changes: 5 additions & 3 deletions packages/anoncreds-shared/src/api/CredentialRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ObjectHandle } from '../ObjectHandle'
import type { JsonObject } from '../types'

import { AnoncredsObject } from '../AnoncredsObject'
import { anoncreds } from '../register'
import { NativeAnoncreds } from '../register'

import { CredentialDefinition } from './CredentialDefinition'
import { CredentialOffer } from './CredentialOffer'
Expand Down Expand Up @@ -37,7 +37,7 @@ export class CredentialRequest extends AnoncredsObject {
? options.credentialOffer.handle
: pushToArray(CredentialOffer.fromJson(options.credentialOffer).handle, objectHandles)

createReturnObj = anoncreds.createCredentialRequest({
createReturnObj = NativeAnoncreds.instance.createCredentialRequest({
entropy: options.entropy,
proverDid: options.proverDid,
credentialDefinition,
Expand All @@ -57,6 +57,8 @@ export class CredentialRequest extends AnoncredsObject {
}

public static fromJson(json: JsonObject) {
return new CredentialRequest(anoncreds.credentialRequestFromJson({ json: JSON.stringify(json) }).handle)
return new CredentialRequest(
NativeAnoncreds.instance.credentialRequestFromJson({ json: JSON.stringify(json) }).handle
)
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { JsonObject } from '../types'

import { AnoncredsObject } from '../AnoncredsObject'
import { anoncreds } from '../register'
import { NativeAnoncreds } from '../register'

export class CredentialRequestMetadata extends AnoncredsObject {
public static fromJson(json: JsonObject) {
return new CredentialRequestMetadata(
anoncreds.credentialRequestMetadataFromJson({ json: JSON.stringify(json) }).handle
NativeAnoncreds.instance.credentialRequestMetadataFromJson({ json: JSON.stringify(json) }).handle
)
}
}
10 changes: 6 additions & 4 deletions packages/anoncreds-shared/src/api/CredentialRevocationState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ObjectHandle } from '../ObjectHandle'
import type { JsonObject } from '../types'

import { AnoncredsObject } from '../AnoncredsObject'
import { anoncreds } from '../register'
import { NativeAnoncreds } from '../register'

import { RevocationRegistryDefinition } from './RevocationRegistryDefinition'
import { RevocationStatusList } from './RevocationStatusList'
Expand Down Expand Up @@ -41,7 +41,7 @@ export class CredentialRevocationState extends AnoncredsObject {
? options.revocationStatusList.handle
: pushToArray(RevocationStatusList.fromJson(options.revocationStatusList).handle, objectHandles)

credentialRevocationStateHandle = anoncreds.createOrUpdateRevocationState({
credentialRevocationStateHandle = NativeAnoncreds.instance.createOrUpdateRevocationState({
revocationRegistryDefinition,
revocationStatusList,
revocationRegistryIndex: options.revocationRegistryIndex,
Expand All @@ -58,11 +58,13 @@ export class CredentialRevocationState extends AnoncredsObject {
}

public static fromJson(json: JsonObject) {
return new CredentialRevocationState(anoncreds.revocationStateFromJson({ json: JSON.stringify(json) }).handle)
return new CredentialRevocationState(
NativeAnoncreds.instance.revocationStateFromJson({ json: JSON.stringify(json) }).handle
)
}

public update(options: UpdateRevocationStateOptions) {
this.handle = anoncreds.createOrUpdateRevocationState({
this.handle = NativeAnoncreds.instance.createOrUpdateRevocationState({
revocationRegistryDefinition: options.revocationRegistryDefinition.handle,
revocationStatusList: options.revocationStatusList.handle,
revocationRegistryIndex: options.revocationRegistryIndex,
Expand Down
6 changes: 4 additions & 2 deletions packages/anoncreds-shared/src/api/KeyCorrectnessProof.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import type { JsonObject } from '../types'

import { AnoncredsObject } from '../AnoncredsObject'
import { anoncreds } from '../register'
import { NativeAnoncreds } from '../register'

export class KeyCorrectnessProof extends AnoncredsObject {
public static fromJson(json: JsonObject) {
return new KeyCorrectnessProof(anoncreds.keyCorrectnessProofFromJson({ json: JSON.stringify(json) }).handle)
return new KeyCorrectnessProof(
NativeAnoncreds.instance.keyCorrectnessProofFromJson({ json: JSON.stringify(json) }).handle
)
}
}
4 changes: 2 additions & 2 deletions packages/anoncreds-shared/src/api/LinkSecret.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { anoncreds } from '../register'
import { NativeAnoncreds } from '../register'

export class LinkSecret {
public static create(): string {
return anoncreds.createLinkSecret()
return NativeAnoncreds.instance.createLinkSecret()
}
}
8 changes: 4 additions & 4 deletions packages/anoncreds-shared/src/api/Presentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { JsonObject } from '../types'
import type { RevocationRegistry } from './RevocationRegistry'

import { AnoncredsObject } from '../AnoncredsObject'
import { anoncreds } from '../register'
import { NativeAnoncreds } from '../register'

import { Credential } from './Credential'
import { CredentialDefinition } from './CredentialDefinition'
Expand Down Expand Up @@ -72,7 +72,7 @@ export class Presentation extends AnoncredsObject {
? options.presentationRequest.handle
: pushToArray(PresentationRequest.fromJson(options.presentationRequest).handle, objectHandles)

presentationHandle = anoncreds.createPresentation({
presentationHandle = NativeAnoncreds.instance.createPresentation({
presentationRequest,
credentials: options.credentials.map((item) => ({
credential:
Expand Down Expand Up @@ -120,7 +120,7 @@ export class Presentation extends AnoncredsObject {
}

public static fromJson(json: JsonObject) {
return new Presentation(anoncreds.presentationFromJson({ json: JSON.stringify(json) }).handle)
return new Presentation(NativeAnoncreds.instance.presentationFromJson({ json: JSON.stringify(json) }).handle)
}

public verify(options: VerifyPresentationOptions) {
Expand All @@ -146,7 +146,7 @@ export class Presentation extends AnoncredsObject {
? options.presentationRequest.handle
: pushToArray(PresentationRequest.fromJson(options.presentationRequest).handle, objectHandles)

verified = anoncreds.verifyPresentation({
verified = NativeAnoncreds.instance.verifyPresentation({
presentation: this.handle,
presentationRequest,
schemas: schemas.map((o) =>
Expand Down
6 changes: 4 additions & 2 deletions packages/anoncreds-shared/src/api/PresentationRequest.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import type { JsonObject } from '../types'

import { AnoncredsObject } from '../AnoncredsObject'
import { anoncreds } from '../register'
import { NativeAnoncreds } from '../register'

export class PresentationRequest extends AnoncredsObject {
public static fromJson(json: JsonObject) {
return new PresentationRequest(anoncreds.presentationRequestFromJson({ json: JSON.stringify(json) }).handle)
return new PresentationRequest(
NativeAnoncreds.instance.presentationRequestFromJson({ json: JSON.stringify(json) }).handle
)
}
}
6 changes: 4 additions & 2 deletions packages/anoncreds-shared/src/api/RevocationRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { JsonObject } from '../types'
import type { RevocationRegistryDefinition } from './RevocationRegistryDefinition'

import { AnoncredsObject } from '../AnoncredsObject'
import { anoncreds } from '../register'
import { NativeAnoncreds } from '../register'

export type UpdateRevocationRegistryOptions = {
revocationRegistryDefinition: RevocationRegistryDefinition
Expand All @@ -13,6 +13,8 @@ export type UpdateRevocationRegistryOptions = {

export class RevocationRegistry extends AnoncredsObject {
public static fromJson(json: JsonObject) {
return new RevocationRegistry(anoncreds.revocationRegistryFromJson({ json: JSON.stringify(json) }).handle)
return new RevocationRegistry(
NativeAnoncreds.instance.revocationRegistryFromJson({ json: JSON.stringify(json) }).handle
)
}
}
Loading