Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: JS wrapper updates #231

Merged
merged 5 commits into from
Aug 17, 2023
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 .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Node.JS 16.x
- name: Set up Node.JS 18.x
uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 18.x

- name: Fetch library artifacts
uses: actions/download-artifact@v3
Expand Down
22 changes: 16 additions & 6 deletions include/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
_Generating the C header:_

1. Install [cbindgen](https://github.com/eqrion/cbindgen/)
1. Install [cargo expand](https://github.com/dtolnay/cargo-expand)
1. use `nightly` and not `stable
- `rustup default nightly`

1. use `nightly` instead of `stable`

```sh
rustup default nightly
```
> **Note**: If you run into _'unknown feature'_ issues by using latest nightly, force it to 1.72.0 by executing: `rustup default nightly-2023-06-15`

2. Install [cbindgen](https://github.com/eqrion/cbindgen/)

```sh
cargo install cbindgen
```

Generate the header file:
3. Install [cargo expand](https://github.com/dtolnay/cargo-expand)

```sh
cargo install cargo-expand
```

4. Generate the header file:

```sh
cbindgen --config include/cbindgen.toml --crate anoncreds --output include/libanoncreds.h
```

Copy to React Native:
5. Copy to React Native:

```sh
cp include/libanoncreds.h wrappers/javascript/anoncreds-react-native/cpp/include/
Expand Down
20 changes: 12 additions & 8 deletions include/libanoncreds.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

/* Generated with cbindgen:0.24.3 */
/* Generated with cbindgen:0.24.5 */

/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */

Expand Down Expand Up @@ -317,19 +317,21 @@ ErrorCode anoncreds_create_presentation(ObjectHandle pres_req,

ErrorCode anoncreds_create_revocation_registry_def(ObjectHandle cred_def,
FfiStr cred_def_id,
FfiStr issuer_id,
FfiStr _issuer_id,
FfiStr tag,
FfiStr rev_reg_type,
int64_t max_cred_num,
FfiStr tails_dir_path,
ObjectHandle *reg_def_p,
ObjectHandle *reg_def_private_p);

ErrorCode anoncreds_create_revocation_status_list(FfiStr rev_reg_def_id,
ErrorCode anoncreds_create_revocation_status_list(ObjectHandle cred_def,
FfiStr rev_reg_def_id,
ObjectHandle rev_reg_def,
FfiStr issuer_id,
int64_t timestamp,
ObjectHandle reg_rev_priv,
FfiStr _issuer_id,
int8_t issuance_by_default,
int64_t timestamp,
ObjectHandle *rev_status_list_p);

ErrorCode anoncreds_create_schema(FfiStr schema_name,
Expand Down Expand Up @@ -415,11 +417,13 @@ ErrorCode anoncreds_set_default_logger(void);
*/
void anoncreds_string_free(char *s);

ErrorCode anoncreds_update_revocation_status_list(int64_t timestamp,
struct FfiList_i32 issued,
struct FfiList_i32 revoked,
ErrorCode anoncreds_update_revocation_status_list(ObjectHandle cred_def,
ObjectHandle rev_reg_def,
ObjectHandle rev_reg_priv,
ObjectHandle rev_current_list,
struct FfiList_i32 issued,
struct FfiList_i32 revoked,
int64_t timestamp,
ObjectHandle *new_rev_status_list_p);

ErrorCode anoncreds_update_revocation_status_list_timestamp_only(int64_t timestamp,
Expand Down
7 changes: 4 additions & 3 deletions wrappers/javascript/anoncreds-nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
"dependencies": {
"@hyperledger/anoncreds-shared": "0.1.0",
"@mapbox/node-pre-gyp": "^1.0.10",
"ffi-napi": "4.0.3",
"@2060.io/ffi-napi": "4.0.5",
"@2060.io/ref-napi": "3.0.4",
"node-cache": "5.1.2",
"ref-array-di": "1.2.2",
"ref-napi": "3.0.3",
"ref-struct-di": "1.1.1"
},
"devDependencies": {
"@types/ffi-napi": "4.0.5",
"@types/2060.io__ffi-napi": "npm:@types/ffi-napi",
"@types/2060.io__ref-napi": "npm:@types/ref-napi",
"@types/node": "17.0.31",
"@types/ref-array-di": "1.2.3",
"@types/ref-napi": "3.0.7",
Expand Down
2 changes: 0 additions & 2 deletions wrappers/javascript/anoncreds-nodejs/src/NodeJSAnoncreds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,12 @@ export class NodeJSAnoncreds implements Anoncreds {
revocationRegistryDefinition: registryDefinition,
revocationRegistryDefinitionPrivate: registryDefinitionPrivate,
registryIndex,
tailsPath,
} = serializeArguments(options.revocationConfiguration)

revocationConfiguration = CredRevInfoStruct({
reg_def: registryDefinition,
reg_def_private: registryDefinitionPrivate,
reg_idx: registryIndex,
tails_path: tailsPath,
})
}

Expand Down
2 changes: 1 addition & 1 deletion wrappers/javascript/anoncreds-nodejs/src/ffi/alloc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { alloc } from 'ref-napi'
import { alloc } from '@2060.io/ref-napi'

import { FFI_STRING, FFI_OBJECT_HANDLE, FFI_INT8 } from '../ffi/primitives'

Expand Down
2 changes: 1 addition & 1 deletion wrappers/javascript/anoncreds-nodejs/src/ffi/conversion.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { reinterpret } from 'ref-napi'
import { reinterpret } from '@2060.io/ref-napi'

export const byteBufferToBuffer = (buffer: { data: Buffer; len: number }) => reinterpret(buffer.data, buffer.len)

Expand Down
2 changes: 1 addition & 1 deletion wrappers/javascript/anoncreds-nodejs/src/ffi/primitives.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { types, refType } from 'ref-napi'
import { types, refType } from '@2060.io/ref-napi'

// Primitives

Expand Down
4 changes: 2 additions & 2 deletions wrappers/javascript/anoncreds-nodejs/src/ffi/serialize.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { ByteBufferStruct } from './structures'
import type { Pointer } from '@2060.io/ref-napi'
import type { TypedArray } from 'ref-array-di'
import type { Pointer } from 'ref-napi'
import type { StructObject } from 'ref-struct-di'

import { NULL } from '@2060.io/ref-napi'
import { ObjectHandle } from '@hyperledger/anoncreds-shared'
import { NULL } from 'ref-napi'

import { ObjectHandleListStruct, StringListStruct, I32ListStruct, Int32Array } from './structures'

Expand Down
3 changes: 1 addition & 2 deletions wrappers/javascript/anoncreds-nodejs/src/ffi/structures.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as ref from '@2060.io/ref-napi'
import RefArray from 'ref-array-di'
import * as ref from 'ref-napi'
import RefStruct from 'ref-struct-di'

import { FFI_INT64, FFI_INT8, FFI_ISIZE, FFI_OBJECT_HANDLE, FFI_STRING, FFI_INT32 } from './primitives'
Expand All @@ -10,10 +10,10 @@
export const StringArray = CArray('string')

const FFI_INT32_ARRAY = CArray('int32')
const FFI_INT32_ARRAY_PTR = ref.refType(FFI_INT32_ARRAY)

Check warning on line 13 in wrappers/javascript/anoncreds-nodejs/src/ffi/structures.ts

View workflow job for this annotation

GitHub Actions / Build and Test JavaScript wrapper

'FFI_INT32_ARRAY_PTR' is assigned a value but never used

const FFI_INT64_ARRAY = CArray('int64')
const FFI_INT64_ARRAY_PTR = ref.refType(FFI_INT64_ARRAY)

Check warning on line 16 in wrappers/javascript/anoncreds-nodejs/src/ffi/structures.ts

View workflow job for this annotation

GitHub Actions / Build and Test JavaScript wrapper

'FFI_INT64_ARRAY_PTR' is assigned a value but never used

export const ByteBufferArray = CArray('uint8')
export const ByteBufferArrayPtr = ref.refType(FFI_STRING)
Expand Down Expand Up @@ -51,7 +51,6 @@
reg_def: FFI_OBJECT_HANDLE,
reg_def_private: FFI_OBJECT_HANDLE,
reg_idx: FFI_INT64,
tails_path: FFI_STRING,
})

export const CredentialEntryStruct = CStruct({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { NativeMethods } from './NativeBindingInterface'

import { Library } from 'ffi-napi'
import { Library } from '@2060.io/ffi-napi'
import fs from 'fs'
import os from 'os'
import path from 'path'
Expand Down
10 changes: 6 additions & 4 deletions wrappers/javascript/anoncreds-nodejs/test/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ describe('API', () => {
registryDefinition: revocationRegistryDefinition,
registryDefinitionPrivate: revocationRegistryDefinitionPrivate,
registryIndex: 9,
tailsPath,
}),
})

Expand Down Expand Up @@ -391,8 +390,6 @@ test('create and verify presentation passing only JSON objects as parameters', (
maximumCredentialNumber: 10,
})

const tailsPath = revocationRegistryDefinition.getTailsLocation()

const timeCreateRevStatusList = 12
const revocationStatusList = RevocationStatusList.create({
credentialDefinition,
Expand All @@ -404,6 +401,12 @@ test('create and verify presentation passing only JSON objects as parameters', (
timestamp: timeCreateRevStatusList,
})

revocationStatusList.update({
credentialDefinition,
revocationRegistryDefinition,
revocationRegistryDefinitionPrivate,
revoked: [1],
})
const credentialOffer = CredentialOffer.fromJson({
schema_id: 'mock:uri',
cred_def_id: 'mock:uri',
Expand Down Expand Up @@ -434,7 +437,6 @@ test('create and verify presentation passing only JSON objects as parameters', (
registryDefinition: revocationRegistryDefinition,
registryDefinitionPrivate: revocationRegistryDefinitionPrivate,
registryIndex: 9,
tailsPath,
}),
})

Expand Down
2 changes: 0 additions & 2 deletions wrappers/javascript/anoncreds-nodejs/test/bindings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@
maximumCredentialNumber: 10,
})

const tailsPath = anoncreds.revocationRegistryDefinitionGetAttribute({

Check warning on line 255 in wrappers/javascript/anoncreds-nodejs/test/bindings.test.ts

View workflow job for this annotation

GitHub Actions / Build and Test JavaScript wrapper

'tailsPath' is assigned a value but never used
objectHandle: revocationRegistryDefinition,
name: 'tails_location',
})
Expand Down Expand Up @@ -297,7 +297,6 @@
revocationRegistryDefinition,
revocationRegistryDefinitionPrivate,
registryIndex: 9,
tailsPath,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tailsPath is not used anymore (eslint warning)

},
})

Expand Down Expand Up @@ -434,7 +433,6 @@
revocationRegistryDefinition,
revocationRegistryDefinitionPrivate,
registryIndex: 9,
tailsPath,
},
})

