Skip to content

Commit

Permalink
Integrate new APIs in node-wrapper
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Stas <[email protected]>
  • Loading branch information
Patrik-Stas committed Dec 30, 2022
1 parent bc7984a commit efb6f00
Show file tree
Hide file tree
Showing 12 changed files with 213 additions and 768 deletions.
2 changes: 2 additions & 0 deletions aries_vcx/src/handlers/issuance/issuer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ fn _build_credential_preview(credential_json: &str) -> VcxResult<CredentialPrevi
"Issuer::_build_credential_preview >>> credential_json: {:?}",
secret!(credential_json)
);

let cred_values: serde_json::Value = serde_json::from_str(credential_json).map_err(|err| {
AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidJson,
Expand All @@ -48,6 +49,7 @@ fn _build_credential_preview(credential_json: &str) -> VcxResult<CredentialPrevi
)
})?;

// todo: should throw err if cred_values is not serde_json::Value::Array or serde_json::Value::Object
let mut credential_preview = CredentialPreviewData::new();
match cred_values {
serde_json::Value::Array(cred_values) => {
Expand Down
12 changes: 11 additions & 1 deletion wrappers/node-napi-rs/api-node/src/api/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn credential_deserialize(data: String) -> napi::Result<u32> {

// todo: flip order of arguments
#[napi]
async fn v2_credential_update_state(
async fn v2_credential_update_state_with_message(
handle_credential: u32,
message: Option<String>,
connection_handle: u32,
Expand All @@ -53,6 +53,16 @@ async fn v2_credential_update_state(
.map_err(to_napi_err)
}

#[napi]
async fn v2_credential_update_state(
handle_credential: u32,
connection_handle: u32,
) -> napi::Result<u32> {
credential::update_state(handle_credential, None, connection_handle)
.await
.map_err(to_napi_err)
}

#[napi]
fn credential_get_state(handle: u32) -> napi::Result<u32> {
credential::get_state(handle).map_err(to_napi_err)
Expand Down
1 change: 1 addition & 0 deletions wrappers/node-napi-rs/api-node/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use vcx::errors::error::LibvcxError;
use vcx::serde_json::json;

pub fn to_napi_err(err: LibvcxError) -> napi::Error {
warn!("to_napi_err: {:?}", err);
let reason = json!({
"vcxErrKind": err.kind().to_string(),
"vcxErrCode": u32::from(err.kind()),
Expand Down
5 changes: 3 additions & 2 deletions wrappers/node-napi-rs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ export function updateWebhookUrl(webhookUrl: string): Promise<void>
export function createAgencyClientForMainWallet(config: string): void
export function provisionCloudAgent(config: string): Promise<string>
export function messagesUpdateStatus(statusCode: string, uidsByConns: string): Promise<void>
export function generatePublicInvitation(publicDid: string, label: string): string
export function credentialCreateWithOffer(sourceId: string, offer: string): number
export function credentialRelease(handle: number): void
export function credentialSendRequest(handle: number, handleConnection: number): Promise<void>
export function credentialDeclineOffer(handle: number, handleConnection: number, comment?: string | undefined | null): Promise<void>
export function credentialSerialize(handle: number): string
export function credentialDeserialize(data: string): number
export function v2CredentialUpdateState(handleCredential: number, message: string | undefined | null, connectionHandle: number): Promise<number>
export function v2CredentialUpdateStateWithMessage(handleCredential: number, message: string | undefined | null, connectionHandle: number): Promise<number>
export function v2CredentialUpdateState(handleCredential: number, connectionHandle: number): Promise<number>
export function credentialGetState(handle: number): number
export function credentialGetOffers(handleConnection: number): Promise<string>
export function credentialGetAttributes(handle: number): string
Expand Down Expand Up @@ -168,4 +170,3 @@ export function getVerkeyFromWallet(did: string): Promise<string>
export function rotateVerkey(did: string): Promise<void>
export function rotateVerkeyStart(did: string): Promise<string>
export function rotateVerkeyApply(did: string, tempVk: string): Promise<void>
export function generatePublicInvitation(publicDid: string, label: string): string
2 changes: 1 addition & 1 deletion wrappers/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"lint-fix": "npm run lint -- --fix",
"jslint:fix": "standard --fix",
"test": "npm run test:connection && npm run test:credentialDef && npm run test:credential && npm run test:disclosedProof && npm run test:issuerCredential && npm run test:proof && npm run test:oob && npm run test:schema && npm run test:utils && npm run test:wallet && npm run test:ffi",
"test:connection": " TS_NODE_PROJECT=./test/tsconfig.json NODE_ENV=test RUST_BACKTRACE=full ./node_modules/.bin/mocha --timeout 60000 --v8-expose-gc --v8-use-strict --exit --recursive --require ts-node/register ./test/suite1/ariesvcx-connection.test.ts",
"test:connection": " TS_NODE_PROJECT=./test/tsconfig.json NODE_ENV=test RUST_BACKTRACE=full ./node_modules/.bin/mocha --timeout 60000 --v8-expose-gc --v8-use-strict --exit --recursive --require ts-node/register test/suite1/ariesvcx-mediated-connection.test.ts",
"test:credentialDef": " TS_NODE_PROJECT=./test/tsconfig.json NODE_ENV=test RUST_BACKTRACE=full ./node_modules/.bin/mocha --timeout 60000 --v8-expose-gc --v8-use-strict --exit --recursive --require ts-node/register ./test/suite1/ariesvcx-credential-def.test.ts",
"test:credential": " TS_NODE_PROJECT=./test/tsconfig.json NODE_ENV=test RUST_BACKTRACE=full ./node_modules/.bin/mocha --timeout 60000 --v8-expose-gc --v8-use-strict --exit --recursive --require ts-node/register ./test/suite1/ariesvcx-credential.test.ts",
"test:disclosedProof": " TS_NODE_PROJECT=./test/tsconfig.json NODE_ENV=test RUST_BACKTRACE=full ./node_modules/.bin/mocha --timeout 60000 --v8-expose-gc --v8-use-strict --exit --recursive --require ts-node/register ./test/suite1/ariesvcx-disclosed-proof.test.ts",
Expand Down
Loading

0 comments on commit efb6f00

Please sign in to comment.