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 3 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
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
1 change: 0 additions & 1 deletion wrappers/javascript/anoncreds-nodejs/src/ffi/structures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export const CredRevInfoStruct = CStruct({
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
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 @@ -297,7 +297,6 @@ describe('bindings', () => {
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 @@ describe('bindings', () => {
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ export class ReactNativeAnoncreds implements Anoncreds {
}

public createRevocationStatusList(options: {
credentialDefinition: ObjectHandle
revocationRegistryDefinitionId: string
revocationRegistryDefinition: ObjectHandle
revocationRegistryDefinitionPrivate: ObjectHandle
issuerId: string
timestamp?: number
issuanceByDefault: boolean
Expand All @@ -50,11 +52,13 @@ export class ReactNativeAnoncreds implements Anoncreds {
}

public updateRevocationStatusList(options: {
timestamp?: number
issued?: number[]
revoked?: number[]
credentialDefinition: ObjectHandle
revocationRegistryDefinition: ObjectHandle
revocationRegistryDefinitionPrivate: ObjectHandle
currentRevocationStatusList: ObjectHandle
issued?: number[]
revoked?: number[]
timestamp?: number
}): ObjectHandle {
const handle = this.handleError(this.anoncreds.updateRevocationStatusList(serializeArguments(options)))
return new ObjectHandle(handle)
Expand Down Expand Up @@ -138,7 +142,6 @@ export class ReactNativeAnoncreds implements Anoncreds {
revocationRegistryDefinition: options.revocationConfiguration.revocationRegistryDefinition.handle,
revocationRegistryDefinitionPrivate:
options.revocationConfiguration.revocationRegistryDefinitionPrivate.handle,
tailsPath: options.revocationConfiguration.tailsPath,
}
: undefined,
})
Expand Down
9 changes: 5 additions & 4 deletions wrappers/javascript/anoncreds-shared/src/Anoncreds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export type NativeCredentialRevocationConfig = {
revocationRegistryDefinition: ObjectHandle
revocationRegistryDefinitionPrivate: ObjectHandle
registryIndex: number
tailsPath: string
}

export interface Anoncreds {
Expand Down Expand Up @@ -158,11 +157,13 @@ export interface Anoncreds {
}): ObjectHandle

updateRevocationStatusList(options: {
timestamp?: number
issued?: Array<number>
revoked?: Array<number>
credentialDefinition: ObjectHandle
revocationRegistryDefinition: ObjectHandle
revocationRegistryDefinitionPrivate: ObjectHandle
currentRevocationStatusList: ObjectHandle
issued?: Array<number>
revoked?: Array<number>
timestamp?: number
}): ObjectHandle

credentialGetAttribute(options: { objectHandle: ObjectHandle; name: string }): string
Expand Down
Loading