Expand Down
24 changes: 17 additions & 7 deletions wrappers/javascript/anoncreds-react-native/cpp/anoncreds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,37 +592,47 @@ jsi::Value createOrUpdateRevocationState(jsi::Runtime &rt,
};

jsi::Value createRevocationStatusList(jsi::Runtime &rt, jsi::Object options) {
auto credentialDefinition =
jsiToValue<ObjectHandle>(rt, options, "credentialDefinition");
auto revocationRegistryDefinitionId =
jsiToValue<std::string>(rt, options, "revocationRegistryDefinitionId");
auto issuerId = jsiToValue<std::string>(rt, options, "issuerId");
auto revocationRegistryDefinition =
jsiToValue<ObjectHandle>(rt, options, "revocationRegistryDefinition");
auto revocationRegistryDefinitionPrivate =
jsiToValue<ObjectHandle>(rt, options, "revocationRegistryDefinitionPrivate");
auto issuerId = jsiToValue<std::string>(rt, options, "issuerId");
auto timestamp = jsiToValue<int64_t>(rt, options, "timestamp");
auto issuanceByDefault = jsiToValue<int8_t>(rt, options, "issuanceByDefault");

ObjectHandle out;

ErrorCode code = anoncreds_create_revocation_status_list(
revocationRegistryDefinitionId.c_str(), revocationRegistryDefinition,
credentialDefinition, revocationRegistryDefinitionId.c_str(),
revocationRegistryDefinition, revocationRegistryDefinitionPrivate,
issuerId.c_str(), timestamp, issuanceByDefault, &out);

return createReturnValue(rt, code, &out);
}

