Skip to content

Commit

Permalink
Added missing method to NodeJS wrapper
Browse files Browse the repository at this point in the history
Signed-off-by: artem.ivanov <[email protected]>
  • Loading branch information
Artemkaaas committed Nov 15, 2023
1 parent 4fae9b1 commit 106d702
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 28 deletions.
2 changes: 2 additions & 0 deletions tests/anoncreds_demos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3029,6 +3029,7 @@ fn anoncreds_demo_works_for_issue_w3c_credential_and_present_w3c_presentation()
.expect("Error processing credential");

// Store W3C credential form in wallet
println!("w3c_credential {}", json!(w3c_credential).to_string());
prover_wallet.w3c_credentials.push(w3c_credential);

// Create and Verify W3C presentation using W3C credential
Expand Down Expand Up @@ -3074,6 +3075,7 @@ fn anoncreds_demo_works_for_issue_w3c_credential_and_present_w3c_presentation()
&cred_defs,
)
.expect("Error creating presentation");
println!("presentation {}", json!(presentation).to_string());

// Verifier verifies presentation
assert_eq!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ export class NodeJSAnoncreds implements Anoncreds {
revocationConfiguration?: NativeCredentialRevocationConfig
encoding?: string
}): ObjectHandle {
const { credentialDefinition, credentialDefinitionPrivate, credentialOffer, credentialRequest } =
const { credentialDefinition, credentialDefinitionPrivate, credentialOffer, credentialRequest, encoding } =
serializeArguments(options)

const attributeNames = StringListStruct({
Expand Down Expand Up @@ -722,7 +722,7 @@ export class NodeJSAnoncreds implements Anoncreds {
attributeNames as unknown as Buffer,
attributeRawValues as unknown as Buffer,
revocationConfiguration?.ref().address() ?? 0,
options.encoding,
encoding,
credentialPtr
)
this.handleError()
Expand Down Expand Up @@ -907,7 +907,7 @@ export class NodeJSAnoncreds implements Anoncreds {
return Boolean(handleReturnPointer<number>(ret))
}

public credentialToW3C(options: { objectHandle: ObjectHandle, credentialDefinition: ObjectHandle }): ObjectHandle {
public credentialToW3C(options: { objectHandle: ObjectHandle; credentialDefinition: ObjectHandle }): ObjectHandle {
const { objectHandle, credentialDefinition } = serializeArguments(options)

const ret = allocatePointer()
Expand Down Expand Up @@ -943,6 +943,20 @@ export class NodeJSAnoncreds implements Anoncreds {
return new ObjectHandle(handleReturnPointer<number>(ret))
}

public w3cCredentialAddNonAnonCredsIntegrityProof(options: {
objectHandle: ObjectHandle
proof: string
}): ObjectHandle {
const { objectHandle, proof } = serializeArguments(options)

const ret = allocatePointer()

this.nativeAnoncreds.anoncreds_w3c_credential_add_non_anoncreds_integrity_proof(objectHandle, proof, ret)
this.handleError()

return new ObjectHandle(handleReturnPointer<number>(ret))
}

public w3cCredentialSetId(options: { objectHandle: ObjectHandle; id: string }): ObjectHandle {
const { objectHandle, id } = serializeArguments(options)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export type NativeBindings = {

w3cCredentialAddType(options: { objectHandle: number; type_: string }): ReturnObject<Handle>

credentialToW3C(options: { objectHandle: number, credentialDefinition: number }): ReturnObject<Handle>
credentialToW3C(options: { objectHandle: number; credentialDefinition: number }): ReturnObject<Handle>

credentialFromW3C(options: { objectHandle: number }): ReturnObject<Handle>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ export class ReactNativeAnoncreds implements Anoncreds {
return new ObjectHandle(handle)
}

public credentialToW3C(options: { objectHandle: ObjectHandle, credentialDefinition: ObjectHandle }): ObjectHandle {
public credentialToW3C(options: { objectHandle: ObjectHandle; credentialDefinition: ObjectHandle }): ObjectHandle {
const handle = this.handleError(this.anoncreds.credentialToW3C(serializeArguments(options)))
return new ObjectHandle(handle)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export type Anoncreds = {

w3cCredentialFromJson(options: { json: string }): ObjectHandle

credentialToW3C(options: { objectHandle: ObjectHandle, credentialDefinition: ObjectHandle }): ObjectHandle
credentialToW3C(options: { objectHandle: ObjectHandle; credentialDefinition: ObjectHandle }): ObjectHandle

credentialFromW3C(options: { objectHandle: ObjectHandle }): ObjectHandle
}
22 changes: 11 additions & 11 deletions wrappers/javascript/packages/anoncreds-shared/src/api/Credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,17 @@ export class Credential extends AnoncredsObject {
// Objects created within this method must be freed up
const objectHandles: ObjectHandle[] = []
try {
const credentialDefinition =
options.credentialDefinition instanceof CredentialDefinition
? options.credentialDefinition.handle
: pushToArray(CredentialDefinition.fromJson(options.credentialDefinition).handle, objectHandles)

credential = new W3CCredential(
anoncreds.credentialToW3C({
objectHandle: this.handle,
credentialDefinition,
}).handle
)
const credentialDefinition =
options.credentialDefinition instanceof CredentialDefinition
? options.credentialDefinition.handle
: pushToArray(CredentialDefinition.fromJson(options.credentialDefinition).handle, objectHandles)

credential = new W3CCredential(
anoncreds.credentialToW3C({
objectHandle: this.handle,
credentialDefinition
}).handle
)
} finally {
objectHandles.forEach((handle) => {
handle.clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,17 @@ export class W3CCredential extends AnoncredsObject {
// Objects created within this method must be freed up
const objectHandles: ObjectHandle[] = []
try {
const credentialDefinition =
options.credentialDefinition instanceof CredentialDefinition
? options.credentialDefinition.handle
: pushToArray(CredentialDefinition.fromJson(options.credentialDefinition).handle, objectHandles)

credential = new W3CCredential(
anoncreds.credentialToW3C({
objectHandle: options.credential.handle,
credentialDefinition,
}).handle
)
const credentialDefinition =
options.credentialDefinition instanceof CredentialDefinition
? options.credentialDefinition.handle
: pushToArray(CredentialDefinition.fromJson(options.credentialDefinition).handle, objectHandles)

credential = new W3CCredential(
anoncreds.credentialToW3C({
objectHandle: options.credential.handle,
credentialDefinition
}).handle
)
} finally {
objectHandles.forEach((handle) => {
handle.clear()
Expand Down

0 comments on commit 106d702

Please sign in to comment.