jsi::Value updateRevocationStatusList(jsi::Runtime &rt, jsi::Object options) {
auto timestamp = jsiToValue<int64_t>(rt, options, "timestamp");
auto issued = jsiToValue<FfiList_i32>(rt, options, "issued");
auto revoked = jsiToValue<FfiList_i32>(rt, options, "revoked");
auto credentialDefinition =
jsiToValue<ObjectHandle>(rt, options, "credentialDefinition");
auto revocationRegistryDefinition =
jsiToValue<ObjectHandle>(rt, options, "revocationRegistryDefinition");
auto revocationRegistryDefinitionPrivate =
jsiToValue<ObjectHandle>(rt, options, "revocationRegistryDefinitionPrivate");
auto revocationStatusList =
jsiToValue<ObjectHandle>(rt, options, "revocationStatusList");
auto issued = jsiToValue<FfiList_i32>(rt, options, "issued");
auto revoked = jsiToValue<FfiList_i32>(rt, options, "revoked");
auto timestamp = jsiToValue<int64_t>(rt, options, "timestamp");

ObjectHandle out;

ErrorCode code = anoncreds_update_revocation_status_list(
timestamp, issued, revoked, revocationRegistryDefinition,
revocationStatusList, &out);
credentialDefinition, revocationRegistryDefinition,
revocationRegistryDefinitionPrivate, revocationStatusList,
issued, revoked, timestamp, &out);

return createReturnValue(rt, code, &out);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

/* Generated with cbindgen:0.24.3 */
/* Generated with cbindgen:0.24.5 */

/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */

Expand Down Expand Up @@ -317,19 +317,21 @@ ErrorCode anoncreds_create_presentation(ObjectHandle pres_req,

ErrorCode anoncreds_create_revocation_registry_def(ObjectHandle cred_def,
FfiStr cred_def_id,
FfiStr issuer_id,
FfiStr _issuer_id,
FfiStr tag,
FfiStr rev_reg_type,
int64_t max_cred_num,
FfiStr tails_dir_path,
ObjectHandle *reg_def_p,
ObjectHandle *reg_def_private_p);

ErrorCode anoncreds_create_revocation_status_list(FfiStr rev_reg_def_id,
ErrorCode anoncreds_create_revocation_status_list(ObjectHandle cred_def,
FfiStr rev_reg_def_id,
ObjectHandle rev_reg_def,
FfiStr issuer_id,
int64_t timestamp,
ObjectHandle reg_rev_priv,
FfiStr _issuer_id,
int8_t issuance_by_default,
int64_t timestamp,
ObjectHandle *rev_status_list_p);

ErrorCode anoncreds_create_schema(FfiStr schema_name,
Expand Down Expand Up @@ -415,11 +417,13 @@ ErrorCode anoncreds_set_default_logger(void);
*/
void anoncreds_string_free(char *s);

ErrorCode anoncreds_update_revocation_status_list(int64_t timestamp,
struct FfiList_i32 issued,
struct FfiList_i32 revoked,
ErrorCode anoncreds_update_revocation_status_list(ObjectHandle cred_def,
ObjectHandle rev_reg_def,
ObjectHandle rev_reg_priv,
ObjectHandle rev_current_list,
struct FfiList_i32 issued,
struct FfiList_i32 revoked,
int64_t timestamp,
ObjectHandle *new_rev_status_list_p);

ErrorCode anoncreds_update_revocation_status_list_timestamp_only(int64_t timestamp,
Expand Down
11 changes: 7 additions & 4 deletions wrappers/javascript/anoncreds-react-native/src/NativeBindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,23 @@ export interface NativeBindings {
}): ReturnObject<Handle>

createRevocationStatusList(options: {
credentialDefinition: Handle
revocationRegistryDefinitionId: string
revocationRegistryDefinition: Handle
revocationRegistryDefinitionPrivate: Handle
issuerId: string
timestamp?: number
issuanceByDefault: number
}): ReturnObject<Handle>

updateRevocationStatusList(options: {
timestamp?: number
issued?: number[]
revoked?: number[]
credentialDefinition: Handle
revocationRegistryDefinition: Handle
revocationRegistryDefinitionPrivate: Handle
currentRevocationStatusList: Handle
issued?: number[]
revoked?: number[]
timestamp?: number
}): ReturnObject<Handle>

updateRevocationStatusListTimestampOnly(options: {
Expand Down Expand Up @@ -61,7 +65,6 @@ export interface NativeBindings {
registryIndex: number
revocationRegistryDefinition: number
revocationRegistryDefinitionPrivate: number
tailsPath: string
}
}): ReturnObject<Handle>
encodeCredentialAttributes(options: { attributeRawValues: Array<string> }): ReturnObject<string>
Expand Down
Loading